1 / 17

Page-replacement policies

This article explores different page replacement policies, including optimal, FIFO, and the enhanced clock algorithm, for managing resident virtual memory pages in the Pentium's virtual memory architecture.

garylane
Download Presentation

Page-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. Page-replacement policies On some standard algorithms for the management of resident virtual memory pages

  2. Use of backing storage • The Pentium’s virtual memory architecture supports the ‘swapping’ of memory pages between physical ram and disk storage • More processes can be in the ‘running’ state if some of their pages are ‘swapped’

  3. More processes can be running 6 processes 3 processes PHYSICAL RAM PHYSICAL RAM DISK STORAGE

  4. Replacing a page • If a running process needs to reference a page that is not current in physical RAM, then that page must be read from the disk • But then some other page current in RAM must be overwritten (i.e., “replaced”) • It’s the Operating System’s job is to decide which page will be the one to get replaced

  5. What could go wrong? • If the OS replaces a page that will soon be referenced again, then that page will have to be re-read back into memory (and some other page will need to be replaced) • Disk-I/O is slow compared to RAM access • A task’s progress is delayed when it needs to wait for disk-I/O operations to complete • A worst-case senario is disk “thrashing”

  6. Intelligent replacement • The OS should try to avoid “replacing” any page that will very soon be needed again • Belady showed (in 1966) that an “optimal” page-replacement policy is to discard the page that won’t be needed again for the greatest amount of time • But of course the OS has no way to know which pages will be needed soonest

  7. The LRU policy • Although the OS can’t know the future, it can keep track of what’s occurred in past • OS can assume a task’s future behavior will probably resemble its past behavior • So a page that has gone unreferenced for the longest amount of time is “most likely” to continue to go unreferenced in future • This is the “Least Recently Used” policy

  8. LRU is too costly • Tracking the time when each page gets referenced is prohibitively expensive • For example, with a 4GB physical memory there would be one million physical pages • Hardware would need to support page-tracking in parallel with task execution • So more practical approaches are needed

  9. The FIFO policy • A fixed-size array of pages is organized as a ring-buffer (FIRST-IN, FIRST-OUT) • Whenever a new page must be brought in from the disk, it will replace the page that has been in RAM for the longest time • This is simple to implement (and can work well if all pages are accessed with roughly the same frequency – but that’s unusual!

  10. The CLOCK policy • An easy way to modify the FIFO policy, so as to avoid replacing frequently accessed pages that got loaded into RAM very early, is the so-called “clock” policy (also called known as the “second chance” algorithm) • It uses a single bit of data for each page, called the ‘accessed’ bit (which the CPU automatically sets upon a page-access), plus a revolving software ‘pointer’

  11. The ‘clockface’ pointer 0 1 0 0 1 1 1 0 0 = unaccessed 1 = accessed

  12. How it works • When a page-replacement is needed, the page pointed to is examined • If its access-bit is 0 (unaccessed), it will get replaced, and the pointer will be advanced • If its access-bit is 1 (accessed), its access-bit will be cleared, and the pointer will advance, and this will be repeated until an unaccessed page is reached (maybe requiring a full circle) • So accessed pages get a second chance!

  13. Clock-policy enhancement? • The Pentium supports an enhancement to this clock page-replacement policy • Each page-table entry has two ‘sticky’ bits: 31 6 5 0 Page-table entry D A A = Accessed – the page has been read ( 1 = yes, 0 = no ) D = Dirty – the page has been modified ( 1 = yes, 0 = no )

  14. Pages: ‘clean’ versus ‘dirty’ • When a page is selected for replacement, it does not need to be written back to disk unless it has been modified (i.e., it’s dirty) • So it’s more efficient if the OS replaces a ‘clean’ page instead of a ‘dirty’ one • This leads to an improvement in the clock page-replacement policy

  15. Keep track of (D,A) bits 1,1 1,1 0,0 0,0 0,1 0,1 1,1 0,0 0,0 = unaccessed 0,1 = accessed (clean) 1,1 = accessed (dirty)

  16. How enhancement works • When a page-replacement is needed, the page pointed to is examined: (D,A)-bits checked • If sticky-bits are 0,0 (unaccessed), page is replaced and the pointer is advanced • If sticky-bits are 0,1 (accessed, but clean), bits are not changed, but the pointer will be advanced • After a full circle, a second scan begins; if a ‘clean’ page is encountered, it gets replaced; otherwise, after a second full scan (all page are dirty), the initial page gets replaced

  17. In-class exercise • Our ‘clockalg.cpp’ demo simulates three page-replacement algorithms: optimal, CLOCK, and FIFO • Try adding your own code to implement a simulation for the ‘enhanced’ clock policy • NOTE: you’ll need to associate a ‘read’ or ‘write’ attribute with every page-access

More Related