Page Replacement Algorithms

Slides:



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

Page Replacement Algorithms
Virtual Memory Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution -
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.
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
Scribe for 7 th April 2014 Page Replacement Algorithms Payal Priyadarshini 11CS30023.
Chapter 4 Memory Management Page Replacement 补充:什么叫页面抖动?
國立台灣大學 資訊工程學系 Chapter 9: Virtual Memory. 資工系網媒所 NEWS 實驗室 Objectives To describe the benefits of a virtual memory system To explain the concepts of demand.
Allocation of Frames Each process needs minimum number of pages
Page 15/4/2015 CSE 30341: Operating Systems Principles Allocation of Frames  How should the OS distribute the frames among the various processes?  Each.
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
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.
Gordon College Stephen Brinton
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems 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.
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.
03/29/2004CSCI 315 Operating Systems Design1 Page Replacement Algorithms (Virtual Memory)
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 Virtual Memory.
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.
Virtual Memory. Background Virtual memory is a technique that allows execution of processes that may not be completely in the physical memory. Virtual.
Operating Systems (CS 340 D) Princess Nora University Faculty of Computer & Information Systems Computer science Department.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Chapter 9: Virtual-Memory Management.
Operating Systems (CS 340 D) Princess Nora University Faculty of Computer & Information Systems Computer science Department.
CSC 360, Instructor: Kui Wu Memory Management II: Virtual Memory.
CS307 Operating Systems Virtual Memory Fan Wu Department of Computer Science and Engineering Shanghai Jiao Tong University Spring 2012.
Silberschatz, Galvin and Gagne  Operating System Concepts Virtual Memory Virtual memory – separation of user logical memory from physical memory.
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.
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.
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.
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 Background Virtual memory – separation of user logical memory.
Chapter 9: Virtual Memory
Chapter 9: Virtual Memory
OPERATING SYSTEM CONCEPTS AND PRACTISE
Computer Architecture
Chapter 9: Virtual Memory
Operating Systems Virtual Memory Alok Kumar Jagadev.
Review.
Module 9: Virtual Memory
Chapter 9: Virtual Memory
Chapter 9: Virtual-Memory Management
Lecture 40 Syed Mansoor Sarwar
5: Virtual Memory Background Demand Paging
Chapter 9: Virtual Memory
Chapter 6 Virtual Memory
Operating Systems CMPSC 473
Module 9: Virtual Memory
Chapter 9: Virtual Memory CSS503 Systems Programming
Chapter 9: Virtual Memory
Virtual Memory.
Presentation transcript:

Page Replacement Algorithms Want lowest page-fault rate Evaluate algorithm by running it on a particular string of memory references (reference string) and computing the number of page faults on that string For example, a reference string is 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5

FIFO Page Replacement

FIFO Page Replacement It replaces the page that has been in memory the longest Thus, it focuses on the length of time a page has been in memory rather than on how much the page is being used FIFO’s main asset is that it is simple to implement Its behavior is not particularly well suited to the behavior of most programs, however, (it is completely independent of the locality of the program), so few systems use it

Number of Page Fault: FIFO Anomaly To illustrate the “weirdness” of FIFO, consider the following reference string 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 Compute the number of page faults for this reference string with 3 frames 4 frames

FIFO Illustrating Belady’s Anomaly

Belady’s Anomaly This most unexpected result is known as Belady’s anomaly – for some page-replacement algorithms, the page fault rate may increase as the number of allocated frames increases Is there a characterization of algorithms susceptible to Belady’s anomaly?

Stack Algorithms Certain demand algorithms are more “well behaved” than others (In the FIFO example), the problem arises because the set of pages loaded with a memory allocation of 3 frames is not necessarily also loaded with a memory allocation of 4 frames There are a set of demand paging algorithms whereby the set of pages loaded with an allocation of m frames is always a subset of the set of pages loaded with an allocation of m +1 frames. This property is called the inclusion property Algorithms that satisfy the inclusion property are not subject to Belady’s anomaly. FIFO does not satisfy the inclusion property and is not a stack algorithm

Optimal Page Replacement An optimal page replacement algorithm has the lowest page-fault rate of all algorithms and will never suffer from Belady’s anomaly Such an algorithm does exist and has been called OPT or MIN. It is simply this: Replace the page that will not be used for the longest period of time Use of this page-replacement algorithm guarantees the lowest possible page-fault rate for a fixed number of pages

Optimal Page Replacement

Optimal Page Replacement Unfortunately, OPT is difficult to implement, because it requires future knowledge of the reference string As a result, OPT is used mainly for comparison purposes For instance, it may be useful to know that, although a new page-replacement algorithm is not optimal, it is within 12.3 % of optimal at worst and within 4.7 % on average

Least Recently Used (LRU) Algorithm If OPT is not feasible, perhaps an approximation of OPT is possible The key distinction between FIFO and OPT (other than looking backward versus forward in time) is that FIFO uses the time when a page was brought into memory whereas OPT uses the time when a page is to be used If we use the recent past as an approximation of the near future, then we can replace the page that has not been used for the longest period of time This approach is the least-recently-used (LRU) algorithm

Least Recently Used (LRU) Algorithm LRU associates with each page the time of that page’s last use When a page must be replaced, LRU chooses the page that has not been used for the longest period of time We can think of this strategy as OPT looking backward in time, rather than forward

Least Recently Used (LRU) Algorithm Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5

LRU Page Replacement LRU is designed to take advantage of “normal” program behavior Programs are written to contain loops, which cause the main line of the code to execute repeatedly, with special- case code rarely being executed This set of pages that contain the code that is executed repeatedly is called the code locality of the process The LRU replacement algorithm is explicitly designed to take advantage of locality by assuming that if a page has been referenced recently, it is likely to be referenced again soon

LRU Page Replacement LRU is often used as a page replacement algorithm and is considered to be good The major problem is how to implement LRU replacement An LRU page replacement algorithm may require substantial hardware assistance

LRU Page Replacement The problem is to determine an order for the frames defined by the time of last use. Two implementations are feasible Counter implementation Every page entry has a time-of-use field; every time page is referenced through this entry, copy the clock into this field When a page needs to be changed, look at the fields to determine which are to change Stack implementation – keep a stack of page numbers implemented as a doubly linked list Page referenced move it to the top requires 6 pointers to be changed No search for replacement

Use Of A Stack to Record The Most Recent Page References

LRU Approximation Algorithms Reference bit With each page associate a bit, 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 Second chance Need reference bit Clock replacement If page to be replaced (in clock order) has reference bit = 1 then: set reference bit 0 leave page in memory replace next page (in clock order), subject to same rules

Second-Chance (clock) Page-Replacement Algorithm

Counting Algorithms Keep a counter of the number of references that have been made to each page LFU Algorithm: replaces page with smallest count MFU Algorithm: based on the argument that the page with the smallest count was probably just brought in and has yet to be used

Allocation of Frames Each process needs minimum number of pages 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

Fixed Allocation Equal allocation – For example, if there are 100 frames and 5 processes, give each process 20 frames. Proportional allocation – Allocate according to the size of process

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

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 Local replacement – each process selects from only its own set of allocated frames

Thrashing If a process does not have “enough” pages, the page-fault rate is very high. This leads to: low CPU utilization operating system thinks that it needs to increase the degree of multiprogramming another process added to the system Thrashing  a process is busy swapping pages in and out

Thrashing (Cont.)

Demand Paging and Thrashing Why does demand paging work? Locality model Process migrates from one locality to another Localities may overlap Why does thrashing occur?  size of locality > total memory size