Understanding Belady's Anomaly in Operating Systems
In modern operating systems, virtual memory allows programs to execute even if they exceed physical RAM capacity . When a program references a page not currently mapped in RAM, a page fault is triggered . The operating system must then allocate one of the physical page frames to load that page from disk .
If all frames are occupied, a page replacement algorithm is invoked to select a "victim" page to evict .
Historically, computer scientists assumed that allocating more physical memory (more page frames) to a process would always decrease (or at least maintain) the number of page faults . However, in 1969, computer scientist László Bélády proved this assumption wrong . He demonstrated that under certain conditions and specific replacement algorithms, increasing the number of page frames can counterintuitively cause an increase in the number of page faults . This phenomenon is known as Belady's Anomaly (or the FIFO anomaly) .
Footnotes
-
Bélády's Anomaly - Wikipedia - Detailed historical context and mathematical properties of non-stack-based memory management. ↩ ↩2 ↩3 ↩4 ↩5 ↩6
-
Belady's Anomaly in OS: Why More Frames Mean More Faults - Unwired Learning guide detailing the history, affected algorithms, and the role of Laszlo Belady in 1969. ↩
-
BELADY'S ANOMALY : Explained - A comprehensive explanation of Belady's anomaly with the classic 3 vs 4 frame example. ↩
Belady's Anomaly in Operating Systems
The FIFO Pitfall
While FIFO is simple to implement using a queue, its lack of consideration for page access frequency or recency makes it highly susceptible to performance degradation and Belady's Anomaly .
Footnotes
-
BELADY'S ANOMALY : Explained - A comprehensive explanation of Belady's anomaly with the classic 3 vs 4 frame example. ↩
Tracing Belady's Anomaly (FIFO with 3 vs 4 Frames)
- 1Step 1
We will use the classic reference string: . We will trace the execution under the First-In-First-Out (FIFO) replacement policy for both and memory frames .
Footnotes
-
BELADY'S ANOMALY : Explained - A comprehensive explanation of Belady's anomaly with the classic 3 vs 4 frame example. ↩
-
- 2Step 2
With frames, the memory states evolve as follows:
- -> (Fault)
- -> (Fault)
- -> (Fault)
- -> (Fault, replaced)
- -> (Fault, replaced)
- -> (Fault, replaced)
- -> (Fault, replaced)
- -> (Hit)
- -> (Hit)
- -> (Fault, replaced)
- -> (Fault, replaced)
- -> (Hit)
Total Page Faults with 3 Frames = 9 .
Footnotes
-
Belady's Anomaly in OS - Testbook - Testbook educational article showing the mathematical proof and step-by-step trace of FIFO. ↩
- 3Step 3
With frames, the memory states evolve as follows:
- -> (Fault)
- -> (Fault)
- -> (Fault)
- -> (Fault)
- -> (Hit)
- -> (Hit)
- -> (Fault, replaced)
- -> (Fault, replaced)
- -> (Fault, replaced)
- -> (Fault, replaced)
- -> (Fault, replaced)
- -> (Fault, replaced)
Total Page Faults with 4 Frames = 10 .
Footnotes
-
Belady's Anomaly in OS - Testbook - Testbook educational article showing the mathematical proof and step-by-step trace of FIFO. ↩
- 4Step 4
Comparing the two scenarios, we observe that increasing the number of frames from to caused the total page faults to increase from to . This counterintuitive outcome is the exact manifestation of Belady's Anomaly .
Footnotes
-
BELADY'S ANOMALY : Explained - A comprehensive explanation of Belady's anomaly with the classic 3 vs 4 frame example. ↩
-
Page Faults vs. Frame Allocation
Comparison of page faults for FIFO with 3 vs 4 frames on the reference string 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
Stack Immunity
To completely eliminate Belady's Anomaly, design your virtual memory system to use stack algorithms like LRU or Optimal Page Replacement .
Footnotes
-
Belady's Anomaly Karim City College Document - Academic analysis of stack-based page replacement algorithms and the inclusion property. ↩
Non-Stack Algorithms (e.g., FIFO, Random)
- Definition: Do not satisfy the inclusion property .
- Belady's Anomaly: Susceptible. Increasing frames can increase page faults .
- Subset Rule: The set of pages in memory with frames is not guaranteed to be a subset of the pages in memory with frames .
- Example Trace: With , memory may contain , while with , memory contains . Here, .
Footnotes
-
Belady's Anomaly Karim City College Document - Academic analysis of stack-based page replacement algorithms and the inclusion property. ↩ ↩2 ↩3 ↩4
Deep Dive into Page Replacement Mechanics
Knowledge Check
Which of the following page replacement algorithms is susceptible to Belady's Anomaly?