Memory Management Techniques

Slides:



Advertisements
Similar presentations
Chapter 4 Memory Management Basic memory management Swapping
Advertisements

Memory.
Basic Memory Management Monoprogramming Protection Swapping Overlaying OS space User space.
Chapter 4 Memory Management Page Replacement 补充:什么叫页面抖动?
Part IV: Memory Management
Chapter 6: Memory Management
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 36 Virtual Memory Read.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 13: Main Memory (Chapter 8)
1 Virtual Memory Management B.Ramamurthy. 2 Demand Paging Main memory LAS 0 LAS 1 LAS 2 (Physical Address Space -PAS) LAS - Logical Address.
Allocating Memory.
Chapter 101 Virtual Memory Chapter 10 Sections and plus (Skip:10.3.2, 10.7, rest of 10.8)
1 CSE 380 Computer Operating Systems Instructor: Insup Lee University of Pennsylvania, Fall 2002 Lecture Note: Memory Management.
Lecture 11: Memory Management
CS 104 Introduction to Computer Science and Graphics Problems
Virtual Memory. Names, Virtual Addresses & Physical Addresses Source Program Absolute Module Name Space P i ’s Virtual Address Space P i ’s Virtual Address.
Memory Management Chapter 7 B.Ramamurthy. Memory Management Subdividing memory to accommodate multiple processes Memory needs to allocated efficiently.
1 Friday, June 30, 2006 "Man's mind, once stretched by a new idea, never regains its original dimensions." - Oliver Wendell Holmes, Jr.
1 Lecture 9: Virtual Memory Operating System I Spring 2007.
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.
Memory Management Five Requirements for Memory Management to satisfy: –Relocation Users generally don’t know where they will be placed in main memory May.
Virtual Memory Management B.Ramamurthy. Paging (2) The relation between virtual addresses and physical memory addres- ses given by page table.
1 Virtual Memory Management B.Ramamurthy Chapter 10.
Chapter 4 Memory Management 4.1 Basic memory management 4.2 Swapping
03/05/2008CSCI 315 Operating Systems Design1 Memory Management Notice: The slides for this lecture have been largely based on those accompanying the textbook.
Memory Management ◦ Operating Systems ◦ CS550. Paging and Segmentation  Non-contiguous memory allocation  Fragmentation is a serious problem with contiguous.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 32 Paging Read Ch. 9.4.
Chapter 9: Memory Management Memory management is an OS activity which controls distribution of memory among processes. The part of the OS that manages.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 8: Main Memory.
Operating Systems Chapter 8
Memory Management. Process must be loaded into memory before being executed. Memory needs to be allocated to ensure a reasonable supply of ready processes.
MEMORY MANAGEMENT Presented By:- Lect. Puneet Gupta G.P.C.G. Patiala.
1 Memory Management Chapter Basic memory management 4.2 Swapping (εναλλαγή) 4.3 Virtual memory (εικονική/ιδεατή μνήμη) 4.4 Page replacement algorithms.
Chapter 10 Memory Management Part_1. 2 Overview Basic Concepts The major tasks of the memory manger are the allocation and deallocation of main memory.
CIS250 OPERATING SYSTEMS Memory Management Since we share memory, we need to manage it Memory manager only sees the address A program counter value indicates.
1 Memory Management 4.1 Basic memory management 4.2 Swapping 4.3 Virtual memory 4.4 Page replacement algorithms 4.5 Modeling page replacement algorithms.
Subject: Operating System.
Virtual Memory. Background Virtual memory is a technique that allows execution of processes that may not be completely in the physical memory. Virtual.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
Memory Management Operating Systems CS550. Memory Manager Memory manager - manages allocation and de-allocation of main memory Plays significant impact.
Main Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation Example: The.
Virtual Memory The memory space of a process is normally divided into blocks that are either pages or segments. Virtual memory management takes.
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.
1 Memory Management n In most schemes, the kernel occupies some fixed portion of main memory and the rest is shared by multiple processes.
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.
Chapter 8: Memory Management. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 8: Memory Management Background Swapping Contiguous.
Logistics Homework 5 will be out this evening, due 3:09pm 4/14
Memory Management.
Chapter 2 Memory and process management
UNIT–IV: Memory Management
Lecture 10: Virtual Memory
Main Memory Management
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy 11/12/2018.
Operating System Concepts
Chapter 9: Virtual-Memory Management
Segmentation Lecture November 2018.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 8 11/24/2018.
Multistep Processing of a User Program
Memory Management.
So far… Text RO …. printf() RW link printf Linking, loading
Main Memory Background Swapping Contiguous Allocation Paging
Lecture 3: Main Memory.
Chapter 8: Memory Management strategies
COMP755 Advanced Operating Systems
CSE 542: Operating Systems
Page Main Memory.
Presentation transcript:

Memory Management Techniques Single Contiguous Overlays Fixed (static) partitions Relocation (Dynamic) Partitions Paging Demand Paging Segmented Segmented/ Demand Paging For each technique, observe: Algorithms, Advantages, Disadvantages and Special Requirements

1. Single Contiguous While (job is ready) Do If (JobSize <= MemorySize) Then Begin Allocate Memory Load and Execute Job Deallocate Memory End Else Error Advantages: Simplicity Disadvantages CPU wasted, Main memory not fully used, Limited job size

II Overlays Programs can be sectioned into modules Not all modules need to be in main memory at the same time A B E C D Programmer specifies which modules can overlay each other Linker inserts commands to invoke the loader when the modules are referenced The “parent” must stay in memory

Overlays(Cont) Advantages: Reduced memory usage Disadvantages: Overlap map must be specified by programmer Programmer must know memory requirements Overlapped modules must be completely disjoint

