Memory Management Chapter 5.

Slides:



Advertisements
Similar presentations
Memory.
Advertisements

Memory Management Chapter 7.
Fixed/Variable Partitioning
Memory Management Chapter 7. Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated efficiently to pack as.
Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable supply of ready processes to.
Allocating Memory.
Chapter 7 Memory Management
Chapter 7 Memory Management Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic, N.Z. ©2009, Prentice.
CS 311 – Lecture 21 Outline Memory management in UNIX
Chapter 7 Memory Management
Modified from Silberschatz, Galvin and Gagne Lecture 16 Chapter 8: Main Memory.
Memory Management Chapter 7. Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated efficiently to pack as.
Memory Management.
Memory Management Chapter 7 B.Ramamurthy. Memory Management Subdividing memory to accommodate multiple processes Memory needs to allocated efficiently.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
Silberschatz, Galvin and Gagne  Operating System Concepts Multistep Processing of a User Program User programs go through several steps before.
03/05/2008CSCI 315 Operating Systems Design1 Memory Management Notice: The slides for this lecture have been largely based on those accompanying the textbook.
Chapter 7 Memory Management
1 Lecture 8: Memory Mangement Operating System I Spring 2008.
1 Memory Management Chapter 7. 2 Roadmap n Memory management u Objectives u Requirements n Simple memory management u Memory partitioning F Fixed partitioning.
Chapter 7 Memory Management Seventh Edition William Stallings Operating Systems: Internals and Design Principles.
Operating System Chapter 7. Memory Management Lynn Choi School of Electrical Engineering.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
Swapping and Contiguous Memory Allocation. Multistep Processing of a User Program User programs go through several steps before being run. Program components.
Operating System 7 MEMORY MANAGEMENT. MEMORY MANAGEMENT REQUIREMENTS.
Memory Management Chapter 7.
Memory Management Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Dr.
Chapter 7 Memory Management
Chapter 7 Memory Management Seventh Edition William Stallings Operating Systems: Internals and Design Principles.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging Segmentation.
Memory Management Chapter 7.
Memory Management. Roadmap Basic requirements of Memory Management Memory Partitioning Basic blocks of memory management –Paging –Segmentation.
Subject: Operating System.
Silberschatz and Galvin  Operating System Concepts Module 8: Memory Management Background Logical versus Physical Address Space Swapping Contiguous.
CE Operating Systems Lecture 14 Memory management.
Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
Main Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation Example: The.
Basic Memory Management 1. Readings r Silbershatz et al: chapters
Informationsteknologi Wednesday, October 3, 2007Computer Systems/Operating Systems - Class 121 Today’s class Memory management Virtual memory.
CS6502 Operating Systems - Dr. J. Garrido Memory Management – Part 1 Class Will Start Momentarily… Lecture 8b CS6502 Operating Systems Dr. Jose M. Garrido.
Chapter 7 Memory Management Eighth Edition William Stallings Operating Systems: Internals and Design Principles.
Memory Management Chapter 5 Advanced Operating System.
1 Memory Management n In most schemes, the kernel occupies some fixed portion of main memory and the rest is shared by multiple processes.
2010INT Operating Systems, School of Information Technology, Griffith University – Gold Coast Copyright © William Stallings /2 Memory Management.
Memory management The main purpose of a computer system is to execute programs. These programs, together with the data they access, must be in main memory.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
Chapter 8: Memory Management. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 8: Memory Management Background Swapping Contiguous.
Chapter 7: Main Memory CS 170, Fall Program Execution & Memory Management Program execution Swapping Contiguous Memory Allocation Paging Structure.
Main Memory CSSE 332 Operating Systems Rose-Hulman Institute of Technology.
MEMORY MANAGEMENT. memory management  In a multiprogramming system, in order to share the processor, a number of processes must be kept in memory. 
Memory Management Chapter 7.
Chapter 7 Memory Management
Memory Management Chapter 7.
ITEC 202 Operating Systems
Chapter 8 Main Memory.
Chapter 8: Main Memory.
Main Memory Background Swapping Contiguous Allocation Paging
Outline Module 1 and 2 dealt with processes, scheduling and synchronization Next two modules will deal with memory and storage Processes require data to.
Lecture 3: Main Memory.
Operating System Chapter 7. Memory Management
Operating Systems: Internals and Design Principles, 6/E
Chapter 7 Memory Management
Page Main Memory.
Presentation transcript:

