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** [^4]. - 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** [^4]. - 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?
Explore Related Topics
Various Addressing Modes of 8051 Microcontroller
The 8051 microcontroller provides multiple addressing modes that define how an instruction identifies the location or value of its operand.
- Immediate (
#data) – constant value encoded in the instruction, used for loading fixed numbers. - Register (
Rn) – operand resides in CPU registers R0‑R7 (or A/B), giving the shortest and fastest code. - Direct (
addr) – 8‑bit address is part of the opcode, accessing internal RAM or SFRs directly. - Register indirect (
@R0,@R1,@DPTR) – a register holds the operand’s address, enabling pointer‑like traversal of memory. - Indexed (
@A+DPTRor@A+PC) – adds the accumulator to DPTR or PC for table look‑ups in code memory; branch modes (relative, absolute, long) extend this concept for short, page‑limited, and full‑range jumps.
Inverted Page Table
The Banker's Algorithm: Deadlock Avoidance in Operating Systems
The Banker's Algorithm is a deadlock‑avoidance method that keeps a system in a safe state by checking each resource request against the maximum declared needs of processes.
- Maintains Available, Max, Allocation, and Need matrices, where .
- The Safety Algorithm uses vectors Work and Finish to find an execution order; if all processes finish, the state is safe.
- The Resource‑Request Algorithm simulates allocation, runs the safety check, and commits only if the resulting state remains safe.
- Time complexity of the safety check is .
- In practice the algorithm is rarely used because processes must predeclare maximum needs and the algorithm’s overhead is high.
