INTERMEDIATEFrequently Tested 4 min read 6 views
Page Replacement Logics (Animated): Belady’s Anomaly in FIFO vs LRU & Optimal Stack Property
Interactive frame-by-frame proof of Belady’s Anomaly (9 faults with 3 frames vs 10 faults with 4 frames under FIFO!), Mattson’s Stack Inclusion Property, Second-Chance Clock, and Working-Set Thrashing.
1. Interactive Belady’s Anomaly Animator (Switch FIFO 3 Frames vs 4 Frames!)
Run FIFO with 3 Frames ( page faults) and then click 4 Frames ( page faults!) on the classic reference string 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5, then switch to LRU ( faults) to see why stack algorithms never suffer from Belady’s Anomaly:
Interactive Step-by-Step Animation
OS Page Replacement (LRU vs FIFO)
Belady Anomaly DemoSpace: 3 vs 4 Page FramesGATE OS Paging Classic
Reference String (Belady Test):Page Faults: 1 • Hits: 0
123412512345
Physical RAM Frames:
F1
1
F2
—
F3
—
Step 1: Cold Page 1 FAULT ⇒ loaded into free frame (Total Faults = 1).
1 / 12
2. Why LRU Needs Hardware Assistance & Clock (Second-Chance) Approximation
- Exact LRU Implementation: Requires either a 64-bit hardware timestamp counter updated on every memory reference or a doubly-linked stack of frame numbers — too expensive for software interrupts on hits!
- Clock (Second-Chance) Algorithm: Arranges frames in a circular buffer with a 1-bit hardware Reference Bit :
- If : evict immediately!
- If : clear (give a second chance) and advance the clock hand. (If all frames have , Clock degenerates to pure FIFO!)
- Thrashing & Working-Set Model : Occurs when (sum of active locality working sets exceeds total RAM frames), causing CPU utilization to plummet as the OS scheduler mistakenly adds even more degree of multiprogramming!
Key Formulas Summary
Mattson’s Stack (Inclusion) Property — Guarantees ZERO Belady’s Anomaly
Note: LRU, Optimal (MIN), and LFU satisfy stack inclusion; FIFO does NOT!
#Operating Systems#Page Replacement#Belady Anomaly#FIFO#LRU#Optimal#Thrashing#GATE CS
Practice Questions on This Chapter (1)
Q1GATE CS 2022NATMEDIUM
+2M • 0 Neg
Consider a system with initially empty page frames and page reference string 1, 2, 3, 4, 2, 1, 5, 3, 2, 4, 6. How many page faults occur under Optimal (MIN) page replacement?