Memory Management Chapter 5

Background Program must be brought into memory and placed within a process for it to be run Input queue – collection of processes on the disk that are waiting to be brought into memory to run the program User programs go through several steps before being run

Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable supply of ready processes to consume available processor time

Memory Management Requirements Relocation Protection Sharing Logical Organization Physical Organization

Memory Management Requirements Relocation Programmer does not know where the program will be placed in memory when it is executed While the program is executing, it may be swapped to disk and returned to main memory at a different location (relocated) Memory references must be translated in the code to actual physical memory address

P1 P2

Memory Management Requirements Protection Processes should not be able to reference memory locations in another process without permission Impossible to check absolute addresses at compile time Must be checked at rum time Memory protection requirement must be satisfied by the processor (hardware) rather than the operating system (software) Operating system cannot anticipate all of the memory references a program will make

Memory Management Requirements Sharing Allow several processes to access the same portion of memory Better to allow each process access to the same copy of the program rather than have their own separate copy

Memory Management Requirements Logical Organization Programs are written in modules Modules can be written and compiled independently Different degrees of protection given to modules (read-only, execute-only) Share modules among processes

Memory Management Requirements Physical Organization Memory available for a program plus its data may be insufficient Overlaying allows various modules to be assigned the same region of memory Programmer does not know how much space will be available

Fixed Partitioning Equal-size partitions Any process whose size is less than or equal to the partition size can be loaded into an available partition If all partitions are full, the operating system can swap a process out of a partition A program may not fit in a partition. The programmer must design the program with overlays

Fixed Partitioning Main memory use is inefficient. Any program, no matter how small, occupies an entire partition. This is called internal fragmentation. E.g: A program of size 2MB occupies an 8MB partition  wasted space internal to a partition, as the data loaded is smaller than the partition size.

Placement Algorithm with Partitions Equal-size partitions Because all partitions are of equal size, it does not matter which partition is used Unequal-size partitions (also fixed) Can assign each process to the smallest partition within which it will fit Queue for each partition Processes are assigned in such a way as to minimize wasted memory within a partition

Dynamic Partitioning Partitions are of variable length and number Process is allocated exactly as much memory as required Eventually get holes in the memory. This is called external fragmentation Must use compaction to shift processes so they are contiguous and all free memory is in one block

Contiguous Allocation Hole – block of available memory; holes of various size are scattered throughout memory When a process arrives, it is allocated memory from a hole large enough to accommodate it Operating system maintains information about: a) allocated partitions b) free partitions (hole) OS OS OS OS process 5 process 5 process 5 process 5 process 9 process 9 process 8 process 10 process 2 process 2 process 2 process 2

Dynamic Partitioning Difficulty with compaction: It is a time consuming procedure – wasteful of processor time. Therefore, needs dynamic relocation capability, i.e. it must be possible to move a program from one region to another (in MM) without invalidating the memory references in the program.

Dynamic Partitioning Placement Algorithm Operating system must decide which free block to allocate to a process First-fit: Allocate the first hole that is big enough Next-fit: Allocate the next hole (from the last allocated block) that is big enough Best-fit: Allocate the smallest hole that is big enough; must search entire list, unless ordered by size. Produces the smallest leftover hole. Worst-fit: Allocate the largest hole; must also search entire list. Produces the largest leftover hole. First-fit and best-fit better than worst-fit in terms of speed and storage utilization

Dynamic Partitioning Placement Algorithm Best-fit algorithm Chooses the block that is closest in size to the request Worst performer overall Since smallest block is found for process, the smallest amount of fragmentation is left Memory compaction must be done more often

Dynamic Partitioning Placement Algorithm First-fit algorithm Scans memory form the beginning and chooses the first available block that is large enough Fastest May have many process loaded in the front end of memory that must be searched over when trying to find a free block

Dynamic Partitioning Placement Algorithm Next-fit Scans memory from the location of the last placement More often allocate a block of memory at the end of memory where the largest block is found The largest block of memory is broken up into smaller blocks Compaction is required to obtain a large block at the end of memory

Last allocated block (14M) To allocate 16M Block

Example 40K 80K 30K 50K 10K 20K The shaded areas are allocated blocks; the white areas are free blocks. The next FOUR memory requests are 20K, 50K, 10K and 30K (loaded in that order). Using the following placement algorithms, show the partition allocated for the requests. First-fit Best-fit Next-fit

