CompSci 143A1 Part II: Memory Management Chapter 7: Physical Memory Chapter 8: Virtual Memory Chapter 9: Sharing Data and Code in Main Memory Spring, 2013.

Slides:



Advertisements
Similar presentations
Memory Management Chapter 7.
Advertisements

Fixed/Variable Partitioning
Memory Management Chapter 7. Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated efficiently to pack as.
7. Physical Memory 7.1 Preparing a Program for Execution
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.
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 4. Memory hierarchy Programmers want a lot of fast, non- volatile memory But, here is what we have:
Memory Management Chapter 7. Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated efficiently to pack as.
CS 342 – Operating Systems Spring 2003 © Ibrahim Korpeoglu Bilkent University1 Memory Management - 2 CS 342 – Operating Systems Ibrahim Korpeoglu Bilkent.
Module 3.0: 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.
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 7 Physical Memory Preparing a program for execution Memory partitioning schemes Allocation strategies for variable partitions Managing insufficient.
Memory Management Chapter 7.
1 Memory Management Memory Management COSC513 – Spring 2004 Student Name: Nan Qiao Student ID#: Professor: Dr. Morteza Anvari.
1 Memory Management (a). 2 Background  Program must be brought into memory and placed within a process for it to be run.  Input queue – collection of.
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
ICS 145B -- L. Bic1 Project: Main Memory Management Textbook: pages ICS 145B L. Bic.
Memory Management Chapter 7.
Memory Management. Roadmap Basic requirements of Memory Management Memory Partitioning Basic blocks of memory management –Paging –Segmentation.
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.
Operating System Concepts and Techniques Lecture 8
Operating Systems Principles Memory Management Lecture 7: Physical 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.
Informationsteknologi Wednesday, October 3, 2007Computer Systems/Operating Systems - Class 121 Today’s class Memory management Virtual memory.
Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo 1 Memory management & paging.
CS6502 Operating Systems - Dr. J. Garrido Memory Management – Part 1 Class Will Start Momentarily… Lecture 8b CS6502 Operating Systems Dr. Jose M. Garrido.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Memory.
Chapter 7 Memory Management Eighth Edition William Stallings Operating Systems: Internals and Design Principles.
Operating Systems Principles Memory Management Lecture 7: Physical Memory 主講人:虞台文.
Ch. 4 Memory Mangement Parkinson’s law: “Programs expand to fill the memory available to hold them.”
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.
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 One of the most important OS jobs.
Memory Management Chapter 7.
Chapter 7 Memory Management
Chapter 17 Free-Space Management
Memory Management Chapter 7.
Memory Management.
ITEC 202 Operating Systems
Day 19 Memory Management.
Main Memory Management
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 8 11/24/2018.
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.
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 (1).
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:

CompSci 143A1 Part II: Memory Management Chapter 7: Physical Memory Chapter 8: Virtual Memory Chapter 9: Sharing Data and Code in Main Memory Spring, 2013

CompSci 143A2 7. Physical Memory 7.1 Preparing a Program for Execution –Program Transformations –Logical-to-Physical Address Binding 7.2 Memory Partitioning Schemes –Fixed Partitions –Variable Partitions –Buddy System 7.3 Allocation Strategies for Variable Partitions 7.4 Dealing with Insufficient Memory Spring, 2013

CompSci 143A3 Preparing Program for Execution Program Transformations –Translation (Compilation) –Linking –Loading Figure 7-1 Spring, 2013

CompSci 143A4 Address Binding Assign Physical Addresses: Relocation Static binding –Programming time –Compilation time –Linking time –Loading time Dynamic binding –Execution time Spring, 2013

CompSci 143A5 Static Address Binding Static Binding = At Programming, Compilation, Linking, and/or Loading Time Figure 7-2 Spring, 2013

CompSci 143A6 Dynamic Address Binding Dynamic Binding = At Execution Time Figure 7-4 Spring, 2013

CompSci 143A7 Address Binding How to implement dynamic binding –Perform for each address at run time: pa = address_map(la) –Simplest form of address_map: Relocation Register: pa = la + RR –More general form: Page/Segment Table (Chapter 8) Spring, 2013

CompSci 143A8 Memory Partitioning Schemes Fixed Partitions –Single-program systems: 2 partitions (OS/user) –Multi-programmed: partitions of different sizes How to assign processes to partitions (cf. Fig 7-5) –Separate queue for each partition: Some partitions may be unused –Single queue: More complex, but more flexible Limitations of fixed partitions –Program size limited to largest partition –Internal fragmentation (unused space within partitions) Spring, 2013

CompSci 143A9 Memory Partitioning Schemes Fixed partitions: 1 queue per partition vs 1 queue for all partitions Figure 7-5 Spring, 2013

CompSci 143A10 Variable Partitions Memory not partitioned a priori Each request is allocated portion of free space Memory = Sequence of variable-size blocks –Some are occupied, some are free (holes) –External fragmentation occurs: memory may be divided into many small pieces Adjacent holes (right, left, or both) must be coalesced to prevent increasing fragmentation Figure 7-6 Spring, 2013

