CS 152 Computer Architecture and Engineering
CS252A Graduate Computer Architecture Lecture 21 - Cache Coherence

Chris Fletcher
UC Berkeley, Spring 2026

Shared Memory

  • Each node is a core running a thread
  • One global memory: the same address on any processor is the same datum
  • Communicate with normal loads/stores + atomics; synchronize with locks and barriers
PPPP interconnect shared memory

Message Passing

The Cache Coherence Problem

StepP1 cacheP2 cacheMemory
P1 reads A5–5
P2 reads A555
P1 writes A = 775 (stale)5

Check Your Understanding

1. What is the defining rule of shared memory vs. message passing?
Shared memory: one address space where an address names the same datum everywhere, accessed with loads/stores. Message passing: private memories, explicit Send/Recv.
2. How do private write-back caches on a bus cause the coherence problem?
Two caches hold A = 5; one writes 7 locally, while the other cache and memory still hold 5.

Snoopy Cache Coherence

MSI stateMeaning
M ModifiedOnly valid copy; dirty vs. memory
S SharedOne or more clean copies
I InvalidNot valid here

MESI and MOESI

Write-Through vs. Write-Back Schemes

Write-throughWrite-back / ownership
On writeUpdate cache + bus write to memory; invalidate/update othersOwner (M or E) writes locally, no bus write
Simplicity✅ very simple❌ more states
Bus bandwidth❌ ~15% of references are writes: only a few processors✅ conserves bandwidth

Classic ownership protocols: Goodman's write-once, Berkeley ownership, Firefly update.

Invalidation vs. Update

InvalidateUpdate
On a writeOther copies → IBroadcast new value to other copies
Bad caseOne producer, many consumers: all N−1 miss after every writeMany writes before anyone reads (x = 1 … x = 100); junk updates to lines no longer used

Check Your Understanding

1. What does MESI's E state buy over MSI for a single-threaded program?
A read of an unshared line loads in E, so the following write upgrades E → M locally with no bus traffic.
2. Two reasons invalidation beats update as the default?
Update broadcasts every intermediate write when one core writes repeatedly, and it keeps pushing data into caches that no longer use those lines.

Snoopy Coherence Doesn't Scale

Directory-Based Coherence

  • Directory: tracks each line's state at its home node
  • Per block: MSI state + sharer bit-vector (1 bit per core)
  • Point-to-point, 2–3 steps:
    1. Local node → home directory (unicast)
    2. Directory → only the cores holding the line (remote nodes)
Localnode Homedirectory Remote Remote 1 2 2

Distributed Directories in Modern Multicores

Check Your Understanding

1. Which two snoopy-bus scalability problems do directories remove?
Bus contention and wasted broadcast snooping; directories send targeted messages only to cores in the sharer vector.
2. 64 cores: how many sharer bits per entry in a full-map directory, and why distribute directories across LLC slices?
64 bits (plus state). Distributing by address hash keeps directory lookups from bottlenecking at one place.