S418 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

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 2 rule, m(S)=m0(S/32 KB)−α with α near 0.5, and misses cost P cycles.
  • This sim assumes the hit time grows half a cycle per doubling, 1+0.5log2⁡(S/4 KB) 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?

Name it

Average memory access time

AMAT=h1+m1(h2+m2(h3+…))

where mi is the local miss rate of level i (misses over accesses reaching it). The global miss rate of level k is m1m2⋯mk. Memory stall cycles per instruction = accesses per instruction × (AMAT − h1), 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

ChangeCutsCosts
larger cachecapacityhit time, area, power
higher associativityconflicthit time, power
larger linescompulsory (spatial locality)miss penalty, pollution
more levelseffective penaltycomplexity

The empirical 2 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
  1. Global L2 miss rate. 0.05×0.2=1%
  2. L2 MPKI. 1000×1.3×0.01=13
  3. Stall cycles. If no misses overlap: 1.3×(3.5−1)=3.25 per instruction.
  4. 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
  1. Compulsory. These are the infinite cache's misses: 2,000.
  2. Capacity. 6,500−2,000=4,500
  3. Conflict. 10,000−6,500=3,500
  4. 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
  1. 32 KB. AMAT=1+0.04×80=4.2cycles
  2. 128 KB. AMAT=2+0.02×80=3.6cycles so the bigger cache wins here.
  3. 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°.

Explain why

Why does a second-level cache help even though its own miss rate often looks poor?

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.