Page Replacement FIFO, LIFO, LRU, NUR, Second chance

Slides:



Advertisements
Similar presentations
9.4 Page Replacement What if there is no free frame?
Advertisements

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
Scribe for 7 th April 2014 Page Replacement Algorithms Payal Priyadarshini 11CS30023.
Chapter 4 Memory Management Page Replacement 补充:什么叫页面抖动?
Virtual Memory Management G. Anuradha Ref:- Galvin.
Virtual Memory Operating System Concepts chapter 9 CS 355
1 Virtual Memory Management B.Ramamurthy. 2 Demand Paging Main memory LAS 0 LAS 1 LAS 2 (Physical Address Space -PAS) LAS - Logical Address.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement.
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.
CS 342 – Operating Systems Spring 2003 © Ibrahim Korpeoglu Bilkent University1 Memory Management – 4 Page Replacement Algorithms CS 342 – Operating Systems.
1 Virtual Memory vs. Physical Memory So far, all of a job’s virtual address space must be in physical memory However, many parts of programs are never.
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.
1 Lecture 9: Virtual Memory Operating System I Spring 2007.
Memory Management Virtual Memory Page replacement algorithms
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Revisiting Virtual Memory.
CS444/CS544 Operating Systems Virtual Memory 4/06/2007 Prof. Searleman
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.
OS Spring’04 Virtual Memory: Page Replacement Operating Systems Spring 2004.
Virtual Memory Basic Concepts Demand Paging
03/29/2004CSCI 315 Operating Systems Design1 Page Replacement Algorithms (Virtual Memory)
CS 333 Introduction to Operating Systems Class 14 – Page Replacement Jonathan Walpole Computer Science Portland State University.
Operating Systems ECE344 Ding Yuan Page Replacement Lecture 9: Page Replacement.
Virtual Memory.
O RERATıNG S YSTEM LESSON 10 MEMORY MANAGEMENT II 1.
Chapter 21 Virtual Memoey: Policies Chien-Chung Shen CIS, UD
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 Virtual Memory A generalization of what demand paging allows A form of memory where the system provides a useful abstraction.
Virtual Memory The memory space of a process is normally divided into blocks that are either pages or segments. Virtual memory management takes.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Chapter 9: Virtual-Memory Management.
Virtual Memory The address used by a programmer will be called a virtual address or logical address. An address in main memory is called a physical address.
VIRTUAL MEMORY Virtual Address Space. In computing, virtual address space (abbreviated VAS) is a memory mapping mechanism available in modern operating.
1 Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples (not covered.
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.
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Background Virtual memory – separation of user logical memory.
PAGE REPLACEMNT ALGORITHMS FUNDAMENTAL OF ALGORITHMS.
Page Replacement FIFO, LIFO, LRU, NUR, Second chance
COS 318: Operating Systems Virtual Memory Paging.
Virtual Memory What if program is bigger than available memory?
Chapter 9: Virtual Memory – Part I
ITEC 202 Operating Systems
Computer Architecture
Chapter 21 Virtual Memoey: Policies
Operating Systems Virtual Memory Alok Kumar Jagadev.
Lecture 10: Virtual Memory
Review.
CSE 120 Principles of Operating
Module 9: Virtual Memory
Chapter 9: Virtual-Memory Management
Lecture 39 Syed Mansoor Sarwar
Lecture 40 Syed Mansoor Sarwar
5: Virtual Memory Background Demand Paging
Demand Paged Virtual Memory
There’s not always room for one more. Brian Bershad
Contents Memory types & memory hierarchy Virtual memory (VM)
Practical Session 8, Memory Management 2
Operating Systems CMPSC 473
Operating Systems Concepts
Module 9: Virtual Memory
Chapter 9: Virtual Memory CSS503 Systems Programming
Practical Session 9, Memory Management continues
Module IV Memory Organization.
Presentation transcript:

Page Replacement FIFO, LIFO, LRU, NUR, Second chance Dynamically adding/subtracting frames Belady’s anomaly

Page Replacement Suppose the OS allocates a fixed number of page frames to a process. If a page from a process is referenced by the process, and it is not currently in memory (this is called a page fault) then a page frame from that process must be selected for removal so the newly referenced page can be put in memory. Which page frame should be selected? Local Replacement When a process needs to bring in a page to memory, the page selected for removal is chosen from the set of pages currently in memory for that same process. Global Replacement When a process needs to bring in a page to memory, the page selected for removal is chosen from the set of all pages currently in memory for any process.

Process A has 3 page frames Process A has pages 0,1,and 4 in main memory in real page frames: 98,96 and 100 respectively

OS allocating page frames The operating system will allocate page frames to a process. It may not be enough frames to load the entire program. When the level of multiprocessing is very high, the number of frames could be low. The number of page frames a process may have can vary dynamically while the program is running.

Selecting a page to remove So if The Operating System currently is giving a process 3 page frames to load pages into (because so many other programs are currently running and space is limited) And currently all 3 pages fames are occupied with process pages The process is now going to execute an instruction from a page not in memory We need to go out to the disk drive and bring the pages in and therefore select a page to remove (write on top of). Note: if we select a page that has been modified, we must also first, write those modifications back to disk before replacing the page. This will take extra time.

Ex) Page 3 needs to come in Where should be page 3 be written to? Why? Discuss: FIFO, LRU, Optimal The Goal is to predict the future from the past but also do not take up a lot of time doing it.

