Skip to content
Tactiverge

School/✦ Research Engineer/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.

About 40 min · 3 goals · Checked by automated tests

1.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.

2.Predict

L1 hits in 1 cycle with a 5% miss rate; memory takes 100 cycles. What is the AMAT?

Guess first. Being wrong here is how the surprise works.

3.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?

Loading the interactive…

Can't use the interactive? Read a description instead

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.

4.Checkpoint: guided practice

Check what you just discovered before going on. Hints appear after a wrong answer.

Practice 1 · a fresh version every time

A cache has a hit time of 3 cycles, a miss rate of 1% and a miss penalty of 100 cycles. What is the AMAT in cycles?

cycles

5.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

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.

Derivation: AMAT for two levels, and back into CPI
  1. One level: every access pays h₁; a fraction m₁ also pays the penalty P₁. AMAT = h₁ + m₁P₁.

  2. 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).

  3. So P₁ = h₂ + m₂·t_mem and AMAT = h₁ + m₁(h₂ + m₂·t_mem).

  4. Global L2 miss rate = m₁·m₂: the fraction of all accesses that reach memory.

  5. Memory stall cycles per instruction = (memory accesses per instruction) × (AMAT − h₁), if the hit time is already counted in base CPI.

  6. 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.

6.Practice on your own

Practice, not a test. Wrong answers get a hint and another try.

Practice 2 · a fresh version every time

L1: hit time 1 cycles, miss rate 10%. L2: hit time 8 cycles, local miss rate 10%. Main memory: 300 cycles. What is the AMAT in cycles?

cycles

Practice 3 · a fresh version every time

A cache has a hit time of 2 cycles, a miss rate of 5% and a miss penalty of 100 cycles. What is the AMAT in cycles?

cycles

Practice 4

L1 miss rate is 4% and L2 local miss rate is 25%. What percentage of all accesses go to main memory?

%

Practice 5

AMAT = 1 + 0.08 × 50. Which single change helps most?

Practice 6

Base CPI is 1. There are 0.4 memory accesses per instruction, L1 hit time is included in base CPI, and AMAT is 3 cycles with a 1-cycle hit time. What is the effective CPI?

7.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.

8.Reflect

Concepts: Memory hierarchy and caches · Pipelining, hazards and the Iron Law