Notes on Page Replacement Algorithms
Notes on Page Replacement Algorithms
When a program starts execution, one or more pages are transferred into
main memory and the page table is set to indicate their position. The
program is executed from main memory until it attempts to reference a
page that is still in auxiliary memory. This condition is called page fault.
When page fault occurs, the execution of the present program is suspended
until the required page is brought into main memory.
Two of the most common replacement algorithms used are the first-in,
FIFO first-out (FIFO) and the least recently used (LRU).
The FIFO algorithm selects for replacement the page that has been in
memory the longest time. When a new page must be loaded, the page least
recently brought in is removed.
The FIFO replacement policy has the advantage of being easy to implement.
It has the disadvantage that under certain circumstances pages are
removed and loaded from memory too frequently.
The LRU policy is more difficult to implement but has been more attractive
on the assumption that the least recently used page is a better candidate
for removal than the least recently loaded page as in FIFO.
Example Using FIFO: Consider a system with virtual space of 8k, main memory
space of 4k and page is of 1k. Find the number of page faults if the system
makes page referencing during execution of a program as 4, 2, 0, 1, 2, 6, 1, 4, 0,
1, 0, 2, 3, 5, and 7.
4 2 0 1 2 6 1 4 0 1 0 2 3 5 7
4 4 4 4 6 6 6 6 5 5
2 2 2 2 4 4 4 4 7
0 0 0 0 2 2 2 2
1 1 1 1 3 3 3
(PF: page fault; NPF: No page fault; Numbers in red colour are least recently
loaded pages which is to be replaced by new page)
4 2 0 1 2 6 1 4 0 1 0 2 3 5 7
4 4 4 4 6 6 6 2 2 2 2
2 2 2 2 2 0 0 0 0 7
0 0 0 4 4 4 3 3 3
1 1 1 1 1 1 5 5
Numbers in red colour are least recently used pages which is to be replaced by
new page)