cache coherence protocol

**Cache Coherence Protocols (MESI, MOESI)** are the **complex, hardware-level state machine algorithms implemented in multi-core processors to guarantee that all parallel CPU cores actively share one mathematically consistent baseline view of memory, even when each core holds decentralized, locally modified copies of the data in its own private L1/L2 cache**. **What Is Cache Coherence?** - **The Stale Data Threat**: If Core A reads a variable from RAM (Value=5) into its private L1 cache, and Core B also reads it (Value=5), both are synchronized. But if Core A overwrites its local copy to Value=10, Core B is suddenly holding "stale" data. If Core B uses its stale 5 to calculate an array index, the program crashes silently. - **The Protocol Solution**: The hardware enforces coherence automatically, totally invisibly to the software programmer, by broadcasting messages between cores every time a piece of shared data is modified. **The MESI Protocol States** Every 64-byte cache line in L1/L2 is tagged with a state: - **M (Modified)**: This core has the *only* valid copy of the data, and it is dirty (different than RAM). It must be written back to RAM eventually. - **E (Exclusive)**: This core is the *only* core holding this data, but it is clean (matches RAM). It can jump to Modified without asking permission. - **S (Shared)**: Multiple cores hold this exact same clean data. If any core wants to write to it, it MUST broadcast an "Invalidate" message to kill all other copies first. - **I (Invalid)**: The data in this cache line is garbage/stale and cannot be read. **Why Coherence Bottlenecks Parallelism** - **The Snooping Bus**: In early quad-cores, every cache broadcasted its state changes on a shared wire loop (snooping). This does not scale. 64-core processors produce a devastating storm of "invalidate" traffic that completely chokes the entire chip's ring bus bandwidth. - **Directory-Based Coherence**: For massive server chips (like 128-core AMD EPYC), snooping is replaced by a central "Directory" (a massive lookup table). Instead of broadcasting to everyone, Core A asks the Directory exactly which cores hold the data, and sends targeted invalidation packets only to those specific cores. Cache Coherence is **the invisible, crushing architectural burden of symmetric multiprocessing** — the mandatory hardware tax paid to maintain the illusion of a single, unified memory space for software developers.

Go deeper with CFSGPT

Get AI-powered deep-dives, save terms, and run advanced simulations — free account.

Create Free Account