Home Knowledge Base Cache Coherence Protocols

Cache Coherence Protocols are hardware mechanisms that ensure all processors in a shared-memory multiprocessor system observe a consistent view of memory by coordinating cache line states across private caches — without coherence protocols, one processor's cached copy of data could become stale when another processor modifies the same memory location.

The Coherence Problem:

<svg viewBox="0 0 760 470" xmlns="http://www.w3.org/2000/svg" font-family="-apple-system,Segoe UI,Roboto,sans-serif">
  <rect x="0" y="0" width="760" height="470" fill="#0d1117"/>
  <text x="380" y="28" fill="#e6edf3" font-size="21" font-weight="700" text-anchor="middle">Cache Coherence — MESI Protocol</text>
  <text x="380" y="48" fill="#8b98a5" font-size="12" text-anchor="middle">hardware ensures all cores see consistent memory — every cache line is in one of 4 states</text>

  <!-- MESI state diagram -->
  <rect x="30" y="65" width="430" height="310" rx="6" fill="#080d14" stroke="#233043" stroke-width="1"/>
  <text x="245" y="86" fill="#e6edf3" font-size="11" font-weight="600" text-anchor="middle">MESI State Machine</text>

  <!-- Modified -->
  <circle cx="150" cy="150" r="35" fill="#0b1220" stroke="#f87171" stroke-width="1.5"/>
  <text x="150" y="147" fill="#fca5a5" font-size="11" font-weight="700" text-anchor="middle">M</text>
  <text x="150" y="162" fill="#f87171" font-size="7" text-anchor="middle">Modified</text>

  <!-- Exclusive -->
  <circle cx="330" cy="150" r="35" fill="#0b1220" stroke="#34d399" stroke-width="1.5"/>
  <text x="330" y="147" fill="#6ee7b7" font-size="11" font-weight="700" text-anchor="middle">E</text>
  <text x="330" y="162" fill="#34d399" font-size="7" text-anchor="middle">Exclusive</text>

  <!-- Shared -->
  <circle cx="330" cy="290" r="35" fill="#0b1220" stroke="#60a5fa" stroke-width="1.5"/>
  <text x="330" y="287" fill="#93c5fd" font-size="11" font-weight="700" text-anchor="middle">S</text>
  <text x="330" y="302" fill="#60a5fa" font-size="7" text-anchor="middle">Shared</text>

  <!-- Invalid -->
  <circle cx="150" cy="290" r="35" fill="#0b1220" stroke="#6b7684" stroke-width="1.5"/>
  <text x="150" y="287" fill="#8b98a5" font-size="11" font-weight="700" text-anchor="middle">I</text>
  <text x="150" y="302" fill="#6b7684" font-size="7" text-anchor="middle">Invalid</text>

  <!-- Transitions -->
  <!-- I → E (read miss, no sharers) -->
  <path d="M175,265 L305,175" fill="none" stroke="#34d399" stroke-width="1" marker-end="url(#arrowG)"/>
  <text x="230" y="210" fill="#34d399" font-size="6.5">read miss</text>
  <text x="230" y="220" fill="#34d399" font-size="6">(no sharers)</text>

  <!-- I → S (read miss, sharers exist) -->
  <path d="M185,290 L295,290" fill="none" stroke="#60a5fa" stroke-width="1"/>
  <polygon points="293,287 299,290 293,293" fill="#60a5fa"/>
  <text x="240" y="284" fill="#60a5fa" font-size="6.5">read miss (sharers)</text>

  <!-- E → M (local write) -->
  <path d="M295,145 L185,145" fill="none" stroke="#f87171" stroke-width="1"/>
  <polygon points="187,148 181,145 187,142" fill="#f87171"/>
  <text x="240" y="138" fill="#f87171" font-size="6.5">local write</text>

  <!-- S → I (remote write / snoop invalidate) -->
  <path d="M305,318 L175,318" fill="none" stroke="#6b7684" stroke-width="1"/>
  <polygon points="177,321 171,318 177,315" fill="#6b7684"/>
  <text x="240" y="332" fill="#6b7684" font-size="6.5">snoop invalidate</text>

  <!-- M → I (remote read) -->
  <path d="M150,185 L150,255" fill="none" stroke="#6b7684" stroke-width="1"/>
  <polygon points="147,253 150,259 153,253" fill="#6b7684"/>
  <text x="115" y="220" fill="#6b7684" font-size="6">flush +</text>
  <text x="115" y="230" fill="#6b7684" font-size="6">invalidate</text>

  <!-- E → S (remote read) -->
  <path d="M340,185 L340,255" fill="none" stroke="#60a5fa" stroke-width="1"/>
  <polygon points="337,253 340,259 343,253" fill="#60a5fa"/>
  <text x="360" y="220" fill="#60a5fa" font-size="6">remote read</text>

  <!-- State descriptions (right) -->
  <rect x="480" y="65" width="250" height="310" rx="6" fill="#080d14" stroke="#233043" stroke-width="1"/>
  <text x="605" y="86" fill="#e6edf3" font-size="10" font-weight="600" text-anchor="middle">State Meanings</text>

  <text x="500" y="112" fill="#f87171" font-size="9" font-weight="600">M (Modified):</text>
  <text x="500" y="128" fill="#8b98a5" font-size="8">only copy, dirty (not in memory)</text>
  <text x="500" y="142" fill="#6b7684" font-size="7.5">must write back before sharing</text>

  <text x="500" y="166" fill="#34d399" font-size="9" font-weight="600">E (Exclusive):</text>
  <text x="500" y="182" fill="#8b98a5" font-size="8">only copy, clean (matches memory)</text>
  <text x="500" y="196" fill="#6b7684" font-size="7.5">can write without bus transaction</text>

  <text x="500" y="220" fill="#60a5fa" font-size="9" font-weight="600">S (Shared):</text>
  <text x="500" y="236" fill="#8b98a5" font-size="8">multiple copies exist, read-only</text>
  <text x="500" y="250" fill="#6b7684" font-size="7.5">must invalidate others before writing</text>

  <text x="500" y="274" fill="#6b7684" font-size="9" font-weight="600">I (Invalid):</text>
  <text x="500" y="290" fill="#8b98a5" font-size="8">line not present or stale</text>
  <text x="500" y="304" fill="#6b7684" font-size="7.5">must fetch from memory or peer cache</text>

  <text x="605" y="332" fill="#f59e0b" font-size="8" text-anchor="middle" font-weight="600">MOESI (AMD) adds Owned state</text>
  <text x="605" y="348" fill="#8b98a5" font-size="7.5" text-anchor="middle">dirty but shared — avoids writeback</text>
  <text x="605" y="366" fill="#6b7684" font-size="7.5" text-anchor="middle">Intel uses MESIF (F = Forward)</text>

  <!-- Bottom -->
  <rect x="30" y="388" width="700" height="42" rx="6" fill="#080d14" stroke="#233043" stroke-width="1"/>
  <text x="380" y="407" fill="#8b98a5" font-size="8.5" text-anchor="middle">coherence traffic is the #1 scaling bottleneck in multi-core chips — every write generates snoops to all cores</text>
  <text x="380" y="422" fill="#6b7684" font-size="7.5" text-anchor="middle">directory-based coherence (server chips) replaces broadcast snooping for &gt;16 cores</text>

  <text x="380" y="452" fill="#6b7684" font-size="11" text-anchor="middle">Cache coherence makes shared memory "just work" — but it costs bandwidth, latency, and design complexity.</text>
</svg>

MESI Protocol:

MOESI and MESIF Extensions:

Snooping Protocols:

Directory-Based Protocols:

Performance Impact:

Cache coherence is invisible to most programmers but fundamentally shapes the performance of parallel software — understanding the underlying protocol helps explain why some parallel data structures scale linearly while others hit performance walls at just a few cores.

cache coherence protocolsmesi protocol statessnooping coherence busdirectory based coherencecache invalidation protocol

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.