Multilevel Caches
Put a bigger, slower cache behind the small fast one, and an L1 miss no longer pays the full trip to memory: it pays the L2's own average access time. Nesting the AMAT formula once gives .
What the symbols mean
- L1 hit time
Time to get the data from L1 when it's there.
- L1 miss rate
Fraction of all accesses that miss in L1.
- L2 hit time
Time to get the data from L2 after an L1 miss, when L2 has it.
- L2 local miss rate
Of the accesses that reach L2 (the L1 misses), the fraction that miss there too.
- Memory time
Time to fetch from main memory.
What the symbols mean
- Global miss rate
Fraction of all accesses that go all the way to main memory.
Explanation
A multilevel cache is simply a stack of caches, each one bigger and slower than the one above it: a tiny L1 cache right next to the processor, a larger L2 behind it (often an L3 behind that) and main memory at the bottom. The "L" just stands for level. The idea is that a miss in L1 shouldn't have to go all the way to main memory; it gets a second chance in L2. The formula looks like a pile of letters, but it's last lesson's formula used twice: and are L1's hit time and miss rate, and are L2's, and is the trip to main memory. If AMAT made sense, this will too.
Why not just make L1 bigger? A bigger memory is a slower memory: signals take longer to cross it and there are more entries to search. L1 has to answer in a cycle or two, so it stays small (tens of KiB) and misses a few percent of the time. L2 can afford to be ten times bigger and ten times slower, because only those few percent of accesses ever ask it anything.
Nesting the formula. Take a look at the single-level formula, . From L1's point of view, what's the miss penalty now? It's however long it takes to get the data from below, and below is L2, with its own hit time and its own miss rate. That's exactly L2's average access time:
Substitute it for L1's penalty and you get . A third level nests once more: replace with . Each level's miss penalty is the average access time of everything below it.
Local vs global miss rate. Here's the subtle part. is the local miss rate: out of the accesses that actually reach L2, what fraction miss there? But L2 only ever sees L1's misses, the hard accesses that already failed once. So a local miss rate of 40% for L2 is normal and doesn't mean L2 is doing badly. The global miss rate asks a different question: out of all the accesses the processor makes, what fraction go all the way to memory? To get there, an access has to miss in L1 (probability ) and then miss in L2 (probability , given it got that far). That's the multiplication rule from Probability Rules:
Multiply out the AMAT formula and the global rate shows up on its own:
Read it term by term: every access pays , the fraction also pays , and the fraction also pays the trip to memory. It's the same expected-value reasoning as before, with one more possible outcome.
A common mistake. It's tempting to plug the global miss rate in for , since it's also "the L2 miss rate." Don't. In , the in front already says only L1's misses reach L2, so using the global rate counts twice. Read the problem carefully: "of the accesses that reach L2" means local, "of all accesses" means global. If you're handed a global rate, divide by to get the local one.
There's a graph further down comparing the average access time with and without an L2 as the L1 hit rate drops.
See it
Worked examples
An L1 cache has a -cycle hit time and a miss rate. Behind it, an L2 has a -cycle hit time and a local miss rate of . Main memory takes cycles. Find the AMAT and the global miss rate, and compare with having no L2.
- 1
Start from the bottom, because L1's miss penalty depends on what's below it. An access that reaches L2 pays L2's -cycle hit time, and of the time it also has to go on to memory.
A simulator runs memory accesses. of them miss in L1, and of those also miss in L2. Find L1's miss rate, L2's local miss rate and the global miss rate.
- 1
L1 sees every access, so its miss rate is L1 misses over all accesses: .
Practice
Type your answer and check it. Solve them all to complete the lesson.
L1: -cycle hit, miss rate. L2: -cycle hit, local miss rate. Memory: cycles. What's the AMAT, in cycles?
L1 misses of all accesses, and L2's local miss rate is . What percent of all accesses go to main memory?
A profiler says of all accesses miss in L1 and of all accesses miss in L2. What's L2's local miss rate, as a decimal?
A student sees that an L2 cache has a local miss rate of and concludes it's nearly useless. What's the best response?
Three levels: L1 cycle with misses, L2 cycles with local misses, L3 cycles with local misses, and memory cycles. What's the AMAT, in cycles?
A chip designer has an L1 with a -cycle hit time and an miss rate, in front of -cycle memory. Adding a -cycle L2 with a local miss rate is being considered. How many times faster does the average memory access get?
A processor has and makes memory accesses per instruction. L1 misses of them; L2 takes cycles and has a local miss rate; memory takes cycles. What's the real CPI? (Uses Hit Rate and AMAT.)
The hardest one here. Get it, and you've got this lesson.
A team needs a CPI of at most . The processor has , makes memory accesses per instruction, and its L1 misses of them. The L2 takes cycles and memory takes cycles. What's the largest local L2 miss rate that meets the goal, and what global miss rate does that mean? Give both as percents, in that order.
Where it's used
Every modern processor has at least three levels: a few tens of KiB of L1 per core answering in about a nanosecond, an L2 of a MiB or so, and a shared L3 of tens of MiB, all in front of DRAM that takes around to ns. Chip architects use exactly this nested formula, with miss rates measured on real programs, to decide how big each level should be and how much slower it can afford to be. The same layering shows up outside chips: a phone keeps recent photos in RAM, then on flash, then in the cloud, and the average wait follows the same nested expected value.