Memory Management Operating Systems - Spring 2003 Gregory (Grisha) Chokler Ittai Abraham Zinovi Rabinovich.

Slides:



Advertisements
Similar presentations
Memory.
Advertisements

Part IV: Memory Management
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.
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
Memory Management Operating Systems - Spring 2003 Gregory (Grisha) Chokler Ittai Abraham Zinovi Rabinovich.
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.
Chapter 7 Memory Management
Memory Management Chapter 7. Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated efficiently to pack as.
CS 104 Introduction to Computer Science and Graphics Problems
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.
Memory Management 2010.
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 Management Chapter 5.
Chapter 5: Memory Management Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Memory Management Chapter 5.
Memory Management Five Requirements for Memory Management to satisfy: –Relocation Users generally don’t know where they will be placed in main memory May.
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.
Chapter 91 Memory Management Chapter 9   Review of process from source to executable (linking, loading, addressing)   General discussion of memory.
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.
Operating System 7 MEMORY MANAGEMENT. MEMORY MANAGEMENT REQUIREMENTS.
Memory Management Chapter 7.
1 Memory Management Memory Management COSC513 – Spring 2004 Student Name: Nan Qiao Student ID#: Professor: Dr. Morteza Anvari.
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.
Memory Management Chapter 7.
Memory Management. Roadmap Basic requirements of Memory Management Memory Partitioning Basic blocks of memory management –Paging –Segmentation.
Subject: Operating System.
CE Operating Systems Lecture 14 Memory management.
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.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
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.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Mono an multiprogramming.
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.
Memory management Ref: Stallings G.Anuradha. What is memory management? The task of subdivision of user portion of memory to accommodate multiple processes.
CSC 360, Instructor Kui Wu Memory Management I: Main Memory.
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.
MEMORY MANAGEMENT. memory management  In a multiprogramming system, in order to share the processor, a number of processes must be kept in memory. 
Chapter 7 Memory Management
Memory Management Chapter 7.
Requirements, Partitioning, paging, and segmentation
Main Memory Management
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy 11/12/2018.
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.
Main Memory Background Swapping Contiguous Allocation Paging
Lecture 3: Main Memory.
Operating System Chapter 7. Memory Management
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 4/5/2019.
Chapter 7 Memory Management
Presentation transcript:

Memory Management Operating Systems - Spring 2003 Gregory (Grisha) Chokler Ittai Abraham Zinovi Rabinovich

Background A compiler creates an executable code An executable code must be brought into main memory to run –Operating system maps the executable code onto the main memory –The “mapping” depends on the hardware Hardware accesses the memory locations in the course of the execution

Memory management Principal operation: Bringing programs into the memory for execution by the processor Address Binding: –Compile time, e.g. MS-DOS.com programs –Load time – relocatable code –Execution time – moved around in memory

Memory management (II) Requirements and issues: –Relocation –Protection –Sharing –Logical and physical organization

Relocation Compiler generated addresses are relative A process can be (dynamically) loaded at different memory location –Actual physical mapping is not known at compile time Simple if processes are allocated contiguous memory ranges Complicated otherwise, e.g. segmentation or paging is used

Protection Processes must be unable to reference addresses of other processes or those of the operating system Cannot be enforced at compile time (especially if relocation is present) Each memory access must be checked for validity –Enforced by hardware

Sharing Protection must be flexible enough to allow controlled sharing of the same portion of the main memory –E.g., shared libraries – load once into main memory and allow several programs access simultaneously

Logical organization Memory is organized as a linear one- dimensional address space Programs are typically organized into modules –can be written/compiled independently, have different degrees of protection, shared A mechanism is desirable for supporting a logical structure of the user programs

Physical organization Two level hierarchical storage –Main memory: fast, expensive, scarce, volatile –Secondary storage: slow, cheap, abundant, persistent Memory management involves 2-directional information flow between the levels –Swapping

Memory management (III) Management: How physical and virtual address spaces of multiple processes correlate? Allocation of physical memory for virtual space intervals –Placement algorithms –Replacement algorithms

Allocator Issues Patterns of memory reuse –Reuse preference for recently-freed intervals –Preference for intervals in certain regions Splitting and Coalescing –Are large free intervals split or allocated as a whole? –Are adjacent free intervals unified into one? Fits –If several possibilities exist for free intervals allocation, which is used? Splitting thresholds –If some portion of allocated interval is not used by virtual counterpart, will the remainder become separate free interval ?

More Problems Fragmentation – inability to reuse memory that is free –External fragmentation – there are free unused fragments in physical memory outside allocated intervals –Internal fragmentation – there is free unused fragment space inside allocated interval

Fragmentation: Sources Isolated deaths –Should allocator place in memory objects that “die” (expire) together, fragmentation would be low Time-varying behavior –For example free small blocks, request larger ones Ramps/Peaks/Plateaus –Should these changes follow a known pattern, allocations could be optimized

Memory management: Allocation Partitioning – now obsolete, but useful for demonstration of basic principles –Fixed –Dynamic By list of intervals By hierarchy of intervals Paging and segmentation –without and with virtual memory

Allocation by Fixed partitioning Main memory is divided into a number of static partitions –all partitions of the same size –a collection of different sizes A process can be loaded into a partition of equal or greater size –A process cannot be scattered among many partitions

Fixed partitioning - Problems Operating System 8 M 12 M 8 M 6 M 4 M 2 M 8 M Operating System Internal fragmentation –wasted space is internal to an allocated region Executing big programs requires explicit memory management by the programmer –overlays

Fixed Partitioning: Placement algorithms New Processes Operating System Operating System New Processes