Fixed Partition(1) Must ensure that a process does not access memory space dedicated to another process Base Register – Holds the address of the beginning of the partition Bounds Register – Hold the size of the job Each relative address is compared to the bounds register and if in range it is added to the base register to produce a physical address

Fixed Partition(2) Partition A A + Virtual Address A + L Bounds Reg L

Dynamic Partitions(1) Consider the following scenario (100K memory): Job 1 arrives; size = 22 K Job 2 arrives; size = 24 K Job 3 arrives; size = 30 K Job 4 arrives; size = 10 K Job 1 terminates Job 3 terminates Job 5 terminates

Dynamic Partitions(2) Lets trace our what happens: 100 100 Where should job 5 be put? What are pros/cons of each placement?

Table Sort Illustration(1) FREE – 22K a IN USE – 24K b FREE - 30K c IN USE – 10K d FREE 14K e

Table Sort Illustration(2) First fit Start addr Length A 22 C 30 E 14 Best fit Start addr Length E 14 A 22 C 30 Worst fit Start addr Length C 30 A 22 E 14

Partition Selection Algorithm Implementation requires a free block table Sorting table in a particular manner results in a specific selection algorithm First Fit Sort by location Best Fit Sort by size (ascending) [don’t break up big blocks) Worst Fit Sort by size (descending) [break up big blocks]

What if we cannot find a big enough hole for an arriving job? Suppose a 35K job arrives? Suppose a 90K job arrives? 22K Free 24K 2 30K Free 4 10K 14K Free

Compaction Shuffle jobs to create larger contiguous free memory Do the values of pointers need changing? Consider the arrival of a 40K job: Job A 15K Job A 15K Job B 20K Job B 20K Job C 7K Job C 7K

Dynamic Partitions Requires two OS operations: Allocation: Form a partition from a free partition of ample size Deallocation: Return partition to free table and merge where possible

Pros/Cons of Dynamic Partitions Advantages: Efficient memory usage Disadvantages: Partition Management Compaction or external fragmentation

Demand Page Management Page Map Table (PMT) Maps page to block Status: Main Memory Secondary Memory In Transit 2) Memory Block Table (MBT) Maps block to page Reference Bit Change Bit 3) File Map Table (FMT) Maps a job’s pages to secondary memory PMT for the disk 1 FMT/ job 1 entry / page

Demand Paging Schematic(1) What does 3 mean? PMTAR OS 3 1 PMT 2 M M 3 1 2 S 4 5 M = In Memory S = On secondary storage I = In transit 6 7

Demand Paging Schematic(2) FMT Disk 1 2

Demand Paging Schematic(3) OS Referenced 1 2 J1 P0 R C 3 4 J1 P1 R C 5 6 7 Changed

Sharing Pages of Reentrant Code or Data Between Processes Q. What problem is caused if a shared page frame corresponds to two different page #s? (Hint: consider page replacement) A. Alias or synonym problem

Address Translation Steps: Look up p in TLB if not found look up p in PMT (must be found) Replace p by p’ to form PA

Page Replacement Local VS Global Page Replacement Local Requires that each process removes a page from its own set of allocated blocks Global A replacement page may be selected from the set of all blocks

Locality At any given time, the locality of a process is the set of pages that are actively being used together Spacial There is a high probability that once a location is referenced, the one after it will be accessed in the near future EX: Sequential code, array processing Temporal A referenced location is likely to be accessed again in the near future EX: Loops. Single data elements

Working Set Theory W (t,) = The set of pages referenced between times t and t+  The number of elements in W is called the working Set Size Working set size is an estimation of locality size A job should not be scheduled unless there is room for its entire working set

Page Replacement Algorithms Optimal Replacement Replace the page which will not be used for the longest period of time Lowest page fault rate of all algorithms Requires future knowledge 2) FIFO Replace the “oldest” page A frequently used page may be swapped out Belady’s Anomaly: For some page replacement algorithms, the page fault rate may increase as the number of blocks increase

Page Trace: 4 3 2 1 4 3 5 4 3 2 1 5 4 3 2 1 4 3 5 4 3 2 1 5 1 2 4 3 2 1 4 3 5 4 3 2 1 5 1 2 3

Replacement Algorithms Continued 3) Least Recently Used (LRU) Uses the recent past as an approximation of the near future Statck algorithm Does NOT suffer from Belady’s Anomaly Hardware/ Overhead intensive 4) LRU Approximation Uses reference bits in the MBT and a static reference pointer(RP) The reference pointer is not reinitialized between calls to LRU Approximation

LRU Approximation Algorithm Initially: RP  0; Begin Done := FALSE; While (NOT Done) Do If (MBT[RP].ref = 1) Then MBT [RP].ref := 0 Else Begin Return(RP); Done :== TRUE; End; RP:=RP+1;

LRU Approximation Example Page Trace: 4 3 2 1 4 3 5 4 2 1 5 NOTE: Slightly different from previous example Page Reference Bit 1 2 RP = 0 Page Fault Rate =

Page Replacement Local VS Global page replacement Local Requires that each process remove a page from its own set of allocated blocks Global A replacement page may be selected from the set of all blocks

VIII Segmentation An alternative to paging Recall variable Size partitioning: Program allocation contiguous Use first fit, etc Segmentation: Put subroutines, arrays, etc. into separate segments Each segment must occupy contiguous locations, but segments may be scattered throughout memory Segmentation = Paging with variable size pages Why do this? What problems arise?

VIII Segmentation Divide each process into logical segments (procedures, arrays, etc) Logical breakdown gives an intuitive structure to main memory Managing segments: Segment Map Table ( SMT ) Length Address 1 SMT/job 1 entry/segment