1 Memory Management Basics. 2 Program P Basic Memory Management Concepts Address spaces Physical address space — The address space supported by the hardware.

Slides:



Advertisements
Similar presentations
Memory.
Advertisements

Part IV: Memory Management
Allocating Memory.
CS 311 – Lecture 21 Outline Memory management in UNIX
OS Fall’02 Memory Management Operating Systems Fall 2002.
1 CSE 380 Computer Operating Systems Instructor: Insup Lee University of Pennsylvania, Fall 2002 Lecture Note: Memory Management.
Operating Systems CMPSCI 377 Lecture 11: Memory Management
Memory Management Chapter 4. Memory hierarchy Programmers want a lot of fast, non- volatile memory But, here is what we have:
CS 104 Introduction to Computer Science and Graphics Problems
Memory Management CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
Memory Management.
1 Friday, June 30, 2006 "Man's mind, once stretched by a new idea, never regains its original dimensions." - Oliver Wendell Holmes, Jr.
Memory Management (continued) CS-3013 C-term Memory Management CS-3013 Operating Systems C-term 2008 (Slides include materials from Operating System.
Memory ManagementCS-3013 A-term Memory Management CS-3013, Operating Systems A-term 2009 (Slides include materials from Modern Operating Systems,
Memory Management 1 CS502 Spring 2006 Memory Management CS-502 Spring 2006.
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
Memory ManagementCS-502 Fall Memory Management CS-502 Operating Systems Fall 2006 (Slides include materials from Operating System Concepts, 7 th.
Memory Management Chapter 5.
CS 333 Introduction to Operating Systems Class 9 - Memory Management
Memory Management Five Requirements for Memory Management to satisfy: –Relocation Users generally don’t know where they will be placed in main memory May.
Memory ManagementCS-3013 C-term Memory Management CS-3013 Operating Systems C-term 2008 (Slides include materials from Operating System Concepts,
Main Memory. Background Program must be brought (from disk) into memory and placed within a process for it to be run Main memory and registers are only.
03/17/2008CSCI 315 Operating Systems Design1 Virtual Memory Notice: The slides for this lecture have been largely based on those accompanying the textbook.
03/05/2008CSCI 315 Operating Systems Design1 Memory Management Notice: The slides for this lecture have been largely based on those accompanying the textbook.
CS 333 Introduction to Operating Systems Class 9 - Memory Management Jonathan Walpole Computer Science Portland State University.
Memory management. Instruction execution cycle Fetch instruction from main memory Decode instruction Fetch operands (if needed0 Execute instruction Store.
Operating System Chapter 7. Memory Management Lynn Choi School of Electrical Engineering.
Example of a Resource Allocation Graph CS1252-OPERATING SYSTEM UNIT III1.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 32 Paging Read Ch. 9.4.
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
Dynamic Partition Allocation Allocate memory depending on requirements Partitions adjust depending on memory size Requires relocatable code –Works best.
1 Memory Management Memory Management COSC513 – Spring 2004 Student Name: Nan Qiao Student ID#: Professor: Dr. Morteza Anvari.
Memory Management. Process must be loaded into memory before being executed. Memory needs to be allocated to ensure a reasonable supply of ready processes.
CS333 Intro to Operating Systems Jonathan Walpole.
Memory Management Chapter 7.
Subject: Operating System.
1 Address Translation Memory Allocation –Linked lists –Bit maps Options for managing memory –Base and Bound –Segmentation –Paging Paged page tables Inverted.
CE Operating Systems Lecture 14 Memory management.
PA0 due 60 hours. Lecture 4 Memory Management OSTEP Virtualization CPU: illusion of private CPU RAM: illusion of private memory Concurrency Persistence.
Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation.
Memory Management. Introduction To improve both the utilization of the CPU and the speed of its response to users, the computer must keep several processes.
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
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Memory Management Overview.
CS6502 Operating Systems - Dr. J. Garrido Memory Management – Part 1 Class Will Start Momentarily… Lecture 8b CS6502 Operating Systems Dr. Jose M. Garrido.
NETW3005 Memory Management. Reading For this lecture, you should have read Chapter 8 (Sections 1-6). NETW3005 (Operating Systems) Lecture 07 – Memory.
Chapter 8: Main Memory. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Memory and Addressing It all starts.
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.
Chapter 2 Memory and process management
CSC 322 Operating Systems Concepts Lecture - 12: by
Partitioned Memory Allocation
Main Memory Management
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy 11/12/2018.
The Operating System Memory Manager
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 8 11/24/2018.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 12/1/2018.
So far… Text RO …. printf() RW link printf Linking, loading
Main Memory Background Swapping Contiguous Allocation Paging
CS399 New Beginnings Jonathan Walpole.
Introduction to Memory Management
Lecture 3: Main Memory.
Operating System Chapter 7. Memory Management
Chapter 8: Memory Management strategies
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 4/5/2019.
Presentation transcript:

1 Memory Management Basics

2 Program P Basic Memory Management Concepts Address spaces Physical address space — The address space supported by the hardware  Starting at address 0, going to address MAX sys Logical/virtual address space — A process’s view of its own memory  Starting at address 0, going to address MAX prog 0 MAX sys 0 MAX prog MOV But where do addresses come from?

3 Which is bigger, physical or virtual address space?  A. Physical address space  B. Virtual address space  C. It depends on the system.

4 Basic Concepts Address generation The compilation pipeline prog P : foo() : end P prog P : foo() : end P P: : push... inc SP, x jmp _foo : foo:... P: : push... inc SP, x jmp _foo : foo:... : push... inc SP, 4 jmp 75 :... : push... inc SP, 4 jmp 75 : Library Routines Library Routines Library Routines CompilationAssemblyLinkingLoading : jmp 1175 :... : jmp 175 :... : jmp 175 :...

5 Program Relocation Program issues virtual addresses Machine has physical addresses. If virtual == physical, then how can we have multiple programs resident concurrently? Instead, relocate virtual addresses to physical at run time.  While we are relocating, also bounds check addresses for safety. I can relocate that program (safely) in two registers…

6 Basic Concepts (Cont’d.) Address Translation 0 MAX sys Program P’s logical address space Program P’s logical address space 0 MAX prog CPU Base Register Logical Addresses ≤ ≤ 500 Limit Register MEMORY EXCEPTION Physical Addresses yes no Instructions P’s physical address space

7 With base and bounds registers, the OS needs a hole in physical memory at least as big as the process.  A. True  B. False

8 Evaluating Dynamic Allocation Techniques The fragmentation problem External fragmentation  Unused memory between units of allocation  E.g, two fixed tables for 2, but a party of 4 Internal fragmentation  Unused memory within a unit of allocation  E.g., a party of 3 at a table for 4 0 MAX Program R’s PAS Program Q’s PAS Execution Stack Program Code (“text”) Data Execution Stack

9 Simple Memory Management Schemes Dynamic allocation of partitions Simple approach:  Allocate a partition when a process is admitted into the system  Allocate a contiguous memory partition to the process 0 MAX Program P 2 Program P 3 Program P 1 P5P5 Program P 4 OS keeps track of... Full-blocks Empty-blocks (“holes”) Allocation strategies First-fit Best-fit Worst-fit

10 First Fit Allocation To allocate n bytes, use the first available free block such that the block size is larger than n. 500 bytes 1K bytes 2K bytes To allocate 400 bytes, we use the 1st free block available 2K bytes 500 bytes

11 Rationale & Implementation Simplicity of implementation Requires:  Free block list sorted by address  Allocation requires a search for a suitable partition  De-allocation requires a check to see if the freed partition could be merged with adjacent free partitions (if any) Advantages u Simple u Tends to produce larger free blocks toward the end of the address space Disadvantages u Slow allocation u External fragmentation

12 Best Fit Allocation To allocate n bytes, use the smallest available free block such that the block size is larger than n. 500 bytes 1K bytes 2K bytes To allocate 400 bytes, we use the 3rd free block available (smallest) 1K bytes 2K bytes

13 Rationale & Implementation To avoid fragmenting big free blocks To minimize the size of external fragments produced Requires:  Free block list sorted by size  Allocation requires search for a suitable partition  De-allocation requires search + merge with adjacent free partitions, if any Advantages u Works well when most allocations are of small size u Relatively simple Disadvantages u External fragmentation u Slow de-allocation u Tends to produce many useless tiny fragments (not really great) Doug Lea’s malloc “In most ways this malloc is a best-fit allocator”

14 Worst Fit Allocation To allocate n bytes, use the largest available free block such that the block size is larger than n. 500 bytes 1K bytes 2K bytes To allocate 400 bytes, we use the 2nd free block available (largest) 1K bytes

15 Rationale & Implementation To avoid having too many tiny fragments Requires:  Free block list sorted by size  Allocation is fast (get the largest partition)  De-allocation requires merge with adjacent free partitions, if any, and then adjusting the free block list Advantages u Works best if allocations are of medium sizes Disadvantages u Slow de-allocation u External fragmentation u Tends to break large free blocks such that large partitions cannot be allocated

16 Allocation strategies First fit, best fit and worst fit all suffer from external fragmentation.  A. True  B. False

17 Dynamic Allocation of Partitions Eliminating Fragmentation Compaction  Relocate programs to coalesce holes 0 MAX Program P 2 Program P 3 Program P 1 Program P 4 Suspended suspended queue ready queue semaphore/condition queues Waiting Running Ready ? Swapping  Preempt processes & reclaim their memory

n -1 Program P’s VAS Memory Management Sharing Between Processes Schemes so far have considered only a single address space per process  A single name space per process  No sharing Program P’s VAS Program Data Program Text Heap Run-Time Stack How can one share code and data between programs without paging?

19 Multiple Name Spaces Example — Protection/Fault isolation & sharing 0 2 n n n n n n 6 -1 Libraries 2 n Program Data Program Text Heap Run-Time Stack Program Text Program Data Run-Time Stack Heap User Code

20 Supporting Multiple Name Spaces Segmentation New concept: A segment — a memory “object”  A virtual address space A process now addresses objects —a pair (s, addr)  s— segment number  addr — an offset within an object  Don’t know size of object, so 32 bits for offset? Segment + Address register scheme saddr Single address scheme n1n1 00n2n2 0 s n addr

21 Implementing Segmentation Base + Limit register scheme 0 Program Base Register Logical Addresses ≤ ≤ 500 Limit Register MEMORY EXCEPTION Physical Memory yes no P’s Segment Segment Table s CPU 0n320 so Program P Program P baselimit STBR Add a segment table containing base & limit register values

22 Memory Management Basics Are We Done? Segmentation allows sharing … but leads to poor memory utilization  We might not use much of a large segment, but we must keep the whole thing in memory (bad memory utilization).  Suffers from external fragmentation  Allocation/deallocation of arbitrary size segments is complex How can we improve memory management?  Paging