Page Replacement Analysis: FIFO vs LRU for a 4-Frame Reference String
In virtual memory systems, a page replacement policy is invoked when a page fault occurs and all available page frames are occupied. The objective is to minimize faults, because each fault may require disk I/O and significantly slow execution.2
This section evaluates the reference string
for a main memory of 4 frames under two classic policies:
- FIFO
- LRU
We will compute the total number of page faults for each policy, compare them, and explain why one is better for this workload. In general, FIFO is simple but may evict pages that are still useful, while LRU attempts to exploit temporal locality by keeping recently referenced pages in memory longer.2
A key result of this analysis is that LRU produces fewer page faults than FIFO for the given string, so LRU is the better policy in this case.2
Footnotes
-
Page replacement algorithm - Wikipedia - Overview of page replacement, page faults, FIFO, and virtual memory concepts. ↩
-
Page replacement (CS 4410, Cornell) - Lecture notes explaining FIFO, LRU, temporal locality, and replacement trade-offs. ↩ ↩2 ↩3
-
Page Replacement in OS - Scaler Topics - Educational explanation of LRU and locality of reference. ↩
-
Day 20: Page Replacement Algorithms - Exploring Operating Systems - Discusses page-fault rate as a core metric for comparing replacement policies. ↩
FIFO vs Optimal vs LRU Page Replacement Algorithms Comparison with Example | Operating Systems
Final Answer in One Line
For 4 page frames and the reference string , LRU is better because it causes page faults, while FIFO causes page faults.2
Footnotes
-
Page replacement (CS 4410, Cornell) - Lecture notes explaining FIFO, LRU, temporal locality, and replacement trade-offs. ↩
-
Day 20: Page Replacement Algorithms - Exploring Operating Systems - Discusses page-fault rate as a core metric for comparing replacement policies. ↩
FIFO Simulation for 4 Frames
- 1Step 1
Start with 4 empty frames. The first distinct references must all cause page faults because nothing is loaded yet.
Footnotes
-
Page replacement algorithm - Wikipedia - Overview of page replacement, page faults, FIFO, and virtual memory concepts. ↩
-
- 2Step 2
References , , and each produce a fault. After that, memory contains . The second reference to and the next reference to are hits.
- 3Step 3
Reference causes a fault, giving memory . At this point, memory is full.
- 4Step 4
Reference is a hit, so FIFO order does not change. FIFO cares about arrival time, not recent use.
Footnotes
-
Page replacement (CS 4410, Cornell) - Lecture notes explaining FIFO, LRU, temporal locality, and replacement trade-offs. ↩
-
- 5Step 5
Reference is a fault. The oldest loaded page is , so FIFO evicts . Memory becomes .
- 6Step 6
Reference is a fault. The oldest remaining page is , so memory becomes .
- 7Step 7
Reference is a fault. The oldest remaining page is , so memory becomes .
- 8Step 8
Reference is now a fault because FIFO previously removed it. The oldest page is , so memory becomes .
- 9Step 9
Reference is a fault. FIFO removes , producing memory .
- 10Step 10
Reference is a fault. FIFO removes , producing memory . The final reference to is a hit. Total FIFO page faults: .
FIFO reference trace
The following table shows the state transition for FIFO. A hit means the page is already resident; a fault means a replacement may be needed once memory is full.2
| Step | Reference | Frames after reference | Result |
|---|---|---|---|
| 1 | 1 | [1, -, -, -] | Fault |
| 2 | 3 | [1, 3, -, -] | Fault |
| 3 | 4 | [1, 3, 4, -] | Fault |
| 4 | 4 | [1, 3, 4, -] | Hit |
| 5 | 3 | [1, 3, 4, -] | Hit |
| 6 | 2 | [1, 3, 4, 2] | Fault |
| 7 | 1 | [1, 3, 4, 2] | Hit |
| 8 | 7 | [7, 3, 4, 2] | Fault |
| 9 | 5 | [7, 5, 4, 2] | Fault |
| 10 | 6 | [7, 5, 6, 2] | Fault |
| 11 | 4 | [7, 5, 6, 4] | Fault |
| 12 | 2 | [2, 5, 6, 4] | Fault |
| 13 | 1 | [2, 1, 6, 4] | Fault |
| 14 | 2 | [2, 1, 6, 4] | Hit |
Therefore,
FIFO is easy to implement with a queue, but it may evict a page simply because it is old, even if it will be used again soon.2
Footnotes
-
Page replacement algorithm - Wikipedia - Overview of page replacement, page faults, FIFO, and virtual memory concepts. ↩
-
Day 20: Page Replacement Algorithms - Exploring Operating Systems - Discusses page-fault rate as a core metric for comparing replacement policies. ↩
-
Page replacement (CS 4410, Cornell) - Lecture notes explaining FIFO, LRU, temporal locality, and replacement trade-offs. ↩
-
Operating System - Belady's Anomaly - TutorialsPoint - Explains FIFO weakness and Belady's anomaly, contrasted with stack-based algorithms like LRU. ↩
LRU Simulation for 4 Frames
- 1Step 1
Start with 4 empty frames. As with FIFO, the first new pages must fault.
Footnotes
-
Page replacement algorithm - Wikipedia - Overview of page replacement, page faults, FIFO, and virtual memory concepts. ↩
-
- 2Step 2
The first three distinct references load these pages. The next references to and are hits, and they update recency information.
- 3Step 3
Reference faults and fills the fourth frame, giving the set .
- 4Step 4
Reference is a hit, but it becomes the most recently used page. This matters for future replacement.
- 5Step 5
The least recently used page among is , so LRU evicts and loads .
- 6Step 6
Among the current pages, is least recently used, so LRU replaces with .
- 7Step 7
Now is the least recently used, so LRU replaces with .
- 8Step 8
Reference faults, and is least recently used at that moment, so LRU replaces with .
- 9Step 9
Reference faults, and is the least recently used, so LRU replaces with .
- 10Step 10
Reference faults and replaces , which is least recently used. The final reference to is a hit. Total LRU page faults: .
LRU reference trace
LRU tries to preserve pages with recent access history, reflecting the common operating-system assumption that recent past usage predicts near-future usage reasonably well.2
| Step | Reference | Frames after reference | Result |
|---|---|---|---|
| 1 | 1 | [1, -, -, -] | Fault |
| 2 | 3 | [1, 3, -, -] | Fault |
| 3 | 4 | [1, 3, 4, -] | Fault |
| 4 | 4 | [1, 3, 4, -] | Hit |
| 5 | 3 | [1, 3, 4, -] | Hit |
| 6 | 2 | [1, 3, 4, 2] | Fault |
| 7 | 1 | [1, 3, 4, 2] | Hit |
| 8 | 7 | [1, 3, 7, 2] | Fault |
| 9 | 5 | [1, 5, 7, 2] | Fault |
| 10 | 6 | [1, 5, 7, 6] | Fault |
| 11 | 4 | [4, 5, 7, 6] | Fault |
| 12 | 2 | [4, 5, 2, 6] | Fault |
| 13 | 1 | [4, 1, 2, 6] | Fault |
| 14 | 2 | [4, 1, 2, 6] | Hit |
Hence,
Since
LRU is better than FIFO for this reference string.2
Footnotes
-
Page replacement (CS 4410, Cornell) - Lecture notes explaining FIFO, LRU, temporal locality, and replacement trade-offs. ↩ ↩2
-
Page Replacement in OS - Scaler Topics - Educational explanation of LRU and locality of reference. ↩
-
Day 20: Page Replacement Algorithms - Exploring Operating Systems - Discusses page-fault rate as a core metric for comparing replacement policies. ↩
Page Fault Comparison for the Given Reference String
Lower is better
Why LRU performs better here
The main reason is locality of reference.2 In the given sequence, some pages are reused after relatively short gaps, and LRU keeps pages that were used recently, whereas FIFO ignores recency and tracks only arrival order.
A particularly important moment occurs after the memory becomes full with pages . The next references are:
Under FIFO, when page arrives, it evicts page because was loaded earliest, even though page had just been used at the previous step. That is a poor eviction choice for this workload.2 LRU, in contrast, evicts page at that moment because is the least recently used among the resident pages, which is more consistent with the observed access pattern.2
This difference illustrates a broader principle:
- FIFO uses age in memory.
- LRU uses recent usage history.
For workloads with temporal locality, LRU often outperforms FIFO because recently used pages are more likely to be referenced again soon.3
Footnotes
-
Page replacement (CS 4410, Cornell) - Lecture notes explaining FIFO, LRU, temporal locality, and replacement trade-offs. ↩ ↩2 ↩3 ↩4 ↩5
-
Page Replacement in OS - Scaler Topics - Educational explanation of LRU and locality of reference. ↩ ↩2 ↩3
-
Operating System - Belady's Anomaly - TutorialsPoint - Explains FIFO weakness and Belady's anomaly, contrasted with stack-based algorithms like LRU. ↩
-
Chapter 9: Virtual Memory | UTC PDF - Course notes describing FIFO, LRU, page-fault comparisons, and why LRU often outperforms FIFO. ↩
Exam Strategy
When comparing FIFO and LRU on a reference string, do not guess from definitions alone. Build the frame table step by step and count faults exactly. Small differences, such as vs , determine the correct answer.
Common Conceptual Questions
With page frames and reference string , FIFO gives page faults while LRU gives . Therefore, LRU is better because it replaces the least recently used page, which better captures temporal locality in this sequence.2
Footnotes
-
Page replacement (CS 4410, Cornell) - Lecture notes explaining FIFO, LRU, temporal locality, and replacement trade-offs. ↩
-
Page Replacement in OS - Scaler Topics - Educational explanation of LRU and locality of reference. ↩
Reasoning Roadmap for Solving Page Replacement Questions
Identify Inputs
Step 1Extract the frame count and the full reference string."
Simulate FIFO
Step 2Track frame contents in arrival order and count every fault."
Simulate LRU
Step 3Track frame contents and update recency after each reference."
Compare Fault Totals
Step 4The policy with fewer faults is better for that string."
Explain the Cause
Step 5Relate the result to temporal locality and the replacement rule."
Common Mistake
Do not update FIFO order on a hit. In FIFO, only loading order matters. By contrast, LRU must update recency on every hit and every fault. Confusing these rules changes the answer.
Footnotes
-
Page replacement (CS 4410, Cornell) - Lecture notes explaining FIFO, LRU, temporal locality, and replacement trade-offs. ↩
Conclusion
For the given page-reference string and 4 available frames:
Therefore,
because LRU uses recent access history and better preserves pages that are likely to be reused soon, while FIFO may evict a recently useful page simply because it has been in memory longer.3
Footnotes
-
Page replacement (CS 4410, Cornell) - Lecture notes explaining FIFO, LRU, temporal locality, and replacement trade-offs. ↩
-
Page Replacement in OS - Scaler Topics - Educational explanation of LRU and locality of reference. ↩
-
Operating System - Belady's Anomaly - TutorialsPoint - Explains FIFO weakness and Belady's anomaly, contrasted with stack-based algorithms like LRU. ↩
Knowledge Check
For the reference string with frames, how many page faults occur under FIFO?
Explore Related Topics
Paging with Translation Lookaside Buffer (TLB) Scheme
Lexical Analysis and the Main Structure Used: Finite Automata
Lexical analysis relies on finite automata—typically deterministic finite automata (DFA)—to recognize token patterns defined by regular expressions.
- Regular expressions for identifiers, numbers, etc., are converted to NFAs then to a DFA for fast scanning.
- The DFA processes the source character by character, tracking a single current state and emitting a token at each accepting state.
- Queues, stacks, and trees support other compiler phases (parsing, AST construction) but are not the primary model for token recognition.
- Lexers output a stream of tokens that the parser consumes for syntax analysis.
Round Robin Scheduling Analysis for Five Processes with Time Quantum 3 ms
