OS Spring’04 Virtual Memory: Page Replacement Operating Systems Spring 2004.

Slides:



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

Page Replacement Algorithms
Virtual Memory 3 Fred Kuhns
Page-replacement policies On some standard algorithms for the management of resident virtual memory pages.
Background Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution. Logical.
Virtual Memory II Chapter 8.
Virtual Memory: Page Replacement
Memory Management.
Chapter 8 Virtual Memory
Chapter 4 Memory Management Page Replacement 补充:什么叫页面抖动?
Chapter 9: Virtual Memory
1 Virtual Memory Management B.Ramamurthy. 2 Demand Paging Main memory LAS 0 LAS 1 LAS 2 (Physical Address Space -PAS) LAS - Logical Address.
Chapter 101 Cleaning Policy When should a modified page be written out to disk?  Demand cleaning write page out only when its frame has been selected.
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
Module 10: Virtual Memory Background Demand Paging Performance of Demand Paging Page Replacement Page-Replacement Algorithms Allocation of Frames Thrashing.
Virtual Memory Background Demand Paging Performance of Demand Paging
Virtual Memory Introduction to Operating Systems: Module 9.
Chapter 101 Virtual Memory Chapter 10 Sections and plus (Skip:10.3.2, 10.7, rest of 10.8)
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Virtual Memory.
Virtual Memory Chapter 8.
Virtual Memory Chapter 8. Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
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.
Virtual Memory Chapter 8.
1 Virtual Memory Chapter 8. 2 Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
1 Lecture 9: Virtual Memory Operating System I Spring 2007.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Revisiting Virtual Memory.
Computer Organization and Architecture
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/29/2004CSCI 315 Operating Systems Design1 Page Replacement Algorithms (Virtual Memory)
Operating Systems ECE344 Ding Yuan Page Replacement Lecture 9: Page Replacement.
CSS430 Virtual Memory Textbook Ch9
Rensselaer Polytechnic Institute CSC 432 – Operating Systems David Goldschmidt, Ph.D.
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.
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.
1 Virtual Memory Chapter 9. 2 Resident Set Size n Fixed-allocation policy u Allocates a fixed number of frames that remains constant over time F The number.
Virtual Memory Chapter 8. Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
1 Virtual Memory Chapter 8. 2 Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
Chapter 8 Virtual Memory Operating Systems: Internals and Design Principles Seventh Edition William Stallings.
Copyright ©: Lawrence Angrave, Vikram Adve, Caccamo 1 Virtual Memory.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Virtual Memory.
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.
Virtual Memory. Background Virtual memory is a technique that allows execution of processes that may not be completely in the physical memory. Virtual.
Lecture 11 Page 1 CS 111 Online Working Sets Give each running process an allocation of page frames matched to its needs How do we know what its needs.
Virtual Memory The memory space of a process is normally divided into blocks that are either pages or segments. Virtual memory management takes.
Virtual Memory Chapter 8. Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
Page Buffering, I. Pages to be replaced are kept in main memory for a while to guard against poorly performing replacement algorithms such as FIFO Two.
1 Lecture 8: Virtual Memory Operating System Fall 2006.
1 Page Replacement Algorithms. 2 Virtual Memory Management Fundamental issues : A Recap Key concept: Demand paging  Load pages into memory only when.
10.1 Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples.
Operating Systems ECE344 Ding Yuan Page Replacement Lecture 9: Page Replacement.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 9: Virtual Memory.
Virtual Memory. 2 Last Week Memory Management Increase degree of multiprogramming –Entire process needs to fit into memory Dynamic Linking and Loading.
Chapter 8 Virtual Memory
Operating Systems Virtual Memory Alok Kumar Jagadev.
Lecture 10: Virtual Memory
Module 9: Virtual Memory
Chapter 9: Virtual Memory
Chapter 9: Virtual-Memory Management
Page Replacement.
5: Virtual Memory Background Demand Paging
Operating Systems CMPSC 473
CSE 153 Design of Operating Systems Winter 19
Operating Systems Concepts
Module 9: Virtual Memory
Virtual Memory.
Presentation transcript:

OS Spring’04 Virtual Memory: Page Replacement Operating Systems Spring 2004

OS Spring’04 Realizing Virtual Memory  Hardware support Memory Management Unit (MMU): address translation, bits, interrupts  Operating system support Page replacement policy Resident set management Load control  degree of multiprogramming

OS Spring’04 Page Replacement Policy  Resident set maintenance Fixed or variable allocation Per-process or global replacement  Page replacement problem A fixed number of frames, M, is used to map the process virtual memory pages Which page should be replaced when a page fault occurs and all M frames are occupied?

OS Spring’04 Requirements and Metrics  Workload: a sequence of virtual memory references (page numbers)  Page fault rate = #page faults/#memory references  Minimize the page fault rate for workloads obeying the principle of locality Keep hardware/software overhead as small as possible

OS Spring’04 Algorithms  Optimal (OPT)  Least Recently Used (LRU)  First-In-First-Out (FIFO)  Clock

