Lite / Independent Engineering Research / Week 21
Average memory access time
A cache hits 95% of the time. Is that good? It depends entirely on what the other 5% cost.
Why should I care?
Architects argue about caches in AMAT. It turns hit rate, latency and memory speed into one number in cycles, and it shows why a slightly bigger, slower L1 can lose to a small fast one backed by a good L2.
- Compute AMAT = hit time + miss rate × miss penalty for one cache level.
- Extend AMAT to two levels using L2 local miss rate.
- Fold memory stalls into the Iron Law and judge which cache change helps most.
Predict
L1 hits in 1 cycle with a 5% miss rate; memory takes 100 cycles. What is the AMAT?
- 1 cycle
- 5 cycles
- 6 cycles
- 100 cycles
Guess first, then reveal
AMAT = 1 + 0.05 × 100 = 6 cycles. The 5% of misses costs five times more than all the hits put together.
Discover
Start with L2 off. Raise main-memory latency and watch AMAT climb. Turn L2 on and find the L2 miss rate at which it stops being worth having. Which change saves more: halving the L1 miss rate, or halving the L2 hit time?
What the interactive shows (text version)
The AMAT explorer shows a stacked bar: L1 hit time, plus L1 misses times L2 time, plus global misses times memory time. With h₁ = 1, m₁ = 5%, h₂ = 10, m₂ = 20% and memory 100 cycles, AMAT = 2.5 cycles; without L2 it is 6.
Understand
One formula, three levers
AMAT = hit time + miss rate × miss penalty. Reduce hit time (small, simple L1), reduce miss rate (bigger, more associative, better prefetching) or reduce miss penalty (an L2, faster memory, critical-word-first). They fight: bigger and more associative usually means slower hits.
Local and global miss rates
L2's local miss rate looks bad (20–50% is common) because L1 has already filtered out the easy accesses. What matters for AMAT is the global rate m₁·m₂, often well under 1%.
Back to the Iron Law
Memory stalls add to CPI. A program with 0.3 memory accesses per instruction and 1.5 extra cycles per access from misses gains 0.45 CPI: as much as many branch-prediction improvements. This is why memory is often called the bottleneck.
Explain it another way
Intuitive
Your average commute: most days the bus is on time, but one day in twenty it breaks down and you wait an hour. That rare hour dominates the average.
Technical
AMAT is an average; real out-of-order cores overlap some misses (memory-level parallelism), so effective stall time can be lower. AMAT remains the standard first-order model.
Mathematical
∂AMAT/∂m₁ = P₁ and ∂AMAT/∂h₁ = 1. With P₁ = 30, cutting the miss rate by 0.01 saves 0.3 cycles; cutting hit time by 1 saves 1 cycle. Compare costs in hardware to choose.
Applied
Embedded designers sometimes place time-critical code in tightly coupled memory (TCM), a small SRAM with a fixed one-cycle access and no misses: AMAT = 1 exactly, which makes deadlines provable.
Derivation: AMAT for two levels, and back into CPI
One level: every access pays h₁; a fraction m₁ also pays the penalty P₁. AMAT = h₁ + m₁P₁.
With L2, an L1 miss is served by L2, whose own average time is h₂ + m₂·t_mem, where m₂ is L2's local miss rate (misses ÷ accesses that reach L2).
So P₁ = h₂ + m₂·t_mem and AMAT = h₁ + m₁(h₂ + m₂·t_mem).
Global L2 miss rate = m₁·m₂: the fraction of all accesses that reach memory.
Memory stall cycles per instruction = (memory accesses per instruction) × (AMAT − h₁), if the hit time is already counted in base CPI.
Example: h₁ = 1, m₁ = 0.05, h₂ = 10, m₂ = 0.2, t_mem = 100: AMAT = 1 + 0.05 × 30 = 2.5 cycles, versus 6 without L2.
Worked example 1
Option A: 1-cycle L1, 6% miss rate. Option B: 2-cycle L1, 3% miss rate. Both backed by a 40-cycle L2 that never misses. Which is better?
A: 1 + 0.06×40 = 3.4. B: 2 + 0.03×40 = 3.2. B wins slightly; with a 30-cycle L2 they tie at 2.8 and 2.9 (A wins). The answer depends on the penalty.
Common mix-ups
A 95% hit rate means memory is 95% as fast as the cache.
✓ With a 100-cycle penalty, AMAT is 6× the hit time. Misses dominate.A 30% L2 miss rate means L2 is useless.
✓ It is a local rate on the hard accesses L1 missed; the global rate is far lower.
Practice
Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.
Apply it
Design a two-level hierarchy for a 'module check': choose L1 and L2 hit times and miss rates (state your assumptions) to achieve AMAT under 2 cycles with a 150-cycle memory. Show the calculation and argue which assumption is least realistic.
Reflect
Which surprised you more: how much a few misses cost, or how much an L2 rescues?
Write your answer on paper or in your own notes. Lite never stores what you write.