Lecture 21: Cache Coherence

Section 1: Multiprocessor Communication Models — Shared Memory vs. Message Passing

Scaling performance across multiple cores—whether on a multi-core CPU, a GPU, or a large server—requires a system-level model for how cores communicate and access memory. There are two fundamental multiprocessor architectures:

1. Shared Memory

In a Shared Memory multiprocessor, multiple processors P connect through an interconnect to one global shared memory (MMMMMMM):

Trade-offs of Shared Memory:

2. Message Passing

In a Message Passing multiprocessor, each node is an independent processor-memory pair (P—M) connected to an interconnect:

Trade-offs of Message Passing:

Centralized Shared Memory (UMA) and the Cache Coherence Problem

The simplest shared-memory hardware is a Centralized Shared Memory System—also called a Uniform Memory Access (UMA) machine—where processors (PROC) share centralized MEMORY over a shared BUS. It is simple to build, but suffers from long latency to memory and severe contention on the bus and memory port.

Adding private caches (PROC \leftrightarrow CACHE \leftrightarrow BUS \leftrightarrow MEMORY) immediately decreases memory latency and reduces bus contention. However, adding private caches creates the Cache Coherence Problem!

Trace what goes wrong when two processors P1 and P2 cache the same shared variable A (initially A = 5 in Memory):

  1. P1 reads A \to brings A = 5 into P1’s cache.
  2. P2 reads A \to brings A = 5 into P2’s cache.
  3. Now P1 executes a store A = 7 into its local cache. Look at the system state: P1’s cache says A = 7, P2’s cache still says A = 5, and Memory still says A = 5! Multiple cached copies of the same memory block (whether modified by processor writes or I/O DMA writes) easily become inconsistent. Whenever P2 reads A, it sees the stale value 5 instead of 7.

✎ Check Your Understanding

  1. What is the defining semantic rule of a Shared Memory multiprocessor compared to a Message Passing multiprocessor? Answer: In Shared Memory, there is one global address space where the same address on any two processors refers to the exact same datum (communicating via normal loads/stores), whereas in Message Passing each node’s memory is private and nodes communicate via explicit Send/Recv messages.

  2. Briefly describe how adding private write-back caches to a shared-memory bus system causes the Cache Coherence Problem. Answer: Two processors can both cache a copy of address A = 5; when one processor updates its local cached copy to A = 7, the other processor’s cache (and main memory) still hold the stale value 5, breaking the single-shared-datum illusion.


Section 2: Snoopy Cache Coherence, Protocols, and Design Trade-offs

To keep private caches coherent on a shared bus, we exploit a key property of any bus: every transaction placed on the bus is visible to every cache simultaneously. This gives us Snoopy Cache Coherence:

(Recall the three baseline coherence states of the standard MSI protocol: M (Modified) means this cache holds the only valid copy and it is dirty relative to memory; S (Shared) means one or more caches hold a clean copy matching memory; and I (Invalid) means the block is not valid in this cache.)

Extending MSI: MESI and MOESI Protocols

Why isn’t basic MSI enough for high performance? Imagine a purely sequential single-threaded program running on one core of a 4-core CPU. Suppose the program reads a variable x, then writes x:

  1. MESI Protocol: Adds the E (Exclusive) state—meaning this cache is the sole owner of the block, and the block is clean (matches memory).
    • If a core reads a line and no other cache asserts a “shared” signal on the bus, the line enters E instead of S.
    • When that core later writes the line, it silently upgrades E \to M with zero bus traffic! Thus, MESI keeps bus traffic close to uniprocessor traffic for sequential apps and reduces bus contention on first writes.
  2. MOESI Protocol: Adds the O (Owned) state—meaning the block is modified (out of sync with memory), yet other caches are allowed to hold clean shared copies in state S!
    • Under MSI or MESI, if Core 1 holds a dirty M line and Core 2 tries to read it, Core 1 must write the dirty block all the way back to lower-level memory (DRAM) before moving to S.
    • Under MOESI, Core 1 moves from M \to O (retaining responsibility to eventually write back to memory) and sends the block directly to Core 2 via a fast cache-to-cache transfer, with Core 2 entering S. This eliminates unnecessary writebacks to slow main memory!