First or Last in First Out FIFO (First In First Out) Method: Select the page that has been in MM the longest and remove it to make room. Implementation: Maintain a linked list data structure of all pages currently in MM and remove the page that is pointed to by the head of the linked list. LIFO (Last In First Out) Method: Select the page that has been in MM the shortest and remove it to make room. Implementation: Maintain a stack of all pages currently in MM and remove the page that is at the top of the stack the linked list.

Statistics based (Least Recently Used) LRU (Least Recently Used) Method: Select the page that has been referenced the least recently of all frames in Main Memory. Implementation 1: Maintain a linked list of all pages currently in MM and each time a page is referenced (read or write), move the page to the tail of the linked list. Implementation 2: Maintain timestamps of all pages currently in MM and each time a page is referenced (read or write), update the timestamp. When replacing a page, pick the page with the oldest timestamp.

Not Used Recently NUR (Not Used Recently) Method: Select the frame that has been referenced the somewhat least recently of all frames in MM. This method is that same idea as LRU but the implementation is much simpler and therefore faster. Implementation: Maintain an array of bits for each page, when a page is referenced, set the bit to 1. At the time when all page reference bits are set to 1, then set all reference bits to zero to start the whole reference recording over. At the time of removal selection, pages that have not been referenced recently will have the reference bit set to 0. Pick on of them.

Second Chance Second Chance Method: Same as NUR but with 2 bits. At the time when a page is selected for removal for the first time, it is allowed to stay in memory for a second chance. Implementation: Maintain 2 arrays of bits for each page, (just like the NUR) but when a page is selected, check if the second chance bit is set, if not, set it, and skip over this process an continue the selections process.

Optimal Page Replacement Method: Look into the future at the pages that will be referenced (if possible), and of all the pages currently in memory, select the page that’s next reference will be the furthest in the future. Implementation: Predict the future. The OS must know the exact sequence of referenced that the process will make. Not feasible if the program has if…then…else statements. Possible if the process is a straight process without decisions. Comment: Although this is not realistic to implement, it is the benchmark to check other algorithms against. That is, if the optimal algorithm produces x page faults, you would compare other algorithms against x.

Example: page reference string Consider a process in Main Memory where the OS has given the process 3 page frames of Main Memory to process out of but the process has a total of four pages numbered 0,1,2 and 3. When a process is running, the list of pages referenced in order is called the reference string for that process. Suppose the reference for this process is 0,1,2,3,2,3,1,0,2,3 and the following page replacements are used.

Example using FIFO Miss ratio = 5/10 Hit ratio = 1 – Miss Ratio = 5/10

Example using LRU Miss ratio = 7/10 hit ratio = 1 – Miss ratio = 3/10

Example using Optimal Best miss ratio for this reference string is 5/10

Conclusions? FIFO is better than LRU in general based on the last example reference string? No, just because it is better here doesn’t mean it is usually better. Does one algorithm take up more processor time (therefore make processes take longer to complete) than another algorithm? Yes, but maybe it would be worth it to produce fewer page faults. Can any algorithm have less page faults than the Optimal algorithm? No, That’s why it is called the optimal algorithm. The best any algorithm can do is tie the optimal algorithm. It is often impossible to know future page references of a running program but once a program has been running, it is easy to calculate how well the Optimal Algorithm would have been and use that as a bench mark to compare the algorithm the OS is actually using.

Dynamically adding/subtracting frames Operating System has 12 available frames to give to 4 processes. How many frames should each process get? Guess 12/4 = 3…why not? Should the OS make adjustments to frame/process?

Working Set (see queuing theory) The working set principle take into account that whichever page replacement algorithm used, to maximize overall throughput, the goal is to have the processor(s) running as close to 100% of the time. A state where all processes are waiting for the disk drives for a page and none are “ready to run” should be avoided.

Belady’s Anomaly Compare FIFO with 3 frames vs. 4 frames