∑GateAndNet
PlannerSign Up
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 (99 page faults) and then click 4 Frames (1010 page faults!) on the classic reference string 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5, then switch to LRU (10→810 \to 8 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 RR:
    • If R=0R = 0: evict immediately!
    • If R=1R = 1: clear R←0R \leftarrow 0 (give a second chance) and advance the clock hand. (If all frames have R=1R = 1, Clock degenerates to pure FIFO!)
  • Thrashing & Working-Set Model Δ\Delta: Occurs when ∑iWSSi>D\sum_i \text{WSS}_i > D (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
St(m)⊆St(m+1)∀t,m  ⟹  Faults(m+1)≤Faults(m)S_t(m) \subseteq S_t(m + 1) \quad \forall t, m \implies \text{Faults}(m + 1) \le \text{Faults}(m)
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 33 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?

Previous TopicPage Replacement (FIFO, LRU, Optimal), Unix Inodes & Disk Arm SchedulingNext Topic OS 2027 Rank-Decider: Hardware CAS/TestAndSet, Priority Inversion, Copy-on-Write & File I/O