A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Cache Coherence Protocols and Memory Consistency

Graduate Depth 99 in the knowledge graph ☐ I know this ☆ Set as goal
1topic build on this
378prerequisites beneath it
See this on the map →
Consistency Models in Distributed SystemsThe Critical Section Problem and Race Conditions+1 more→→Multilevel Cache Design and Coordination
caching consistency coherence

Core Idea

Cache coherence protocols maintain consistency between multiple caches in a system. MESI (Modified, Exclusive, Shared, Invalid) is a common protocol that tracks cache line states and coordinates through snooping or directory-based schemes. Correct coherence is essential to prevent processes from seeing inconsistent data when multiple CPUs or nodes have copies of the same memory location.

Explainer

From your work with consistency models and the synchronization problem, you know that when multiple processors or nodes share data, concurrent access without coordination leads to inconsistent views. Cache coherence is the specific instance of this problem that arises when multiple processors each maintain their own local cache of shared memory. If processor A writes a new value to address X in its cache, processor B's cache still holds the stale old value — and without a coherence protocol, B has no way of knowing its copy is outdated.

The MESI protocol solves this by assigning each cache line one of four states. Modified means this cache holds the only valid copy and it has been changed — main memory is stale. Exclusive means this cache holds the only copy and it matches main memory — no other cache has it. Shared means multiple caches hold this line and all copies match main memory. Invalid means this cache line is not usable — it has been invalidated because another processor modified the data. Every read and write triggers state transitions: when processor A writes to a Shared line, the protocol sends an invalidation message to all other caches holding that line, transitioning their copies to Invalid and A's copy to Modified.

There are two main coordination mechanisms. In snooping protocols, every cache watches (snoops on) a shared bus and reacts when it sees transactions involving addresses it holds. This works well for small numbers of processors sharing a bus, but does not scale — every cache must see every transaction. In directory-based protocols, a central directory tracks which caches hold copies of each memory block. When a write occurs, the directory sends targeted invalidation messages only to caches that actually hold the line, avoiding broadcast overhead. This scales to larger systems but adds latency for the directory lookup.

Understanding cache coherence bridges the gap between the abstract consistency models you have studied and the physical reality of how hardware enforces them. The consistency model tells you what ordering guarantees the system provides to programmers; the coherence protocol is the mechanism that delivers those guarantees at the hardware level. When coherence works correctly, programmers can reason about shared memory without thinking about caches at all. When it breaks down — or when the performance cost of maintaining coherence becomes the bottleneck — it explains phenomena like false sharing (two unrelated variables on the same cache line causing constant invalidations) and motivates the design of systems that minimize shared mutable state entirely.

Practice Questions 5 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Introduction to Exponents → Order of Operations → Integer Order of Operations → Variable Expressions → The Distributive Property → Variables and Expressions Review → Introduction to Polynomials → Adding and Subtracting Polynomials → Multiplying Polynomials → Factorial → Permutations → Combinations → Counting Principles: Addition and Multiplication Rules → Introduction to Graph Theory → Propositional Logic Foundations → Logical Equivalences → Boolean Algebra → Boolean Type and Truth Values → Comparison Operators and Boolean Tests → Logical Operators and Boolean Algebra → Boolean Algebra and Fundamental Laws → Logic Gates Fundamentals → Implementing Boolean Functions with Gates → Karnaugh Map Simplification → Combinational Circuit Design → Flip-Flops and Latches → Binary Counters: Design and Analysis → Binary Arithmetic → Fixed-Point Number Representation → Two's Complement Representation → Overflow and Underflow Detection → Binary Adders: Half-Adders and Full-Adders → Full Adder and Carry Propagation → Carry Lookahead Adder Design → Half Adder Circuit Design → Multiplication Circuit Design → Sequential Circuit Design → Registers and Register Files → Instruction Set Architecture (ISA) → Kernel Architecture and OS Structure → System Calls and User/Kernel Mode → Processes and the Process Control Block → Process Creation: fork() and exec() → Process Termination and Resource Cleanup → Process States and State Transitions → Threads and Concurrency → The Critical Section Problem and Race Conditions → Cache Coherence Protocols and Memory Consistency

Longest path: 100 steps · 378 total prerequisite topics

Prerequisites (3)

Leads To (1)