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

Cache Write-Through and Write-Back Policies

College Depth 96 in the knowledge graph ☐ I know this ☆ Set as goal
2topics build on this
356prerequisites beneath it
See this on the map →
Cache Memory DesignCache Line Organization and Byte Offset→→Cache Coherence Protocols and Memory Consistency
cache write-policy memory-consistency

Core Idea

Write-through writes to both cache and main memory immediately; it guarantees memory consistency but is slow. Write-back writes only to the cache, marking the block dirty; the block is written back when evicted. Write-back is faster but requires careful coherence protocols in multi-core systems. Most modern systems use write-back with a write-combine buffer.

Explainer

From your study of cache design, you know that caches exploit temporal and spatial locality to keep frequently accessed data close to the processor. But reads are only half the story — the cache must also handle writes, and the policy it uses has significant implications for performance, complexity, and correctness. The two fundamental approaches are write-through and write-back, and understanding their tradeoffs is essential to reasoning about memory system behavior.

In a write-through cache, every write updates both the cache line and main memory simultaneously. The advantage is simplicity: main memory always contains the most recent data, so there is never a question of staleness. If the cache line is evicted, nothing special needs to happen because memory already has the current value. The disadvantage is bandwidth: every store instruction generates a write to main memory, which is slow (hundreds of cycles). To mitigate this, write-through caches typically use a write buffer — a small queue that absorbs writes so the processor does not stall waiting for each one to reach memory. As long as writes arrive slower than the buffer can drain, the processor runs at full speed.

In a write-back cache, writes update only the cache line. The line is marked with a dirty bit indicating that it has been modified and differs from main memory. The modified data is written to memory only when the line is evicted (replaced by a new line). This dramatically reduces memory traffic — if a program writes to the same variable 100 times, only one write reaches memory, on eviction. The cost is complexity: the cache controller must track dirty bits, and eviction of a dirty line stalls the incoming load until the writeback completes. Many designs add a write-back buffer to overlap this writeback with the new line's fetch.

The choice between policies becomes critical in multiprocessor systems. With write-through, other cores can snoop the memory bus to see writes as they happen, keeping their caches consistent relatively easily. With write-back, a modified value may exist only in one core's cache, invisible to others. This is why write-back caches require cache coherence protocols (like MESI) to ensure that when one core modifies a line, other cores that hold copies are notified. Modern systems overwhelmingly use write-back for its bandwidth advantages, accepting the coherence complexity as a necessary cost. A related decision is write-allocate versus no-write-allocate: on a write miss, does the cache fetch the line first (write-allocate, paired with write-back) or write directly to memory without caching (no-write-allocate, often paired with write-through)?

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) → Assembly Language Basics → Memory Organization and Addressing → Memory Hierarchy → Cache Memory Design → Cache Line Organization and Byte Offset → Cache Write-Through and Write-Back Policies

Longest path: 97 steps · 356 total prerequisite topics

Prerequisites (2)

Leads To (1)