Preview Part K: Deep Dive · Chapter 40 · 13 min read · 20 practice questions
After this chapter you will be able to
explain the memory wall and why caches exist
compare L1, L2 and L3 by size, latency and sharing
explain inclusive and exclusive cache designs
map a memory block to cache lines using direct, fully associative and set-associative mapping
calculate hit ratio and average memory access time
explain, in general terms, why extra cache is stacked on top of the processor
Chapter 40 at a glanceCache is the answer to the memory wall. Move from L1 to RAM and things get bigger and slower.
40.1 The Memory Wall
Since the 1980s, processors have become much faster than memory. A CPU core can finish a simple operation in well under a nanosecond, but a request to main RAM can take about 80 ns. On a 4 GHz core, that is roughly 320 clock cycles of waiting.
Speed gap between processor and RAM kept growing for decades. This growing gap is called the memory wall. The term was popularised by researchers in the mid-1990s.
The main tool for climbing the wall is cache: a small, fast memory that keeps copies of the data the CPU is likely to need next (see Chapter 6).
Caches work because of locality. Temporal locality: recently used data is likely to be used again. Spatial locality: data near a recently used address is likely to be used next.
Clock cycle at 4 GHz: 1 ÷ 4,000,000,000 s = 0.25 ns. So 80 ns ÷ 0.25 ns = 320 cycles.
40.2 Cache Levels at a Glance
Cache levels inside a CPUCloser to the core means smaller and faster. L1 is private, L3 is shared, and RAM is the slowest step.Desk, shelf, library, warehouse Think of cache levels as places to fetch a book. The desk (L1) is closest and fastest, and the warehouse (RAM) is the farthest.
Feature
L1
L2
L3
Location
Inside each core
Inside each core, or on the chip close to it
On the chip, shared by all cores
Typical size
32–64 KB per core, often split into instruction and data parts
About 256 KB to 2 MB per core
Several MB to tens of MB in most chips
Latency (typical)
About 4–5 cycles (about 1 ns)
About 10–20 cycles (2.5–5 ns)
About 30–50 cycles (7.5–12.5 ns)
Speed rank
Fastest
Middle
Slowest of the three, but still far faster than RAM
Each level is larger and slower than the one before it.
A request goes to L1 first. If it misses, it goes to L2, then L3, and only then to RAM.
Latency figures are typical orders of magnitude at about 4 GHz; real designs vary.
Historically, L2 cache sat on the motherboard in the 1990s and later moved onto the processor chip. L3 became common on desktop chips around the late 2000s.
★ EXAM POINT - L1 is the smallest and fastest, and it is private to each core. L3 is the largest of the three and is shared by all cores. The order is L1 < L2 < L3 in size.
What the full chapter covers
The full chapter has these sections:
40.1 The Memory Wall
40.2 Cache Levels at a Glance
40.3 The Latency Ladder
40.4 Private, Shared and Inclusive Caches
40.5 Mapping: How a Block Finds Its Cache Line
40.6 Hit Ratio and Average Access Time
40.7 Why Cache Is Stacked in 3D
40.8 How to Read Cache Figures on a CPU Spec
Chapter Quick Revision
Most Important Terms
Common Confusions
Rapid Recall
Sample questions from this chapter
1. Mapping where a block can go in any line?
Set-associative
Fully associative
Direct mapped
Write-through
Show answer
Answer: B. Fully associative
A fully associative cache lets any block go into any line, so it has the fewest conflict misses.
2. Cache coherence protocol with four states?
MSI
MOESI
MESIF
MESI
Show answer
Answer: D. MESI
MESI uses four cache-line states: Modified, Exclusive, Shared and Invalid.
3. Approximate RAM access time in ns?
80
10
320
3
Show answer
Answer: A. 80
A request to main RAM takes about 80 ns, the largest jump in the memory hierarchy.
4. Total L2 of 8 cores with 1 MB L2 each?
4 MB
1 MB
8 MB
16 MB
Show answer
Answer: C. 8 MB
Total L2 = 8 cores × 1 MB = 8 MB, since L2 is listed per core.
5. Vertical links used in stacked cache?
Bond wires
Heat spreaders
Through-hole vias
Through-silicon vias
Show answer
Answer: D. Through-silicon vias
TSVs are tiny vertical connections that link the stacked dies.