Virtual Memory Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution -

Slides:



Advertisements
Similar presentations
Page Replacement Algorithms
Advertisements

Page Replacement Algorithms
Virtual Memory (Chapter 4.3)
Module 10: Virtual Memory
Chapter 10: Virtual Memory
Page Replacement Algorithms (Virtual Memory)
Background Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution. Logical.
Chapter 9: Virtual Memory
Virtual Memory.
Chapter 10: Virtual Memory
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 38 Frame Allocation Read.
03/31/2004CSCI 315 Operating Systems Design1 Allocation of Frames & Thrashing (Virtual Memory)
9.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Virtual Memory OSC: Chapter 9. Demand Paging Copy-on-Write Page Replacement.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 15: Background Information for the VMWare ESX Memory Management.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement.
Module 9: Virtual Memory
Advanced Operating Systems - Spring 2009 Lecture 17 – March 23, 2009 Dan C. Marinescu Office: HEC 439 B. Office hours:
Module 10: Virtual Memory Background Demand Paging Performance of Demand Paging Page Replacement Page-Replacement Algorithms Allocation of Frames Thrashing.
Chapter 9: Virtual-Memory Management. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 9: Virtual Memory Background Demand Paging.
Virtual Memory Background Demand Paging Performance of Demand Paging
Virtual Memory Introduction to Operating Systems: Module 9.
Virtual-Memory Management
Gordon College Stephen Brinton
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Virtual Memory.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement.
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Chapter 9: Virtual Memory Background.
Chapter 10: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Chapter 10: Virtual Memory.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Revisiting Virtual Memory.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 9: Virtual Memory.
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Chapter 9: Virtual Memory Background.
03/29/2004CSCI 315 Operating Systems Design1 Page Replacement Algorithms (Virtual Memory)
Chapter 9: Virtual Memory. Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating Kernel.
Page 19/17/2015 CSE 30341: Operating Systems Principles Optimal Algorithm  Replace page that will not be used for longest period of time  Used for measuring.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 9: Virtual Memory.
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Chapter 9: Virtual Memory Background.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Virtual Memory.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement.
Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples Operating.
Operating Systems CMPSC 473 Virtual Memory Management (3) November – Lecture 20 Instructor: Bhuvan Urgaonkar.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Page Replacement Allocation of.
9.1 Silberschatz, Galvin and Gagne ©2003 Operating System Concepts Chapter 9: Virtual-Memory Management Background Demand Paging Page Replacement Allocation.
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Outline n Background n Demand.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Chapter 9: Virtual-Memory Management.
Silberschatz, Galvin and Gagne  Operating System Concepts Virtual Memory Virtual memory – separation of user logical memory from physical memory.
9.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 9: Virtual Memory.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 9: Virtual Memory.
Chapter 9: Virtual-Memory Management. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 9: Virtual-Memory Management 9.1 Background.
1 Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples (not covered.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 9: Virtual Memory.
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 9: Virtual Memory Background Demand Paging Process.
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Background Virtual memory – separation of user logical memory.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 9: Virtual Memory.
Chapter 9: Virtual Memory
Chapter 9: Virtual Memory
Chapter 9: Virtual Memory
Chapter 9: Virtual Memory
Chapter 9: Virtual Memory
Module 9: Virtual Memory
Chapter 9: Virtual Memory
Chapter 9: Virtual-Memory Management
5: Virtual Memory Background Demand Paging
Chapter 9: Virtual Memory
Chapter 6 Virtual Memory
Operating Systems CMPSC 473
Chapter 9: Virtual Memory
Module 9: Virtual Memory
Virtual Memory.
Presentation transcript:

Virtual Memory Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution - some can be on disk Disk address can be stored in place of frame number A valid–invalid bit is associated with each page table entry (1  in-memory, 0  not-in-memory) During address translation, if valid–invalid bit in page table entry is 0  page fault  bring in to memory Operating System Concepts

Page Table When Some Pages Are Not in Main Memory Sum logical address space can therefore be much larger than physical address space. More processes Operating System Concepts

Page Faults Bringing a Page into Memory Get empty frame. Swap page into frame. Reset tables, validation bit = 1. Restart instruction Operating System Concepts

Need For Page Replacement Operating System Concepts

What happens if there is no free frame? Page replacement – find some page in memory, but not really in use, swap it out. Use modify (dirty) bit to reduce overhead of page transfers – only modified pages are written to disk. Operating System Concepts

Basic Page Replacement Find the location of the desired page on disk. Find a free frame: If there is a free frame, use it. If there is no free frame, use a page replacement algorithm to select a victim frame. If victim is dirty, write it out to disk Read the desired page into the (newly) free frame. Update the page and frame tables. Restart the process Operating System Concepts

Page Replacement Policies Global vs. Local Allocation Global replacement – process selects a replacement frame from the set of all frames; one process can take a frame from another - only for crucial OS processes Local replacement – each process selects from only its own set of allocated frames - the normal case I/O interlock Pages that are used for copying a file from a device must be locked Operating System Concepts

Thrashing VM works because of locality Process migrates from one locality to another. Localities may overlap What happens if  size of localities > total memory size Operating System Concepts

Thrashing If a process does not have “enough” pages for its locality, the page-fault rate is very high. Thrashing  a process is busy swapping pages in and out. Thrashing may lead to: low CPU utilization. operating system thinks that it needs to increase the degree of multiprogramming. another process added to the system It is important to allocate enough frames to each process If that’s not possible, the process must be swapped out Operating System Concepts

Allocation of Frames Each process needs minimum number of frames Example: IBM 370 – 6 pages to handle SS MOVE instruction: instruction is 6 bytes, might span 2 pages. 2 pages to handle from. 2 pages to handle to. Two major allocation schemes. fixed allocation priority allocation Operating System Concepts

Fixed Allocation Equal allocation – e.g., if 100 frames and 5 processes, give each 20 frames. Proportional allocation – Allocate according to the size of process. Operating System Concepts

Priority Allocation Use a proportional allocation scheme using priorities rather than size. If process Pi generates a page fault, select for replacement one of its frames. select for replacement a frame from a process with lower priority number. Operating System Concepts

Page-Fault Frequency Scheme Establish “acceptable” page-fault rate. If actual rate too low, process loses frame. If actual rate too high, process gains frame. Operating System Concepts

Initial Load Load pages predicted to be needed (compiler flags) or Load no pages Allows for more efficient process creation Operating System Concepts

Performance of Demand Paging Page Fault Rate 0  p  1.0 (hopefully low, e.g. 5%) if p = 0 no page faults if p = 1, every reference is a fault Effective Access Time (EAT) EAT = (1 – p) x memory access + p (page fault overhead + [swap page out ] + swap page in + restart overhead) Values Assume memory access roughly 1 (with TLB hits) Page fault overhead is small Swap is about 10000 Restart is small Operating System Concepts

Page Replacement Algorithms Want lowest page-fault rate (disk is slow) Evaluate algorithm by running it on a particular string of page references (reference string) and computing the number of page faults on that string. A page fault means a disk access (or two), and that’s where the time goes. Assume no initial load, local replacement, no I/O (no interlock issues) Operating System Concepts

Optimal Algorithm Replace page that will not be used for longest period of time in future. 3 frames example: 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1 (9) 4 frames example: 1 2 3 4 1 2 5 1 2 3 4 5 (6) But the future is unknown (like SJF scheduling) Operating System Concepts

First-In-First-Out (FIFO) Algorithm 3 frames example: 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1 (15) Operating System Concepts

FIFO Illustrating Belady’s Anamoly 4 frames example: 1 2 3 4 1 2 5 1 2 3 4 5 (10) 3 frames example: 1 2 3 4 1 2 5 1 2 3 4 5 (9) Belady’s Anomaly - more frames does not imply less page faults Operating System Concepts

Counting Algorithms Keep a counter of the number of references that have been made to each page. Count is reset each time a page is brought in LFU Algorithm: replaces page with smallest count. May delay start of counting to avoid bias from an initial rush MFU Algorithm: based on the argument that the page with the smallest count was probably just brought in and has yet to be used. See example in Geoff’s notes Operating System Concepts

LRU Page Replacement 3 frames example: 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1 (11) 4 frames example: 1 2 3 4 1 2 5 1 2 3 4 5 (?) Operating System Concepts

Least Recently Used (LRU) Algorithm Counter implementation Every page entry has a counter; every time page is referenced through this entry, copy the clock into the counter. When a page needs to be changed, look at the counters to determine which are to change. Stack implementation – keep a stack of page numbers in a double link form: Page referenced: move it to the top requires 6 pointers to be changed No search for replacement Both need HW support, as they are done very very often Operating System Concepts

Use Of A Stack to Record The Most Recent Page References Operating System Concepts

LRU Approximation Algorithms Usually not enough HW support for full LRU, so … Reference bit in the page table With each page associate a bit, in HW initially = 0 When page is referenced bit set to 1. Replace the one which is 0 (if one exists). We do not know the order, however. Clear when all 1 Reference bytes in the page table Make top bit the reference bit Shift right reference byte at regular intervals Victim is page with smallest value byte Second chance bit associated with each frame Looks through frames in order, with wrap-around, starting at frame after last loaded If frame has bit = 1 then: set bit 0. leave page in memory. replace next page, subject to same rules. Operating System Concepts

Second-Chance (clock) Page-Replacement Algorithm Operating System Concepts

Enhanced Second Chance Keep a reference bit and a modified bit with each frame 0,0 => not recently used or modified => best to replace 0,1 => not recently used but modified => must be written out 1,0 => recently used but not modified => may be used again soon 1,1 => Recently used and modified => best keep this one in RAM Victim selection After each load, the current position is set to the frame after the loaded one. Scan from current position round for a 0,0 frame If not found, scan round for a 0,1 frame, reseting the use bit (ala 2nd chance) If not found, start again (a victim must be found) Used by Mac OS Operating System Concepts

Page Buffering Keep some frames free -a frame pool Immediately swap in on page fault Write out while first process uses CPU Remember what pages are in the frame pool, in case they are requested again - used by VMS with FIFO to recover from preemptive removal Write out modified pages whenever the swap disk is idle Operating System Concepts

Other Techniques Pre-paging - predicting page needs Copy-on-Write Windows NT clustering Copy-on-Write Copy-on-Write (COW) allows both parent and child processes to initially share the same pages in memory. If either process modifies a shared page, only then is the page copied. COW allows more efficient process creation as only modified pages are copied. Operating System Concepts

Other Considerations Program structure int A[ ][ ] = new int[1024][1024]; Each row is stored in one page Program 1 for (j = 0; j < A.length; j++) for (i = 0; i < A.length; i++) A[i,j] = 0; 1024 x 1024 page faults Program 2 for (i = 0; i < A.length; i++) for (j = 0; j < A.length; j++) A[i,j] = 0; 1024 page faults Operating System Concepts

Windows NT Uses demand paging with clustering. Clustering brings in pages surrounding the faulting page. Processes are assigned working set minimum and working set maximum. Working set minimum is the minimum number of pages the process is guaranteed to have in memory. A process may be assigned as many pages up to its working set maximum. When the amount of free memory in the system falls below a threshold, automatic working set trimming is performed to restore the amount of free memory. Working set trimming removes pages from processes that have pages in excess of their working set minimum. On single x86 CPUS, uses a second chance style algorithm to select victims On Alpha and SMP, uses a modified FIFO Operating System Concepts

Solaris 2 Maintains a list of free pages to assign faulting processes. Lotsfree – threshold parameter to begin pageout. Pageout is called more frequently depending upon the amount of free memory available. Pageout scans pages using variation on the second chance algorithm (2 handed clock algorithm) Scanrate is the rate at which pages are scanned. This ranged from slowscan to fastscan. This increases as free memory decreases Handspread affects time process has to reuse a page before the big-hand send the page out Pages from shared libraries are kept in memory (recent variation) Operating System Concepts