Example: First-fit 20K, 50K, 10K and 30K (in that order). Allocate for 20K

Example: First-fit 20K, 50K, 10K and 30K (in that order). Allocate for 20K Allocate for 50K

Example: First-fit 20K, 50K, 10K and 30K (in that order). Allocate for 20K Allocate for 50K Allocate for 10K

Example: First-fit 20K, 50K, 10K and 30K (in that order). Allocate for 20K Allocate for 50K Allocate for 10K Allocate for 30K

Example: Best-fit 20K, 50K, 10K and 30K (in that order). 40K 80K 30K

Example: Best-fit 20K, 50K, 10K and 30K (in that order). Allocate for 20K

Example: Best-fit 20K, 50K, 10K and 30K (in that order). Allocate for 20K Allocate for 50K

Example: Best-fit 20K, 50K, 10K and 30K (in that order). Allocate for 20K Allocate for 50K Allocate for 10K

Example: Best-fit 20K, 50K, 10K and 30K (in that order). Allocate for 20K Allocate for 50K Allocate for 10K Allocate for 30K

Example: Next-fit 20K, 50K, 10K and 30K (in that order). most recently added block 20K, 50K, 10K and 30K (in that order).

Example: Next-fit 20K, 50K, 10K and 30K (in that order). most recently added block 20K, 50K, 10K and 30K (in that order). Allocate for 20K

Example: Next-fit 20K, 50K, 10K and 30K (in that order). most recently added block 20K, 50K, 10K and 30K (in that order). Allocate for 20K Allocate for 50K

Example: Next-fit 20K, 50K, 10K and 30K (in that order). most recently added block 20K, 50K, 10K and 30K (in that order). Allocate for 20K Allocate for 50K Allocate for 10K

Example: Next-fit 20K, 50K, 10K and 30K (in that order). most recently added block 20K, 50K, 10K and 30K (in that order). Allocate for 20K Allocate for 50K Allocate for 10K Allocate for 30K

Buddy System Entire space available is treated as a single block of 2U If a request of size s such that 2U-1 < s <= 2U, entire block is allocated Otherwise block is split into two equal buddies Process continues until smallest block greater than or equal to s is generated

Relocation When program loaded into memory the actual (absolute) memory locations are determined A process may occupy different partitions which means different absolute memory locations during execution (from swapping) Compaction will also cause a program to occupy a different partition which means different absolute memory locations

Addresses Logical Relative Physical Reference to a memory location independent of the current assignment of data to memory Translation must be made to the physical address Logical address – generated by the CPU; also referred to as virtual address Relative Address expressed as a location relative to some known point Physical The absolute address or actual location in main memory Physical address – address seen by the memory unit

Memory-Management Unit (MMU) Hardware device that maps virtual to physical address In MMU scheme, the value in the relocation register is added to every address generated by a user process at the time it is sent to memory The user program deals with logical addresses; it never sees the real physical addresses

Dynamic relocation using a relocation register

Registers Used during Execution Base register Starting address for the process Bounds/limit register Ending location of the process These values are set when the process is loaded or when the process is swapped in

Registers Used during Execution The value of the base register is added to a relative address to produce an absolute address The resulting address is compared with the value in the bounds register If the address is not within bounds, an interrupt is generated to the operating system

A base and a limit register define a logical address space

Paging Partition memory into small equal fixed-size chunks and divide each process into the same size chunks The chunks of a process are called pages and chunks of memory are called frames Operating system maintains a page table for each process Contains the frame location for each page in the process Memory address consist of a page number and offset within the page

Assignment of Process Pages to Free Frames

Assignment of Process Pages to Free Frames

Page Tables for Example

Paging Example Page # Frame #

Paging Example Page # Frame # Page size = 4 bytes Physical memory = 32 bytes => 32/4 = 8 partitions

Free Frames Before allocation After allocation

Shared Pages Example

Segmentation Memory-management scheme that supports user view of memory A program is a collection of segments. A segment is a logical unit such as: main program, procedure, function, method, object, arrays local variables, global variables, common block, stack, symbol table,

User’s View of a Program

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

Example of Segmentation

Sharing of Segments

Segmentation All segments of all programs do not have to be of the same length There is a maximum segment length Addressing consist of two parts - a segment number and an offset Since segments are not equal, segmentation is similar to dynamic partitioning