Presentation is loading. Please wait.

Presentation is loading. Please wait.

Page-replacement policies On some standard algorithms for the management of resident virtual memory pages.

Similar presentations


Presentation on theme: "Page-replacement policies On some standard algorithms for the management of resident virtual memory pages."— Presentation transcript:

1 Page-replacement policies On some standard algorithms for the management of resident virtual memory pages

2 Use of backing storage The Pentiums 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 DISK STORAGE PHYSICAL RAM 3 processes 6 processes

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) Its the Operating Systems 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 tasks 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 wont 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 cant know the future, it can keep track of whats occurred in past OS can assume a tasks 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 thats 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 0 0 1 0 1 1 1 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: Page-table entry AD 56031 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., its dirty) So its 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 0,0 0,1 0,0 0,1 1,1 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: youll need to associate a read or write attribute with every page-access


Download ppt "Page-replacement policies On some standard algorithms for the management of resident virtual memory pages."

Similar presentations


Ads by Google