Cache Coherence Protocols
Cache coherence maintains a sensible view of each cache line across processors. A directory makes the ownership transition explicit and moves part of the cost into metadata.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 3
- Reading time
- 2 min
In this article3 chapters
One writer and many readers
A coherence protocol tracks whether caches hold a line privately, sharably or not at all. In MESI, a modified line has one dirty owner. An exclusive clean line may become modified without first invalidating other sharers, because no other cache has it. Shared copies can coexist when no processor has exclusive write permission. A useful stable-state invariant is
\[ |\mathrm{writers}|\le1,\quad |\mathrm{writers}|=1 \ \Rightarrow\ |\mathrm{readers}_{\mathrm{other}}|=0 . \]
Actual implementations also have transient states while ownership changes. Proving coherence requires reasoning about those states and in-flight responses.
Basic cache coherence explains ownership transfer for a shared line. False sharing shows why writes to distinct fields can still require such transfers when both fields occupy that line.
A directory waits for permissions to move
A directory records an owner or a set of sharers for each line. When a core requests exclusive access to a shared line, the protocol invalidates or revokes existing read permissions before granting it. In-flight responses can otherwise carry an earlier value into a cache that now believes it has permission. Tags, acknowledgments and transient states tie each response to the appropriate request. A directory can avoid global broadcasts, at the cost of keeping and looking up sharing metadata.
Dirty sharing tracks which cache supplies the current value
MOESI includes an owned state, allowing one cache to be responsible for supplying dirty data while others hold shared copies. That owner need not have immediate exclusive write permission. Coherence puts constraints on one address at a time. A separate memory model relates observations of different addresses, as in weak memory models. Verification can model directory transitions with hardware model checking, and multiple memory tiers add questions of locality and bandwidth in heterogeneous memory.[1]