4.1.13 · D1Computer Architecture (Deep)

Foundations — Cache coherence — MESI protocol in multicore

1,974 words9 min readBack to topic

Before you can read the parent note MESI protocol, you must own every word it throws at you. This page builds each one from nothing, in the order that lets the next one stand on the previous.


1. Core, DRAM, and cache — the three boxes

Figure — Cache coherence — MESI protocol in multicore

Look at the figure. The amber warehouse in the middle is DRAM. Each cyan box beside a core is that core's private cache. Notice that address X can appear in three places at once — that duplication is the entire reason coherence exists. If those copies drift apart, the cores disagree about reality.


2. Cache line — the unit everything happens to

Why does the topic need this? Because coherence is tracked and enforced per line, not per byte. Every state we meet next is a label attached to a line.


3. Dirty vs. clean — does the copy match the warehouse?

Figure — Cache coherence — MESI protocol in multicore

In the figure the clean line (top) shows matching values in cache and DRAM. The dirty line (bottom) shows the cache holding 9 while DRAM still holds 5 — the amber "STALE" flag marks the warehouse as out of date. Whoever holds the dirty copy owns the truth and must eventually hand it back.


4. Write-back — the "pay later" policy

Why the topic needs it: the parent note says "memory now stale (still 0), but that's fine; M owns the truth." That sentence only makes sense once you know writes go to cache first and to DRAM lazily.


5. Stale vs. fresh — the failure MESI prevents


6. The shared interconnect and "snooping"

Figure — Cache coherence — MESI protocol in multicore

The figure shows the shared bus as a horizontal cyan rail. One core broadcasts a request (amber arrow); the other caches are drawn with "ear" symbols — they all hear it and each decides how to respond. That overhearing is what lets private caches coordinate without a central boss.


7. The SWMR invariant — the promise in symbols

Why the topic needs it: the four MESI states are nothing but cheap bookkeeping that keeps SWMR true. Every transition in the parent note is enforcing this one sentence.


8. Coherence vs. consistency — the trap word

MESI gives you coherence only. It does not order writes to different addresses — that still needs fences and atomic operations. The parent note's biggest "steel-manned mistake" is confusing these two; make sure you feel the difference now.


9. Latency symbols used in the cost formula

The parent note derives Average Memory Access Time. Here is each symbol, in words, before you see it in a formula:

Every symbol is a rate a latency; nothing is magic. With these defined, the parent's reads like plain English.


Prerequisite map

Core

Private cache

DRAM main memory

Cache line 64 bytes

Clean vs dirty

Write-back policy

Stale vs fresh value

Interconnect and snooping

SWMR invariant

MESI four states

Coherence vs consistency

Bus messages BusRd BusRdX Invalidate

Read it top to bottom: the physical boxes define the line, the line can be clean or dirty, write-back explains when it goes stale, snooping is how cores notice, and SWMR is the promise that the four MESI states finally enforce.


Equipment checklist

Cover the right side and answer aloud; if any stalls, re-read that section.

What is a cache, in one phrase?
A small fast private copy of a slice of DRAM sitting next to a core.
Why does DRAM being ~100 ns force us to cache?
A multi-GHz core would stall hundreds of cycles per access; caches make common accesses a few cycles.
What is the unit coherence tracks — byte or line?
A whole cache line (typically 64 bytes), never a single byte.
Clean vs. dirty — one sentence each.
Clean = matches DRAM; dirty = this core wrote it but hasn't pushed the change back to DRAM yet.
What does write-back do on a write?
Updates only the local cache and marks the line dirty; DRAM is updated lazily later.
What makes a cached copy "stale"?
Another copy of the same line was written more recently, so this one holds an old value.
What is snooping?
Every cache listens to all interconnect transactions and reacts to ones it did not start.
Name the four bus messages.
BusRd (read), BusRdX/RFO (read-to-write), BusUpgr/Invalidate (drop others' copies), Flush/Write-back (supply dirty data).
State the SWMR invariant.
Per address at all times: exactly one writer or any number of readers, never both.
Coherence vs. consistency?
Coherence = agreement on one address's timeline; consistency = ordering across different addresses — MESI gives only the first.
In AMAT, what is ?
The fraction of misses caused by another core invalidating your line (coherence misses).