Page Replacement Algorithms
Page Replacement Algorithms
If no page frame is free, the virtual memory manager performs a page replacement operation to
replace one of the pages existing in memory with the page whose reference caused the page fault. It
is performed as follows: The virtual memory manager uses a page replacement algorithm to select
one of the pages currently in memory for replacement, accesses the page table entry of the selected
page to mark it as “not present” in memory, and initiates a page-out operation for it if the modified
bit of its page table entry indicates that it is a dirty page.
This is the simplest page replacement algorithm. In this algorithm, the operating system keeps track
of all pages in the memory in a queue, the oldest page is in the front of the queue. When a page
needs to be replaced page in the front of the queue is selected for removal.
Example 1: Consider page reference string 1, 3, 0, 3, 5, 6, 3 with 3 page frames.Find the number of
page faults using FIFO Page Replacement Algorithm.
Initially, all slots are empty, so when 1, 3, 0 came they are allocated to the empty slots —> 3 Page
Faults.
when 3 comes, it is already in memory so —> 0 Page Faults. Then 5 comes, it is not available in
memory so it replaces the oldest page slot i.e 1. —> 1 Page Fault. 6 comes, it is also not available in
memory so it replaces the oldest page slot i.e 3 —> 1 Page Fault. Finally, when 3 come it is not
available so it replaces 0 1 page fault.
Belady’s anomaly proves that it is possible to have more page faults when increasing the number of
page frames while using the First in First Out (FIFO) page replacement algorithm. For example, if we
consider reference strings 3, 2, 1, 0, 3, 2, 4, 3, 2, 1, 0, 4, and 3 slots, we get 9 total page faults, but if
we increase slots to 4, we get 10-page faults.
In this algorithm, pages are replaced which would not be used for the longest duration of time in the
future.
Initially, all slots are empty, so when 7 0 1 2 are allocated to the empty slots —> 4 Page faults
0 is already there so —> 0 Page fault. when 3 came it will take the place of 7 because it is not used
for the longest duration of time in the future.—> 1 Page fault. 0 is already there so —> 0 Page fault.
4 will takes place of 1 —> 1 Page Fault.
Now for the further page reference string —> 0 Page fault because they are already available in the
memory. Optimal page replacement is perfect, but not possible in practice as the operating system
cannot know future requests. The use of Optimal Page replacement is to set up a benchmark so that
other replacement algorithms can be analyzed against it.
Initially, all slots are empty, so when 7 0 1 2 are allocated to the empty slots —> 4 Page faults
0 is already their so —> 0 Page fault. when 3 came it will take the place of 7 because it is least
recently used —> 1 Page fault
0 is already in memory so —> 0 Page fault .
4 will takes place of 1 —> 1 Page Fault
Now for the further page reference string —> 0 Page fault because they are already available in the
memory.