Skip to content

The Coherence Problem

Consider two cores, each with a private L1 cache, sharing main memory:

  1. Core 0 reads address AA → cached in Core 0’s L1
  2. Core 1 reads address AA → cached in Core 1’s L1
  3. Core 0 writes A=7A = 7Core 0’s cache is updated, but Core 1 still sees the old value

This is a coherence violation: two caches disagree on the value at the same address. Without a protocol to manage this, multicore systems would produce incorrect results.

Interactive: Step Through the Violation (and the Fix)

Section titled “Interactive: Step Through the Violation (and the Fix)”

Click through the canonical scenario. Switch between “no protocol” (you’ll watch the caches diverge) and “MSI protocol” (Core 1’s stale copy is invalidated before it can be observed).

A coherent memory system must satisfy:

  1. Write propagation: A write to AA by any core must eventually become visible to all cores
  2. Write serialization: All cores observe writes to the same address in the same order

These guarantee that there is a single, consistent view of memory — even though data is replicated across caches.

MechanismHow it worksScalability
SnoopingAll caches monitor (snoop) a shared bus for transactionsGood for 2–8 cores; bus becomes bottleneck
Directory-basedA central directory tracks which caches hold each lineScales to many cores; higher per-operation latency

Most desktop/laptop CPUs use snooping (simpler, lower latency for small core counts). Server chips with many cores often use directory-based protocols.

These are often confused but are distinct concepts:

  • Coherence: guarantees about a single address — all cores see the same sequence of values for address AA
  • Consistency: guarantees about multiple addresses — the order in which writes to different addresses become visible

Coherence is the mechanism (MSI, MESI). Consistency is the contract (Sequential Consistency, TSO). We cover consistency models in Section 3.

  • MSI Protocol — the simplest coherence protocol with three states
  • MESI & MOESI — practical extensions that reduce bus traffic