Page Replacement Algorithms

Slides:



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

Chapter 4 Memory Management Basic memory management Swapping
9.4 Page Replacement What if there is no free frame?
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 3.3 : OS Policies for Virtual Memory
CS 333 Introduction to Operating Systems Class 14 – Page Replacement
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.
Memory Management.
Scribe for 7 th April 2014 Page Replacement Algorithms Payal Priyadarshini 11CS30023.
Chapter 4 Memory Management Page Replacement 补充:什么叫页面抖动?
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 Introduction to Operating Systems: Module 9.
Memory management, part 2: outline  Page replacement algorithms  Modeling PR algorithms o Working-set model and algorithms  Virtual memory implementation.
1 Memory Management Managing memory hierarchies. 2 Memory Management Ideally programmers want memory that is –large –fast –non volatile –transparent Memory.
Virtual Memory Today Virtual memory Page replacement algorithms
Memory management, part 2: outline
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.
Paging Algorithms Vivek Pai / Kai Li Princeton University.
Introduction to Systems Programming Lecture 7
Memory Management Virtual Memory Page replacement algorithms
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Revisiting Virtual Memory.
CS 333 Introduction to Operating Systems Class 14 – Page Replacement Jonathan Walpole Computer Science Portland State University.
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.
CS 333 Introduction to Operating Systems Class 14 – Page Replacement
Page Replacement Algorithms
Chapter 4 Memory Management 4.1 Basic memory management 4.2 Swapping
Demand Paging Virtual memory = indirect addressing + demand paging –Without demand paging, indirect addressing by itself is valuable because it reduces.
CS 333 Introduction to Operating Systems Class 14 – Page Replacement Jonathan Walpole Computer Science Portland State University.
CSC 322 Operating Systems Concepts Lecture - 15: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
Virtual Memory.
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.
Memory Management From Chapter 4, Modern Operating Systems, Andrew S. Tanenbaum.
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.
Page Replacement Algorithms Memory Management. Optimal Page Replacement ▪The label for each page in memory is labeled with the number of instructions.
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.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Paging.
Operating Systems CMPSC 473 Virtual Memory Management (3) November – Lecture 20 Instructor: Bhuvan Urgaonkar.
#include pthread_mutex_t sem_mut = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t cond_mut = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
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.
Page Replacement Algorithms and Simulation Neville Allen.
Demand Paging Reference Reference on UNIX memory management
Operating Systems Practical Session 10, Memory Management continues.
1 Memory Management Chapter Basic memory management 4.2 Swapping 4.3 Virtual memory 4.4 Page replacement algorithms 4.5 Modeling page replacement.
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.
PAGE REPLACEMNT ALGORITHMS FUNDAMENTAL OF ALGORITHMS.
COS 318: Operating Systems Virtual Memory Paging.
CS 333 Introduction to Operating Systems Class 14 – Page Replacement
Virtual Memory What if program is bigger than available memory?
Demand Paging Reference Reference on UNIX memory management
Chapter 9: Virtual Memory
Demand Paging Reference Reference on UNIX memory management
Practical Session 8, Memory Management 2
Chapter 9: Virtual-Memory Management
What Happens if There is no Free Frame?
Demand Paged Virtual Memory
Practical Session 9, Memory Management continues
Practical Session 8, Memory Management 2
Operating Systems CMPSC 473
Practical Session 9, Memory Management continues
Practical Session 8, Memory Management 2
Presentation transcript:

Page Replacement Algorithms So, when we have a page fault we have to find an eviction candidate. Optimally, we would like to evict the page that will not be referenced again for the longest amount of time. In reality the OS has no way of knowing when each of the pages will be referenced next.

Not Recently Used Examine M and R bits associated with each page. Page fault occurs, OS places all pages in 1 or 4 classifications Class 0: R=0, M=0 Class 1: R=0, M=1 Class 2: R=1, M=0 Class 3: R=1, M=1 NRU Algorithm says to remove a page at random from the lowest nonempty class.

FIFO Simple design of having a queue maintained for pages in memory. The head of the queue contains oldest page in memory. The tail of the queue contains the newest page in memory. Is there a potential problem with evicting the head of the queue each time?

FIFO with second chance Performs like FIFO, but inspects the R bit. If R bit of the head page is 1, it is cleared and placed at the tail. What happens if all pages in memory have the R bit set to one?

Clock Page Replacement Behaves liked FIFO with second chance except that it is a circular linked list.

Least Recently Used Assume pages used recently will be used again soon throw out page that has been unused for longest time Must keep a linked list of pages most recently used at front, least at rear update this list every memory reference !! Keep counter in each page table entry choose page with lowest value counter periodically zero the counter

LRU (cont.) All values in matrix intially set to 0 Alternatively used a n by n matrix. n is the number of page frames. All values in matrix intially set to 0 When a page frame, k, is referenced, the hardware first sets all the bits in row k to 1. Then sets all the bits in column k to 0. The row whose binary value is lowest is the LRU at any instant.

Example of LRU using Matrix Pages referenced in order 0,1,2,3,2,1,0,3,2,3

Simulated LRU – Not Frequently Used Most machines do not have the hardware to perform true LRU, but it may be simulated. We can use a counter to keep track of each R bit for each page upon a timer tick. Page with the lowest R-bit is evicted. What is the problem with this type of history keeping?

Modified NFU Counters are each shifted right 1 bit before the R bit is added. R bit is added to the leftmost, rather than the rightmost bit. This modified algorithm is known as aging.

Modified NFU (Aging)

Issues with NFU References can happen between timer interrupts. What happens if we are comparing two pages which have identical references over the past n timer ticks? We make a random choice. Is it the right one?

Working Set Page Replacement Locality of Reference – a process references only a small fraction of its pages during any particular phase of its execution. The set of pages that a process is currently using is called the working set. Thrashing – results when a program causes a page fault every few instructions, causing the pages to have to pulled up from memory. No “real” useful work is being accomplished.

Working Set Page Replacement (cont.) So, what happens in a multiprogramming environment as processes are switched in and out of memory? Do we have to take a lot of page faults when the process is first started? It would be nice to have a particular processes working set loaded into memory before it even begins execution. This is called prepaging.

Working Set Page Replacement (cont.) The working set algorithm is based on determining a working set and evicting any page that is not in the current working set upon a page fault.

Working Set Page Replacement (cont.) Age = current virtual time – time of last use

Working Set Page Replacement (cont.) What happens when there is more than one page with R=0 and age less then or eq to tau? What happens when all pages have R=1? This algorithm requires the entire page table be scanned at each page fault until a suitable candidate is located. All entries must have their Time of last use updated even after a suitable entry is found.

WSClock Page Replacement

WSClock Page Replacement (Cont.) What happens when R=0? Is age > , and page is clean then it is evicted If it is dirty then we can proceed to find a page that may be clean and avoid a process switch. We will still need to write to disk and this write is scheduled. What happens if we go all the way around? (Two Scenarios) At least one write has been scheduled. Keep Looking… someone eventually write to disk. No writes have been scheduled… all pages are in the working set, so evict a clean page or the current page if a clean page does not exist.

Page Replacement Algorithm Summary