Belady's Anomaly and Stack Algorithms
Belady’s anomaly
Belady’s anomaly is the counter-intuitive phenomenon where increasing the number of available frames can increase the number of page faults — for a given reference string and a given algorithm.
FIFO is the classic example. Consider the reference string 1 2 3 4 1 2 5 1 2 3 4 5:
- With 3 frames: 9 page faults.
- With 4 frames: 10 page faults — more frames, more faults.
The anomaly occurs because FIFO’s eviction decision depends only on load order, not on recency of use. Adding a frame changes load order in ways that can cause a just-evicted page to be demanded again immediately on the next reference.
Stack algorithms
A page-replacement algorithm is a stack algorithm if the set of pages in memory with frames is always a subset of the set of pages in memory with frames (subject to the same reference string).
Stack algorithms are immune to Belady’s anomaly: adding frames can only reduce or keep the same the number of page faults, never increase them.
LRU is a stack algorithm. The set of pages in memory with frames under LRU is always the most-recently-used pages. The most-recently-used pages strictly contain the most-recently-used pages.
OPT is a stack algorithm. With frames, OPT keeps the pages whose next use is farthest in the future. With frames, OPT adds one more page (whose next use is nearer than the farthest among the ). The set is always a subset of the set — they differ by exactly the one additional page, or are identical if the extra frame is never needed.
FIFO is NOT a stack algorithm. The set of pages in memory depends on load order, which changes when the number of frames changes. A page may be in memory with 3 frames but absent with 4 frames at the same point in the reference string.
Proof sketch: LRU is a stack algorithm
Define as the set of pages in memory with frames after reference . Under LRU:
- = the most-recently-referenced distinct pages after reference .
- If a page is among the most-recently-referenced, it is necessarily among the most-recently-referenced (since the ordering is the same, and ).
- Therefore for all .
This subset property implies the inclusion property: a page fault with frames implies a page fault with frames. The number of page faults with frames ≤ the number with frames.
Why this matters for the Tripos
The question typically asks:
- State Belady’s anomaly and give an example (FIFO with 3 vs 4 frames on a reference string).
- Explain why OPT and LRU do not exhibit it (they are stack algorithms). Show the subset argument for LRU.
- Explain why FIFO can (eviction depends on load order, not recency; changing frame count changes the set composition in non-monotonic ways).
Summary
- Belady’s anomaly: more frames → more faults. Counter-intuitive and pathological.
- Stack algorithms satisfy , guaranteeing no Belady’s anomaly.
- LRU and OPT are stack algorithms; FIFO is not.
- The subset property directly implies the monotonicity property (more frames never increase faults).