Belady’s anomaly

On this page 7

Belady’s anomaly is the phenomenon in which increasing the number of page frames allocated to a process increases the number of page faults for the same sequence of memory references. It is a classic result in operating systems memory management, because it contradicts the natural assumption that more physical memory always means fewer trips to secondary storage.

The anomaly was described in 1969 by László Bélády, together with R. A. Nelson and G. S. Shedler, while studying paging behavior on experimental IBM hardware. It occurs with first-in, first-out (FIFO) replacement and several related policies, and it never occurs with the class of policies known as stack algorithms, which includes LRU and the optimal algorithm.

How Belady’s anomaly arises under FIFO replacement

Belady’s anomaly arises because FIFO evicts pages by arrival time, not by usefulness. When a page fault occurs and every frame is occupied, FIFO removes the page that has been resident the longest, even if that page is about to be referenced again.

With a different number of frames, the queue of resident pages evolves differently. A larger memory can keep an old page long enough that it becomes the eviction victim at exactly the wrong moment, while a smaller memory would already have replaced it and reloaded it at a convenient time. The result is that the set of resident pages with n frames is not necessarily a subset of the set resident with n + 1 frames.

The standard demonstration uses the reference string 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5. The table below counts page faults for that string under three policies, assuming every frame starts empty.

Policy3 frames4 framesAnomaly present
FIFO9 faults10 faultsYes
LRU10 faults8 faultsNo
Optimal (OPT)7 faults6 faultsNo
Page faults for the classic reference string

Under FIFO with four frames, the reference to page 5 evicts page 1, and the following references to 1, 2, 3, 4 and 5 then fault one after another in a cascade of misses. With three frames, pages 1 and 2 happen to be resident at the right time and produce two hits.

Why stack algorithms are immune

A replacement policy is a stack algorithm when it satisfies the inclusion property: for every point in any reference string, the pages resident with n frames are always a subset of the pages resident with n + 1 frames. Mattson and colleagues formalized this property in 1970.

If the inclusion property holds, any reference that hits with n frames must also hit with more frames, so the fault count can only fall or stay the same as memory grows. LRU satisfies it because it ranks pages by recency, a ranking that does not depend on the number of frames. OPT satisfies it because it ranks pages by the distance to their next use, which is equally independent of memory size.

The following table summarizes how common replacement policies relate to the anomaly.

PolicyRanking criterionStack algorithmCan show the anomaly
FIFOLoad timeNoYes
Second chance and ClockLoad time plus reference bitNoYes
RandomNoneNoYes, on some runs
LRUTime of last useYesNo
LFU with consistent tie-breakingReference countYesNo
Optimal (OPT)Time of next useYesNo
Replacement policies and susceptibility

Clock-based algorithms deserve attention because they are widely deployed. When every reference bit is set, Clock degenerates into FIFO, so it inherits the same theoretical exposure, although real workloads rarely trigger a measurable effect.

Relation to neighboring memory management concepts

Belady’s anomaly is a property of a page replacement algorithm, not of the hardware. It concerns how many page faults a policy produces as the allocation changes, so it connects to several neighboring ideas in virtual memory without being the same thing.

ConceptWhat it describesConnection to the anomaly
ThrashingSystem spends most time servicing faultsThe anomaly can add faults but does not by itself cause thrashing
Working setPages a process actively uses in a time windowAllocating at least the working set reduces faults for any sane policy
Demand pagingPages load only on first referenceThe anomaly is measured under demand paging
Optimal algorithmTheoretical lower bound on faultsShares the name of Bélády, who also defined OPT
How the anomaly differs from related concepts

The name association causes confusion: the optimal replacement algorithm is often called Bélády’s algorithm, and it is precisely the policy that cannot exhibit Belady’s anomaly. The two concepts come from the same researcher but describe opposite ends of the design space.

Practical significance for operating system design

In practice, Belady’s anomaly matters less for its magnitude than for what it proves about predictability. A policy without the inclusion property makes capacity planning unreliable, because adding RAM or raising a process memory limit is not guaranteed to help that process.

Modern kernels rarely use pure FIFO. Linux relies on approximations of LRU with active and inactive lists and, in recent versions, the multi-generational LRU framework. Windows manages per-process working sets with aging, and BSD systems use Clock variants. These designs aim to keep the benefits of recency without the cost of exact LRU bookkeeping on every memory access.

The following decision table shows how designers typically weigh the anomaly against implementation cost.

SituationTypical choiceReason
General-purpose kernelLRU approximationGood hit rate at low overhead
Teaching or simulationFIFO and OPT side by sideShows the anomaly and the lower bound
Small embedded cacheFIFO or RandomMinimal hardware state
Database buffer poolLRU-K or Clock variantsResists sequential scan pollution
Choosing a policy with the anomaly in mind

Limitations and common misconceptions

Several misunderstandings surround Belady’s anomaly, and they usually stem from overgeneralizing a single textbook example.

  • It is not universal for FIFO. Most reference strings do not trigger it; the anomaly requires specific reference patterns.
  • It is not limited to one extra fault. Later research showed that the ratio of FIFO faults between larger and smaller memories has no fixed upper bound for constructed reference strings.
  • It does not mean more RAM is harmful. In real workloads, larger memory almost always lowers the fault rate, even under FIFO-like policies.
  • Exact LRU is not the cure in practice. It is immune but too expensive to implement precisely, so kernels accept approximations that may lose strict inclusion.

A further limitation is that the anomaly is defined for a fixed reference string. Real processes change behavior with memory size, for example through caching decisions in user space, so measured effects in production are noisy and hard to attribute.

The idea in brief

Imagine a small shelf for books you are reading. When the shelf is full, you remove the book that has been there longest. A bigger shelf should mean fewer trips to the library.

Belady’s anomaly shows that this is not always true. With the oldest-out rule, a bigger shelf can sometimes keep the wrong books. You then make more trips, not fewer. Smarter rules, such as removing the book you used least recently, never have this problem.

A practical scenario

An operating systems course asks students to build a paging simulator. A student runs the reference string 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 with FIFO replacement. Three frames produce 9 page faults. Raising the limit to four frames produces 10 faults, and the student first suspects a bug.

The instructor asks for the same run with LRU and OPT. LRU drops from 10 to 8 faults, and OPT drops from 7 to 6. The comparison shows that the simulator is correct. The extra fault comes from FIFO itself, because its eviction order ignores how pages are used.

The student then adds a check of the inclusion property after every reference. Under FIFO, the check fails at the reference to page 5 with four frames. Under LRU, it never fails. The exercise turns the anomaly into a concrete test of whether a policy is a stack algorithm.