Technical guide
CPU Cache Coherency Explained: Cache Lines, MESI States, Ownership, and False Sharing
Understand why multicore CPUs need cache coherence, what MESI states mean, how cache-line ownership works, and why false sharing can hurt threaded software.
On this page
- Why multiple CPU caches create a consistency problem
- The cache line is the unit that coherence tracks
- MESI explains ownership without pretending every CPU is identical
- False sharing shows why the cache-line boundary matters to software
- Coherence, consistency, and cache hierarchy answer different questions
At a glance
Key facts
- Coherence unit
- A cache line, not an individual variable
- MESI states
- Modified, Exclusive, Shared, Invalid
- Main job
- Coordinate cached copies when cores share and modify memory
- Not the same as
- Locks, atomics, language memory models, virtual memory, or cache replacement
- Common pitfall
- False sharing between unrelated variables on the same line
Why multiple CPU caches create a consistency problem
Modern CPUs use caches because repeatedly reaching main memory would be far slower than serving frequently used data close to the execution cores. A multicore design can therefore have several cached copies of data in flight at once: private caches near individual cores and additional cache capacity elsewhere in the hierarchy.
The problem appears when one core modifies data that another core has cached. Without a coherence mechanism, different cores could continue using incompatible cached copies of the same memory. Coherence protocols track cache-line state and coordinate ownership, invalidation and data movement so the cache hierarchy does not behave like a collection of unrelated memories.
The cache line is the unit that coherence tracks
Caches do not normally track each C or C++ variable as an independent coherence object. They move and manage fixed-size cache lines. AMD software-optimization documentation gives a concrete x86 example: a naturally aligned 64-byte data-cache line is treated as a unit, and modifying any byte marks that line as modified.
That distinction matters because two logically unrelated variables can occupy the same line. Hardware sees accesses to the line, not the programmer’s intent about which field belongs to which thread. It also means that a cache-line transfer or invalidation should not be described as an automatic trip to DRAM; another cache or another level of the hierarchy may be involved depending on the processor and state.
| State | Conceptual meaning | Can another cache have a valid copy? |
|---|---|---|
| Modified | This cache owns a changed copy; the corresponding memory copy is not current. | No valid peer copy in textbook MESI |
| Exclusive | This cache has the only valid clean copy. | No |
| Shared | The line is clean and can be present in more than one cache. | Yes |
| Invalid | This cache does not have a usable copy of the line. | Yes or no |
MESI explains ownership without pretending every CPU is identical
Intel’s architecture manual describes MESI—Modified, Exclusive, Shared and Invalid—as the cache protocol used to maintain consistency across its relevant data and unified caches. In the conceptual model, a Shared line must gain exclusive ownership before that cache can modify it, while an Exclusive clean line can be written without first invalidating another valid cached copy because no peer copy exists.
MESI is best used as a vocabulary for the state transitions a coherent system needs, not as a transistor-level blueprint for every current processor. Commercial CPUs can use protocol extensions, extra states, directory information, snoop filters and different interconnect or topology mechanisms. Those implementation details can change how coherence traffic is located and transported without changing the basic reason coherence exists.
False sharing shows why the cache-line boundary matters to software
False sharing occurs when threads modify different variables that happen to reside on the same cache line. The variables may be logically independent, but the coherence machinery still tracks the whole line. Ownership can therefore move or peer copies can be invalidated as the threads write their separate fields.
AMD explicitly documents this mechanism and recommends separating per-thread data, giving 64-byte alignment as an example for the processors covered by that guide. Intel’s current optimization material likewise describes unnecessary cache invalidations and updates when multiple threads contend for different variables in one line. The actual penalty is workload- and topology-dependent, so there is no honest universal percentage to subtract from performance.
Practical context
What this means when reading CPU specifications or tuning code
Coherence terminology explains a mechanism, not a benchmark result. Cache size, topology and protocol details can influence behavior, but they do not independently establish application or gaming performance.
- Do not infer FPS, IPC, memory latency or bandwidth from a MESI state diagram.
- Do not treat a larger L3 cache as proof that coherence is faster; capacity and coherence are different properties.
- When profiling threaded software, false sharing is a plausible mechanism to investigate when frequently written per-thread data occupies shared cache lines.
- Use architecture-specific documentation and measurements before making claims about a particular CPU’s coherence topology or cost.
Coherence, consistency, and cache hierarchy answer different questions
L1, L2 and L3 labels describe levels in a cache hierarchy and are commonly discussed in terms of capacity, latency, sharing and inclusivity behavior. Coherence describes how cached copies are coordinated. Memory consistency describes rules about the ordering and visibility of memory operations. These subjects interact, but collapsing them into one concept creates misleading explanations.
The practical mental model is simple: caches make copies useful, cache lines define the granularity, and coherence keeps those copies coordinated when multiple cores participate. MESI provides a compact conceptual vocabulary for that coordination. For real performance questions, the next step is measurement on the actual processor and workload rather than extrapolating from protocol names.
Sources
Primary and technical sources
Technical details can vary by exact model, firmware, and platform. These are the sources used for the factual claims in this article.
01 Intel
Intel 64 and IA-32 Architectures Software Developer’s Manuals: cache control protocol and MESI states02 Intel
Intel 64 and IA-32 Architectures Optimization Reference Manual: false sharing and multicore scalability03 AMD
Software Optimization Guide for AMD Family 15h Processors: data sharing, 64-byte cache lines, and false sharing04 AMD
Software Optimization Guide for the AMD Zen 5 Microarchitecture