Home▸Articles▸Distributed & Parallel Computing

Page Replacement Algorithms in 2D: Understanding LRU, FIFO & Optimal

Explore the intricacies of managing virtual memory with these fundamental algorithms.

mysimulator teamUpdated June 2026≈ 3 min read▶ Open the simulation

What Page Replacement Algorithms Are

Page replacement is a crucial aspect of virtual memory management in operating systems. It involves deciding which pages to evict from the main memory when new pages need to be loaded, aiming to minimize page faults and improve system performance.

The 2D simulator allows you to visualize these algorithms by running them over a reference string and observing how they handle page replacements.

Why It Matters

Efficient page replacement policies are essential for optimizing memory usage, reducing the number of page faults, and enhancing overall system performance. Poorly chosen algorithms can lead to increased overhead and decreased efficiency.

Understanding these algorithms helps in designing better operating systems and improving user experience by ensuring smooth application execution.

live demo · related simulation● LIVE

How LRU, FIFO & Optimal Work

The Least Recently Used (LRU) algorithm evicts the page that has not been used for the longest time. This policy assumes that pages not recently accessed are less likely to be needed soon.

First-In-First-Out (FIFO) replaces the oldest page in memory, regardless of its access pattern. It is simple but can lead to high page fault rates if the reference string exhibits a high degree of locality.

Optimal Page Replacement

The optimal algorithm always selects the page that will not be used for the longest time in the future. While it is theoretically perfect, it cannot be implemented in real systems due to its reliance on future information.

This simulator allows you to compare the performance of LRU and FIFO with the optimal policy, providing insights into their relative strengths and weaknesses.

Frequently asked questions

What is Bélády's anomaly?

Bélády's anomaly occurs when increasing the number of frames in memory actually increases the number of page faults. This counterintuitive phenomenon can be observed with certain reference strings and algorithms.

How does LRU compare to FIFO in practice?

LRU tends to perform better than FIFO, especially when there is a high degree of temporal locality in the reference string. However, both have their limitations and are not always optimal.

Why can't we use the optimal algorithm in real systems?

The optimal page replacement algorithm requires knowledge of future memory accesses, which is impossible to predict accurately in a real system. Therefore, it serves as a benchmark for evaluating other algorithms.

What does Bélády's anomaly preset button do?

The Bélády's anomaly preset button sets the reference string and number of frames to demonstrate this phenomenon, showing how increasing frame size can paradoxically increase page faults.

Try it live

Everything above runs in your browser — open Page Replacement 2D — LRU, FIFO & Optimal and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.

▶ Open Page Replacement 2D — LRU, FIFO & Optimal simulation

What did you find?

Add reproduction steps (optional)