Ez Computerहिन्दीOpen app

Deep Dive 2 — Cache and the Memory Wall

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
Cache Memory wall CPU far faster than RAM RAM takes about 80 ns 4 GHz cycle = 0.25 ns Locality Temporal: reused soon Spatial: nearby data Why caches work Cache levels L1 private, smallest L2 middle, L3 shared Each level: bigger, slower Inclusive/exclusive Inclusive: L3 has copies Exclusive: victim cache MESI: M, E, S, I states Mapping Direct: block mod lines Set: block mod sets Tag, index, offset bits Hit ratio and AMAT Hit ratio = hits ÷ total AMAT: time formula 95%→98%: 5 → 2.6 ns Stacked cache Cache die on top of CPU TSV links the layers Bigger, but hotter Reading specs L1, L2 usually per core L3 usually shared, total Per-core × core count
Chapter 40 at a glance Cache 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.

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

CPU chip Core 1 L1 L2 Core 2 L1 L2 L3 · shared by all cores RAM · main memory L1 · 32–64 KB · each core’s own · ~1 ns L2 · 256 KB–2 MB · usually own · ~3 ns L3 · several MB · shared by all cores · ~10 ns RAM · about 80 ns away
Cache levels inside a CPU Closer to the core means smaller and faster. L1 is private, L3 is shared, and RAM is the slowest step.
Farther from the core: bigger, slower L1 your desk L2 your shelf L3 shared library RAM warehouse Desk → shelf → library → warehouse = L1 → L2 → L3 → RAM
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

★ 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:

  1. 40.1 The Memory Wall
  2. 40.2 Cache Levels at a Glance
  3. 40.3 The Latency Ladder
  4. 40.4 Private, Shared and Inclusive Caches
  5. 40.5 Mapping: How a Block Finds Its Cache Line
  6. 40.6 Hit Ratio and Average Access Time
  7. 40.7 Why Cache Is Stacked in 3D
  8. 40.8 How to Read Cache Figures on a CPU Spec
  9. Chapter Quick Revision
  10. Most Important Terms
  11. Common Confusions
  12. Rapid Recall

Sample questions from this chapter

1. Mapping where a block can go in any line?

  1. Set-associative
  2. Fully associative
  3. Direct mapped
  4. 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?

  1. MSI
  2. MOESI
  3. MESIF
  4. MESI
Show answer

Answer: D. MESI

MESI uses four cache-line states: Modified, Exclusive, Shared and Invalid.

3. Approximate RAM access time in ns?

  1. 80
  2. 10
  3. 320
  4. 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?

  1. 4 MB
  2. 1 MB
  3. 8 MB
  4. 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?

  1. Bond wires
  2. Heat spreaders
  3. Through-hole vias
  4. Through-silicon vias
Show answer

Answer: D. Through-silicon vias

TSVs are tiny vertical connections that link the stacked dies.