CSC501 Operating Systems Principles. Memory Management

Similar documents
Memory management basics (1) Requirements (1) Objectives. Operating Systems Part of E1.9 - Principles of Computers and Software Engineering

Chapter 7 Memory Management

Chapter 7 Memory Management

Memory Management Outline. Background Swapping Contiguous Memory Allocation Paging Segmentation Segmented Paging

CS5460: Operating Systems

Operating Systems, 6 th ed. Test Bank Chapter 7

Operating Systems OBJECTIVES 7.1 DEFINITION. Chapter 7. Note:

How do Users and Processes interact with the Operating System? Services for Processes. OS Structure with Services. Services for the OS Itself

Technical Properties. Mobile Operating Systems. Overview Concepts of Mobile. Functions Processes. Lecture 11. Memory Management.

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Objectives. Chapter 2: Operating-System Structures. Operating System Services (Cont.) Operating System Services. Operating System Services (Cont.

OPERATING SYSTEMS MEMORY MANAGEMENT

& Data Processing 2. Exercise 3: Memory Management. Dipl.-Ing. Bogdan Marin. Universität Duisburg-Essen

Introduction Disks RAID Tertiary storage. Mass Storage. CMSC 412, University of Maryland. Guest lecturer: David Hovemeyer.

Operating System Overview. Otto J. Anshus

OPERATING SYSTEM - MEMORY MANAGEMENT

The Deadlock Problem. Deadlocks. Deadlocks. Bridge Crossing Example

ELEC 377. Operating Systems. Week 1 Class 3

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Virtual vs Physical Addresses

Page 1 of 5. IS 335: Information Technology in Business Lecture Outline Operating Systems

System Structures. Services Interface Structure

Linux Process Scheduling Policy

Operating Systems. Design and Implementation. Andrew S. Tanenbaum Melanie Rieback Arno Bakker. Vrije Universiteit Amsterdam

Outline. Operating Systems Design and Implementation. Chap 1 - Overview. What is an OS? 28/10/2014. Introduction

OS OBJECTIVE QUESTIONS

Lesson Objectives. To provide a grand tour of the major operating systems components To provide coverage of basic computer system organization

Chapter 11 I/O Management and Disk Scheduling

Introduction. What is an Operating System?

Operating System Components and Services

CS 377: Operating Systems. Outline. A review of what you ve learned, and how it applies to a real operating system. Lecture 25 - Linux Case Study

Chapter 6, The Operating System Machine Level

Memory unit sees only the addresses, and not how they are generated (instruction counter, indexing, direct)

Review from last time. CS 537 Lecture 3 OS Structure. OS structure. What you should learn from this lecture

Operating Systems. Lecture 03. February 11, 2013

I/O Management. General Computer Architecture. Goals for I/O. Levels of I/O. Naming. I/O Management. COMP755 Advanced Operating Systems 1

Memory Management 1. Memory Management. Multitasking without memory management is like having a party in a closet.

3 - Introduction to Operating Systems

Red Hat Linux Internals

COS 318: Operating Systems. Virtual Memory and Address Translation

Memories Are Made of This

Memory Management CS 217. Two programs can t control all of memory simultaneously

Operating System Components

Chapter 3: Operating-System Structures. Common System Components

Virtualization for Cloud Computing

CS 61C: Great Ideas in Computer Architecture Virtual Memory Cont.

CS420: Operating Systems OS Services & System Calls

Cloud Computing. Up until now

Timing of a Disk I/O Transfer

An Implementation Of Multiprocessor Linux

CS3600 SYSTEMS AND NETWORKS

Operating System Structure

Operating Systems Concepts: Chapter 7: Scheduling Strategies

Operating Systems. Virtual Memory

Lecture 17: Virtual Memory II. Goals of virtual memory

Segmentation Segmentation: Generalized Base/Bounds

Chapter 3 Operating-System Structures

Operating Systems 4 th Class

ò Paper reading assigned for next Thursday ò Lab 2 due next Friday ò What is cooperative multitasking? ò What is preemptive multitasking?

Microkernels, virtualization, exokernels. Tutorial 1 CSC469

Kernel Types System Calls. Operating Systems. Autumn 2013 CS4023

OPERATING SYSTEM SERVICES

Real-Time Systems Prof. Dr. Rajib Mall Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

CS5460: Operating Systems. Lecture: Virtualization 2. Anton Burtsev March, 2013

Chapter 12. Paging an Virtual Memory Systems

Embedded & Real-time Operating Systems

Chapter 1: Introduction. What is an Operating System?

W4118: segmentation and paging. Instructor: Junfeng Yang

Operating Systems. Rafael Ramirez (T, S)

Chapter 2 System Structures

CS161: Operating Systems

Chapter 7: Distributed Systems: Warehouse-Scale Computing. Fall 2011 Jussi Kangasharju

CSE 120 Principles of Operating Systems. Modules, Interfaces, Structure

COS 318: Operating Systems

I/O. Input/Output. Types of devices. Interface. Computer hardware

Chapter 3: Operating-System Structures. System Components Operating System Services System Calls System Programs System Structure Virtual Machines

Chapter 2 Basic Structure of Computers. Jin-Fu Li Department of Electrical Engineering National Central University Jungli, Taiwan

Convenience: An OS makes a computer more convenient to use. Efficiency: An OS allows the computer system resources to be used in an efficient manner.

Chapter 2: OS Overview

Example of Standard API

a storage location directly on the CPU, used for temporary storage of small amounts of data during processing.

How To Write A Page Table

Principles and characteristics of distributed systems and environments

VMware Server 2.0 Essentials. Virtualization Deployment and Management

The Classical Architecture. Storage 1 / 36

Introduction to Virtual Machines

Introduction. Application Performance in the QLinux Multimedia Operating System. Solution: QLinux. Introduction. Outline. QLinux Design Principles

Virtualization. Explain how today s virtualization movement is actually a reinvention

Memory Allocation. Static Allocation. Dynamic Allocation. Memory Management. Dynamic Allocation. Dynamic Storage Allocation

Outline: Operating Systems

How To Understand The History Of An Operating System

CS 3530 Operating Systems. L02 OS Intro Part 1 Dr. Ken Hoganson

Operating System Structures

Virtual Hosting & Virtual Machines

Operating System Software

Chapter 11 I/O Management and Disk Scheduling

Chapter 14 MS-DOS Operating System

APP INVENTOR. Test Review

End to End Defense against Rootkits in Cloud Environment. Design- Part 2

Lesson 06: Basics of Software Development (W02D2

Transcription:

CSC501 Operating Systems Principles Memory Management 1

Previous Lectures q Linker & Loader q Today Q Memory Management 2

Layer user filesystem inter-machine net. memory mgr (high) device mgr + drivers real-time clock mgr IPC process coord process mgr memory mgr (low) user/kernel boundary Why? hardware

Memory Management q Low-level memory management Q Manages memory within kernel address space Q Allocates address spaces for processes Q Treats memory as a single, exhaustible resource Q In layered-os design, it is positioned in the hierarchy below process manager q High-level memory management Q Manages pages within address space Q Divides memory into abstract resources Q Positioned in the hierarchy above device manager 4

Low-level Memory Management q Conceptual Uses Q Allocation of process stack v getstk, freestk v Used by OS Q Allocation of heap storage v getmem, freemem v Used by applications and OS 5

Possible Allocation Strategies q Single free list Q First-fit: scan free list and allocate first hole that is large enough Q Next-fit: start search from end of last allocation Q Best-fit: find smallest hole that is adequate Q Worst fit: find largest hole q Multiple lists Q By exact size (static / dynamic) q Hierarchy Q Binary size allocation q FIFO cache with above methods 6

Example Implementation in Xinu q Single free list Q Ordered by increasing address Q Singly-linked Q Initialized at system startup to all free memory q Allocation policy Q Heap: first-fit Q Stack: last-fit Q Minimizes fragmentation 7

Result of Xinu Allocation Policy q Stack allocation from highest free memory q Heap allocation from lowest free memory 8

Illustration of Xinu Free List q List in order of address q Related Files: h/mem.h sys/getmem.c sys/freemem.c 9

High-level Memory Management q Memory is cheap today, and getting cheaper Q But applications are demanding more and more memory, there is never enough! q Let s take a look at the history

In the Beginning (prehistory) q Batch systems Q One program loaded in physical memory Q Runs to completion q If job larger than physical memory, use overlays Q Identify sections of program that v Can run to a result v Can fit into the available memory Q Add statement after result to load a new section Q Like passes in a compiler

In the Beginning (multi-programming) q Multiple processes in physical memory at the same time Q Allows fast switching to a ready process Q Divide physical memory into multiple pieces partitioning q Partition requirements Q Protection keep processes from smashing each other Q Fast execution memory accesses can t be slowed by protection mechanisms Q Fast context switch can t take forever to setup mapping of addresses

Physical Memory Empty 0x0000FFFF Process 3 Process 2 Physical address space Process 1 0x00000000 OS Kernel

Loading a Process q Relocate all addresses relative to start of partition Q See Linking and Loading q Memory protection assigned by OS Q Block-by-block to physical memory q Once process starts Q Partition cannot be moved in memory Q Why?

Physical Memory 0x0001FFFF Empty Process 3 Physical address space Empty Process 1 0x00000000 OS Kernel

Problem q What happens when Process 4 comes along and requires space larger than the largest empty partition? v Wait v Complex resource allocation problem for OS v Potential starvation

Physical Memory Empty Process 3 Process 4 Empty Process 1 OS Kernel

Solution q Logical Address: an address used by the program that is translated by computer into a physical address each time it is used q When the program utters 0x00105C, Q The machine accesses 0x01605C instead

Simplest Implementation q Base and Limit registers Q Base added to all addresses Q Limit checked on all memory references q Loaded by OS at each context switch Limit Reg Reloc Reg CPU logical address < no yes + physical address Physical Memory error

Physical Memory 0x0003FFFF Physical address space Empty Process 3 Empty Process 1 Limit Base 0x00000000 OS Kernel

Advantages q No relocation of program addresses at load time Q All addresses relative to zero q Built-in protection provided by Limit Q No physical protection per page or block q Fast execution Q Addition and limit check at hardware speeds within each instruction q Fast context switch Q Need only change base and limit registers q Partition can be suspended and moved at any time Q Process is unaware of change Q Expensive for large processes!

Physical Memory 0x0003FFFF Process 4 Physical address space Process 3 Process 1 Limit Base 0x00000000 OS Kernel

Challenge Memory Allocation q Fixed partitions q Variable partitions

Partitioning Strategies Fixed q Fixed Partitions divide memory into equal sized pieces (except for OS) Q Degree of multiprogramming = number of partitions Q Simple policy to implement v All processes must fit into partition space v Find any free partition and load the process q Problem Internal Fragmentation Q Unused memory in a partition that is not available to other processes Question: What is the right partition size?

Partitioning Strategies Variable q Memory is dynamically divided into partitions based on process needs Q More complex management problem v Need data structures to do tracking of free and used memory v New process is allocated memory from hole large enough to fit it q Problem External Fragmentation Q Unused memory between partitions that is not too small to be used by any processes

Partitioning Strategies Variable OS OS OS process 1 process 1 process 1 process 2 Process 2 Terminates Process 4 Starts process 4 process 3 process 3 process 3 26

User s View of a Program Question: Can we have multiple sets of base and limit registers?

Logical View of Segmentation 1 2 1 4 3 4 2 3 user space physical memory space

Segmentation q Logical address consists of a pair: <segment-number, offset> q Segment table where each entry has: Q Base: contains the starting physical address where the segments reside in memory. Q Limit: specifies the length of the segment.

Segment Lookup Index to segment register table segment # virtual address offset Segment register table limit base R RWX X physical memory segment 0 segment 1 segment 2 <? no yes + Physical Address segment 3 raise protection fault segment 4

Segmentation q Common in early minicomputers Q Small amount of additional hardware 4 or 8 segments Q Used effectively in Unix q Good idea that has persisted and supported in current hardware and OSs Q X86 supports segments Q Linux supports segments Question: Do we still have external fragmentation problem? If yes, can we further improve it?

Next Lecture q Paging 32