CompSci 143A11 Linked List Implementation 1 Type, Size tags at the start of each Block Holes contain links to predecessor hole and to next hole –Must be sorted by physical address Checking neighbors of released block b (= block C below): –Right neighbor (easy): Use size of b –Left neighbor (clever): Use sizes to find first hole to b ’s right, follow its predecessor link to first hole on b ’s left, and check if it is adjacent to b. Figure 7-7a Spring, 2013

CompSci 143A12 Linked List Implementation 2 Better solution: Replicate tags at end of blocks (need not be sorted) Checking neighbors of released block b : –Right neighbor: Use size of b as before –Left neighbor: Check its (adjacent) type, size tags Figure 7-7b Spring, 2013

CompSci 143A13 Bitmap Implementation Memory divided into fix-size blocks States of the blocks represented by a binary string, the bitmap –State of each block represented by a bit in the bitmap –0 = free, 1 = allocated Can be implemented as char or int array (or in Java as a byte array) Operations use bit masks –Release: & (Boolean bitwise and ) –Allocate: | (Boolean bitwise or ) ' –Search for free block: Find left-most 0 bit Repeatedly, check left-most bit and shift mask right Spring, 2013

CompSci 143A14 Example A3 KBFree B2 KBOccupied C5 KBOccupied D1 KBOccupied E5 KBFree Map[0]Map[1] Assume Memory broken into blocks of size 1KB Use array of bytes (Map) for memory map Release block D: Map[1] = Map[1] & ' ' Allocate first 2 blocks of block A: Map[0] = Map[0] | ' ' Spring, 2013

CompSci 143A15 The Buddy System Compromise between fixed and variable partitions Fixed number of possible hole sizes; typically, 2 i –Each hole can be divided (equally) into 2 buddies. –Track holes by size on separate lists, 1 list for each partition size When n bytes requested, find smallest i so that n  2 i : If hole of this size is available, allocate it Otherwise, consider a larger hole: Recursively… split hole into two buddies continue with one, and place the other on appropriate free list for its size …until smallest adequate hole is created. Allocate this hole On release, recursively coalesce buddies –Buddy searching for coalescing can be inefficient Spring, 2013

CompSci 143A16 The Buddy System Figure 7-9 Sizes: 1, 2, 4, 8, 16 a)3 blocks allocated & 3 holes left b)Block of size 1 allocated c)Block released Spring, 2013

CompSci 143A17 Allocation Strategies with Variable Partitions Problem: Given a request for n bytes, find hole ≥ n Goals: –Maximize memory utilization (minimize external fragmentation) –Minimize search time Search Strategies: –First-fit: Always start at same place. Simplest. –Next-fit: Resume search. Improves distribution of holes. –Best-fit: Closest fit. Avoid breaking up large holes. –Worst-fit: Largest fit. Avoid leaving tiny hole fragments First Fit is generally the best choice Spring, 2013

CompSci 143A18 Measures of Memory Utilization How many blocks are used, how many are holes? How much memory is wasted? –Average hole size is not the same as average block size Spring, 2013

CompSci 143A19 Used Blocks vs. Holes How many blocks are used, how many are holes? –50% rule (Knuth, 1968): #holes = p × #full_blocks/2 p = probability of inexact match (i.e., remaining hole) –In practice p=1, because exact matches are highly unlikely, so Of the total number of (occupied) blocks and holes, 1/3 are holes Spring, 2013

CompSci 143A20 How much memory is unused (wasted) Utilization depends on the ratio k=hole_size/block_size When p=1 ( p is probability of inexact match) unused_memory = k/(k+2) Intuition: –When k , unused_memory  1 (100% empty) –When k=1, unused_memory  1/3 (50% rule) –When k  0, unused_memory  0 (100% full) What determines k ? The block size b relative to total memory size M –Determined experimentally via simulations: When b  M/10, k=0.22 and unused_memory  0.1 When b=M/3, k=2 and unused_memory  0.5 Conclusion: M must be large relative to b Spring, 2013

CompSci 143A21 Dealing with Insufficient Memory Memory compaction –How much and what to move? Swapping –Temporarily move process to disk –Requires dynamic relocation Overlays –Allow programs large than physical memory –Programs loaded as needed according to calling structure. Spring, 2013

CompSci 143A22 Dealing with Insufficient Memory Memory compaction Figure 7-10 Initial Complete Partial Minimal Movement Spring, 2013

CompSci 143A23 Dealing with Insufficient Memory Overlays –Allow programs large than physical memory –Programs loaded as needed according to calling structure Figure 7-11 Spring, 2013

CompSci 143A24 History Originally developed by Steve Franklin Modified by Michael Dillencourt, Summer, 2007 Modified by Michael Dillencourt, Spring, 2009 Modified by Michael Dillencourt, Spring, 2013 Spring, 2013