Facebook Pixel

Belady's Anomaly

There is a reasonable assumption most people make about memory management: give a process more physical frames to work with, and it will produce fewer page faults. More space means more pages can stay in RAM, which means fewer trips to the disk. This logic feels airtight.

Belady's Anomaly is the discovery that this assumption is completely wrong, at least for certain page replacement algorithms. Under specific conditions, handing a process extra frames actually causes MORE page faults. It is one of those counterintuitive results in computer science that genuinely surprises people.

What Exactly is Belady's Anomaly?

Named after László Bélády who documented it in 1969, the anomaly describes a situation where increasing the number of available physical page frames leads to a mathematical increase in page faults.

Algorithms known to exhibit this bizarre behavior include:

  • FIFO (First In First Out)
  • Random Page Replacement
  • Second Chance Page Replacement (Clock Algorithm)

A Normal Scenario

Normally, adding frames helps. Let's look at a standard reference string processed using FIFO to see how it usually works.

text
Reference string: 1, 2, 3, 1, 4, 2, 5, 1, 4, 2, 3, 5

Case 1: Three Frames

ReferenceMemory StatePage Fault
11Yes (1)
21, 2Yes (2)
31, 2, 3Yes (3)
11, 2, 3No
42, 3, 4Yes (4)
22, 3, 4No
53, 4, 5Yes (5)
14, 5, 1Yes (6)
44, 5, 1No
25, 1, 2Yes (7)
31, 2, 3Yes (8)
52, 3, 5Yes (9)

Total Page Faults with 3 frames = 9

Case 2: Four Frames

ReferenceMemory StatePage Fault
11Yes (1)
21, 2Yes (2)
31, 2, 3Yes (3)
11, 2, 3No
41, 2, 3, 4Yes (4)
21, 2, 3, 4No
52, 3, 4, 5Yes (5)
13, 4, 5, 1Yes (6)
43, 4, 5, 1No
24, 5, 1, 2Yes (7)
35, 1, 2, 3Yes (8)
55, 1, 2, 3No

Total Page Faults with 4 frames = 8

Adding a frame successfully reduced the faults from 9 to 8. But now let's look at a reference string that specifically triggers the anomaly.

The Anomaly Scenario

text
Reference string: 3, 2, 1, 0, 3, 2, 4, 3, 2, 1, 0, 4

Case 1: Three Frames

ReferenceMemory StatePage Fault
33Yes (1)
23, 2Yes (2)
13, 2, 1Yes (3)
02, 1, 0Yes (4)
31, 0, 3Yes (5)
20, 3, 2Yes (6)
43, 2, 4Yes (7)
33, 2, 4No
23, 2, 4No
12, 4, 1Yes (8)
04, 1, 0Yes (9)
44, 1, 0No

Total Page Faults with 3 frames = 9

Case 2: Four Frames

ReferenceMemory StatePage Fault
33Yes (1)
23, 2Yes (2)
13, 2, 1Yes (3)
03, 2, 1, 0Yes (4)
33, 2, 1, 0No
23, 2, 1, 0No
42, 1, 0, 4Yes (5)
31, 0, 4, 3Yes (6)
20, 4, 3, 2Yes (7)
14, 3, 2, 1Yes (8)
03, 2, 1, 0Yes (9)
42, 1, 0, 4Yes (10)
The Anomaly Confirmed
Going from 3 frames to 4 frames INCREASED the page faults from 9 to 10. The extra frame actually disrupted the eviction pattern in a way that caused pages needed later in the sequence to be pushed out earlier.

Why Does This Happen?

The root cause comes down to how FIFO makes its decisions. It evicts pages based purely on arrival order, completely ignoring whether a page is still being actively used. An old page that gets referenced constantly has absolutely no protection.

When you increase frames, the set of pages that happen to be in memory shifts in a different way, and certain reference patterns end up with worse coverage at key moments in the sequence.

The technical explanation involves the concept of stack algorithms versus non-stack algorithms.

The Stack Algorithm Property
A stack algorithm guarantees the following property: P(n) is a subset of P(n+1). In plain terms: every single page that fits in memory with n frames will ALSO be in memory when n+1 frames are available. Adding a frame never displaces a page that would have stayed with fewer frames.

FIFO violates this subset property. The pages present in memory with 3 frames are NOT necessarily a subset of the pages present with 4 frames. The addition of a frame completely reshuffles which pages get evicted and when.

Algorithms That Are Immune

LRU and Optimal are both stack algorithms. They satisfy the subset property, which mathematically guarantees they will NEVER exhibit Belady's Anomaly. More frames will always result in the same or fewer page faults, never more.

AlgorithmExhibits Belady's AnomalyType
FIFOYesNon-stack
RandomYesNon-stack
Second ChanceYesNon-stack
LRUNoStack
OptimalNoStack

Summary

Belady's Anomaly is not a constant problem that plagues FIFO every time. It shows up only with specific, rare reference patterns. Many real workloads run FIFO without ever triggering it.

The anomaly matters more as a conceptual warning: memory management has non-obvious consequences, and naive intuitions do not always hold true. When predictable behavior under increasing frames is required, a stack-based algorithm like LRU is the safer choice.

Sort the Concepts

Classify the following Page Replacement Algorithms based on whether they are immune to Belady's Anomaly.

Immune (Stack Algorithms)
Vulnerable (Non-Stack Algorithms)
Unsorted Items:
First-In-First-Out (FIFO)
Least Recently Used (LRU)
Optimal Page Replacement
Second Chance (Clock Algorithm)
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.