1 / 27

Memory Replacement Policies

Memory Replacement Policies. Lecture 32 Klara Nahrstedt. CS241 Administrative. Read Stallings Chapter 8.1 and 8.2 about VM LMP2 (Part II due on Monday, April 16) See also lecture notes, self-assessment quiz, discussion section LMP2 quiz on Monday, April 16

dyre
Download Presentation

Memory Replacement Policies

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Memory Replacement Policies Lecture 32 Klara Nahrstedt

  2. CS241 Administrative • Read Stallings Chapter 8.1 and 8.2 about VM • LMP2 (Part II due on Monday, April 16) • See also lecture notes, self-assessment quiz, discussion section • LMP2 quiz on Monday, April 16 • If you found Dr. Cerf’s lecture interesting, you can • Pay attention next two weeks in cs241 were we cover socket interfaces to TCP/IP - Internet • Learn more about Internet material in classes cs438 (Communication Networking – TCP/IP), cs425 (Distributed Systems), ece435 (Computer Networking Lab – Implementation of TCP/IP), cs414 (Multimedia Systems), cs463 (Computer Security

  3. Concepts this Lecture • Introduction to Demand Paging • Replacement • Principle of Optimality • Replacement Policies

  4. Introduction to Demand Paging - Paging Policies • Fetch Strategies • When should a page be brought into primary (main) memory from secondary (disk) storage. • Placement Strategies • When a page is brought into primary storage, where is it to be put? • Replacement Strategies • Which page now in primary storage is to be removed from primary storage when some other page or segment is to be brought in and there is not enough room.

  5. Demand Paging Example VM fault ref Load M i Page table Free frame

  6. Page Replacement Algorithm • find a free page frame • if free page frame use it • otherwise, select a page frame using the page replacement algorithm • write the selected page to the disk and update any necessary tables • find location of page on disk • read the requested page from the disk. • restart the user process.

  7. Page Replacement • It is necessary to be careful of synchronization problems. For example, page faults may occur for pages being paged out.

  8. Page Replacement Issues • if no frames are free, a disk read and write of page is required • if the page to be replaced has not been changed since it was read in, it can be discarded and does not need to be copied out to secondary storage. • read only pages are never written but may be shared!

  9. Page Replacement Issues • a dirty bit is set in the page table by hardware to indicate that the page has been modified. • need to minimize page faults. • reference string is the memory references generated by a program.

  10. Page Replacement Strategies • the principle of optimality • replace the page that will not be used again the farthest time in the future. • random page replacement • choose a page randomly • FIFO - first in first out replace the page that has been in primary memory the longest

  11. Terminology • Reference string: the memory reference sequence generated by a program. • Paging – moving pages to (from) disk • Optimal – the best (theoretical) strategy • Eviction – throwing something out • Pollution – bringing in useless pages/lines

  12. Page Replacement Strategies • LRU - least recently used • replace the page not used for the longest time • LFU - least frequently used • replace the page that is used least often • NUR - not used recently • an approximation to LRU. • working set • keep in memory those pages that the process is actively using.

  13. Principal of Optimality • provides a basis for comparison with other schemes. • is difficult to implement because of trying to predict the reference string for a program. • compiler technology can help by providing hints.

  14. Principal of Optimality • if the reference string can be predicted accurately, then shouldn't use demand paging but should use pre-paging instead as this would allow paging activity of pages needed in the future to be overlapped with computation.

  15. Optimal Example 12 references, 7 faults

  16. FIFO 12 references, 9 faults

  17. Paging Behavior with IncreasingNumber of Page Frames

  18. Belady's Anomaly (for FIFO) As the number of page frames increase, so does the fault rate. 12 references, 10 faults

  19. LRU 12 references, 10 faults

  20. Least Recently Used Issues • does not suffer from Belady's anomaly • use time • record time of reference with page table entry • use counter as clock • search for smallest time. • use stack • remove reference of page from stack (linked list) • push it on top of stack • both approaches require large processing overhead, more space, and hardware support.

  21. LRU and Anomalies Anomalies cannot occur, why? 12 references, 8 faults

  22. NUR: A LRU Approximation • additional reference bits • a register is kept per page • a one bit is set in the register if the page is referenced • the register is shifted by one after some time interval • 00110011 would be accessed more recently than 00010111 • the page with register holding the lowest number is the least recently used. • the value may not be unique. use fifo to resolve conflicts.

  23. Second Chance • second chance algorithm uses a register size one: a reference bit. • the page table entry has a reference bit • initially, the reference bit for a page is set to 0 • when a page is referenced, the page is set to 1 • pages are kept in FIFO order using a circular list. • select head of FIFO

  24. Second Chance • if page has reference bit set, reset bit and select next page in FIFO list. • keep processing until reach page with zero reference bit and page that one out. • system v, r4 uses a variant of second chance.

  25. Second Chance Example 12 references, 9 faults

  26. Page Classes • 1.(0,0) neither referenced nor dirtied • 2.(0,1) not referenced (recently) but dirtied • 3.(1,0) referenced but clean • 4.(1,1) referenced and dirtied • select a page from lowest class • if conflict, use random or FIFO.

  27. Summary • Fetch, placement, page replacement. • Demand paging algorithm. • Simple page replacement policies. • Optimal • FIFO • LRU • NUR • Second chance, page classes

More Related