5.4.15 · D3Memory Hierarchy & Caches

Worked examples — MESI - MOESI coherence protocols

2,525 words11 min readBack to topic

This page is the exhaustive drill room for the parent topic. The parent taught the state machine; here we walk every kind of situation the protocol can face — every state you can start in, every bus event you can snoop, the weird zero/degenerate cases (self-writes, evictions, already-invalid lines), and the timing twists exam-setters love. If you can predict the outcome of all cells below, you own the protocol.

Before we start, the vocabulary we will lean on (all defined in the parent, restated here so no symbol is used unearned):

Related reading you may want open in another tab: Snooping vs Directory-based protocols, Write-back vs Write-through caches, False Sharing, MOESI in AMD, MESIF in Intel.


The scenario matrix

Coherence is a state machine, so "every scenario" = (starting state) × (event) × (protocol), plus the degenerate/timing edge cases. Here is the full grid we will cover. Each cell names the example that hits it.

Case class Concrete situation Covered by
Cold miss → sole owner Read address nobody has Ex 1 (step 1)
Cold miss → sharer Read address someone else has Ex 1 (step 2)
Silent upgrade Write while E (zero bus traffic) Ex 2
Write while Shared Store from S needs invalidate Ex 3
Write miss (I→M) Store to a line you don't hold Ex 4
Snoop BusRd while M (MESI) Forced write-back, M→S Ex 5
Snoop BusRd while M (MOESI) M→O, cache-to-cache, no memory write Ex 6
Owner shares again Third reader off an O line Ex 6 (extension)
Eviction of dirty line O/M evicted → the one memory write Ex 7
Degenerate: self write-write Same core writes twice, no bus Ex 8
Degenerate: already-I snoop Bus event on a line you don't hold Ex 8 (verify)
Real-world word problem Producer/consumer flag Ex 9
Exam twist: false sharing Two vars, one line, ping-pong Ex 10

Worked examples

Figure — MESI - MOESI coherence protocols
Figure — MESI - MOESI coherence protocols

Active recall

Recall Cover the answers and predict each cell
  • Two reads on a fresh line: final states? ::: Both S (first went E, dropped to S on the second reader).
  • Bus messages for E→M silent upgrade? ::: 0.
  • Store from S uses which message? ::: BusRdX (invalidate others), then S→M.
  • M snoops a BusRd in MESI vs MOESI? ::: MESI: flush + M→S (memory write). MOESI: M→O, cache-to-cache, no memory write.
  • When is the deferred MOESI memory write finally paid? ::: On eviction of the O (or M) line.
  • False sharing: why traffic despite different variables? ::: Coherence is per cache line, not per variable.
  • Snoop event on an I line? ::: Do nothing — no data to lose or invalidate.