Write-Through vs. Write-Back / Ownership Schemes

When designing a snoopy bus protocol, how should writes propagate?

Invalidation vs. Update Strategies

When Core 1 does write to a shared block held by Core 2, should Core 1 invalidate Core 2’s copy or update it with the new value?

  1. Invalidation: On a write, all other caches holding a copy mark their copy Invalid (I).
    • When Invalidation is bad: Single producer and many consumers—every time the producer writes a shared flag or data structure, all N-1 consumers are invalidated and immediately suffer cache misses on the bus to re-fetch the new value.
  2. Update: On a write, the new value is broadcast so all other caches holding a copy update their data in place.
    • When Update is bad: First, multiple consecutive writes by one core before another core reads waste bus bandwidth broadcasting every intermediate write (x = 1; x = 2; ... x = 100;). Second, junk data accumulates in large caches—caches keep receiving updates for lines that their local core stopped using long ago!

Overall, invalidation schemes are much more popular as the default because programs typically perform multiple local writes between synchronization points, and invalidation naturally cleans out unused shared copies.

[Editor Note: removed three blank transition slides.]

✎ Check Your Understanding

  1. What advantage does the MESI protocol’s E (Exclusive) state provide over basic MSI for a single-threaded application? Answer: When a single core reads a block that no other cache holds, it loads the line in state E (clean, sole owner) rather than S, allowing a subsequent write to upgrade E \to M locally with zero bus contention/invalidation traffic.

  2. Give two reasons why Invalidation coherence protocols are generally preferred over Update protocols as the default. Answer: Update protocols waste bus bandwidth broadcasting every intermediate write when one core writes a variable multiple times before another core reads it, and they keep pushing updates (“junk data”) into large caches that no longer actively use those blocks.


Section 3: Scaling Beyond the Bus — Directory-Based Coherence and Modern Interconnects

Snoopy coherence is wonderfully simple because every coherence transaction completes in a single step (broadcast onto the bus, everyone snoops at once). However, a snoopy bus does not scale to dozens or hundreds of cores for two reasons:

  1. Performance bottleneck: One shared bus cannot carry traffic when all cores want to communicate constantly.
  2. Wasted work: Sending a coherence message intended for one other core forces a broadcast to every core on the chip, burning tag-lookup energy in every cache.

Directory-Based Cache Coherence

To eliminate broadcasts and scale to scalable point-to-point networks, processors replace the snoopy bus with Directories:

Modern Multi-Banked Interconnects and Distributed Directories

Wait: if we put the entire directory in one central chip location, wouldn’t that single directory become a bottleneck just like the bus?

Intel multicores from Nehalem through Haswell (2008–2013) solved this using distributed directories over a multi-hop network:

Thus, whether scaling inside a single core via out-of-order execution and SMT, across regular arrays via vectors and GP-GPUs, or across many independent cores via directory-coherent shared memory, modern computer architecture balances hardware simplicity, communication bandwidth, and exposed parallelism to match the structure of each workload.

[Editor Note: removed acknowledgements slide.]

✎ Check Your Understanding

  1. What are the two scalability problems of snoopy bus coherence that directory-based coherence eliminates? Answer: Snoopy buses suffer from bus contention (all cores fighting over one shared broadcast medium) and wasted broadcast work (forcing every core to snoop and check tags even when only one or two cores share the block). Directories replace broadcasts with targeted point-to-point messages sent only to the cores listed in the line’s sharer bit-vector.

  2. In a directory-based system with 64 cores, how many sharer tracking bits are required per directory entry in a full-map bit-vector directory, and why do modern multicore chips distribute directories across LLC slices? Answer: A full-map bit-vector needs 64 sharer bits per tracked block (1 bit per core) alongside the state bits. Modern chips distribute directories across LLC slices (selected by hashing physical address bits) so that directory lookups themselves do not bottleneck at a single central location.