Chapter 3.3 : OS Policies for Virtual Memory

Slides:



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

Chapters 7 & 8 Memory Management Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College, Venice,
Chapter 4 Memory Management Basic memory management Swapping
9.4 Page Replacement What if there is no free frame?
CS 241 Spring 2007 System Programming 1 Memory Replacement Policies Lecture 32 Klara Nahrstedt.
4.4 Page replacement algorithms
Page Replacement Algorithms
Chapter 101 The LRU Policy Replaces the page that has not been referenced for the longest time in the past By the principle of locality, this would be.
Chapter 11 – Virtual Memory Management
CS 333 Introduction to Operating Systems Class 14 – Page Replacement
Virtual Memory 3 Fred Kuhns
Module 10: Virtual Memory
Chapter 3 Memory Management
Chapter 10: 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.
Virtual Memory II Chapter 8.
Memory Management.
Page Replacement Algorithms
Chapter 8 Virtual Memory
Chapter 4 Memory Management Page Replacement 补充:什么叫页面抖动?
PSSA Preparation.
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.
Virtual Memory Background Demand Paging Performance of Demand Paging
Virtual Memory Introduction to Operating Systems: Module 9.
Day 23 Virtual Memory. Operating system’s role in VM Hardware-support Use VM or not Use paging or segmentation or both Software domain Algorithms for.
Chapter 101 Virtual Memory Chapter 10 Sections and plus (Skip:10.3.2, 10.7, rest of 10.8)
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.
1 Virtual Memory Chapter 9. 2 Characteristics of Paging and Segmentation n Memory references are dynamically translated into physical addresses at run.
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.
Memory Management Virtual Memory Page replacement algorithms
1 Virtual Memory Chapter 8. 2 Process Execution n The OS brings into main memory only a few pieces of the program (including its starting point) n Each.
Chapter 8 Virtual Memory
1 Virtual Memory Management B.Ramamurthy Chapter 10.
A. Frank - P. Weisberg Operating Systems Virtual Memory Policies.
O RERATıNG S YSTEM LESSON 10 MEMORY MANAGEMENT II 1.
Memory Management Page replacement algorithms, segmentation Tanenbaum, ch. 3 p Silberschatz, ch. 8, 9 p
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.
Page Replacement Algorithms Memory Management. Optimal Page Replacement ▪The label for each page in memory is labeled with the number of instructions.
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.
1 Virtual Memory Chapter 8. 2 Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
1 First-in, First-out Remove the oldest page Determine the age based on the loading time, not on the time being referenced Old pages may be heavily used.
1 Virtual Memory Chapter 8. 2 Virtual memory concept Simple paging/ segmentation  pages or segments are loaded into frames that may not necessarily be.
Virtual Memory Chapter 8. Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
Demand Paging Reference Reference on UNIX memory management
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 Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples (not covered.
1 Page Replacement Algorithms. 2 Virtual Memory Management Fundamental issues : A Recap Key concept: Demand paging  Load pages into memory only when.
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 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Background Virtual memory – separation of user logical memory.
COS 318: Operating Systems Virtual Memory Paging.
CS 333 Introduction to Operating Systems Class 14 – Page Replacement
Virtual Memory Chapter 8.
ITEC 202 Operating Systems
Day 22 Virtual Memory.
Day 23 Virtual Memory.
Day 24 Virtual Memory.
Chapter 8 Virtual Memory
Virtual Memory Chapter 8.
Lecture 10: Virtual Memory
Practical Session 8, Memory Management 2
Operating Systems CMPSC 473
Operating Systems Concepts
Practical Session 9, Memory Management continues
Presentation transcript:

Chapter 3.3 : OS Policies for Virtual Memory Fetch policy Placement policy Replacement policy Resident set management Cleaning policy Load control From : Operating Systems by W. Stallings, Prentice-Hall, 1995 Ceng 334 - Operating Systems

Ceng 334 - Operating Systems Fetch Policy Demand Paging: Pages are fetched when needed (ie., when a page fault occurs) Process starts with a flurry of page faults, eventually locality takes over Prepaging (anticipatative): Pages other than the one needed are brought in Prepaging makes use of disk storage characteristics. If pages are stored contiguously it may be more efficient to fetch them in one go The policy is ineffective if the extra pages are not referenced Ceng 334 - Operating Systems

Ceng 334 - Operating Systems Placement Policy The placement policy is concerned with determining where in real memory a process piece is to reside With anything other than pure segmentation this is not an issue (refer to best-fit, first-fit etc.) Ceng 334 - Operating Systems

Ceng 334 - Operating Systems Replacement Policy All page frames are used. A page fault has occurred. New page must go into a frame. Which one do you take out? Ceng 334 - Operating Systems

Replacement Algorithm Objectives The page being replaced should be the page least likely to be referenced in the near future There is a link between past history and the future because of locality Thus most algorithms base their decision on past history Ceng 334 - Operating Systems

Replacement Algorithms Optimal Not-recently-used (NRU) First-in, first-out (FIFO) Least recently used (LRU) Not frequently used (NFU) Modified NFU (~LRU) Ceng 334 - Operating Systems

Ceng 334 - Operating Systems Scope of Replacements The set of frames from which these algorithms choose is based on the scope Local Scope: Only frames belonging to the faulting process can be replaced. Global Scope: All frames can be replaced Some frames will be locked (e.g. Kernel, system buffers etc.,) Ceng 334 - Operating Systems

Optimal Replacement Algorithm Replace the page which is least likely to be referenced or for which the time to the next reference is the longest (Replace page needed at the farthest point in future) This algorithm is impossible to implement because OS must have perfect knowledge of future events This algorithm is used to compare other algorithms Ceng 334 - Operating Systems

Optimal Replacement Example F 2 3 1 5 4 Ceng 334 - Operating Systems

Optimal Replacement Example (Cont.) 1’st page fault : page 1 is replaced by page 5 because page 1 does not appear in the page address stream in the future 2’nd page fault: page 2 is replaced by page 4 because page 2 will be referenced after two (pages 5 and 3) references 3’rd page fault: page 4 is replaced by 2 because page 4 is not in the stream any more Ceng 334 - Operating Systems

Not-Recently-Used (NRU) Replace the page which is not used recently Use the referenced (R) & modified (M) bits in the page table entry R bit is set when the page is referenced (read or written) M bit is set when the page is modified (contents changed - written) Ceng 334 - Operating Systems

Ceng 334 - Operating Systems NRU Implementation Hardware R & M bits are set by hardware on every memory reference Software R & M bits in the page table entry is modified at page faults Ceng 334 - Operating Systems

Ceng 334 - Operating Systems NRU Algorithm When process starts both R & M bits are cleared R bit is cleared on every clock interrupt At a page fault, a page from the lowest numbered nonempty class is removed: Class 0 : not referenced, not modified Class 1 : not referenced, modified Class 2 : referenced, not modified Class 3 : referenced, modified Class 1 appears when clock interrupt clears R bits of class 3 processes Ceng 334 - Operating Systems

First-in First-out (FIFO) Replace the page which has been in memory for the longest time Simple to implement (use a circular buffer) There is a chance that the oldest page may be used heavily (thrashing - page moves back & forth between memory & disk) Inspect R & M bits (ie., classes) to skip over heavily used pages to decrease thrashing Ceng 334 - Operating Systems

Ceng 334 - Operating Systems FIFO Example 2 3 1 5 4 F F F F F F Ceng 334 - Operating Systems

Least Recently Used (LRU) Replace the page which has been unused for the longest time Does almost as well as optimal Implementation poses overheads Implementation uses a time stamp for each page (time of last reference) Ceng 334 - Operating Systems

Ceng 334 - Operating Systems LRU Example F 2 3 1 5 4 F Ceng 334 - Operating Systems

Ceng 334 - Operating Systems LRU Example (Cont.) 1’st page fault: page 5 replaces page 3 because page 3 hasn’t been referenced in the last two references 2’nd page fault: page 4 replaces page 1 because page 1 hasn’t been referenced in the last two references 3’rd page fault: page 3 replaces page 2 because page 2 hasn’t been referenced in the last two references 4’th page fault: page 2 replaces page 4 because page 4 hasn’t been referenced in the last two references Ceng 334 - Operating Systems

Hardware Implementation of LRU Maintain a linked list of all pages ordered from the most recently used to the least recently used. Maintaining a list on every instruction execution is very expensive and time consuming An approximate solution A hardware counter is incremented after each instruction Page table also has a field to store the number of references (counter value) At a page fault remove the page which has the minimum number of references Ceng 334 - Operating Systems

Software Implementation of LRU : Not Frequently Used (NFU) At every clock interrupt the R bit value is added to the fields in page tables At a page fault, replace the page with the minimum counter value Since the counter update is done at every clock interrupt, the algorithm is an approximation Ceng 334 - Operating Systems

Ceng 334 - Operating Systems NFU Example Ceng 334 - Operating Systems

Ceng 334 - Operating Systems Modified NFU : ~LRU Aging of pages Algorithm Shift right counter values (in page table) by 1 Put R bit value (0 - not referenced or 1- referenced ) as the new leftmost bit at every clock tick At a page fault replace the page with the lowest counter value (this is the least recently used page) Ceng 334 - Operating Systems

Modified NFU : ~LRU (Cont.) Example Suppose counter is 1 0 1 1 0 & R bit = 0 New counter becomes 0 1 0 1 1 Leading zeros represent the number of clock ticks that the page has not been referenced Ceng 334 - Operating Systems

Differences Between NFU & ~LRU NFU counts the number of times that a page is accessed in a given period ~LRU incorporates a time factor by shifting right (aging) the counter value Ceng 334 - Operating Systems

Resident Set Management Resident Set: Set of a process' pages which are in main memory OS must manage the size and allocation policies which effect the resident set Ceng 334 - Operating Systems

Ceng 334 - Operating Systems Factors Include Smaller resident set per process, implies more processes in memory, implies OS will always find at least one ready process (if not swapping must occur) If process' resident set is small, page fault frequency will be higher Increasing the resident set size beyond some limit does not effect page fault frequency Ceng 334 - Operating Systems

Resident Set Management Policies Fixed allocation policy Each process has a fixed number of pages Variable allocation policy The number of pages per process can change Ceng 334 - Operating Systems

Ceng 334 - Operating Systems Allocation vs Scope Ceng 334 - Operating Systems

Fixed Allocation, Local Scope Frame number per process is decided beforehand and can't be changed Too Small: High page faults, poor performance Too Large: Small number of processes, high processor idle time and/or swapping Ceng 334 - Operating Systems

Variable Allocation, Global Scope Easiest to implement Processes with high page fault rates will tend to grow. However replacement problems exist Ceng 334 - Operating Systems

Variable Allocation, Local Scope Allocate new process a resident set size. Prepaging or demand to fill up allocation Select replacement from within faulting process Re-evaluate allocation occasionally Ceng 334 - Operating Systems

Working Set (Denning’s) 1 2 3 5 6 7 8 4 Routine 2 Routine 1 Main program Main loop Program Execution Start with main program (page 8) Main program loads the main loop (pages 4,5,6,7) Program executes in the main loop for 20 seconds Then routine 1 is called (page 1) which executes 2 seconds Finally routine 2 (pages 2, 3) is called to execute for 3 seconds Ceng 334 - Operating Systems

Ceng 334 - Operating Systems Working Set (Cont.) In the previous example, the process needs pages 4, 5, 6, 7 for most of the time (20 seconds in a total of 25 seconds execution time) If these pages are kept in memory the number of page faults will decrease. Otherwise, thrashing may occur The set of pages that a process is currently using is called its working set Rule: Do not run a process if its working set can not be kept in memory Ceng 334 - Operating Systems

The Working Set Page Replacement Algorithm The working set is the set of pages used by the k most recent memory references w(k,t) is the size of the working set at time, t Ceng 334 - Operating Systems

Working Set Implementation Use aging as in ~LRU Pages with 1 (referenced) in “n” clock ticks are assumed to be a member of the working set “n” is experimentally determined Ceng 334 - Operating Systems

Ceng 334 - Operating Systems Cleaning Policy Cleaning Policy: Deciding when a modified page should be written out to secondary memory Demand Precleaning: Page is written out only when it has been selected for replacement Means a page fault may imply two I/O operations which severely effects performance Ceng 334 - Operating Systems

Ceng 334 - Operating Systems Precleaning: Pages written before frames are needed (so they can be written out in batches) No sense writing out batches of pages and then finding them changed again Page Buffering is a nice compromise Ceng 334 - Operating Systems

Ceng 334 - Operating Systems Load Control Load Control: Controlling the number of processes that are resident in memory Too few processes imply lack of ready processes, implies swapping Too many processes implies high page fault frequency which leads to thrashing Ceng 334 - Operating Systems