OS Spring’04 Optimal Policy (OPT)  Replace the page which will be referenced again in the most remote future  Impossible to implement Why?  Serves as a baseline for other algorithms

OS Spring’04 Least Recently Used (LRU)  Replace the page that has not been referenced for the longest time  The best approximation of OPT for the locality constrained workloads  Possible to implement  Infeasible as the overhead is high Why?

OS Spring’04 First-In-First-Out (FIFO)  Page frames are organized in a circular buffer with a roving pointer  Pages are replaced in round-robin style When page fault occur, replace the page to which the pointer points to  Simple to implement, low overhead  High page fault rate, prone to anomalous behavior

OS Spring’04 Clock (second chance)  Similar to FIFO but takes page usage into account Circular buffer + page use bit When a page is referenced: set use_bit=1 When a page fault occur: For each page: if use_bit==1: give page a second chance: use_bit=0; continue scan; if use_bit==0: replace the page

OS Spring’04 Example: Page 727 is needed n... Page 9 use = 1 Page 19 use = 1 Page 1 use = 0 Page 45 use = 1 Page 191 use = 1 Page 556 use = 0 Page 13 use = 0 Page 67 use = 1 Page 33 use = 1 Page 222 use = 0 next frame pointer

OS Spring’04 After replacement n... Page 9 use = 1 Page 19 use = 1 Page 1 use = 0 Page 45 use = 0 Page 191 use = 0 Page 727 use = 0 Page 13 use = 0 Page 67 use = 1 Page 33 use = 1 Page 222 use = 0 next frame pointer

OS Spring’04 Example of all algorithms

OS Spring’04 LRU and non-local workloads  Workload: … Typical for array based applications  What is the page fault rate for M=1, …,5?  A possible alternative is to use a Most Recently Use (MRU) replacement policy

OS Spring’04 Belady ’ s Anomaly  It is reasonable to expect that regardless of a workload, the number of page faults should not increase if we add more frames: not true for the FIFO policy: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4,

OS Spring’04 Algorithm comparison

OS Spring’04 Clock algorithm with 2 bits  Use “ modified ” bit to evict unmodified (clean) pages in preference over modified (dirty) pages  Four classes: u=0; m=0: not recently used, clean u=0; m=1: not recently used, dirty u=1; m=0: recently used, clean u=1; m=1: recently used, dirty

OS Spring’04  First scan: look for (0,0) frame, do not change the use bit If (0,0) frame is found, replace it  Second scan: look for (0,1) frame, set use bit to 0 in each frame bypassed If (0,1) frame is found, replace it  If all failed, repeat the above procedure this time we will certainly find something Clock algorithm with 2 bits

OS Spring’04 Page buffering  Evicted pages are kept on two lists: free and modified page lists  Pages are read into the frames on the free page list  Pages are written to disk in large chunks from the modified page list  If an evicted page is referenced, and it is still on one of the lists, it is made valid at a very low cost

OS Spring’04 Page Buffering B B B B B 36N 21N 3N 78N 2N 47N 22N 39N 4N 8N 55N B B B B 36N 21N 3N 78N 2N 47N 22B 39N 4N 8N Page fault: 55 is needed 22 is evicted Buffered frames (B) Normal frames (N)

OS Spring’04 Resident set management  With multiprogramming, a fixed number of memory frames are shared among multiple processes  How should the frames be partitioned among the active processes?  Resident set is the set of process pages currently allocated to the memory frames

OS Spring’04 Global page replacement  All memory frames are candidates for page eviction A faulting process may evict a page of other process  Automatically adjusts process sizes to their current needs  Problem: can steal frames from “ wrong ” processes Leads to thrashing

OS Spring’04 Local page replacement  Only the memory frames of a faulting process are candidates for replacement  Dynamically adjust the process allocation Working set model Page-Fault Frequency (PFF) algorithm

OS Spring’04 The working set model [Denning ’ 68]  Working set is the set of pages in the most recent page references  Working set is an approximation of the program locality

OS Spring’04 The working set strategy  Monitor the working set for each currently active process  Adjust the number of pages assigned to each process according to its working set size  Monitoring working set is impractical  The optimal value of is unknown and would vary

OS Spring’04 Page-Fault Frequency (PFF)  Approximate the page-fault frequency: Count all memory references for each active process When a page fault occurs, compare the current counter value with the previous page fault counter value for the faulting process If < F, expand the WS; Otherwise, shrink the WS by discarding pages with use_bit==0

OS Spring’04 Swapping  If a faulting process cannot expand its working set (all frames are occupied), some process should be swapped out  The decision to swap processes in/out is the responsibility of the long/medium term scheduler  Another reason: not enough memory to run a new process

OS Spring’04 Long (medium) term scheduling  Controls multiprogramming level  Decision of which processes to swap out/in is based on CPU usage (I/O bound vs. CPU bound) Page fault rate Priority Size Blocked vs. running

OS Spring’04 UNIX process states running user running kernel ready user ready kernel blocked zombie sys. call interrupt schedule created return terminated wait for event event done schedule preempt interrupt ready swapped blocked swapped Swap out event done Swap out Swap in

OS Spring’04 Next: File system, disks, etc