Cache Write-Through and Write-Back Policies

College Depth 65 in the knowledge graph I know this Set as goal
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

Counting to 10Counting to 20Understanding ZeroThe Number ZeroCounting to FiveOne-to-One CorrespondenceCombining Small Groups Within 5Addition Within 10Addition Within 20Two-Digit Addition Without RegroupingTwo-Digit Addition with RegroupingAddition Within 100Repeated Addition as MultiplicationMultiplication Facts Within 100Division as Equal SharingDivision as Grouping (Measurement Division)Division: Grouping (Repeated Subtraction) ModelDivision: Fair Sharing ModelDivision as Equal SharingDivision as GroupingBasic Division FactsDivision Facts Within 100Two-Digit by One-Digit DivisionDivision with RemaindersRemainders and Quotients in DivisionDivision Word ProblemsIntroduction to Long DivisionFactors and MultiplesPrime and Composite NumbersEquivalent FractionsRelating Fractions and DecimalsDecimal Place ValueReading and Writing DecimalsComparing and Ordering DecimalsAdding and Subtracting DecimalsMultiplying DecimalsDividing DecimalsDividing FractionsMixed Number ArithmeticOrder of OperationsOperators and ExpressionsArithmetic Operators and Operator PrecedenceComparison Operators and Boolean TestsLogical Operators and Boolean AlgebraBoolean Algebra and Fundamental LawsCombinational Circuit DesignFlip-Flops and LatchesBinary Counters: Design and AnalysisBinary ArithmeticFixed-Point Number RepresentationTwo's Complement RepresentationOverflow and Underflow DetectionBinary Adders: Half-Adders and Full-AddersFull Adder and Carry PropagationCarry Lookahead Adder DesignHalf Adder Circuit DesignMultiplication Circuit DesignSequential Circuit DesignRegisters and Register FilesInstruction Set Architecture (ISA)Assembly Language BasicsMemory Organization and AddressingMemory HierarchyCache Memory DesignCache Line Organization and Byte OffsetCache Write-Through and Write-Back Policies

Longest path: 66 steps · 239 total prerequisite topics

Prerequisites (2)

Leads To (0)

No topics depend on this one yet.