Skip to content
About
Main content

LRU and its two failure modes

Why does LRU wipe the working set on a scan and score zero on a loop, while random replacement degrades smoothly?

LRU, and the correction it deserves

LRU (Least Recently Used) bets that the reference stream has temporal locality of a particular shape: that recency predicts imminence. On workloads with that shape the bet is close to optimal. It has two failure modes, and both are structural, not unlucky.

Failure 1: sequential flooding

A scan of a table larger than the pool touches every page exactly once. Under each scanned page is the most recently used at the moment it arrives. So the scan evicts the entire to cache pages that it will never look at again. The afterwards is zero until the working set is read back in. This is not a rare pathology. It is what analytics workloads do all day. (This was Amara's 10:00 am scan.)

Failure 2: cyclic access, where LRU is not only bad but bimodal

Take a loop over n pages with a pool of c < n frames. When you reference page pᵢ, the pool holds the c most recent pages. But pᵢ was last referenced n steps ago, so it has been evicted. The hit rate is exactly zero for every c from 1 to n − 1, and then jumps to 100% at c = n. A cliff with nothing on it.

Worked trace. Pages 1–5 are read in a loop; the pool has 4 frames.

ReferencePool beforeResultEvicts (LRU)
1, 2, 3, 4(filling)4 misses—
5{1,2,3,4}miss1
1{2,3,4,5}miss2
2{3,4,5,1}miss3
3{4,5,1,2}miss4
4{5,1,2,3}miss5

Every reference after the first four is a miss, forever, although 4 of the 5 pages would fit.

Random replacement degrades smoothly

Random replacement on the same loop behaves differently. A page survives each eviction with probability (1 − 1/c). Between two references to the same page there are about n(1 − h) misses (where h is the hit rate). So the steady-state hit rate is the fixed point of

pages in the loop
frames in the pool
the steady-state hit rate (a fixed point)
random replacementLRU
Data table
Hit rate on a loop larger than the pool, by pool size
Pool ÷ loop c/nseriesHit rate
0.1random replacement0
0.114random replacement0
0.128random replacement0
0.141random replacement0.001
0.155random replacement0.002
0.169random replacement0.003
0.182random replacement0.004
0.196random replacement0.006
0.21random replacement0.009
0.224random replacement0.012
0.237random replacement0.016
0.251random replacement0.02
0.265random replacement0.025
0.279random replacement0.031
0.292random replacement0.037
0.306random replacement0.044
0.32random replacement0.052
0.334random replacement0.06
0.347random replacement0.069
0.361random replacement0.078
0.375random replacement0.088
0.389random replacement0.098
0.402random replacement0.109
0.416random replacement0.121
0.43random replacement0.133
0.444random replacement0.146
0.458random replacement0.159
0.471random replacement0.173
0.485random replacement0.187
0.499random replacement0.202
0.512random replacement0.217
0.526random replacement0.233
0.54random replacement0.249
0.554random replacement0.265
0.568random replacement0.282
0.581random replacement0.3
0.595random replacement0.318
0.609random replacement0.336
0.622random replacement0.355
0.636random replacement0.374
0.65random replacement0.393
0.664random replacement0.413
0.677random replacement0.433
0.691random replacement0.454
0.705random replacement0.475
0.719random replacement0.496
0.732random replacement0.518
0.746random replacement0.54
0.76random replacement0.562
0.774random replacement0.585
0.787random replacement0.607
0.801random replacement0.631
0.815random replacement0.654
0.829random replacement0.678
0.842random replacement0.702
0.856random replacement0.727
0.87random replacement0.752
0.884random replacement0.777
0.897random replacement0.802
0.911random replacement0.828
0.925random replacement0.854
0.939random replacement0.88
0.952random replacement0.907
0.966random replacement0.933
0.98random replacement0.96
0.994random replacement0.985
1.01random replacement0.998
1.02random replacement1
1.03random replacement1
1.05random replacement1
1.06random replacement1
1.08random replacement1
1.09random replacement1
1.1random replacement1
1.12random replacement1
1.13random replacement1
1.15random replacement1
1.16random replacement1
1.17random replacement1
1.19random replacement1
1.2random replacement1
0.1LRU0
0.114LRU0
0.128LRU0
0.141LRU0
0.155LRU0
0.169LRU0
0.182LRU0
0.196LRU0
0.21LRU0
0.224LRU0
0.237LRU0
0.251LRU0
0.265LRU0
0.279LRU0
0.292LRU0
0.306LRU0
0.32LRU0
0.334LRU0
0.347LRU0
0.361LRU0
0.375LRU0
0.389LRU0
0.402LRU0
0.416LRU0
0.43LRU0
0.444LRU0
0.458LRU0
0.471LRU0
0.485LRU0
0.499LRU0
0.512LRU0
0.526LRU0
0.54LRU0
0.554LRU0
0.568LRU0
0.581LRU0
0.595LRU0
0.609LRU0
0.622LRU0
0.636LRU0
0.65LRU0
0.664LRU0
0.677LRU0
0.691LRU0
0.705LRU0
0.719LRU0
0.732LRU0
0.746LRU0
0.76LRU0
0.774LRU0
0.787LRU0
0.801LRU0
0.815LRU0
0.829LRU0
0.842LRU0
0.856LRU0
0.87LRU0
0.884LRU0
0.897LRU0
0.911LRU0
0.925LRU0
0.939LRU0
0.952LRU0
0.966LRU0
0.98LRU0
0.994LRU0
1.01LRU1
1.02LRU1
1.03LRU1
1.05LRU1
1.06LRU1
1.08LRU1
1.09LRU1
1.1LRU1
1.12LRU1
1.13LRU1
1.15LRU1
1.16LRU1
1.17LRU1
1.19LRU1
1.2LRU1

The shape matters more than the value: , and both are poor when c ≪ n.

The general statement to keep: LRU is not a conservative default. It is a bet on a specific access shape, and its failure is a cliff rather than a slope. This contrast between graceful and is the "variance matters more than the mean" idea in a new setting. You will meet the identical shape again in Degradation, where a spilling behaves the same way for the same structural reason.

One-line compression: LRU turns a scan into a working-set wipe and a cycle into a zero, because "most recent" and "most useful" coincide only for one shape of workload.