S4 · Lesson 18 · Cache performance and the three Cs
Average memory access time across levels, local and global miss rates, and classifying misses
A processor that executes an instruction every fraction of a nanosecond is fed by a DRAM that answers in about a hundred nanoseconds. Caches bridge that gap, and their quality shows in a single number: the average memory access time. Improving it means knowing where the misses come from. Some are unavoidable first touches, some happen because the program's data doesn't fit, and some because two addresses fight over the same set. Each kind has a different cure, and every cure has a cost, often a slower hit.
- Average memory access time for a single cache against its size, when the miss rate follows the empirical rule, with α near 0.5, and misses cost P cycles.
- This sim assumes the hit time grows half a cycle per doubling, cycles, since bigger arrays have longer wires.
- The total has a minimum: a bigger cache misses less but every hit gets slower. That's why real systems use several levels, small and fast near the core, large and slower behind.
Predict
An L1 cache hits in 1 cycle and misses 5% of the time; the L2 hits in 10 cycles and misses 20% of what reaches it; memory takes 200 cycles. What's the average access time?
3.5 cycles: . The L2's 20% looks bad, but it's a local miss rate: only 5% of accesses reach the L2, so its global miss rate is 0.05 × 0.2 = 1%. Without the L2, every L1 miss would cost 200 cycles and the AMAT would be 11.
Name it
Average memory access time
where is the local miss rate of level i (misses over accesses reaching it). The global miss rate of level k is . Memory stall cycles per instruction = accesses per instruction × (AMAT − ), when misses don't overlap. MPKI, misses per thousand instructions, = 1000 × accesses per instruction × global miss rate.
The three Cs
- Compulsory: the first access to a line; even an infinite cache has them. A single pass over D bytes with B-byte lines has D/B.
- Capacity: the working set doesn't fit; these remain in a fully associative cache of the same size.
- Conflict: too many lines map to the same set; these vanish with full associativity.
Counting misses for an infinite cache, a fully associative cache of the size, and the real cache separates them: compulsory = infinite; capacity = fully associative − compulsory; conflict = real − fully associative. (Multiprocessors add a fourth C, coherence misses, lesson 32.)
Remedies and their costs
| Change | Cuts | Costs |
|---|---|---|
| larger cache | capacity | hit time, area, power |
| higher associativity | conflict | hit time, power |
| larger lines | compulsory (spatial locality) | miss penalty, pollution |
| more levels | effective penalty | complexity |
The empirical rule: doubling a cache's size divides its miss rate by about √2 (α ≈ 0.5).
Worked example
For the 1 / 10 / 200-cycle hierarchy above, with 1.3 memory accesses per instruction, find the global L2 miss rate, the L2 MPKI and the stall cycles per instruction.
Show the solution
- Global L2 miss rate.
- L2 MPKI.
- Stall cycles. If no misses overlap: per instruction.
- In practice. An out-of-order core overlaps many of them, which is why measured stalls are usually lower.
Answer a global L2 miss rate of 1%, an L2 MPKI of 13, and 3.25 stall cycles per instruction if no misses overlap.
Worked example
A program has 10,000 misses on a direct-mapped cache, 6,500 on a fully associative cache of the same size, and 2,000 on an infinite one. Classify them.
Show the solution
- Compulsory. These are the infinite cache's misses: 2,000.
- Capacity.
- Conflict.
- What helps each. Higher associativity could remove up to 3,500 misses; only a larger cache helps the 4,500 capacity misses; nothing but prefetching helps the compulsory ones.
Answer 2,000 compulsory, 4,500 capacity and 3,500 conflict misses.
Worked example
A 32 KB L1 hits in 1 cycle and misses 4% of the time; a 128 KB L1 would miss half as often (the √2 rule, twice over) but hit in 2 cycles. The miss penalty is 80 cycles. Which gives the lower AMAT?
Show the solution
- 32 KB.
- 128 KB. so the bigger cache wins here.
- Shorter penalties. With a 50-cycle penalty both give 3.0, and with a shorter one the small, fast cache wins, which is why L1s stay small when an L2 sits close behind them.
Answer the 128 KB cache gives the lower AMAT, 3.6 cycles against 4.2.
Check
L1 hits in 1 cycles and misses 0.03; L2 hits in 14 cycles and misses 0.4 locally; memory takes 150 cycles. What's the AMAT?
Check
L1 misses 0.02 of accesses; L2's local miss rate is 0.1. What's L2's global miss rate?
Check
A program makes 1.2 memory accesses per instruction; AMAT is 2.5 cycles and the hit time 2. How many stall cycles per instruction does memory add, with no overlap?
Check
A 32 KB cache misses 0.04 of the time. By a power law with exponent 0.5, what miss rate should a 512 KB cache have?
Check
A program streams once through 8 MB of data with 32-byte cache lines. How many compulsory misses does it take?
Check
A program has 8000 misses on a direct-mapped cache, 5000 on a fully associative one of the same size, and 2500 on an infinite cache. How many are conflict misses?
Check
An L1 hits in 1 cycles with a 0.03 miss rate; its L2 hits in 14 cycles with a local miss rate of 0.5; memory takes 150 cycles. There are 1.3 memory accesses per instruction, and misses don't overlap.
(a)
What is the AMAT?
(b)
What is the global L2 miss rate?
(c)
How many stall cycles per instruction does memory add?
Check
A cache of size S misses at rate m; the √2 rule predicts how the rate changes at size T. Hits take h cycles and misses P.
Step 1
What miss rate does size T have?
Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.
Step 2
What is its AMAT?
Explain why
Why does a second-level cache help even though its own miss rate often looks poor?
The L2 only sees the accesses that already missed in the L1, and those are the hardest ones: the first-level cache has already caught the easy, frequently reused data. So the L2's local miss rate, measured over its own accesses, is naturally high, perhaps 20 to 50%. What matters is how many accesses it saves from main memory. Without an L2, every L1 miss pays the full memory latency; with it, most of them pay only the L2's much shorter hit time, and only the L2's misses, a small global fraction of all accesses, go to memory. The average access time can drop by a factor of several even with a local miss rate that sounds bad.
Practice
Keep practicing
10 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.