What is MESI protocol?

A coherence protocol that tracks each cache line in one of four states: Modified, Exclusive, Shared or Invalid. On a write it invalidates other cores' copies.

Field: Multicore & Synchronization

Japanese name: MESIプロトコル

MESI protocol state transitions Local write Remote write Remote write Local read (others have it) Remote write Local read (no others) Local write (invalidate others) Remote read (write back) Local write (no bus msg) Remote read M I S E Local core read/write Snooped read/write by others M: Modified, only here E: Clean, only here S: Clean, shared I: Invalid
MESI protocol state transitions · View in diagrams

The four states

Modified (M): this cache holds the only copy and has written it, so memory is stale and the data must be written back or supplied to others. Exclusive (E): the only copy, but identical to memory. Shared (S): an unmodified copy that other caches may also hold. Invalid (I): the line holds no usable data. The protocol guarantees a single-writer, multiple-reader rule for each line: at any time either one cache may write it (M or E) or any number may read it (S), never both.

Key transitions

On a read miss the cache requests the line; if no other cache has it, it is loaded in E, otherwise in S. If another cache holds it in M, that cache writes it back to memory (it may also supply the data directly) and drops to S. A write to an S line must first invalidate all other copies, an upgrade request, before moving to M. A write miss issues a read-for-ownership that fetches the line and invalidates other copies in one step. When another core's write request is observed, any local copy goes to I, and an M copy hands over its data first.

Why the E state matters

The simpler MSI protocol has no E state, so a core that reads private data and then writes it must send an extra invalidation on the bus even though no other cache holds a copy. E records that the line is clean and unshared, allowing the later write to move silently to M. Since much data is private to one core, this saves a large amount of coherence traffic. Variants add more states: MOESI adds Owned, letting a dirty line be shared without first updating memory, and MESIF adds Forward, naming the one sharer that answers requests.

False sharing

Coherence works per cache line, typically 64 bytes, not per variable. If two cores repeatedly write different variables that happen to share a line, each write must invalidate the other core's copy, so the line bounces between M in one cache and I in the other even though the threads never touch the same data. This false sharing can make parallel code slower than sequential code. The fix is to separate frequently written per-thread data, such as counters, onto different lines by padding or alignment.

Try it: questions about MESI protocol

In the MESI protocol, what does it mean when a cache line is in the Modified (M) state?

  1. AOnly this core holds the line, and its contents differ from main memory (it must be written back)
  2. BSeveral cores hold the same contents, which also match main memory
  3. CThe line's contents are unusable and must be fetched again to read
Show answer and explanation

Answer: A. Only this core holds the line, and its contents differ from main memory (it must be written back)

The M state means this core has written the line and alone holds the latest value. Main memory is stale, so when the line is evicted or another core wants to read it, the latest value must be written back to main memory (it may also be supplied directly to the reading core). A line in M can be written again any number of times without notifying other cores, so repeated writes by the same core are fast.

In the MESI protocol, what happens when a core writes to a line it holds in the Exclusive (E) state?

  1. AIt sends invalidation requests to all other cores before writing
  2. BIt cannot write, so it writes to main memory and reads the line back
  3. CNo other core needs to be notified, and the line simply becomes M
Show answer and explanation

Answer: C. No other core needs to be notified, and the line simply becomes M

The E state means only this core holds the line and its contents match main memory. Since there are known to be no other copies, the core can move to M on a write without sending invalidations. The benefit of having E is saving that communication in the common pattern of reading and then writing data used by a single core. Writing from S, by contrast, requires invalidating other copies.

FAQ

What is the difference between MESI and MSI?

MESI adds the Exclusive state for clean lines that no other cache holds. A core can then write such a line without broadcasting an invalidation, which MSI would require.

What does the Modified state mean in MESI?

This cache has the only valid copy and has changed it, so main memory is out of date. The line must be written back on eviction or supplied to another core that requests it.

What is false sharing?

A slowdown that occurs when threads on different cores write separate variables located in the same cache line, forcing the coherence protocol to move the line back and forth between their caches.

Books on Multicore & Synchronization Ad

As an Amazon Associate I earn from qualifying purchases.

Comparisons that include this term

This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.

Back to the glossary