Maps to: CMU 15-440/640 Spring 2026, learning outcome “cache quality metrics” (Part II, caching). Readings (optional, course list):
- N. Megiddo and D. S. Modha, Outperforming LRU with an Adaptive Replacement Cache Algorithm (IEEE Computer, April 2004);
- J. Yang, Z. Qiu, Y. Zhang, Y. Yue and K. V. Rashmi, FIFO can be Better than LRU: the Power of Lazy Promotion and Quick Demotion (HotOS 2023);
- J. Yang, Y. Zhang, Z. Qiu, Y. Yue and K. V. Rashmi, FIFO Queues are All You Need for Cache Eviction (SOSP 2023; S3-FIFO).
Project: P2’s proxy must evict whole files of different sizes under a byte limit using LRU. §6 explains what changes when objects have sizes; it does not design the proxy. Problem set: PS2 has replacement questions; the scenarios and numbers here are different. Sources: the readings above. Background:
- L. A. Belady, A Study of Replacement Algorithms for a Virtual-Storage Computer (IBM Systems Journal 1966);
- R. L. Mattson et al., Evaluation Techniques for Storage Hierarchies (IBM Systems Journal 1970);
- F. J. Corbató, A Paging Experiment with the Multics System (1968; CLOCK);
- D. Sleator and R. Tarjan, Amortized Efficiency of List Update and Paging Rules (CACM 1985);
- P. Cao and S. Irani, Cost-Aware WWW Proxy Caching Algorithms (USITS 1997; GreedyDual-Size);
- L. Cherkasova, Improving WWW Proxies Performance with Greedy-Dual-Size-Frequency Caching Policy (HP Labs 1998).
The slides are not public; this is not a transcript. Numbers from papers are labelled as such. Every other number comes from
code/lecture08/, run on the author’s machine (Apple M4 Pro, macOS, Python 3.13 and 3.9). Code:code/lecture08/. Reading time: ~85 minutes, plus ~10 to run the demos.
0. How to read this lecture
0.1 Learning goals
After this lecture you should be able to:
- Explain Belady’s MIN, prove (informally) why it is optimal, and use it as the yardstick for any policy.
- Predict how FIFO, Random, LRU, CLOCK and LFU behave on popularity-driven, phased, looping and scanning workloads, and explain each failure from what the policy bets on.
- Explain Belady’s anomaly, the inclusion property and stack algorithms, and why they matter for measuring caches.
- Describe ARC’s four lists and its learning rule, and say what “adaptive” buys and costs.
- Explain lazy promotion and quick demotion, why one-hit wonders dominate caches, and how S3-FIFO is built from three FIFO queues.
- Reason about variable-sized objects: object vs byte hit ratio, why MIN stops being optimal, GreedyDual-Size(-Frequency), and admission control.
- Weigh a policy’s miss ratio against its implementation cost: metadata, work per hit, and locks.
0.2 Prerequisites and scope
- Prerequisites:
- Lecture 6: hit ratio, Zipf popularity, loops and scans, stack distances and miss-ratio curves;
- Lecture 7: what makes a cached copy valid. This lecture assumes every cached copy is valid and only asks which one to keep.
- Scope: one cache, one replacement decision. Prefetching (bringing things in before they are asked for) is Lecture 9. Caches spread over many machines, and how keys are mapped to them, return in Lecture 25.
0.3 Section → code map
| Section | Idea | Demo in code/lecture08/ |
|---|---|---|
| §2 | Belady’s MIN; optimality checked exhaustively | 01_belady_min.py Parts A–B |
| §3 | FIFO, Random, LRU, CLOCK, LFU; loops, scans, phases | 02_classic_policies.py |
| §3.5 | Belady’s anomaly, inclusion, stack algorithms | 01_belady_min.py Part C |
| §4 | ARC: adaptive recency/frequency | 03_arc.py |
| §5 | lazy promotion, quick demotion, S3-FIFO | 04_lazy_promotion_quick_demotion.py |
| §6 | variable sizes, size-aware policies, admission | 05_variable_sizes.py |
| all | eleven policies behind one interface | replacement.py (python3 replacement.py runs its self-test) |
0.4 Notation
- = cache capacity (objects, or bytes in §6). A reference string (or trace) is the sequence of requested keys.
- Miss ratio = misses / requests (lower is better). The papers on S3-FIFO report miss ratios; the ARC paper reports hit ratios (= 1 − miss ratio).
- Workloads (Lecture 6’s
cachelab.py, plus this lecture’sreplacement.py):- zipf: independent requests, Zipf(0.8) popularity over 2,000 items;
- loop: a program cycling over items;
- phases: a hot set of 400 items that moves to new items every 20,000 requests;
- zipf+scan: Zipf with a one-time scan of new items every few thousand requests;
- web: objects that appear, are requested for a while, and fade. 60% of them are requested exactly once. “Life” is the mean delay of the later requests (in units where one new object appears per unit).
1. The problem
1.1 The intuition
Your desk holds ten books; the library holds a million. When you need an eleventh, one book must go back to the shelf. Which one? You would like to return the book you will not need for the longest time. You do not know the future, so you guess from the past. Maybe the book you have not opened for the longest time (recency). Maybe the one you open least often (frequency). Maybe the one that has been on the desk longest (FIFO). Every replacement policy is such a guess.
The guess matters because a miss is expensive. A miss can cost thousands to millions of times a hit, from a DRAM cache in front of disk to a client cache in front of a wide-area server (Lecture 6). Changing the policy changes nothing but a few lines of code, yet it can change the miss ratio by a factor of two or more (§3, §5).
1.2 What a policy may know, and what it may do
At each miss with a full cache, the policy chooses a victim to evict (or, in a software cache, may decline to admit the new item: bypass). It may use anything it has recorded about the past: when each item was inserted, last used, or how often used. It may even remember items that are no longer cached (§4’s ghost lists). It may not see the future.
Two quantities judge it:
- Efficiency: the miss ratio, for a given capacity.
- Cost: memory for metadata, and CPU work per request, especially per hit. Hits are the common case, and in a multithreaded cache any work on a hit that changes shared metadata needs synchronization (§5.5).
Lecture 6 measured caches under one policy (LRU). This lecture keeps the cache and changes the policy.
2. The yardstick: Belady’s MIN
2.1 Evict the item needed farthest in the future
In 1966 Laszlo Belady, studying virtual memory at IBM, described the optimal policy:
MIN (also called OPT): on a miss with a full cache, evict the item whose next use is farthest in the future (or never).
It needs the whole future reference string, so it is an offline policy: no real cache can run it. But it can be computed for any recorded trace, and it gives the lowest possible miss ratio for that trace and capacity. Every other number in this lecture should be read as “how far from MIN?”.
2.2 Why it is optimal
The argument is an exchange. Take any policy P that, at some miss, evicts item while MIN would evict , where ‘s next use comes after ‘s. Build P′, which evicts instead and otherwise copies P, with standing in for :
- Until is next requested, neither nor is requested (x’s next use is later still). So P and P′ hit and miss on exactly the same requests; P′ simply holds where P holds .
- At ‘s next use, P misses and P′ hits. P′ is now one miss ahead.
- From then on P′ copies P’s choices. The only request on which P′ can do worse than P is a later request for , which P may still hold and P′ does not. That can cost P′ at most one miss, giving back the one it saved, and after it the two caches are identical.
So P′ never misses more than P. Repeat the exchange at every decision where a policy differs from MIN, and you arrive at MIN with no more misses than P.
01_belady_min.py Part B checks this by exhaustive search: a dynamic program tries every possible eviction (and bypass) at every miss, on 400 random small strings.
| Model | MIN equals the exhaustive optimum |
|---|---|
| bypass allowed (software cache) | 400 of 400 |
| must cache every page (demand paging) | 400 of 400 |
On those random strings every online policy was 18–19% above the optimum on average (LRU, FIFO, CLOCK, Random, LFU all within a point). Uniformly random references have no locality to exploit, so the policies cannot be told apart. The workloads of §3 can tell them apart.
2.3 MIN step by step
Part A replays the reference string used in operating-systems textbooks, with 3 frames:
step page MIN: cached page(next use) LRU: least recent first FIFO: oldest first
4 2 MISS 0(5) 2(9) 1(14) MISS 0 1 2 MISS 0 1 2
6 3 MISS 0(7) 2(9) 3(10) MISS 2 0 3 MISS 1 2 3
8 4 MISS 2(9) 3(10) 4(-) MISS 3 0 4 MISS 3 0 4
9 2 hit 3(10) 2(13) 4(-) MISS 0 4 2 MISS 0 4 2
10 3 hit 3(12) 2(13) 4(-) MISS 4 2 3 MISS 4 2 3
...
faults: MIN 9, LRU 12, FIFO 15; MIN allowed to skip caching a page: 8
At step 8 MIN evicts page 0, whose next use is at step 11, and keeps 2 and 3, needed at steps 9 and 10. LRU evicts 2, the least recently used, and misses on it one step later. Where both evicted something, they chose differently 2 times out of 6. That was enough to cost LRU 3 extra faults.
Look at what MIN keeps at step 8: page 4, with no future use, displayed as 4(-). In demand paging the missed page must be loaded. A software cache may simply not cache it (“bypass”), and then MIN needs 8 faults instead of 9.
2.4 Uses of an impossible policy
MIN cannot run online, but it is far from useless:
- A yardstick: if LRU is within 5% of MIN on your trace, no policy can buy you much; if it is 50% worse (§5), it is worth looking further.
- A training signal: recent learned policies predict “would MIN evict this?” from features of the past (“relaxed Belady”, LRB; Song et al., NSDI 2020).
- A diagnostic: §5.3 compares where policies spend their space with where MIN does.
3. The classic policies and the bets they make
3.1 Five policies in one paragraph each
- FIFO evicts the item inserted longest ago. Hits change nothing. Its bet: none really, beyond “old items are less likely needed”.
- Random evicts a random item. It bets on nothing, which also means no workload can systematically defeat it.
- LRU evicts the item used least recently. Each hit moves the item to the front of a list. Its bet: recency, “what was used recently will be used again soon”. That is the temporal locality of Lecture 6.
- CLOCK (Corbató 1968; also “second chance”, or FIFO-Reinsertion) is FIFO plus one reference bit. A hit sets the bit. At eviction, the oldest item with its bit set gets the bit cleared and goes to the back; the first item found with a clear bit is evicted. It approximates LRU with a hit cost of one bit.
- LFU evicts the item with the fewest hits. Its bet: frequency, “what is popular stays popular”. “In-cache” LFU forgets an item’s count when it is evicted; “perfect” LFU remembers every count forever.
3.2 The results
02_classic_policies.py runs them all, with MIN, on four workloads. Miss ratios at 200 items:
| Policy | zipf | loop (1,100) | phases | zipf+scan |
|---|---|---|---|---|
| MIN | 0.356 | 0.820 | 0.245 | 0.573 |
| Random | 0.643 | 0.996 | 0.571 | 0.775 |
| FIFO | 0.644 | 1.000 | 0.571 | 0.769 |
| CLOCK | 0.587 | 1.000 | 0.555 | 0.735 |
| LRU | 0.601 | 1.000 | 0.560 | 0.743 |
| LFU (in-cache) | 0.510 | 1.000 | 0.905 | 0.676 |
| LFU (perfect) | 0.464 | 1.000 | 0.890 | 0.646 |
Read it column by column:
- zipf — the independent reference model of Lecture 6: requests are independent draws from a fixed popularity distribution. Here only popularity predicts the future, and LFU, which estimates popularity directly, wins. Keeping the items with the highest request probabilities is optimal among online policies under this model, as the ARC paper notes, and perfect LFU’s counts converge to those probabilities. Recency is only a noisy proxy: an unpopular item that happened to be requested a moment ago looks “hot” to LRU.
- phases — the hot set moves. Recency adapts within a few hundred requests; LFU never does (§3.4). LRU at 1,000 items reaches 0.070, essentially MIN’s 0.069.
- zipf+scan — one-time scans push LRU from 0.601 to 0.743: scanned items are never reused, but each enters at the most-recent end and pushes a useful item out. LFU suffers less (0.676): a scanned item enters with a count of 1 and is the first to leave.
- loop — everything except Random gets nothing. That deserves its own section.
Even the best online policy remained far from MIN: 0.107 (zipf), 0.176 (loop), 0.310 (phases) and 0.073 (zipf+scan) above it. That gap is the opportunity §4 and §5 go after.
3.3 The loop cliff
A program loops over items, and the cache holds . Part B, with :
| Policy | = 150 | 200 | 201 | 220 | 300 | 400 | 800 |
|---|---|---|---|---|---|---|---|
| MIN | 0.004 | 0.005 | 0.010 | 0.096 | 0.338 | 0.505 | 0.755 |
| Random | 0.004 | 0.005 | 0.015 | 0.179 | 0.585 | 0.797 | 0.981 |
| FIFO, CLOCK, LRU, LFU | 0.004 | 0.005 | 1.000 | 1.000 | 1.000 | 1.000 | 1.000 |
At the loop fits and everything hits after the first pass. At — one item too many — LRU misses on every request. Each request is for the item used longest ago, which is exactly the one LRU just evicted. FIFO and CLOCK do the same (on a loop, insertion order is use order), and so does LFU (all counts equal, ties broken by recency). This is thrashing: the working set (Lecture 6) does not fit, and the policy makes it as bad as it can be.
MIN, on the other hand, keeps items of the loop permanently and lets the rest stream through: with bypass its miss ratio is , which is 0.091 for (measured: 0.092 including cold misses). Random lands in between: it keeps a random subset, which preserves some items across passes. Some hardware caches use (pseudo-)random replacement, partly because it is cheap and partly because no access pattern can trap it like this.
Lesson: a deterministic policy has a worst case, and for LRU it is a workload as ordinary as a loop. Sleator and Tarjan (1985) made this precise: for any deterministic online policy with capacity , some reference string makes it miss times as often as MIN. LRU and FIFO achieve this bound, so in the worst case all reasonable deterministic policies look the same, and the theory cannot rank them. What separates policies is the workloads they meet in practice, which is why this lecture, like the papers, is mostly measurement.
3.4 LFU and the moving hot set
Part C splits the phases workload into its five phases (cache of 500 items, hot set 400):
| Policy | phase 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|
| LRU | 0.08 | 0.08 | 0.07 | 0.07 | 0.08 |
| LFU (in-cache) | 0.07 | 0.76 | 1.00 | 1.00 | 1.00 |
| LFU (perfect) | 0.07 | 0.70 | 0.94 | 0.96 | 0.98 |
| MIN | 0.07 | 0.07 | 0.07 | 0.07 | 0.07 |
LFU is as good as anything in phase 1, then collapses. The items of phase 1 have counts in the hundreds and are never requested again. Each new item enters with a count of 1, is the least frequently used item in the cache, and is evicted at the next miss — before it can earn a second hit. The cache is polluted by stale counts. Perfect LFU is no better: it remembers every count, so each new hot set must outrun the counts of all previous ones.
The fix is aging: decay counts over time (halve all counts periodically, or weight hits by recency as LRFU does). Every fix adds a parameter: how fast to forget. Choosing such parameters per workload was the problem ARC set out to remove (§4).
3.5 Belady’s anomaly and stack algorithms
Belady found something stranger in 1969: with FIFO, more memory can mean more misses. 01_belady_min.py Part C:
reference string: 1 2 3 4 1 2 5 1 2 3 4 5
policy 1 frame 2 frames 3 frames 4 frames 5 frames 6 frames
FIFO 12 12 9 10 5 5
LRU 12 12 10 8 5 5
MIN 10 8 7 6 5 5
FIFO faults 9 times with 3 frames and 10 times with 4. The mechanism shows at step 7 (the request for 5). The 3-frame cache now holds {1, 2, 5}, the 4-frame cache {2, 3, 4, 5}: the small cache holds page 1, which the big one has already evicted. At step 8 (page 1) the small cache hits and the big one misses.
LRU cannot do this. An LRU cache of size always holds the most recently used items, and the most recent items include the most recent. So the small cache’s contents are always a subset of the big one’s: the inclusion property. Every hit in the small cache is then a hit in the big one. Mattson et al. (1970) called policies with this property stack algorithms: their caches of all sizes can be described by one ordering of the items (the “stack”), with a cache of size holding the top . LRU, MIN and perfect LFU are stack algorithms; FIFO, CLOCK, Random and in-cache LFU are not.
The demo searched 3,000 random strings (30 references to 7 pages, 1 to 7 frames):
| Policy | strings with an anomaly | steps where the 3-frame cache is not inside the 4-frame one (500 strings) |
|---|---|---|
| FIFO | 5 | 2,709 |
| CLOCK | 76 | 689 |
| in-cache LFU | 8 | 677 |
| Random | 572 (partly luck: its random choices differ per size) | 6,490 |
| perfect LFU, LRU, MIN | 0 | 0 |
Two things to take away:
- The anomaly is rare for FIFO. A first search with shorter strings found none at all; the textbook string is special. Breaking inclusion makes an anomaly possible, and breaking it thousands of times produced an anomaly in 5 strings out of 3,000.
- Inclusion is what makes miss-ratio curves cheap. For a stack algorithm, one pass over the trace computes each reference’s stack distance, and the miss ratio for every cache size follows (Lecture 6, Mattson’s algorithm). For FIFO, CLOCK, ARC or S3-FIFO you must simulate each size separately, which is why the demos here run each size as its own simulation.
4. ARC: recency and frequency, balanced online
4.1 Background: the tuning problem
By 2000 many policies combined recency and frequency, and many beat LRU. The ARC paper surveys them. LRU-2 evicts the item whose second-most-recent use is oldest. 2Q holds new items in a probationary FIFO and promotes them only on a second hit. LIRS, LRFU, FBR and MQ are variations on the same idea. Every one of them has a knob — how long the probation lasts, how fast counts decay — and the right setting depends on the workload and the cache size. A file system or a disk array cannot be tuned per workload by hand, and the workload changes during the day.
Megiddo and Modha’s ARC (FAST 2003; the course reading is their 2004 summary) removes the knob by learning it online.
4.2 The mechanism
ARC keeps four LRU lists:
| List | Holds | Meaning |
|---|---|---|
| T1 | cached items seen once recently | recency |
| T2 | cached items seen at least twice recently | frequency |
| B1 | keys only (no data) recently evicted from T1 | “ghosts” of T1 |
| B2 | keys only recently evicted from T2 | “ghosts” of T2 |
Together (the cache), and the four lists remember at most keys. A real number is the target size of T1.
- A hit (in T1 or T2) moves the item to the front of T2: it has now been seen twice.
- A miss on a key in ghost list B1 means: “had T1 been a little bigger, this would have been a hit”. ARC grows by and caches the item in T2.
- A miss on a key in ghost list B2 means T2 should have been bigger, so shrinks by .
- A miss on a brand-new key puts it at the front of T1.
- To make room, ARC evicts from T1 if , otherwise from T2, sending the victim’s key to the corresponding ghost list.
The step sizes are larger when the opposite ghost list is longer, so moves quickly toward the side that is failing. With frozen, the same structure is the fixed replacement cache FRC(). The paper’s claim is that ARC performs about as well as the best FRC() chosen with hindsight for each workload and size.
A trace with (from replacement.py, which follows the paper’s pseudocode):
a miss T1 [a] T2 [] B1 [] B2 [] p = 0
b miss T1 [a, b] T2 [] B1 [] B2 [] p = 0
a hit T1 [b] T2 [a] B1 [] B2 [] p = 0 a seen twice: to T2
c miss T1 [c] T2 [a] B1 [b] B2 [] p = 0 b's key becomes a ghost
b miss T1 [c] T2 [b] B1 [] B2 [a] p = 1 ghost hit in B1: grow T1's target
d miss T1 [c, d] T2 [] B1 [] B2 [a, b] p = 1
a miss T1 [d] T2 [a] B1 [c] B2 [b] p = 0 ghost hit in B2: shrink it again
4.3 Does adaptation work?
03_arc.py Part A compares ARC with every FRC(), , on five workloads (cache 200):
| Workload | LRU | LFU | ARC | best FRC() | worst FRC() | ARC’s mean | MIN |
|---|---|---|---|---|---|---|---|
| zipf | 0.601 | 0.510 | 0.522 | 0.518 ( = 0) | 0.908 | 10 | 0.356 |
| phases | 0.560 | 0.905 | 0.537 | 0.534 ( = 0) | 0.752 | 11 | 0.245 |
| zipf+scan | 0.743 | 0.676 | 0.682 | 0.680 ( = 0) | 0.943 | 10 | 0.573 |
| web (life 300) | 0.354 | 0.673 | 0.336 | 0.335 ( = 50) | 0.846 | 53 | 0.243 |
| pairs | 0.501 | 0.998 | 0.502 | 0.501 ( = 60) | 0.998 | 198 | 0.501 |
ARC was within 0.004 of the hindsight-best fixed split on every workload, without being told which workload it was on. A wrong fixed split can be catastrophic: 0.91 instead of 0.52 on zipf. ARC also beat LRU on everything except “pairs”, where it tied. That workload is pure recency: every item is requested exactly twice, 60 new items apart. T1 must be long enough to hold the reuse, and ARC duly pushed to the top (mean 198).
One result surprised us: the best fixed split was on three workloads — “keep T1 as small as possible, protect only what is seen twice”. That is 2Q’s idea taken to its limit, and §5 will meet it again as “quick demotion”.
The real test of adaptation is a workload whose best split changes over time. Part B concatenates four phases: pairs (recency), Zipf with scans (frequency), pairs, Zipf with scans:
| Policy | miss ratio |
|---|---|
| FRC( = 0) | 0.757 |
| FRC( = 60), the best fixed split | 0.491 |
| FRC( = 200) | 0.681 |
| ARC | 0.484 |
| LRU | 0.507 |
| LFU | 0.804 |
| S3-FIFO | 0.613 |
| MIN | 0.429 |
ARC's p / c over the run (' ' = 0, '@' = c):
|@@@@@@@@@@@@@@@@@@@@@-. ---------------------: . |
recency frequency recency frequency
ARC beat every fixed split. You can watch rise toward in the recency phases (B1 hits: “T1 was too small”) and collapse in the frequency phases (B2 hits). The ghost lists are a cheap form of hindsight: remembering the keys of recent victims costs a few bytes each and tells the policy which of its halves should have been bigger.
4.4 Scan resistance
A new key enters T1. If it is never requested again, which is the case for every item of a scan, it leaves through B1 without ever touching T2. So a scan can flush T1, never T2. Part C adds a scan after every 500 requests of a Zipf(0.9) hot set and reports the miss ratio on the hot requests only:
| Policy | no scans | scan 100 | scan 200 | scan 4,000 |
|---|---|---|---|---|
| LRU | 0.390 | 0.458 | 0.497 | 0.497 |
| CLOCK | 0.377 | 0.438 | 0.478 | 0.497 |
| LFU | 0.323 | 0.324 | 0.324 | 0.324 |
| ARC | 0.346 | 0.328 | 0.322 | 0.322 |
| S3-FIFO | 0.326 | 0.318 | 0.318 | 0.321 |
| MIN | 0.205 | 0.205 | 0.205 | 0.205 |
LRU loses a quarter of its hits, and the damage saturates once a scan is as long as the cache: a scan that flushes everything cannot do more harm. ARC even improves slightly, because the scans push toward 0 (mean 10 → 7), the frequency-heavy split that suits Zipf. A first version of this experiment, with a scan only every 2,000 requests, showed almost nothing (LRU 0.390 → 0.415): between scans the hot set refilled the cache. Scan resistance matters when scans are frequent relative to the time the cache needs to recover.
4.5 What ARC costs
- Memory: up to ghost keys besides the cached items. The paper reports 0.75% of the cache size for its implementation (keys are tiny compared with 4 KB pages).
- Time: constant per request, like LRU — but a hit moves an item between lists, so ARC has LRU’s work per hit (§5.5).
- Patents and variants: ARC was patented by IBM, which is one reason other systems adopted variants. CAR (Bansal and Modha, FAST 2004) replaces ARC’s LRU lists with CLOCKs; ZFS uses an ARC derivative.
5. FIFO strikes back: lazy promotion and quick demotion
5.1 The argument
For decades the accepted ranking was LRU first, with CLOCK and FIFO as cheaper but less effective approximations. Yang et al. (HotOS 2023) simulated eviction on 5,307 production traces (block, key-value and CDN caches; the paper reports 814 billion requests) and challenged both halves of that view:
- Lazy promotion beats eager promotion. LRU promotes on every hit (“eager”). FIFO-Reinsertion (= CLOCK) promotes only when an item reaches the eviction point and has been hit since it was inserted (“lazy”). The paper reports that CLOCK has a lower miss ratio than LRU on most traces, at a fraction of the work.
- Quick demotion is what good policies share. Most objects that enter a cache are never requested again while they are cached. A good policy evicts them soon after insertion instead of letting them travel the whole queue. The paper adds a small probationary FIFO to five state-of-the-art policies and reports lower miss ratios for all of them.
S3-FIFO (SOSP 2023) builds a whole policy from these two ideas and three FIFO queues.
5.2 Why caches are full of one-hit wonders
A one-hit wonder is an object requested exactly once. In a trace where few objects are requested only once overall, a cache can still be full of them, because it only sees a window of the trace. Part A of 04_lazy_promotion_quick_demotion.py:
| Trace | window | distinct objects seen | requested exactly once in the window |
|---|---|---|---|
| Zipf(1.0), 1M requests | whole trace | 100% | 30% |
| 10% of requests | 30% | 67% | |
| 1% of requests | 5% | 81% | |
| web (life 300) | whole trace | 100% | 60% |
| 10% | 11% | 64% | |
| 1% | 1.7% | 74% |
An object requested 50 times over a month is requested once or not at all in most hours. The SOSP paper makes the same point with its traces (a median one-hit-wonder ratio of 26% over full traces, rising sharply for shorter sequences; paper’s figures).
What does LRU do with a one-hit wonder? It inserts it at the most-recent end, and the object must then travel the entire list, pushed by newer insertions or hits, before it is evicted. All that time it occupies space a useful object could have had.
5.3 Where the space goes
replacement.py charges each cached item its space-time (size × requests spent in the cache) and records whether the item was hit at all during that stay. Part C (1% cache):
| Workload | FIFO | LRU | CLOCK | 2-bit CLOCK | ARC | S3-FIFO | MIN |
|---|---|---|---|---|---|---|---|
| web, life 300 | 72% | 64% | 58% | 52% | 43% | 25% | 0% |
| web, life 3000 | 81% | 75% | 70% | 68% | 22% | 21% | 1% |
LRU spends two thirds of its space on objects that leave without ever earning a hit. MIN spends essentially none: it knows which objects will not be reused and never keeps them. The efficient online policies are the ones that come closest to that — the “resource consumption” argument of the HotOS paper, which shows the same ordering on its traces.
5.4 S3-FIFO
S3-FIFO uses three FIFO queues:
| Queue | Size | Holds |
|---|---|---|
| S (small) | 10% of the space | new objects, on probation |
| M (main) | 90% | objects that proved themselves |
| G (ghost) | as many keys as M holds objects | keys of objects recently evicted from S |
- Insert: a new object goes to S — unless its key is in G (it was evicted from S recently and came back), then it goes straight to M.
- Hit: increment a 2-bit counter, capped at 3. That is all: no list is touched.
- Evict from S: look at S’s oldest object. If it was hit more than once while in S, move it to M (counter cleared); otherwise evict it and put its key in G. Most new objects are one-hit wonders and leave after only 10% of the cache’s worth of insertions: quick demotion.
- Evict from M: FIFO-Reinsertion with the counter. An object with a nonzero counter is reinserted with the counter decremented; one with zero is evicted. This is lazy promotion (2-bit CLOCK).
S3-FIFO borrows the idea of a probation queue from 2Q and the idea of ghost keys from ARC, but it fixes S at 10% instead of adapting it. Quick demotion with a fixed small queue is the bet.
5.5 Results on web-like workloads
Part B (miss ratios; cache = 0.1% / 1% / 10% of the 20,000 objects):
| Policy | life 300: 20 | 200 | 2,000 | life 3000: 20 | 200 | 2,000 |
|---|---|---|---|---|---|---|
| FIFO | 0.657 | 0.390 | 0.241 | 0.871 | 0.630 | 0.365 |
| LRU | 0.611 | 0.354 | 0.241 | 0.851 | 0.582 | 0.333 |
| CLOCK | 0.598 | 0.345 | 0.241 | 0.838 | 0.568 | 0.325 |
| 2-bit CLOCK | 0.583 | 0.335 | 0.241 | 0.823 | 0.553 | 0.318 |
| ARC | 0.519 | 0.336 | 0.248 | 0.721 | 0.490 | 0.319 |
| S3-FIFO | 0.508 | 0.349 | 0.267 | 0.706 | 0.487 | 0.330 |
| MIN | 0.430 | 0.243 | 0.240 | 0.635 | 0.401 | 0.240 |
- Lazy promotion works: CLOCK beat LRU in 5 of the 6 cases (and tied to three decimals in the sixth), and 2-bit CLOCK beat CLOCK in 5. A CLOCK hit sets one bit. The HotOS paper explains part of the reason: under CLOCK a newly inserted object is pushed toward eviction by all later insertions, including those of objects that have not been promoted. Under LRU only newer insertions and hits push it. So lazy promotion is also a mild form of quick demotion.
- Quick demotion works at small sizes: at 0.1% S3-FIFO missed 0.508 vs LRU 0.611 and ARC 0.519; with slow decay (life 3000) 0.706 vs 0.851 and 0.721. In both cases it was the best online policy.
- But not everywhere: at 10% with life 300, S3-FIFO (0.267) was worse than LRU and CLOCK (0.241). In our generator a second request can come thousands of requests after the first. A cache large enough to keep every new object that long catches it, while S3-FIFO has let it go after 10% of the cache’s insertions. The ghost queue catches some of these and misses others. Yang et al. report averages over thousands of production traces, where short-term reuse is stronger. We cannot reproduce those traces, so this is not a refutation of their result. It does show that quick demotion is a bet about the workload, like every other policy.
5.6 Work per hit and the lock problem
Why do FIFO-based caches matter so much in practice? Part D counts, for each policy, how often a hit had to modify the policy’s metadata. It also measures time per request for these Python implementations (Zipf, cache 200):
| Policy | miss ratio | metadata writes per hit | ns per request (measured, Python) |
|---|---|---|---|
| FIFO | 0.644 | 0.00 | 412 |
| CLOCK | 0.587 | 0.47 | 444 |
| S3-FIFO | 0.504 | 0.39 | 565 |
| LRU | 0.601 | 1.00 | 419 |
| ARC | 0.522 | 1.00 | 492 |
| LFU | 0.510 | 1.00 | 976 |
Single-threaded and in Python, the times hardly differ. The numbers vary by a few percent from run to run and mostly measure interpreter overhead. The column that matters is the second. An LRU hit unlinks an item from a doubly linked list and relinks it at the head, which takes about six pointer writes on shared memory. With many threads, those writes need a lock (or a delicate lock-free list), and every hit on every core contends for it. If a locked list update takes ~100 ns, an LRU cache tops out near 10 million hits per second however many cores it has. A CLOCK or S3-FIFO hit writes a small counter, at most a few times per object; the write needs no lock and usually changes nothing. The SOSP paper reports S3-FIFO at more than 6× the throughput of an optimized LRU at 16 threads (paper’s measurement, in Cachelib).
This is why production caches have moved away from strict LRU:
- memcached uses a segmented LRU that bumps items lazily;
- the Linux page cache uses active/inactive lists, a 2Q-like design, and since Linux 6.1 the multi-generational LRU;
- Caffeine (Java) uses W-TinyLFU, a small LRU window in front of a frequency-filtered main cache.
All of these do little work per hit and include some form of probation for new items.
5.7 S3-FIFO’s knobs, and where it fails
Part E varies the size of S and the promotion threshold (web, life 300):
- The best S grew with the cache: 1% of the space at 20 items, 50% at 200 and at 2,000. The default 10% was never more than 0.024 worse than the best choice: a robust compromise, not an optimum.
- Moving objects with any hit (threshold 0, as in the HotOS paper’s QD-LP-FIFO) instead of more than one (the SOSP pseudocode) changed the miss ratio by at most 0.010.
Part F returns to §4.3’s recency/frequency mix:
| Policy | miss ratio |
|---|---|
| ARC | 0.484 |
| LRU | 0.507 |
| S3-FIFO, S = 10% | 0.613 |
| S3-FIFO, S = 25% | 0.618 |
| S3-FIFO, S = 50% | 0.486 |
| MIN | 0.429 |
After a frequency phase has filled M, S is only 20 items. In the pairs phase, a pair’s second request comes about 60 new objects later, after the object has left S. Finding the key in G would only help a third request, and that never comes. S must hold the reuse distance: 50 items (25%) is still too small, 100 (50%) fixes it, but a large S costs elsewhere (Part E, small caches). A fixed split cannot adapt to a workload that changes character; ARC’s can. S3-FIFO bets that real workloads rarely look like the pairs phase. The papers’ traces suggest the bet usually wins, but it is a bet.
6. Objects of different sizes
6.1 Two hit ratios
In virtual memory every page has the same size. Web objects, files and key-value items do not: their sizes are typically heavy-tailed, with most objects small and a few huge. Then there are two measures of success:
- Object hit ratio: the fraction of requests served from the cache. It drives user-perceived latency and the request load on the server.
- Byte hit ratio: the fraction of bytes served from the cache. It drives network bandwidth and the bill for origin traffic.
They can pull in opposite directions. Evicting one 5 MB object makes room for 250 objects of 20 KB. If those 250 together are requested more often than the big one, the object hit ratio improves and the byte hit ratio falls.
6.2 MIN is no longer optimal
With sizes, choosing what to keep is a knapsack problem: each object has a value (its future hits) and a weight (its size), and the cache is the knapsack. The offline optimum is NP-hard to compute. Belady’s rule ignores the weights. 05_variable_sizes.py (5,000 objects, Zipf(0.9), lognormal sizes with a 20 KB median and a tail to 10 MB, independent of popularity; 310 MB in all) shows the consequence, in Part A:
| Policy | 1% of bytes: obj / byte | 5%: obj / byte | 20%: obj / byte |
|---|---|---|---|
| FIFO | 0.784 / 0.902 | 0.618 / 0.773 | 0.402 / 0.503 |
| LRU | 0.748 / 0.888 | 0.575 / 0.753 | 0.361 / 0.455 |
| LFU | 0.599 / 0.825 | 0.470 / 0.676 | 0.304 / 0.350 |
| S3-FIFO | 0.619 / 0.831 | 0.487 / 0.684 | 0.318 / 0.373 |
| LargestFirst | 0.601 / 0.917 | 0.389 / 0.819 | 0.175 / 0.676 |
| GDSF | 0.535 / 0.858 | 0.347 / 0.730 | 0.150 / 0.530 |
| GDSF (cost = size) | 0.655 / 0.853 | 0.498 / 0.701 | 0.324 / 0.371 |
| MIN* (farthest next use) | 0.545 / 0.748 | 0.405 / 0.541 | 0.202 / 0.238 |
MIN* — Belady’s rule applied to objects of different sizes — missed 0.405 of requests at 5%, while the online GDSF missed 0.347 and even the crude LargestFirst 0.389. MIN* is still excellent for bytes (0.541), since keeping the objects needed soonest is close to right when each byte counts the same. For requests, it wastes space on big objects.
6.3 Size-aware policies
- SIZE / LargestFirst (Williams et al. 1996) evicts the largest object. It maximizes how many objects fit and ignores popularity entirely. Its object miss ratio is good when sizes and popularity are unrelated, and its byte miss ratio is terrible (0.819 at 5%).
- GreedyDual-Size (Cao and Irani 1997) gives each object a priority and evicts the lowest. GDSF (Cherkasova 1998) adds frequency: . The trick is , the inflation value: after each eviction, is set to the victim’s . An object that is not hit keeps its old , while every newly inserted or hit object gets the current, higher . Unused objects therefore sink below newcomers over time, an aging mechanism without timestamps.
- The cost term selects the goal:
- cost = 1 per miss maximizes the object hit ratio (0.347 / 0.730 at 5%);
- cost = size makes , which is LFU with aging. It is size-blind and good for bytes (0.498 / 0.701, close to LFU’s 0.470 / 0.676);
- cost = the miss latency, or the dollars of origin bandwidth, optimizes that.
6.4 The correlation between size and popularity decides
Part B keeps the same sizes but assigns them to objects in three ways (cache 5% of all bytes):
| Policy | popular objects small | independent | popular objects big |
|---|---|---|---|
| LRU | 0.420 / 0.922 | 0.575 / 0.753 | 0.903 / 0.623 |
| S3-FIFO | 0.251 / 0.894 | 0.487 / 0.684 | 0.889 / 0.491 |
| LargestFirst | 0.153 / 0.859 | 0.389 / 0.819 | 0.914 / 0.927 |
| GDSF | 0.174 / 0.866 | 0.347 / 0.730 | 0.934 / 0.869 |
| GDSF (cost = size) | 0.332 / 0.913 | 0.498 / 0.701 | 0.877 / 0.393 |
When popular objects are small, which is common on the web (icons, scripts, thumbnails vs videos), size-aware policies win big. When popular objects are big (a video service, a dataset cache), LargestFirst throws out exactly what is wanted. GDSF does no better, because one hit on a big object is worth little in . The size-blind frequency policies win there. Before choosing a size-aware policy, look at the joint distribution of size and popularity in your trace.
6.5 One huge object, and admission control
Part C adds one 30 MB file, requested every 4,000 requests, to a stream of small objects in a 40 MB LRU cache:
| Configuration | object miss ratio | hits on the big file | objects evicted per big-file miss |
|---|---|---|---|
| LRU, admit everything | 0.386 | 0 of 30 | 922 |
| LRU, admit only objects ≤ 4 MB | 0.310 | 0 of 30 | 0 |
| GDSF, admit everything | 0.275 | 0 of 30 | 932 |
Each time the big file arrives, LRU evicts about 922 small objects to make room, and the file is itself evicted before its next request: pure loss. Admission control is a separate decision from eviction: “is this object worth caching at all?” Refusing objects over 4 MB improved the miss ratio from 0.386 to 0.310. GDSF did better still without a rule: it admits the file but gives it a low priority (), so the file is the first to go and the small objects come back quickly.
Production caches use richer admission rules:
- a CDN may cache an object only on its second request, using a Bloom filter to remember first requests, which filters out one-hit wonders (Maggs and Sitaraman 2015);
- TinyLFU admits a newcomer only if its estimated frequency beats the victim’s.
Admission is quick demotion taken to its extreme: the object is demoted before it is even inserted.
6.6 Capacity is bytes
Part D sizes an LRU cache in objects (1,000) and measures what it holds. It holds between 53.7 MB and 79.1 MB over the run, while 1,000 × the median size suggests 20 MB. With heavy-tailed sizes the few big objects decide the memory used. A memory budget can only be enforced in bytes. Then one miss may need many evictions — “evict until the new object fits” — and an object larger than the whole cache can never be admitted. Both are details every byte-limited cache must get right, Project 2’s proxy among them.
7. Choosing a policy
| If your workload… | Prefer | Avoid | Because |
|---|---|---|---|
| has stable popularity (IRM-like) | LFU with aging, S3-FIFO, ARC | FIFO, Random | frequency estimates popularity (§3.2) |
| has moving hot sets / phases | LRU, CLOCK, ARC | LFU without aging | stale counts pollute the cache (§3.4) |
| loops over slightly more than the cache | Random, MIN-like bypass, partitioning | LRU, FIFO, CLOCK | deterministic recency thrashes (§3.3) |
| has frequent one-time scans | ARC, S3-FIFO, 2Q | LRU | scans pass through probation (§4.4) |
| has many one-hit wonders (web, CDN, KV) | S3-FIFO, ARC, admission filters | LRU | quick demotion saves space (§5) |
| needs many threads on hits | FIFO-based: CLOCK, S3-FIFO | strict LRU, ARC | no lock per hit (§5.6) |
| has very different object sizes, popular objects small | GDSF, size-threshold admission | plain LRU | knapsack: small objects first (§6) |
| has popular objects that are big, or you pay for bytes | frequency-based, GDSF(cost = size) | LargestFirst, GDSF(cost = 1) | byte hit ratio matters (§6.4) |
| is unknown | measure: replay a trace through several policies and compare with MIN | guessing | no policy wins everywhere |
Summary
- MIN (evict the farthest next use) is optimal for equal sizes. It matched an exhaustive search in 400 of 400 cases. It is offline, and it is the yardstick: on the textbook string MIN faulted 9 times, LRU 12 and FIFO 15.
- Classic policies bet on one thing each:
- LFU on frequency: best under stable popularity (zipf: 0.464 for perfect LFU vs LRU 0.601), never recovers when the hot set moves (0.07 → 1.00);
- LRU on recency: good with phases (0.070 vs MIN 0.069 at 1,000 items), polluted by scans (0.601 → 0.743), and 100% misses on a loop one item larger than the cache, where Random got 0.179 and MIN 0.096;
- every deterministic online policy has such a worst case, so practice, not theory, separates them.
- Belady’s anomaly: FIFO faulted 9 times with 3 frames and 10 with 4. Stack algorithms (LRU, MIN, perfect LFU) keep the inclusion property and never show it. Inclusion is also what makes one-pass miss-ratio curves possible. The anomaly is rare even for FIFO: 5 of 3,000 random strings.
- ARC balances recency (T1) and frequency (T2) with a target split learned from ghost hits. It was within 0.004 of the hindsight-best fixed split on five workloads, and on a workload that changes character it beat every fixed split (0.484 vs 0.491; LRU 0.507). It is scan-resistant.
- Lazy promotion and quick demotion:
- in a cache’s window most objects are one-hit wonders (30% of a Zipf trace’s objects, 81% within a 1% window);
- CLOCK beat LRU in 5 of 6 web cases;
- S3-FIFO’s three FIFOs were best at small sizes (0.508 vs LRU 0.611), but not at 10% of a slowly fading web stream, and its fixed 10% probation queue failed on a recency phase (0.613 vs ARC 0.484);
- LRU spent 64% of its space-time on items never hit, S3-FIFO 25%, MIN 0%;
- FIFO-based hits need no lock: 0–0.47 metadata writes per hit vs 1.0 for LRU and ARC.
- Sizes turn replacement into a knapsack problem:
- object and byte hit ratios diverge, and “farthest next use” stops being optimal (MIN* 0.405 vs GDSF 0.347 of requests);
- GDSF’s inflation value ages objects without timestamps, and its cost term picks the goal;
- the size–popularity correlation can flip the ranking;
- huge objects call for admission control;
- capacity must be enforced in bytes.
Common pitfalls
- Comparing policies without MIN. “ARC is 10% better than LRU” means little if both are 50% worse than MIN, or if both are within 2% of it.
- Testing on one workload. Every policy here wins somewhere and loses somewhere. A random-reference benchmark shows no difference at all (§2.2).
- Assuming more cache can only help. Not for FIFO or CLOCK (Belady’s anomaly). And it never helps LRU on a loop until the whole loop fits.
- LFU without aging. It will eventually fill with yesterday’s hits.
- Counting capacity in objects when sizes vary, or forgetting that one admission may need many evictions — and that an object bigger than the cache must not be admitted at all.
- Optimizing the wrong hit ratio: object hit ratio for latency, byte hit ratio for bandwidth. They can move in opposite directions.
- Ignoring the cost of a hit. A policy with a 2% better miss ratio that takes a global lock on every hit can be slower overall on a many-core server.
- Believing a paper’s average applies to your trace. The S3-FIFO and ARC papers report results over many traces; our synthetic workloads found cases where each loses. Replay your trace.
Exercises
-
MIN by hand. For the reference string
a b c d a b e a b c d eand 3 frames, compute the faults of MIN (demand paging), LRU and FIFO. Then repeat with 4 frames. Which policy shows Belady’s anomaly?Answer
3 frames: MIN 7, LRU 10, FIFO 9. 4 frames: MIN 6, LRU 8, FIFO 10. FIFO gets worse with more frames: this is the anomaly string of §3.5 in letters. (MIN with bypass gives the same counts here; check with `replacement.simulate`.) -
MIN on a loop. A loop over items runs through a cache of items many times. Derive MIN’s miss ratio (a) with demand paging, (b) with bypass. Compare with the simulation for , (0.092).
Answer
(b) With bypass, MIN can keep any $c$ items of the loop forever and never cache the others: each pass hits $c$ times and misses $k - c$, so the miss ratio is $(k-c)/k = 20/220 = 0.091$; the simulation adds the 200 cold misses of the first pass over 200,000 requests (+0.001), giving 0.092. (a) With demand paging the missed item must occupy one frame for its moment, so only $c - 1$ items can be kept permanently: miss ratio $(k-c+1)/k = 21/220 = 0.095$. LRU: 1.0. The gap between 0.09 and 1.0 for a loop just 10% larger than the cache is the whole case for not using pure recency on loops. -
ARC by hand. With , trace ARC on
a b a c b d a b: give T1, T2, B1, B2 and after each request, and count hits.Answer
See §4.2 for the first seven steps. The eighth, `b`, is a ghost hit in B2 ($p$ = max(0, 0 − max(1/1, 1)) = 0): REPLACE evicts d from T1 to B1, and b goes to T2. Final state: T1 [], T2 [a, b], B1 [c, d], B2 [], $p$ = 0. One hit (the third request). ARC's ghost hits are misses in the cache: they adjust $p$ and promote the key straight to T2, but the data must still be fetched. -
One-hit wonders and quick demotion. A cache of 100,000 objects inserts 1,000 new objects per second, and 70% of inserted objects are never requested again while cached. (a) With LRU, roughly how long does a one-hit wonder stay, and what fraction of the cache do one-hit wonders occupy at any moment? (b) The same with S3-FIFO’s 10% probationary queue. (c) What does the freed space buy?
Answer
(a) An inserted item travels the whole LRU list, pushed by roughly one insertion per miss (hits move other items too, so this is a rough lower bound): about 100,000 / 1,000 = 100 s. One-hit wonders arrive at 700/s, so about 700 × 100 = 70,000 of them are cached at any time: 70% of the cache holds objects that will never be hit. (b) In S they last about 10,000 / 1,000 = 10 s, so about 7,000 are cached: 7%. (c) About 63,000 slots now hold objects that *do* get reused. Under a Zipf-like popularity that is like making the useful part of the cache 3× larger, which by Lecture 6's miss-ratio curves can cut the miss ratio substantially. The risk: objects whose second request comes after 10 s but within 100 s are lost unless the ghost queue catches them (§5.5). -
GDSF by hand. A GDSF cache (cost = 1) with holds: X (size 10 KB, freq 3), Y (100 KB, freq 20), Z (1 KB, freq 1). (a) Compute each (use sizes in KB). Which is evicted first? (b) After that eviction, a new object W (5 KB) is inserted. What is its ? (c) Why does prevent Z-like objects that were popular long ago from staying forever?
Answer
(a) H(X) = 3/10 = 0.3, H(Y) = 20/100 = 0.2, H(Z) = 1/1 = 1.0. Y is evicted first, despite being the most popular: per byte, its hits are worth the least. (b) L becomes 0.2; H(W) = 0.2 + 1/5 = 0.4. (c) Every eviction raises L to the victim's H. Objects hit or inserted later receive priorities above the current L, while an object that stops being hit keeps its old H. As L climbs past it, it becomes the lowest and is evicted. L is a clock that ticks with evictions instead of time. -
Which hit ratio? A CDN edge cache serves two kinds of objects: page assets (10 KB each, 95% of requests) and videos (50 MB each, 5% of requests). Its operator is billed per byte fetched from the origin, but its customers complain about page-load latency. (a) Which hit ratio matters to whom? (b) Name a policy or configuration for each goal. (c) Can one cache serve both?
Answer
(a) Latency depends on the object hit ratio of the page assets, which make up most requests; the bill depends on the byte hit ratio, dominated by videos. (b) For latency: GDSF with cost 1, or a size threshold that keeps videos out of the memory tier. For the bill: a byte-oriented policy (LFU-like, GDSF with cost = size) with enough capacity for the popular videos. (c) Commonly, two tiers or two partitions: a small memory cache for small objects, admission-filtered, and a large flash or disk cache for big ones. Partitioning by size class (as memcached does with slab classes) keeps one class from evicting the other. -
Inclusion. (a) Prove that LRU satisfies the inclusion property. (b) In the anomaly string
1 2 3 4 1 2 5 1 2 3 4 5, find the first step at which FIFO’s 3-frame cache holds a page that the 4-frame cache does not, and show how that turns into an extra fault.Answer
(a) At any moment an LRU cache of size $c$ holds exactly the $c$ most recently used distinct pages (or all pages seen, if fewer). The $c$ most recent are among the $c + 1$ most recent, so cache($c$) ⊆ cache($c + 1$). (b) After step 7 (page 5): 3 frames hold {1, 2, 5}, 4 frames hold {2, 3, 4, 5}. With 4 frames, page 1 has been cached since step 1 — its hit at step 5 does not change FIFO order — so it is the oldest page when 5 arrives and is evicted. With 3 frames, page 1 was evicted at step 4 and re-inserted at step 5, so it is young. At step 8 (page 1) the 3-frame cache hits and the 4-frame cache misses. The bigger cache's extra room changed *when* pages were inserted, so FIFO's order, and therefore its contents, differ between sizes and are not nested. -
The price of a lock. A cache server has 32 cores and serves 95% hits. With LRU, each hit takes a global lock for 100 ns to relink the list; everything else in a request takes 2 µs of parallelizable work. (a) What is the maximum throughput with LRU? (b) With CLOCK, whose hits need no lock (misses still take a 100 ns lock to evict)? (c) What lesson does this give about comparing miss ratios?
Answer
(a) Every request needs the lock for 100 ns (hits to relink, misses to evict and insert), so at most 10⁷ requests/s. The parallel part alone would allow 32 / 2 µs = 1.6 × 10⁷/s. So LRU caps the server at 10 M requests/s, and adding cores does nothing. (b) Only misses take the lock: 5% × 100 ns = 5 ns of locked time per request on average, so the lock allows 2 × 10⁸/s and the cores allow 1.6 × 10⁷/s: CLOCK reaches 16 M requests/s, 60% more. (c) A policy can win on miss ratio and lose on throughput. If CLOCK's miss ratio were 1–2% worse than LRU's — and §5.5 suggests it is often *better* — the throughput gain would still dominate as long as the backend can absorb the extra misses.
Related project and problem set (concepts only)
- Project 2 asks for LRU replacement of whole files of different sizes under a cache-size limit. §6.6 is the relevant concept: the budget is in bytes, one new file may require evicting several old ones, a file bigger than the cache cannot be cached at all, and a file with readers using it needs care before it is evicted. How your proxy tracks recency, and what it does with files in use, are your design.
- Problem Set 2 has replacement questions in the style of exercises 1–3. The method is §2 (MIN step by step) and §3 (what each policy keeps); the answers and PS2’s scenarios are not here.
Further reading
- N. Megiddo and D. S. Modha, “Outperforming LRU with an Adaptive Replacement Cache Algorithm”, IEEE Computer 37(4), 2004 (course reading), and the full paper “ARC: A Self-Tuning, Low Overhead Replacement Cache”, FAST 2003.
- J. Yang et al., “FIFO can be Better than LRU: the Power of Lazy Promotion and Quick Demotion”, HotOS 2023 (course reading).
- J. Yang et al., “FIFO Queues are All You Need for Cache Eviction”, SOSP 2023 (course reading) — S3-FIFO, with ring-buffer and lock-free implementation notes.
- L. A. Belady, “A Study of Replacement Algorithms for a Virtual-Storage Computer”, IBM Systems Journal 5(2), 1966; and L. A. Belady, R. A. Nelson, G. S. Shedler, “An Anomaly in Space-Time Characteristics of Certain Programs Running in a Paging Machine”, CACM 12(6), 1969.
- R. L. Mattson, J. Gecsei, D. R. Slutz, I. L. Traiger, “Evaluation Techniques for Storage Hierarchies”, IBM Systems Journal 9(2), 1970 — stack algorithms.
- T. Johnson and D. Shasha, “2Q: A Low Overhead High Performance Buffer Management Replacement Algorithm”, VLDB 1994.
- P. Cao and S. Irani, “Cost-Aware WWW Proxy Caching Algorithms”, USITS 1997.
- G. Einziger, R. Friedman, B. Manes, “TinyLFU: A Highly Efficient Cache Admission Policy”, ACM TOS 13(4), 2017.
- B. Berg et al., “The CacheLib Caching Engine: Design and Experiences at Scale”, OSDI 2020.
Preview of Lecture 9 — Prefetching, hints and buffer bloat
Replacement decides what to throw out after a miss. Prefetching tries to avoid the miss altogether, by fetching what will be needed before it is asked for — a bet on the future like replacement, but one that also spends bandwidth and cache space. Lecture 9 measures prefetching by accuracy, coverage and timeliness. It asks where hints come from: access history, applications that disclose their intentions, and semantic knowledge such as which header files a C file includes. It studies vTube, which streams virtual machines over last-mile networks, and buffer bloat: how aggressive prefetching and oversized network buffers turn bandwidth into latency.
术语表 (Glossary, English → 中文)
| English | 中文 |
|---|---|
| replacement policy / eviction policy | 替换策略 / 驱逐策略 |
| victim | 被驱逐项(牺牲者) |
| reference string / trace | 引用串 / 访问轨迹 |
| fault (page fault) / miss | 缺页 / 未命中 |
| Belady’s MIN (OPT) | Belady 最优替换算法 |
| offline / online policy | 离线 / 在线策略 |
| demand paging | 请求调页 |
| bypass | 旁路(不缓存) |
| admission control / admission filter | 准入控制 / 准入过滤器 |
| exhaustive search / dynamic programming | 穷举搜索 / 动态规划 |
| FIFO (first in, first out) | 先进先出 |
| least recently used (LRU) | 最近最少使用 |
| CLOCK / second chance / FIFO-Reinsertion | 时钟算法 / 第二次机会 / FIFO 重插入 |
| reference bit | 引用位 |
| least frequently used (LFU) | 最不经常使用 |
| in-cache LFU / perfect LFU | 缓存内 LFU / 完全 LFU |
| aging (of counts) | (计数)老化 |
| cache pollution | 缓存污染 |
| recency / frequency | 近期性 / 频率 |
| independent reference model (IRM) | 独立引用模型 |
| loop / thrashing | 循环访问 / 抖动 |
| scan / scan resistance | 扫描 / 抗扫描 |
| competitive ratio | 竞争比 |
| Belady’s anomaly | Belady 异常 |
| inclusion property | 包含性质 |
| stack algorithm | 栈算法 |
| adaptive replacement cache (ARC) | 自适应替换缓存 |
| ghost list / ghost entry | 幽灵列表 / 幽灵条目 |
| fixed replacement cache (FRC) | 固定划分替换缓存 |
| target size (p) | 目标大小 |
| 2Q / segmented LRU | 双队列 / 分段 LRU |
| eager promotion / lazy promotion | 急切提升 / 惰性提升 |
| quick demotion | 快速降级 |
| one-hit wonder | 一次性对象(只被请求一次的对象) |
| probationary queue | 试用队列 |
| S3-FIFO (small, main, ghost queues) | S3-FIFO(小队列、主队列、幽灵队列) |
| popularity decay | 流行度衰减 |
| space-time (resource consumption) | 空间-时间占用(资源消耗) |
| metadata / work per hit | 元数据 / 每次命中的工作量 |
| lock contention / lock-free | 锁争用 / 无锁 |
| object hit ratio / byte hit ratio | 对象命中率 / 字节命中率 |
| heavy-tailed size distribution | 重尾大小分布 |
| knapsack problem / NP-hard | 背包问题 / NP 难 |
| GreedyDual-Size (GDS) / GDSF | 贪心对偶-大小算法 / 带频率的 GDS |
| inflation value (L) | 膨胀值 |
| largest-first (SIZE) | 最大优先 |
| TinyLFU / Bloom filter | TinyLFU / 布隆过滤器 |