Course contentsShow
← Computer Science
Lesson 1121 of 2,87226. Memory Hierarchy and CachingFree lesson

Cache Levels: L1, L2, L3

The multi-level cache hierarchy with L1 closest to CPU, trading size for speed at each level.

Cache Levels: L1, L2, L3

What you'll learn: You'll understand how modern CPUs organize multiple cache layers to balance speed and capacity.

Why Multiple Cache Levels?

Remember the speed vs capacity tradeoff we discussed? A single cache can't be both massive and lightning-fast. Instead, CPUs use multiple cache levels arranged in a hierarchy, each trading size for speed.

The Three-Level Cache System

L1 Cache (Level 1)

  • Closest to the CPU cores – literally on the same chip die
  • Smallest capacity (typically 32-64 KB per core)
  • Fastest access time (1-4 CPU cycles)
  • Often split into separate instruction cache (I-cache) and data cache (D-cache)

L2 Cache (Level 2)

  • Slightly further away but still on-chip
  • Larger capacity (typically 256 KB - 1 MB per core)
  • Slower than L1 (10-20 CPU cycles)
  • Acts as a backup when L1 misses

L3 Cache (Level 3)

  • Shared across all CPU cores
  • Much larger (several MB, sometimes 16-32 MB)
  • Slower than L2 (40-75 CPU cycles)
  • Last stop before accessing main memory (which takes 200+ cycles)

How They Work Together

When the CPU needs data, it checks L1 first. If it's a miss, it checks L2. If L2 misses, it checks L3. Only if all three miss does it resort to slow main RAM. Each level "catches" data that the faster level missed, progressively reducing the penalty of going all the way to memory.

Key Takeaway: Modern CPUs use a multi-level cache hierarchy (L1, L2, L3) where each level is larger but slower than the one before it, creating a buffer system that balances speed and capacity to bridge the memory gap.