Fixed Partitioning: Replacement algorithm If all partitions are occupied some process should be swapped out Select a process that –occupies the smallest partitions that will hold the incoming process –blocked process

Allocation by Dynamic partitioning Partitions created dynamically Each process is loaded into a partition of exactly the same size as that process What data structure and How is it used to support information about free physical memory intervals?

Dynamic partitioning example Operating System 128 K 896 K Operating System Process K 576 K Operating System Process K Process K 352 K

Dynamic partitioning example Operating System Process K Process 2 Process K 288 K 64 K Operating System Process K Process K 288 K 64 K Operating System Process K Process 3288 K 64 K Process K 96 K

Dynamic partitioning example Operating System 320 K Process 3288 K 64 K Process K 96 K Operating System Process 3288 K 64 K Process K 96 K Process 2224 k 96 K

Problem: External fragmentation Dynamic partitioning is subject to external fragmentation –situation when the memory which is external to the allocated partitions becomes fragmented Can be reduced using compaction –wastes the processor time

Placement algorithms Free regions are organized into a linked list ordered by the memory addresses –simplifies coalescing of free regions –increases insertion time First-fit: allocate the first region large enough to hold the process –optimization: use a roving pointer: next-fit Best-fit: allocate the smallest region which is large enough to hold the process

An example Last allocated block (14K) Before After 8K8K 8K8K 12K 22K 18K 6K6K 6K6K 8K8K 8K8K 14K 6K6K 2K2K 36K 20K Next Fit Free block Allocated block Best Fit First Fit

Placement algorithms discussion First-fit: –efficient and simple –tends to create more fragmentation near the beginning of the list solved by next-fit Best-fit: –less efficient (might search the whole list) –tends to create small unusable fragments

Buddy systems Hierarchy of free intervals Approximates the best-fit principle Efficient search –first (best) fit has a linear complexity Simplified coalescing

Buddy Systems: Variations Binary buddies – system allocates memory in blocks which are powers of 2 Fibonacci buddies –Block sizes are Fibonacci numbers, recall every Fibonacci number is sum of previous two Weighted buddies –Block sizes are either power of two, or three times the power of two: 2,3,4,6,8,12… Double buddies –Two different buddy system with staggered sizes, e.g. one with 2,4,8,16… and second with 3,6,12,24…

Binary buddy system Memory blocks are available in size of 2 K where L <= K <= U and where –2 L = smallest size of block allocated –2 U = largest size of block allocated(generally, the entire memory available) Initially, all the available space is treated as a single block of size 2 U

Creating buddies A request to allocate a block of size s: –If 2 U-1 < s <= 2 U, allocate the entire block –Otherwise, split the block into two equal buddies of size 2 U-1 –If 2 U-2 < s <= 2 U-1, then allocate the request to one of the buddies, otherwise split further –Proceed until the smallest block is allocated

Maintaining buddies Existing non-allocated buddies (holes) are kept on several lists –Holes of size 2 i are kept on the ith list –Hole is removed from the (i+1)th list by splitting it into two bodies and putting them onto the ith list –Whenever two adjacent buddies on the ith list are freed they are coalesced and moved to the (i+1)th list

Finding a free buddy get_hole(i): if (i==U+1) then failure; if (list i is empty) { get_hole(i+1); split hole into buddies; put buddies on list i; } take first hole on list i;

An example

Remarks Buddy system is a reasonable compromise between the fixed and dynamic partitioning Internal fragmentation is a problem –Expected case is about 28% which is high Buddy System is not used for (system) memory management nowadays Used for memory management by user level libraries (malloc)

Relocation with partitioning Interrupt to operating system Process image in main memory Relative address Absolute address Text Data Stack Adder Comparator Base Register Bounds Register

Paging The most efficient and flexible method of memory allocation Process memory is divided into fixed size chunks of the same size, called pages Pages are mapped onto frames in the main memory Internal fragmentation is possible with paging (negligible)

Paging support Process pages can be scattered all over the main memory Process page table maintains mapping of process pages onto frames Relocation becomes complicated –Hardware support is needed to support translation of relative addresses within a program into the memory addresses

Paging example A.0 A.1 A.2 A.3 C.0 C.1 C.2 C.3 D.0 D.1 D.2 D.3 D Process A Process B Process C Process D Free Frame List 13 14

Address translation Page (frame) size is a power of 2 –with page size = 2 r, a logical address of l+r bits is interpreted as a tuple (l,r) –l = page number, r = offset within the page Page number is used as an index into the page table

Hardware support ProgramPagingMain Memory Logical address Register Page Table Page Frame Offset P# Frame # Page Table Ptr Page #OffsetFrame #Offset +

Segmentation A program can be divided into segments Segments are of variable size Segments reflect the logical (modular) structure of a program Text segment, data segment, stack segment… Similar to dynamic partitioning except segments of the same process can be scattered subject to external fragmentation

Address translation Maximum segment size is always a power of 2 Process’ segment table maps segment numbers into their base addresses in the memory With the maximum segment size of 2 r, a logical address of l+r bits is interpreted as a pair (l,r): –l = segment number, r = offset within the segment l is used as an index into the segment table

Hardware support Base + d ProgramSegmentationMain Memory Virtual Address Register Segment Table Segment d S# Length Base Seg Table Ptr Seg #Offset = d Segment Table + +

Remarks The price of paging/segmentation is a sophisticated hardware But the advantages exceed by far Paging decouples address translation and memory allocation –Not all the logical addresses are necessary mapped into physical memory at every given moment - virtual memory Paging and segmentation are often combined to benefit from both worlds