Memory Hierarchy and AMAT: Average Memory Access Time

No memory is both big and fast. Registers and small SRAM caches answer in a cycle or a few but hold kilobytes; DRAM holds gigabytes but takes on the order of a hundred cycles; storage holds far more and is slower still. A memory hierarchy stacks them so that most accesses are served by the small fast levels, and the average access time, AMAT, ends up close to the fastest level's. This page builds AMAT up from one level to three, with worked numbers at each step.

Learning objectives

  • Explain why a hierarchy works: locality in time and in space
  • Compute AMAT for one, two and three levels of cache
  • Tell local miss rates from global ones, and use the right one
  • Turn AMAT into stall cycles per instruction and CPI

Prerequisites

  • Part 3: hits, misses, lines and sets
  • Percentages and a weighted average

The levels

LevelBuilt fromTypical sizeExample access time
Registersflip-flops32 registerspart of the cycle
L1 cacheSRAM32 to 64 KiB per coreabout 4 cycles
L2 cacheSRAM256 KiB to a few MiBabout 12 cycles
L3 cacheSRAM, sharedseveral to tens of MiBabout 40 cycles
Main memoryDRAMgigabytesabout 200 cycles

The access times are example values for the worked numbers; real ones vary by design and are in each processor's manual. The hierarchy works because programs show locality: a byte used now is likely to be used again soon (temporal locality, as in a loop variable), and its neighbors are likely to be used next (spatial locality, as in an array sweep). Caches keep recently used lines for the first and fetch whole lines for the second.

AMAT, one level and more

For one cache level, AMAT = hit time + miss rate x miss penalty. Every access pays the hit time, since the cache is checked first, and the fraction that misses pays the penalty on top. With a second level, the L1 miss penalty is itself an AMAT: the L2 hit time plus the L2 miss rate times the memory penalty.

HierarchyMiss penalty seen by L1AMAT
L1 (1 cycle, 5% misses) and memory (100 cycles)100 cycles6.0 cycles
Add an L2 (10 cycles, 20% local misses)30 cycles2.5 cycles
Three levels (worked example below)37 cycles6.96 cycles
The same without its L362 cycles8.96 cycles
Average memory access time rising with L1 miss rate, with and without an L2 cache
AMAT against the L1 miss rate: an L2 flattens the line because each L1 miss costs 30 cycles instead of 100.

Local and global miss rates

The L2's miss rate here is local: 20 percent of the accesses that reach L2, not of all accesses. Only 5 percent of accesses reach L2, so the global rate, the share of all accesses that go to memory, is 5 percent x 20 percent = 1 percent. Plugging the global rate into the L2 term instead of the local one is the most common AMAT mistake.

Worked example: three levels

A typical desktop-class example: L1 4 cycles with 8 percent misses, L2 12 cycles with 25 percent local misses, L3 40 cycles with 30 percent local misses, and memory 200 cycles away. Work from the bottom up: the L3 miss penalty seen by L2 is 40 + 0.3 x 200 = 100 cycles, so L1's miss penalty is 12 + 0.25 x 100 = 37 cycles, and AMAT = 4 + 0.08 x 37 = 6.96 cycles. Removing the L3 raises it to 8.96 cycles.

Common mistakes

  • Adding the miss penalty to every access. Only the missing fraction pays it; the hit time is paid by all.
  • Using a global miss rate where a local one belongs, or the other way round.
  • Working top down in a multi-level hierarchy. Start at the level next to memory and work up.
  • Mixing cycles and nanoseconds. Convert once, at the end, with the clock frequency.
  • Making L1 bigger without checking the hit time. A slower L1 can raise AMAT even with fewer misses (exercise 2).

Quick check

1. L1 hit 1 cycle, miss rate 5 percent, memory 100 cycles: what is AMAT?

1 + 0.05 x 100 = 6 cycles.

2. 5 percent of accesses miss L1 and 20 percent of those miss L2. What fraction of all accesses goes to memory?

1 percent: the global L2 miss rate is 0.05 x 0.20.

3. Why do caches fetch whole lines instead of single bytes?

Spatial locality: the bytes next to the one used are likely to be used soon, and fetching them together costs little more.

Exercises

E1 (easy). Hit time 2 cycles, miss rate 10 percent, miss penalty 50 cycles. AMAT?

2 + 0.1 x 50 = 7 cycles.

E2 (medium). A bigger L1 cuts the miss rate from 5 to 3 percent but takes 2 cycles to hit instead of 1. With the two-level example above, is it worth it?

No. The small L1 gives 1 + 0.05 x 30 = 2.5 cycles; the big one 2 + 0.03 x 30 = 2.9. The extra hit cycle is paid on every access, while the saving applies only to 2 percent of them.

E3 (medium). With a 1-cycle hit and a 30-cycle miss penalty, what L1 miss rate keeps AMAT at or below 2 cycles?

1 + m x 30 <= 2, so m <= 1/30: 3.33 percent.

E4 (hard). For the three-level example, what is AMAT in nanoseconds at 3 GHz, and what is the CPI with a base CPI of 1 and 1.3 memory accesses per instruction?

6.96 cycles is 2.32 ns. The hit time of 4 cycles is hidden by the pipeline here, so each access stalls for AMAT minus the hit time, 2.96 cycles, and CPI = 1 + 1.3 x 2.96 = 4.85. Memory stalls, not arithmetic, dominate the run time.

Interview questions

  • Q1. Why have several cache levels instead of one large cache? Answer: a large cache is slow; a small fast L1 keeps the common case quick, and larger slower levels catch most of its misses before they reach DRAM.
  • Q2. What is the difference between local and global miss rate? Answer: local is misses over accesses that reach that level; global is misses over all accesses from the processor.
  • Q3. Name two ways to reduce AMAT. Answer: lower the miss rate (more capacity or associativity, prefetching) or the miss penalty (another cache level, faster memory), or the hit time (a smaller, simpler L1).

Summary

  • AMAT = hit time + miss rate x miss penalty, applied level by level from memory upward.
  • Local miss rates go in the formula; the global rate is the product of local rates.
  • Locality in time and space is what lets a small fast level serve most accesses.
  • Memory stalls per instruction often decide CPI more than the pipeline does.

Related

Sources

Last verified

Every number on this page was computed and checked on 27 November 2026.