Page replacement is an important part of virtual memory management in an operating system. When a process requests a page that is not currently available in physical memory, a page fault occurs. If all available page frames are already occupied, the operating system must decide which existing page should be removed so that the required page can be loaded.
The method used to select the page that will be removed is called a page replacement algorithm. Different algorithms make this decision using different information such as the order in which pages entered memory, their recent usage, or their expected future usage.
Page Replacement Algorithm is a technique used by an operating system to select a page for removal from physical memory when a new page must be loaded and all available frames are occupied.
A page fault occurs when a process references a page that is not currently present in its allocated physical memory frames. The operating system must then locate the required page in secondary storage, bring it into RAM, and update the necessary memory-management information.
If an empty frame is available, the required page can be loaded directly. If no free frame exists, a page replacement algorithm is required to select a victim page for removal.
A page hit occurs when the requested page is already present in one of the available page frames. Since the page is already in physical memory, the operating system does not need to fetch it from secondary storage.
Page Hit = Requested page is already in memory.
Page Fault = Requested page is not in memory.
Physical memory is limited, while a process may reference more pages than can fit into the currently available frames. Therefore, when all frames are occupied and a new page is required, the operating system needs a systematic method for deciding which page should leave memory.
| Term | Meaning |
|---|---|
| Page | A fixed-size unit of a process's virtual address space. |
| Frame | A fixed-size block of physical memory that can hold a page. |
| Reference String | The sequence in which pages are requested by a process. |
| Page Hit | The requested page is already present in memory. |
| Page Fault | The requested page is absent from physical memory. |
| Victim Page | The page selected for removal when a replacement is required. |
Several page replacement algorithms have been proposed to make replacement decisions. The most commonly studied algorithms in operating-system courses are:
FIFO stands for First In First Out. It replaces the page that has been present in memory for the longest time. The algorithm follows the same basic principle as a queue: the page that entered first is considered for removal first.
Figure: FIFO Page Replacement Example
Consider the following page reference string with three available frames.
The first three different pages can occupy the three available frames. When page 2 is requested, all frames are occupied, so FIFO removes page 7 because it was the first page loaded into memory.
The same procedure continues for every subsequent page reference. Whenever the requested page is already present, the event is counted as a hit. Otherwise, a page fault occurs and FIFO replaces the oldest resident page.
Page fault rate is calculated using the total number of page references, not the number of page frames.
Correct Formula: Page Fault Rate = Page Faults / Total Page References × 100
FIFO removes the page that entered memory first. Do not confuse oldest page with least recently used page. These are different concepts.
LRU stands for Least Recently Used. Instead of looking at the arrival order of pages, LRU considers their recent access history. When replacement becomes necessary, it removes the page that has not been used for the longest period of time.
Figure: LRU Page Replacement Example
During execution, every page reference is checked against the four available frames. If the requested page is already present, the reference is a hit. Otherwise, a page fault occurs.
Once all four frames are occupied, LRU examines the previous access history. The page that has remained unused for the longest time is selected as the victim.
LRU does not remove the oldest page merely because it arrived first. It removes the page whose most recent use is farthest in the past.
The Optimal Page Replacement Algorithm, also known as OPT or MIN, replaces the page whose next use occurs farthest in the future.
If a page will never be referenced again, it becomes an ideal candidate for replacement. Because the algorithm assumes knowledge of future references, it provides a theoretical lower bound on the number of page faults for a particular reference string and number of frames.
Figure: Optimal Page Replacement Example
When all four frames are occupied and a new page is required, the algorithm looks ahead in the reference string. It determines which currently resident page will be required farthest in the future and replaces that page.
An actual operating system cannot normally know the exact future page references of a running program. Therefore, Optimal replacement is mainly used as a theoretical benchmark for comparing other algorithms.
MRU stands for Most Recently Used. It follows a strategy opposite to LRU in one important respect. When replacement is required, MRU selects the page that was accessed most recently.
This approach may be useful for workloads where recently accessed pages are less likely to be referenced again immediately. However, it is not generally the default choice for every workload.
Figure: MRU Page Replacement Example
The reference string contains 20 page requests. Using the MRU replacement rule, a page fault occurs whenever the requested page is not in memory. Once the frames become full, the most recently accessed resident page is selected for replacement.
MRU should not be considered universally better or worse than LRU. Its usefulness depends on the access pattern of the application. The main distinction is simple: LRU removes the least recently accessed page, whereas MRU removes the most recently accessed page.
Page fault rate and page hit rate are useful measures for analyzing the behavior of a page replacement algorithm. They must be calculated with respect to the total number of page references.
Do not calculate page fault rate as Page Faults / Number of Frames. The number of frames describes the memory configuration, while the rate describes how many references resulted in faults.
| Algorithm | Replacement Basis | Future Knowledge Required? | Main Advantage | Main Limitation |
|---|---|---|---|---|
| FIFO | Oldest loaded page | No | Simple implementation | May remove frequently used pages |
| LRU | Least recently used page | No | Uses recent access behavior | Requires usage tracking |
| Optimal | Page used farthest in future | Yes | Minimum theoretical page faults | Future references are not known in practice |
| MRU | Most recently used page | No | Useful for selected access patterns | Can perform poorly for common locality patterns |
The main difference between these algorithms is the information used to select the victim page.
A page fault can involve accessing secondary storage, which is considerably slower than accessing RAM. Therefore, excessive page faults can increase the time required to satisfy memory references.
A good replacement strategy attempts to keep useful pages in memory and avoid unnecessary transfers. However, the best algorithm depends on the characteristics of the workload, available hardware support, implementation cost, and access pattern.
Fewer page faults generally mean fewer expensive page transfers, but the replacement algorithm itself may introduce computational or hardware overhead. Therefore, algorithm selection is a trade-off rather than a single universal rule.
Belady's Anomaly is a well-known phenomenon associated with some page replacement strategies, particularly FIFO. It describes a situation where increasing the number of available page frames can unexpectedly increase the number of page faults for a particular reference string.
This result may seem counterintuitive because more frames normally appear to provide more room for pages. The phenomenon demonstrates that the behavior of a replacement algorithm depends on its replacement policy and the reference pattern.
Remember the association: FIFO → Belady's Anomaly.
Programs often exhibit locality of reference, meaning that a process tends to access a relatively small group of pages repeatedly during a particular period.
Temporal locality means that recently used data or instructions are likely to be used again soon. Spatial locality means that addresses near a recently accessed location may also be accessed.
LRU is particularly connected with temporal locality because it attempts to retain pages that have been accessed recently.
FIFO: Replaces the page that entered memory earliest. It is simple and queue based.
LRU: Replaces the page that has not been used for the longest period.
Optimal: Replaces the page whose next use is farthest in the future. It gives the theoretical minimum number of page faults.
MRU: Replaces the page that was accessed most recently.
Page Fault Rate: Page Faults divided by total page references, multiplied by 100.
Page Hit Rate: Page Hits divided by total page references, multiplied by 100.
It is a method used by an operating system to select a page for removal when a new page must be loaded and all available frames are occupied.
A page fault occurs when a requested page is not currently present in physical memory.
A page hit occurs when the requested page is already present in a physical memory frame.
FIFO replaces the page that entered memory first among the currently resident pages.
LRU replaces the page that has not been accessed for the longest period.
Because, when the complete future reference sequence is known, it can select replacements that produce the minimum possible number of page faults.
Exact Optimal replacement is generally impractical because the operating system does not know the complete future reference sequence of a process.
Page Fault Rate = (Page Faults / Total Page References) × 100.
FIFO is the standard example associated with Belady's Anomaly.
LRU often performs well for workloads with strong temporal locality, but no replacement strategy should be assumed to be universally optimal for every workload.
A reference string contains 25 page requests. An algorithm produces 10 page faults. Calculate the page fault rate and page hit rate.
Three frames contain pages A, B and C in that order. A new page D arrives and memory is full. Which page will FIFO replace?
Four pages are currently present in memory. Page A was accessed 10 references ago, B was accessed 5 references ago, C was accessed 2 references ago and D was accessed 1 reference ago. Which page would LRU select for replacement?
A page reference sequence contains 30 references. If 9 references result in page faults, determine the number of page hits and both rates.
Page replacement algorithms are an essential component of virtual memory management because physical memory cannot hold every page that a process may need during execution. Whenever a requested page is absent and no free frame is available, the operating system must select a resident page for replacement.
FIFO makes this decision using the arrival order of pages. LRU uses recent access history, while Optimal examines future references and therefore serves as an ideal theoretical benchmark. MRU uses the opposite principle of LRU by selecting the most recently accessed page.
For numerical questions, students should carefully distinguish between a page fault and a page hit, correctly maintain the contents of each frame, and use the total number of page references when calculating page fault or hit rates. Understanding these fundamentals makes problems involving FIFO, LRU, Optimal and MRU much easier to solve.