Maps to: CMU 15-440/640 Spring 2026, learning outcomes “prefetching: benefits and risks”, “extraction of hints”, “application-specific consistency” and “buffer bloat” (Part II, caching). Reading (optional, course list): Y. Abe, R. Geambasu, K. Joshi, H. A. Lagar-Cavilla and M. Satyanarayanan, vTube: Efficient Streaming of Virtual Appliances Over Last-Mile Networks (SoCC 2013).
Problem set: PS2’s caching questions touch prefetching; the scenarios and numbers here are different. Sources: the reading above. Background:
- R. H. Patterson, G. A. Gibson, E. Ginting, D. Stodolsky and J. Zelenka, Informed Prefetching and Caching (SOSP 1995);
- A. J. Smith, Sequentiality and Prefetching in Database Systems (ACM TODS 1978);
- J. Gettys and K. Nichols, Bufferbloat: Dark Buffers in the Internet (CACM 2012);
- K. Nichols and V. Jacobson, Controlling Queue Delay (ACM Queue 2012; CoDel), and RFC 8289 (CoDel), RFC 8290 (fq_codel);
- G. Appenzeller, I. Keslassy and N. McKeown, Sizing Router Buffers (SIGCOMM 2004);
- RFC 8985 (RACK loss detection), RFC 9111 (HTTP caching).
The slides are not public; this is not a transcript. Numbers from papers are labelled as such. Every other number comes from
code/lecture09/, run on the author’s machine (Apple M4 Pro, macOS, Python 3.13 and 3.9). Code:code/lecture09/. Reading time: ~80 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:
- Compute how far ahead a reader must prefetch to hide a given latency, and recognize when no prefetching can help (the bandwidth floor).
- Judge a prefetcher by accuracy, coverage and timeliness, and predict which predictor (sequential, stride, adaptive, history, disclosed hints) suits which access pattern.
- Explain the three ways a wrong prefetcher makes things worse — wasted bandwidth, demand requests queued behind prefetches, cache pollution — and the fix for each.
- Name the sources of hints (history, disclosure, semantics) and design application-specific consistency with freshness hints.
- Describe how vTube streams a VM over 4G: clusters, history-based prediction, deliberate buffering, video-streaming metrics.
- Explain buffer bloat: why loss-based congestion control fills buffers, why one bandwidth-delay product suffices, and what CoDel, fair queueing and fq_codel each fix.
0.2 Prerequisites and scope
- Prerequisites:
- Lecture 2: latency vs bandwidth, the bandwidth-delay product, TCP windows;
- Lectures 6 and 8: hit ratios, LRU, cache pollution;
- Lecture 7: TTLs, check-on-use, leases;
- Lecture 5: the Andrew benchmark’s file trace.
- Scope: one client fetching from one server. Mobile clients that must adapt when the network changes are Lecture 10. Queueing theory proper is Lecture 11.
0.3 Section → code map
| Section | Idea | Demo in code/lecture09/ |
|---|---|---|
| §2 | how far ahead; the bandwidth floor | 01_latency_hiding.py |
| §3–4 | accuracy, coverage, timeliness; the double-edged sword | 02_accuracy_coverage_timeliness.py |
| §5 | hints: history, disclosure, semantics | 03_hints.py |
| §5.4 | application-specific consistency | 04_app_specific_consistency.py |
| §6 | vTube: streaming a VM | 05_vtube_streaming.py |
| §7 | buffer bloat, CoDel, fair queueing; real socket buffers | 06_buffer_bloat.py |
| all | client + link + predictors; VM streaming; router + TCP on dsim | prefetch.py, vastream.py, bloat.py |
0.4 Notation
- RTT = round trip; tx = transfer time of one block = size × 8 / bandwidth; a fetch costs RTT + tx.
- think = the client’s compute time per block (its useful work between accesses).
- Depth = how many blocks the prefetcher keeps requested ahead.
- BDP = bandwidth × RTT, the bytes “in flight” on a full pipe.
- The prefetching link model (
prefetch.Link): a request takes RTT/2 to reach the server; the server sends one block at a time at the link rate, either in one FIFO queue or demand first; the data takes another RTT/2. Prefetched blocks enter the client’s LRU cache when they arrive.
1. The problem
1.1 The intuition
A cook who starts chopping onions only when the recipe says “add onions” spends half the evening waiting. A good cook reads ahead and preps while the pan heats. Prefetching is reading ahead: asking for data before it is needed, so that fetching overlaps with useful work.
Caching (Lectures 6–8) avoids the second miss on the same data. Prefetching tries to avoid even the first. It is the only remedy for compulsory misses, and the only way to hide latency that no amount of cache can remove, such as the round trip to a server 100 ms away.
1.2 Why it is a bet
Prefetching spends resources now on a guess about the future:
- bandwidth — every wrong guess is bytes nobody wanted, on a link others may need;
- cache space — a prefetched block may push out a block that would have been used (pollution, Lecture 8’s problem again);
- queue position — a prefetch occupies the link, and a demand request that arrives behind it waits.
So the questions are always the same: how good is the guess, how early does it arrive, and what does a wrong one cost? The rest of this lecture puts numbers on each. It also looks at the most important hidden queue in modern networks, the buffer in front of a slow link, where the cost of sending too much shows up as latency for everyone.
2. How far ahead?
2.1 The arithmetic
A program reads a file block by block over the network and computes think ms on each block. Without prefetching, every block costs a full fetch:
With perfect sequential readahead, fetches overlap with computing, and the time approaches the larger of the two rates:
To overlap completely, enough requests must be in flight to cover one fetch time. That is Little’s law (requests in flight = rate × latency), or Lecture 2’s bandwidth-delay product applied to the consumer’s rate:
01_latency_hiding.py (2,000 blocks of 8 KB, 5 ms of compute each, so 10 s of useful work):
| Network | tx per block | fetch | depth to hide | limited by | no prefetching | best possible |
|---|---|---|---|---|---|---|
| LAN (0.5 ms, 1 Gbps) | 0.07 ms | 0.6 ms | 1 | latency | 11.1 s | 10.0 s |
| broadband (60 ms, 14.4 Mbps) | 4.55 ms | 64.6 ms | 13 | latency | 139.1 s | 10.0 s |
| 4G-like (120 ms, 7.2 Mbps) | 9.10 ms | 129.1 ms | 26 | bandwidth | 268.2 s | 18.2 s |
2.2 The simulation
Completion time in seconds, with stall time in parentheses, against readahead depth:
| Network | = 0 | 1 | 2 | 4 | 8 | 12 | 13 | 26 | 64 |
|---|---|---|---|---|---|---|---|---|---|
| LAN | 11.1 (1.1) | 10.0 (0.0) | 10.0 | 10.0 | 10.0 | 10.0 | 10.0 | 10.0 | 10.0 |
| broadband | 139.1 (129.1) | 129.1 (119.1) | 64.6 | 32.4 | 16.2 | 10.9 (0.9) | 10.1 (0.1) | 10.1 | 10.1 |
| 4G-like | 268.2 (258.2) | 258.2 | 129.2 | 64.7 | 32.5 | 21.7 | 20.1 | 18.4 (8.4) | 18.4 (8.4) |
Three lessons:
- A readahead of one block barely helps on a long link. The next block is requested when this one is used, 5 ms before it is needed, while a fetch takes 64.6 ms. Shallow prefetching on a WAN is almost pointless.
- The formula is exact: on broadband, 12 blocks of readahead still stalled 0.9 s, and 13 reached the floor. Each extra block of depth halved the stall until the pipe was full. Depth is bandwidth × latency, as everywhere else in networking.
- Prefetching hides latency, never a lack of bandwidth. On 4G a block takes 9.1 ms to transfer and only 5 ms to use, so the program must wait for the link no matter how early it asks. Even = 64 stalled 8.4 s; the floor is 18.2 s. When the consumer is faster than the link, the remedies are fetching less (compression, deduplication, lower fidelity — Lecture 10) or a faster link.
3. Judging a prefetcher
3.1 Three numbers
- Accuracy = useful prefetches / prefetches issued. Low accuracy wastes bandwidth and cache.
- Coverage = misses removed / misses without prefetching. Low coverage means the prefetcher misses most of the opportunity. A negative coverage means prefetching created misses.
- Timeliness = useful prefetches that arrived before they were needed / useful prefetches. A late prefetch still saves part of the wait, but not all of it.
They are independent. A prefetcher that fetches the entire disk has perfect coverage and terrible accuracy. One that fetches only what it is sure of has great accuracy and little coverage. And a perfect prediction made too late has neither problem but still makes the client wait.
3.2 Predictors and patterns
02_accuracy_coverage_timeliness.py scores six predictors on four access patterns (broadband, 5 ms compute, LRU cache of 500 blocks):
| Predictor | its model of the program |
|---|---|
| sequential() | after block come (fixed readahead) |
| adaptive readahead | as above, but the window doubles while access stays sequential and collapses on a jump (like Linux) |
| stride() | once the same step is seen twice, |
| history (Markov) | “after X came Y” counts learned from 10 earlier sessions |
| disclosed hints() | the application tells the next accesses (perfect, by construction) |
Coverage (and stall in seconds; no prefetching: seq runs 194, strided 194, random 193, activities 32):
| Predictor | seq runs | strided | random | activities |
|---|---|---|---|---|
| sequential(8) | +0.97 (17) | 0.00 (288) | 0.00 (287) | −2.86 (183) |
| adaptive readahead | +0.95 (29) | 0.00 (194) | 0.00 (193) | 0.00 (32) |
| stride(8) | +0.92 (27) | +1.00 (9) | 0.00 (193) | 0.00 (32) |
| history | +0.01 (192) | 0.00 (194) | 0.00 (195) | +0.96 (3) |
| disclosed hints(8) | +1.00 (9) | +1.00 (9) | +1.00 (9) | +1.00 (2) |
- Each predictor wins only where its model is right. Sequential readahead removed 97% of misses on sequential runs and nothing elsewhere; stride removed all of them on the strided walk; history removed 96% on the application whose activities repeat (accuracy 1.00) and nothing on the others.
- Only the application can predict random access. Disclosed hints removed 100% of misses everywhere, including on uniformly random blocks that no pattern detector can guess.
- Coverage is not timeliness. Even perfect hints left 13% of useful prefetches late on sequential runs (timeliness 0.87): after each jump, the first blocks are needed sooner than a hint 8 accesses ahead can deliver them.
- Wrong prefetching is negative coverage. On “activities”, sequential(8) turned 492 misses into 1,897 and the stall from 32 s into 183 s.
4. The double-edged sword
4.1 Three ways to lose
Part B of demo 02 takes sequential(8) on the two workloads where it is wrong and adds one fix at a time:
| Configuration | random: misses / pollution / stall | ms per miss | MB moved | activities: misses / pollution / stall |
|---|---|---|---|---|
| no prefetching | 2,986 / 0 / 193 s | 65 | 24.5 | 492 / 0 / 32 s |
| sequential(8), one FIFO link queue | 2,991 / 341 / 287 s | 96 | 220.7 | 1,897 / 1,328 / 183 s |
| … demand requests first | 2,991 / 330 / 205 s | 69 | 220.7 | 1,896 / 1,316 / 131 s |
| … and a 100,000-block cache | 2,622 / 0 / 180 s | 68 | 193.2 | 440 / 0 / 30 s |
The three costs separate cleanly:
- Wasted bandwidth: 221 MB moved to deliver 24.5 MB of useful data. Demand priority does not change this. On a metered cellular link the user pays for it, and on a shared link everyone else does (§7).
- Queueing: with one FIFO queue at the server, each demand miss waited behind up to 8 useless prefetches: 96 ms per miss instead of 65. On “random” this was most of the damage, and serving demand requests first removed most of it (287 → 205 s). The general rule: prefetches must never delay demand traffic. Give them lower priority, at the server, in the network and in the disk queue.
- Pollution: useless blocks evicted useful ones. On “activities” this was most of the damage: with demand priority the stall was still 131 s, with 1,316 misses on blocks that a prefetch had pushed out. Only a cache big enough to hold every useless block (an option nobody has) brought it back to 30 s. Practical fixes:
- insert prefetched blocks at the LRU end, or in a small separate partition, so that they must prove themselves (Lecture 8’s quick demotion);
- stop prefetching when measured accuracy is low (feedback-directed prefetching).
4.2 How aggressive?
Part C sweeps the depth on the sequential-runs workload (runs average 40 blocks; demand first):
| Predictor | stall (s) | accuracy | wasted MB |
|---|---|---|---|
| none | 194 | — | 0 |
| sequential(1) | 179 | 0.97 | 0.6 |
| sequential(4) | 40 | 0.90 | 2.5 |
| sequential(16) | 10 | 0.70 | 10.1 |
| sequential(32) | 10 | 0.54 | 20.2 |
| sequential(64) | 21 | 0.38 | 39.7 |
| adaptive readahead (max 16) | 24 | 0.71 | 9.5 |
Depth 16 hides the latency (§2: 13 is the minimum). Deeper buys nothing and wastes more, because every run ends with up to blocks fetched past its end. At 64 the waste even costs time: useless transfers delay the first fetch after each jump.
Adaptive readahead did not beat the best fixed depth here (24 s vs 10 s). It ramps up again after every jump, and its window is largest exactly when a run ends. Its virtue is safety: on random and strided access it wasted nothing, where sequential(8) wasted 393 MB. That is why operating systems use it. They do not know the workload, and wasting a disk’s bandwidth on a random-access database is worse than being a bit slow on a sequential scan.
5. Where hints come from
A prefetcher is only as good as its information about the future. There are three sources.
5.1 History
Programs repeat themselves. Opening the same document touches the same code and data blocks in the same order; a game area loads the same textures. A history-based predictor records “after X came Y” in earlier runs and replays it. Demo 03 Part A trains a Markov predictor on earlier sessions of an application and tests it on three new ones:
| Training sessions | accuracy | coverage | stall (s) |
|---|---|---|---|
| none (no prefetching) | — | — | 34.9 |
| 0 (learns online only) | 0.33 | 0.06 | 32.7 |
| 1 | 1.00 | 0.62 | 14.8 |
| 2 | 1.00 | 0.75 | 10.7 |
| 5 | 0.99 | 0.88 | 6.5 |
| 20 | 1.00 | 0.92 | 5.5 |
One earlier session already removed 62% of the misses, and five removed 88%. Beyond that, little changes. The remaining misses are the first blocks of activities whose order the history cannot foresee: it knows what follows “open file”, not whether the user will open a file next. Learning only from the current session barely helps, because by the time a pattern has been seen once in this session it is mostly over.
History-based hints across users (not just across runs of one user) are what vTube uses (§6). They are also what CDNs and app stores use when they push the assets most users fetch next.
5.2 Disclosure
The best source is the application itself. A compiler knows which files it will read, a database knows its query plan, a video player knows the next segments. Informed prefetching (Patterson et al. 1995) gave applications a way to disclose their future reads to the file system. The file system then decided how deep to prefetch and how much cache to give to prefetched blocks, using a cost-benefit model.
Accuracy is perfect by construction, but depth still matters. Part B discloses future accesses of a random workload:
| Hint depth | stall (s) | of the unhinted stall |
|---|---|---|
| none | 192.7 | 100% |
| 1 | 177.8 | 92% |
| 4 | 33.4 | 17% |
| 8 | 9.3 | 5% |
| 13 | 0.1 | 0% |
The depth needed is §2’s formula again: ⌈(RTT + tx) / think⌉ = 13. Disclosure turns an unpredictable workload into a perfectly prefetchable one, but only if the application looks far enough ahead.
Modern examples of disclosure are everywhere:
posix_fadvise(POSIX_FADV_SEQUENTIAL / WILLNEED)andmadvise;- the HTTP
Link: rel=preloadheader and<link rel="prefetch">in HTML; - a database’s asynchronous I/O for a known scan;
- video players requesting the next segments.
5.3 Meaning: semantic hints
Sometimes the system can infer the future from what the data is. Part C replays Lecture 5’s Make phase on a cold client, fetching whole files over 30 ms / 10 Mbps (161 opens of 52 files; 1.26 s of the run is computing):
| Hints | Make time (s) | stall (s) | demand misses |
|---|---|---|---|
| none | 2.95 | 1.68 | 52 |
semantic: parse #include lines | 2.72 | 1.46 | 38 |
| directory: next 2 files by name | 1.61 | 0.35 | 7 |
| semantic + directory | 1.51 | 0.24 | 3 |
| disclosed: next 8 opens | 1.32 | 0.06 | 1 |
#includeparsing knows exactly which headers a.cfile needs. Here it helps only the 14 headers, each fetched once, because the 38.cfiles dominate the misses.- Directory order works because Make compiles a directory’s files in name order. It is a guess about the program, and it would waste bandwidth in a directory full of files nobody opens. Here accuracy was 1.00 because Make reads everything.
- Together they come within a factor of 4 of full disclosure. Coda’s hoarding (Lecture 22) uses the same kind of knowledge to decide what a laptop must carry before it disconnects.
5.4 Hints about freshness: application-specific consistency
Hints need not be about what will be read; they can be about how fresh it must be. Lecture 7 picked one consistency protocol for all data. An application, though, knows things the cache does not. 04_app_specific_consistency.py runs Lecture 7’s server and 5 clients on three kinds of data:
- a static asset (never written);
- a configuration file (written about every 100 s; 30 s of staleness is acceptable);
- a shared document (any staleness is a bug).
| Policy | messages/s (all clients) | stale reads | violations of the application’s tolerance |
|---|---|---|---|
| check-on-use for everything | 35.8 | 0 | 0 |
| TTL 3 s for everything | 7.8 | 290 | 247 (the document) |
| leases 10 s for everything | 5.7 | 0 | 0 |
| application hints: asset immutable, config TTL 30 s, document leased | 4.0 | 393 | 0 |
Check-on-use was always right but spent 20 of its 35.8 messages/s re-validating a file that never changes. A uniform TTL was cheap and wrong for the document. With hints, traffic fell to 11% of check-on-use with no violations. The configuration was “stale” in 393 reads by the cache’s definition, at most 29.4 s old: fresh enough by the application’s. The immutable asset cost 0.02 messages/s, one fetch per client, ever.
This is how the web works. HTTP lets the origin declare freshness:
Cache-Control: max-age=…for a time bound;immutablefor “never revalidate”;no-cachefor “always revalidate”;- validators (
ETag,Last-Modified) for cheap check-on-use.
Sites make assets immutable on purpose by putting a version or a content hash in the name (app.3f9a2c.js): a new version is a new name, so no cache ever has to ask whether its copy is still good. The mechanism (TTL, validation, leases) belongs to the cache; the policy belongs to the application, because only it knows what “fresh enough” means.
6. vTube: streaming a whole virtual machine
6.1 The problem
Abe, Geambasu, Joshi, Lagar-Cavilla and Satyanarayanan asked whether a “YouTube for executable content” was possible. The idea: click on a game, an old application or a research artifact packaged as a virtual appliance (VA), wait briefly, then use it interactively — over broadband or 4G. Running the VM in the cloud and streaming the screen (a thin client) is sluggish at cellular round trips of 50–300 ms, so the VM must run close to the user. But a VA is gigabytes. The paper’s example: a plain Ubuntu image is a 507 MB download, more than nine minutes at the 7.2 Mbps US average of the time (paper’s numbers).
Two observations about VM execution make streaming possible (paper’s findings):
- Sessions differ, but not completely. Two sessions of the same game shared most of their state, but 24–34% of each session’s state was unique to it. A static plan must fetch either the union (too much) or the intersection (too little).
- State is accessed in bursts that are predictable once they start. When the user enters a new game area, a burst of code and data is touched, in nearly the same order every time, and some bursts reliably follow others. So the first accesses of a burst predict the rest, and history predicts which burst comes next.
vTube’s design:
- Clusters: chunks accessed together within 2 s in past traces; overlapping clusters from different traces are split into intersection and complements.
- Prediction: on a demand miss in cluster X, also send each cluster Y that history says may follow, if . Small clusters are cheap to fetch, so they need little evidence; a large cluster must be likely.
- Buffering vs streaming: from the predicted access times and the current bandwidth, compute how much must arrive before the VM resumes so that the rest can stream without further stalls, and pause the VM until then, with a notice to the user.
- Video-streaming metrics: initial buffering delay, number of buffering events, buffering ratio (time stalled / time played).
- The paper reports: on AT&T 4G LTE, under 40 s of initial buffering even for a game touching hundreds of MB, then fewer than 12 interruptions in 15 minutes, about half of them under a second. It also reports at least 2× fewer unnecessary bytes than VMTorrent, a static-order streaming system (paper’s measurements).
6.2 A synthetic appliance
vastream.py builds a simplified stand-in, not vTube’s real VMs:
- a 2 GB image of 64 KB chunks;
- 365 MB of it in 120 clusters (0.5–64 MB, heavy-tailed);
- 40 user activities, each touching 1–4 clusters at 128 MB/s;
- user think times between activities, and an unpredictable single chunk every ~20 s.
A 15-minute session uses 140–175 MB. Sessions differ about as much as vTube’s: 4–40% of one session’s state was unused by another (mean 21%), and 12–16% of a test session’s state was unused by all five training sessions.
Part B compares five strategies (means of 3 test sessions; the server learned from 5 others):
| Strategy (4G-like, 7.2 Mbps / 120 ms) | initial wait | stalls | interruptions (> 1 s) | stall after start | buffering ratio | bytes / used |
|---|---|---|---|---|---|---|
| full download first | 2,222 s | 0 | 0 | 0 s | 0.00 | 13.0 |
| demand paging | 0 s | 2,365 | 57 (17) | 456 s | 0.32 | 1.00 |
| intersection of past sessions | 0 s | 1,414 | 53 (12) | 234 s | 0.19 | 1.02 |
| union of past sessions | 0 s | 884 | 45 (6) | 142 s | 0.13 | 1.48 |
| vTube-like | 26 s | 59 | 48 (6) | 59 s | 0.06 | 1.32 |
On 14.4 Mbps / 60 ms the ranking was the same (vTube: 13 s up front, 28 s of stalls, ratio 0.03).
- Downloading everything first took 37 minutes before the first click, for 13× the bytes used.
- Demand paging started at once but stalled 2,365 times: every chunk paid a round trip.
- The static union cut stalls but moved 48% more bytes than needed; the intersection was frugal and slow.
- vTube waited 26 s up front (the paper reports under 40 s on 4G) and stalled 59 s over 15 minutes, for 1.32× the bytes — inside its goal of at most 2×.
6.3 Which idea did what
Part C switches vTube’s two ideas off one at a time:
| vTube variant (4G) | stalls | interruptions | stall after start | bytes / used |
|---|---|---|---|---|
| push predicted clusters + pause | 59 | 48 | 59 s | 1.32 |
| push only (never pause) | 715 | 48 | 59 s | 1.32 |
| pause only (no history) | 97 | 57 | 155 s | 1.00 |
| neither (just fetch each cluster as one bulk request) | 2,005 | 57 | 155 s | 1.00 |
- Bulk fetches did most of the work. Asking for a whole cluster in one request, instead of one round trip per chunk, cut the stall from 456 s to 155 s. This is §2’s lesson: keep the pipe full.
- History did the rest: pushing the clusters likely to follow, during the user’s think time, cut it from 155 s to 59 s.
- Pausing on purpose did not reduce stall time (59 s either way) or the merged interruptions (48). The same bytes must cross the same link. What it changed was the character of the waiting: 59 separate stalls instead of 715, so one announced pause per new cluster instead of hundreds of back-to-back hiccups. We expected pausing to save time and it did not. vTube’s argument for it is about how waiting feels, and our numbers support only that.
What we did not model: real VM traces, deduplication across VAs, the free-memory list, cluster construction from traces (we gave the simulator the true clusters), and variable bandwidth (Lecture 10).
7. Buffer bloat
7.1 Where latency hides
Every slow link has a queue in front of it: a home router’s uplink, a cellular base station, a Wi-Fi access point, a socket’s send buffer. The queue absorbs bursts — without it, every momentary overload would drop packets. Since memory became cheap, vendors gave these queues megabytes: “more buffer, fewer drops” sounded like an improvement.
Then Gettys and Nichols (2011–2012) noticed that interactive traffic slowed to a crawl whenever anyone uploaded a file. Their name for it was buffer bloat. The cause is the interaction with loss-based congestion control: TCP Reno and Cubic increase their sending rate until a packet is dropped. A drop happens only when the buffer is full, so a TCP flow fills whatever buffer exists and keeps it nearly full. Everything else that shares the queue waits behind it: a keystroke, a game update, a DNS lookup, a demand fetch.
7.2 How much buffer does a link need?
bloat.py builds the classic experiment on Lecture 1’s simulator. A bulk TCP-like flow and a ping (one small packet every 100 ms) share a 10 Mbps bottleneck; the base round trip is about 22 ms, so the BDP is about 18 packets of 1,500 bytes. Part A of 06_buffer_bloat.py varies the router’s tail-drop buffer:
| Buffer (packets) | link used | ping p50 | ping p99 | bulk flow’s RTT |
|---|---|---|---|---|
| 5 (0.27 BDP) | 89% | 22.3 ms | 27.0 ms | 23.4 ms |
| 10 (0.55 BDP) | 95% | 26.7 ms | 33.0 ms | 27.6 ms |
| 18 (1 BDP) | 100% | 34.9 ms | 42.6 ms | 34.8 ms |
| 73 (4 BDP) | 100% | 83.5 ms | 107.9 ms | 85.2 ms |
| 293 (16 BDP) | 100% | 265.2 ms | 315.6 ms | 266.5 ms |
| 1,100 (60 BDP) | 100% | 686.3 ms | 1,332.6 ms | 686.8 ms |
- About one BDP of buffer is enough for full throughput. When a Reno-like flow halves its window after a loss, the buffer must hold enough to keep the link busy while the window grows back. That is the classic rule of thumb (Villamizar and Song 1994). With many desynchronized flows, Appenzeller, Keslassy and McKeown (2004) showed that BDP / suffices.
- Every packet beyond that is pure delay. At 60 BDPs the ping took 686 ms (p99 1.3 s), 33× the 21 ms base round trip, for exactly the same throughput. A video call would be unusable while the upload ran.
7.3 Remedies
Part B (buffer of 1,100 packets, and of 18):
| Queue discipline | link used | ping p50 / p99 | bulk flow’s RTT | max queue |
|---|---|---|---|---|
| tail drop | 100% | 686.3 / 1,332.6 ms | 686.8 ms | 1,100 |
| CoDel | 93% | 23.6 / 30.9 ms | 25.2 ms | 107 |
| fair queueing (FQ) | 100% | 22.8 / 23.4 ms | 692.8 ms | 1,101 |
| fq_codel | 93% | 22.6 / 23.4 ms | 25.2 ms | 106 |
- CoDel (Nichols and Jacobson 2012) is active queue management keyed to time, not length. It timestamps each packet on arrival and measures its sojourn time when it leaves. A brief spike is a “good queue” that absorbs a burst. If sojourn stays above a target (5 ms) for a whole interval (100 ms), there is a standing “bad queue”, and CoDel drops packets at the head, ever faster (spacing interval/√count), until sojourn falls below the target. Time works where queue length does not, because the link rate of Wi-Fi or cellular varies: 100 packets may be 10 ms or 1 s. With CoDel the buffer size stopped mattering: the queue never exceeded 107 packets, and both the ping and the bulk flow saw ~25 ms. The price in our setup was 7% of throughput. A single Reno-like flow, halved by every drop, cannot keep a 5 ms queue full on an 18-packet BDP. With many flows, or with senders that do not rely on losses (BBR), the loss is smaller.
- Fair queueing gives each flow its own queue and serves them in turn (deficit round robin). The ping no longer waited behind the bulk flow: 22.8 ms with any buffer. But the bulk flow was still bloated, 693 ms behind its own packets. That hurts the bulk flow’s own interactive parts, such as a web page that uploads and then waits for a reply.
- fq_codel (RFC 8290) does both: per-flow queues for isolation, CoDel on each for short queues. Most Linux distributions make it the default queue discipline (systemd sets it), and many home routers have adopted it since the buffer-bloat campaign.
7.4 The same effect on this machine
Buffer bloat is not only in routers. Part C measures a real TCP connection over loopback whose reader consumes exactly 2 MB/s. The writer stamps each 16 KB frame with the time of its write(), and the reader measures how long the frame waited:
| Socket buffers requested | send buffer the OS set | frame delay p50 | max | a ping on another connection |
|---|---|---|---|---|
| 16 KB | 63 KB | 42 ms | 60 ms | 0.09 ms |
| OS default | 143 KB | 0.5–0.8 s (varied across runs) | ~1 s | 0.08 ms |
| 1 MB | 1,036 KB | 1,195 ms | 1,344 ms | 0.10 ms |
| 4 MB | 4,098 KB | 3,327 ms | 4,226 ms | 0.07 ms |
The delay is (bytes buffered) / (reader’s rate): with 4 MB buffers on both ends, an urgent message written now is read 3.3 s later. The OS-default row varied from run to run because macOS grows the receive buffer automatically. A ping on a separate connection to the same process took ~0.1 ms throughout: on loopback there is no shared bottleneck, so the bloat lived entirely in this connection’s own buffers.
Some consequences:
- Do not multiplex urgent and bulk data on one TCP connection with large buffers. HTTP/2 does exactly that and suffers head-of-line blocking; QUIC (HTTP/3) and per-stream flow control address it.
- Keep unsent data out of the kernel: Linux’s
TCP_NOTSENT_LOWATlets an application keep its own queue, where it can still reorder or drop. - A prefetcher is a bulk flow. Demo 02’s sequential(8) on random data kept the link 41% busy with useless blocks and made demand misses wait 96 ms instead of 65. Aggressive prefetching over a shared, bloated link delays not only its own demand fetches but everyone else’s traffic.
8. A summary of the trade-offs
| Decision | Lean one way when… | Lean the other way when… |
|---|---|---|
| prefetch depth | RTT × consumer rate is large (WAN, cellular) | accuracy is low, or the cache is small |
| predictor | the pattern is known: sequential, strided, repeating sessions | the pattern is unknown: use adaptive, or ask the application |
| prefetch priority | always below demand traffic | — |
| where prefetched blocks go | a probation area / LRU end | the MRU end only if accuracy is proven high |
| hints | the application knows (disclose), the data says (semantics), history repeats | the cost of a wrong hint exceeds the benefit |
| consistency | per-kind freshness hints from the application | one strict protocol when you cannot trust the hints |
| pausing on purpose | stalls would otherwise come in rapid bursts | the network can keep up |
| router / socket buffers | about one BDP; AQM (CoDel) plus FQ | never “as big as memory allows” |
Summary
- How far ahead: prefetch depth must cover one fetch time, . On broadband 13 blocks reached the floor (10.1 s vs 139.1 s without prefetching) and 12 did not. A depth of 1 barely helped. Prefetching hides latency, never a lack of bandwidth: on 4G the floor was 18.2 s at any depth.
- Judging a prefetcher: accuracy, coverage and timeliness are independent.
- Each predictor won only where its model of the program was right (sequential 97%, stride 100%, history 96% coverage on their own patterns, ~0 elsewhere).
- Disclosed hints covered everything, even random access, but needed enough depth.
- The double-edged sword: a wrong prefetcher made things worse (random: 193 → 287 s; activities: 32 → 183 s) through
- wasted bandwidth: 221 MB moved for 24.5 MB used;
- demand requests queued behind prefetches, fixed by demand priority (287 → 205 s);
- pollution: 1,328 extra misses, fixed only by keeping prefetched blocks from displacing proven ones.
- Hints:
- history from one earlier session removed 62% of misses, from five 88%;
- semantic hints (
#include, directory order) cut Make’s stall from 1.68 s to 0.24 s; - freshness hints let one cache serve immutable, tolerant and strict data at 4.0 instead of 35.8 messages/s with no violations.
- vTube: on 4G, full download meant a 37-minute wait; demand paging 456 s of stalls; a vTube-like scheme waited 26 s, stalled 59 s, and moved 1.32× the bytes it used. Bulk cluster fetches gave most of the gain, history the rest. Deliberate pauses made waiting predictable (59 vs 715 stalls) without shortening it.
- Buffer bloat:
- one BDP of buffer was enough for 100% throughput, and 60 BDPs only added delay (ping 21 ms → 686 ms);
- CoDel kept queues short regardless of buffer size (at a 7% throughput cost for one Reno-like flow), FQ isolated the ping, and fq_codel did both;
- on this machine, 4 MB socket buffers delayed a message 3.3 s behind a 2 MB/s reader.
Common pitfalls
- Prefetching one block ahead on a WAN and concluding that prefetching does not help. The depth must cover the round trip.
- Expecting prefetching to fix a bandwidth shortage. It cannot; only fetching less can.
- Letting prefetches compete with demand requests in the same FIFO queue, at the server, the disk or the network.
- Inserting prefetched data at the MRU end of a small cache. Unproven guesses then evict proven data.
- Reporting accuracy or coverage alone. Report stall time and bytes moved too; coverage counts late prefetches as successes.
- One consistency policy for all data, when the application could say “immutable”, “30 s is fine” or “must be fresh”.
- “More buffer is better.” Beyond one BDP it is only delay. Size buffers by time, and manage them actively.
- Sending urgent messages behind bulk data on the same connection with large socket buffers.
Exercises
-
Bandwidth-bound readahead. A program reads 1,000 blocks of 64 KB over a 20 Mbps link with an 80 ms RTT, computing 10 ms per block. (a) Is it latency- or bandwidth-bound? (b) What is the best possible completion time? (c) What readahead depth keeps the link busy? (d) Compare with the simulation: depth 4 gives 26.6 s, depth 5 25.8 s, depth 8 25.8 s.
Answer
(a) tx = 64,000 × 8 / 20 × 10⁶ = 25.6 ms > 10 ms of compute: bandwidth-bound. (b) About 1,000 × 25.6 ms = 25.6 s, plus the first fetch (105.6 ms). (c) To keep the link busy, enough blocks must be in flight to cover one fetch: ⌈(80 + 25.6) / 25.6⌉ = ⌈4.1⌉ = 5. Note the divisor is now tx, not think, because the link is the bottleneck. (d) Depth 4 leaves gaps (96.6% link utilization, 26.6 s); depth 5 saturates it (99.5%, 25.8 s); more depth changes nothing. Without prefetching: 1,000 × (10 + 105.6) ms = 115.6 s. -
Three numbers. A prefetcher issues 1,000 prefetches; 600 are used before eviction, 450 of them arrived before they were needed. Without prefetching the run had 2,000 misses; with it, 1,450 demand misses. Compute accuracy, timeliness and coverage. Why is coverage lower than 600 / 2,000?
Answer
Accuracy = 600 / 1,000 = 0.60. Timeliness = 450 / 600 = 0.75. Coverage = (2,000 − 1,450) / 2,000 = 0.275, although 600 prefetches were used: 600 would have given 0.30. The difference, 50 misses, is pollution: prefetched blocks pushed out blocks that were then requested and missed. The 150 late prefetches count as avoided misses but still caused some waiting, which is why stall time should be reported too. -
A history table. Three earlier sessions read
A B C D,A B E,A B C F. (a) Build the successor counts. (b) After A, what does a Markov predictor with depth 3 and min_prob 0.5 fetch? (c) After B, with min_prob 0.7?Answer
(a) A→B: 3; B→C: 2, B→E: 1; C→D: 1, C→F: 1. (b) From A: B (3/3 = 1.0 ≥ 0.5), then from B: C (2/3 ≥ 0.5), then from C: D or F with 1/2 each. The tie-break picks one, and 0.5 ≥ 0.5 passes, so it fetches B, C and one of D/F (`prefetch.Markov` breaks ties toward the larger key, so F: it returns B, C, F). (c) From B the best successor is C with 2/3 = 0.67 < 0.7: nothing is fetched. The threshold trades coverage for accuracy. -
vTube’s threshold. An appliance has seven clusters of 0.5, 1, 2, 4, 8, 16 and 32 MB. For each, compute Percentile(Size(Y)), the fraction of all clustered bytes in smaller clusters. History says that after cluster X, the 4 MB cluster follows with probability 0.3 and the 32 MB cluster with 0.45. Which are pushed?
Answer
Total = 63.5 MB. Percentiles: 0.5 MB → 0; 1 → 0.008; 2 → 0.024; 4 → 0.055; 8 → 0.118; 16 → 0.244; 32 → 0.496. The 4 MB cluster is pushed (0.3 > 0.055); the 32 MB one is not (0.45 < 0.496). A wrong push of 32 MB costs 36 s at 7.2 Mbps, so it needs stronger evidence. The rule is a cheap stand-in for an expected-cost calculation. -
Sizing a router buffer. A home router has a 50 Mbps uplink, flows see a 40 ms base RTT, and the router holds 1,000 packets of 1,500 bytes. (a) What is the BDP in packets? (b) How much delay does a full buffer add? (c) If 100 desynchronized flows share the link, what does Appenzeller’s rule suggest? (d) With CoDel, does the buffer size matter?
Answer
(a) 50 × 10⁶ × 0.04 / 8 = 250 KB ≈ 167 packets. (b) 1,000 × 1,500 × 8 / 50 × 10⁶ = 0.24 s added to every round trip when full (and a loss-based upload keeps it full). (c) 167 / √100 ≈ 17 packets. (d) Much less: CoDel keeps the standing queue near its 5 ms target (about 21 packets at 50 Mbps) whatever the physical buffer. A large buffer then only absorbs genuine bursts, which is what buffers are for. -
Why sojourn time? CoDel measures how long packets waited, not how many are queued, and drops at the head of the queue, not on arrival. Explain both choices for a Wi-Fi link whose rate varies between 5 and 500 Mbps.
Answer
A queue of 100 packets is 0.24 s at 5 Mbps and 2.4 ms at 500 Mbps; only time says whether the queue is a problem, and time is what users feel. Dropping at the head signals congestion to the sender one queue-length sooner than dropping the newest arrival, and the dropped packet is the one that waited longest, the most "stale". The interval (100 ms) separates good queues (bursts that drain within a round trip) from bad ones (standing queues that never drain). -
Freshness hints. For each kind of data, choose a freshness hint and say what goes wrong without it: (a) a font file
roboto.v3.woff2; (b) a stock price shown on a dashboard that refreshes every 5 s; (c) a user’s shopping cart; (d) the list of available product categories, edited once a week.Answer
(a) Immutable (the version is in the name); without it every page view revalidates a font that never changes. (b) TTL of about 5 s, or no caching; check-on-use would add a round trip per read for no benefit, and a long TTL would show old prices. (c) Never stale: check-on-use or a lease, or do not cache it in shared caches at all (it is per-user and private). (d) A TTL of minutes to hours, or leases. Without a hint, the cache must choose one policy for all four: too strict for (a) and (d), too loose for (b) and (c). -
The urgent message. A server pushes a large file to a client over one TCP connection with 4 MB socket buffers on each end; the client reads at 1 MB/s. The server then needs to send a 100-byte “cancel” message. (a) Roughly how long until the client reads it? (b) Give three ways to make cancellation fast.
Answer
(a) Up to about 8 MB of data can sit in the two buffers ahead of it: about 8 s (Part C measured 3.3 s with 4 MB buffers at 2 MB/s, the same law). (b) Any of: send control messages on a separate connection (Part C's ping took 0.1 ms); keep socket buffers small and queue data in the application, where it can be reordered (`TCP_NOTSENT_LOWAT`); use a transport with independent streams and priorities (QUIC); or make the client pull data in bounded chunks so there is never much in flight.
Related project and problem set (concepts only)
- Project 2 is about caching, not prefetching, but its proxy faces §4’s choices if it ever fetches ahead: never let a speculative fetch delay a client’s demand request, and never let speculative data evict files clients are using.
- Problem Set 2’s caching questions may involve prefetch arithmetic in the style of exercises 1 and 2. The method is §2 (depth and floors) and §3 (the three numbers); the answers are not here.
Further reading
- Y. Abe et al., “vTube: Efficient Streaming of Virtual Appliances Over Last-Mile Networks”, SoCC 2013 (course reading).
- R. H. Patterson et al., “Informed Prefetching and Caching”, SOSP 1995 — disclosure hints and cost-benefit buffer allocation.
- A. J. Smith, “Sequentiality and Prefetching in Database Systems”, ACM TODS 3(3), 1978.
- S. Srinath, O. Mutlu, H. Kim, Y. Patt, “Feedback Directed Prefetching”, HPCA 2007 — throttling by measured accuracy.
- J. Gettys and K. Nichols, “Bufferbloat: Dark Buffers in the Internet”, CACM 55(1), 2012.
- K. Nichols and V. Jacobson, “Controlling Queue Delay”, ACM Queue 10(5), 2012; RFC 8289 (CoDel); RFC 8290 (fq_codel).
- G. Appenzeller, I. Keslassy, N. McKeown, “Sizing Router Buffers”, SIGCOMM 2004.
- N. Cardwell et al., “BBR: Congestion-Based Congestion Control”, ACM Queue 14(5), 2016.
- M. Satyanarayanan, “The Emergence of Edge Computing”, IEEE Computer 50(1), 2017 — next lecture’s reading.
Preview of Lecture 10 — Mobile and edge computing
vTube assumed a fixed bandwidth. A phone on the move does not have one: bandwidth swings by 10× in seconds, the battery is finite, and the device is weak compared with a server. Lecture 10 asks what that does to distributed systems. It covers Satyanarayanan’s four constraints of mobility; adaptation (lowering fidelity when the network cannot keep up, and how quickly to react); offloading computation to the cloud or to a nearby cloudlet, and when that saves time or energy; and why the speed of light makes some applications impossible from a distant data center.
术语表 (Glossary, English → 中文)
| English | 中文 |
|---|---|
| prefetching / readahead | 预取 / 预读 |
| latency hiding | 延迟隐藏 |
| prefetch depth / distance | 预取深度 / 距离 |
| compulsory (cold) miss | 强制(冷)缺失 |
| bandwidth floor / bandwidth-bound | 带宽下限 / 带宽受限 |
| latency-bound | 延迟受限 |
| Little’s law | 利特尔定律 |
| accuracy / coverage / timeliness | 准确率 / 覆盖率 / 及时性 |
| late prefetch | 迟到的预取 |
| wasted prefetch / wasted bandwidth | 无用预取 / 浪费的带宽 |
| cache pollution | 缓存污染 |
| demand fetch / demand miss | 按需获取 / 按需缺失 |
| priority (demand before prefetch) | 优先级(按需优先于预取) |
| head-of-line blocking | 队头阻塞 |
| sequential / strided access | 顺序 / 跨步访问 |
| adaptive readahead | 自适应预读 |
| history-based (Markov) prediction | 基于历史(马尔可夫)的预测 |
| informed prefetching / disclosure hints | 知情预取 / 披露提示 |
| semantic hints | 语义提示 |
| hint extraction | 提示提取 |
| hoarding | 囤积(断连前预取) |
| application-specific consistency | 应用相关的一致性 |
| freshness hint / immutable | 新鲜度提示 / 不可变 |
| Cache-Control / max-age / ETag | 缓存控制 / 最大存活时间 / 实体标签 |
| virtual appliance (VA) | 虚拟设备(虚拟应用镜像) |
| thin client | 瘦客户端 |
| last-mile network | 最后一英里网络 |
| state cluster | 状态簇 |
| buffering ratio / buffering event | 缓冲比 / 缓冲事件 |
| initial buffering delay | 初始缓冲延迟 |
| interruption / stall | 中断 / 停顿 |
| buffer bloat | 缓冲区膨胀 |
| bottleneck link | 瓶颈链路 |
| tail drop (drop-tail) | 尾部丢弃 |
| loss-based congestion control | 基于丢包的拥塞控制 |
| active queue management (AQM) | 主动队列管理 |
| CoDel (controlled delay) / sojourn time | 受控延迟算法 / 逗留时间 |
| good queue / bad queue (standing queue) | 好队列 / 坏队列(常驻队列) |
| fair queueing / deficit round robin | 公平排队 / 赤字轮询 |
| fq_codel | 公平排队 + CoDel |
| bandwidth-delay product (BDP) | 带宽时延积 |
| socket buffer (SO_SNDBUF / SO_RCVBUF) | 套接字缓冲区 |
| RACK (time-based loss detection) | 基于时间的丢包检测 |