5.4.17 · D1Memory Hierarchy & Caches

Foundations — Prefetching strategies

2,053 words9 min readBack to topic

This page assumes nothing. Before you read the parent note, you must be fluent in every letter, ratio, and picture it throws at you. We build each one from the ground up, in an order where every symbol is earned before it is used.


0. The stage everything sits on: a cache

Look at the picture below: the CPU never talks to slow memory directly if it can help it — it looks in the fast cache first.

Figure — Prefetching strategies

WHY the topic needs this: prefetching's entire job is turning misses into hits. If you don't have the words "block", "hit", "miss" as pictures in your head, the metrics later are meaningless. This is the ground floor — see Cache Basics — Blocks and Locality.


1. Time measured in cycles, and why memory is so slow

WHY the topic needs this: the entire motivation for prefetching is that a stall is enormous. Every formula later is really asking "how many of these 400-cycle freezes can we avoid?"


2. Two kinds of "you'll want it soon" — locality

Figure — Prefetching strategies

WHY the topic needs this: locality is the reason a guess can succeed at all. Next-line prefetching lives on spatial locality; correlation prefetching lives on repeated (temporal) patterns of misses. No locality → no predictable future → prefetching is pure luck. Full detail in Spatial vs Temporal Locality.


3. Address, block number, and stride — the arithmetic of "where"

Let's make "stride" a picture — a ruler with evenly spaced ticks:

Figure — Prefetching strategies

WHY the topic needs this: next-line prefetch is the special case stride block (one box forward). Stride prefetch is the general case, usually expressed in bytes. The parent's formula is nothing but "start here, take equal steps of size stride" — with and in the same unit (bytes).


4. Degree and the multiplier — how far ahead to run

WHY the topic needs this: the parent uses and in both next-line and stride strategies. If you read without knowing just counts , the formula looks mysterious. It isn't — it's just "take evenly spaced steps forward."


5. Fractions that grade a prefetcher — , ,

Everything the parent measures is a fraction: a number between and meaning "this portion of a whole."

The two pie charts below make the "different wholes" point visual. Look at what each pie is a slice of: the left pie is cut from the set of original misses — its green wedge () is the portion of those misses we killed. The right pie is cut from a completely different set, the prefetches we issued — its green wedge () is the portion that got used, and the red "wasted / pollution" slice is bandwidth thrown away. The two greens are not comparable numbers: they answer different questions because they are slices of different circles. That is exactly why you must never multiply into a coverage formula.

Figure — Prefetching strategies

WHY the topic needs this: the parent's central formula only makes sense once you see that is already "the misses actually eliminated". The related metrics feed Cache Pollution and Replacement Policies (bad accuracy → pollution) and are the vocabulary of the whole page.


6. Reading before the parent does

We now have every piece. Read the formula in plain words:

If (prefetcher does nothing), . If (kills every miss), . Every value in between is a straight line — no hidden accuracy factor, because already counts only the ones that worked. See Average Memory Access Time (AMAT) for where plugs in.


7. Symbols you'll meet later (so they're not new when you get there)

Recall

and = time for a cache hit (small, ~1 cycle). = extra penalty of a miss (~100 cycles). AMAT : you always pay the hit-probe, and only survivors pay the penalty.

Recall

(pollution) Extra misses created when a useless prefetch evicts a still-needed block. Written . This is why an inaccurate prefetcher can make things worse.

Recall PC and the Reference Prediction Table

PC = program counter = the address of the instruction doing the load. The table is indexed by PC so different loads (A[i] vs B[j]) keep separate stride histories and don't corrupt each other.

Recall MLP and Out-of-Order

Memory-Level Parallelism (Memory-Level Parallelism (MLP)) = having several memory fetches in flight at once. Out-of-Order Execution lets the CPU keep working past a stall — the useful computation that prefetch overlaps with. Compiler Optimizations — Loop Blocking is the software cousin that reshapes access patterns to be prefetch-friendly.


Prerequisite map

Cache blocks hits misses

Prefetching strategies

Cycles and stall cost

Spatial and temporal locality

Address block number stride

Degree D and index k

Fractions m c a

Effective miss rate m_eff

AMAT


Equipment checklist

Test yourself — reveal only after answering out loud.

What is a cache block (line)?
The fixed-size chunk (e.g. 64 bytes) that the cache moves as one unit — never a single byte.
Hit vs miss?
Hit = data already in the fast cache. Miss = must walk to slow memory and stall.
How many CPU cycles does a typical DRAM miss cost?
About 400 cycles (~100 ns at 4 GHz).
Difference between spatial and temporal locality?
Spatial = you'll touch nearby addresses soon; temporal = you'll touch the same address again soon.
How do you compute a stride from two addresses?
Later address minus earlier address (the gap on the number line).
A stride can be counted in two units — which?
Bytes (e.g. 32 B) or blocks (whole boxes forward); "stride = 1 block" means one box, i.e. a byte-stride equal to the block size.
What does prefetch degree count, and what does measure?
= number of lines fetched (a count); = how far ahead in bytes the farthest prefetch reaches (a length).
In , what values does take?
— it just names each of the prefetched lines.
Coverage — numerator and denominator?
(Misses turned into hits) ÷ (original misses).
Accuracy — numerator and denominator?
(Prefetches actually used) ÷ (prefetches issued).
Why can't you multiply accuracy into ?
Because already counts only the misses truly eliminated — accuracy is a separate bandwidth metric over a different denominator.
Read in words.
The fraction of original misses that survive (still miss).
What is ?
Extra misses created by pollution when a useless prefetch evicts a still-needed block.