CS 3733 Operating Systems
Lecture 12 [10/6/97]: Page Replacement Policies (Cont)
Reading: Tanenbaum Section 3.4
Page Replacement
When a new page needs to
be brought in, there will not always be an empty frame. Which frame
should be replaced?
- FIFO - first-in-first-out
- This is very simple to implement - just keep a FIFO queue and
add an entry to the back when a page is placed in a frame.
- Unfortunately the most heavily used pages are often the ones
brought in first.
- Note that the FIFO queue gets updated only when there is a page
fault, not on each reference. This implies that it is possible
to generate reference strings which do worse when there are more
frames.
- Example:
Calculate the number of page faults obtained for the following reference
string:
1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
- When the memory has 3 frames
- When the memory has 4 frames
- Optimal Replacement
Look to the future. Impossible to implement, but gives the best possible
result. Example:
Calculate the number of page faults obtained for the following reference
string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
- Least Recently Used
- Each page keeps time of last use.
- Since this must be done on every reference (in contrast to FIFO which
only needs an update when the page is put in the frame), the bookkeeping
must be done in hardware (in fact it isn't done for page replacement,
but it is often used for TLB replacement).
- Two possible implementations of this are:
- Counter - incremented on every memory reference and copied into
the page table when the page is referenced. In this case, you must
search the page table for the LRU page when a replacement is to be done.
- Stack - keep a list of page numbers in order of reference. When
a page is referenced, move the page number to back.
- Why these cannot be used --- time and number of bits.
- Example: LRU with three frames and the reference string
1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
- Least Recently Used Approximation
- Keep a reference bit in the page table entry. (Or keep a register with
all of the bits together.)
- When a page is referenced, the bit is set.
- Use this information to replace unused pages first.
- A more sophisticated approach is to keep an 8-bit byte for each
page table entry. Periodically the operating system shifts the reference
bit into the high-order bit of the byte. Lowest-numbered byte is the
least recently used.
- Second Chance = FIFO + reference bit
- Keep pages in a FIFO list.
- If a page is selected for replacement, look at reference bit. If 0
replace. If 1, clear the reference bit and put it at end of FIFO list
(give it a second chance).
- Pages which are used often won't get moved out.
Revision Date: 10/6/97 at 9 pm