Skip to content
We areTOP 1%

Compare FIFO, LRU and Optimal page replacement.

MediumConceptPage Replacement & Thrashing
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews

Answer

When a page fault occurs and no frame is free, the OS must evict (remove) a page from RAM. The page-replacement algorithm chooses which one.

  • FIFO (First-In, First-Out): evict the page that has been in memory the longest. It is simple (a queue), but it may evict a heavily used page, and it suffers from Belady's anomaly.
  • LRU (Least Recently Used): evict the page that has not been used for the longest time, using the recent past to predict the future. It performs close to optimal but is costly to track exactly on every memory access.
  • Optimal (OPT): evict the page that will not be used for the longest time in the future. It gives the fewest possible faults but needs knowledge of the future, so it serves only as a benchmark.

Example: reference string 7, 0, 1, 2, 0, 3, 0, 4, 2, 3 with 3 empty frames. The first four references fault in every algorithm (7, 0 and 1 fill the frames, and 2 evicts 7).

AlgorithmFaultsKey decision
FIFO9on 3, evicts 0 (the oldest), which is needed immediately
LRU8on 3, evicts 1 and keeps the recently used 0
Optimal6on 4, evicts 0, which is never used again

More in Page Replacement & Thrashing

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account