4.1.12 · D3Computer Architecture (Deep)

Worked examples — Write policies — write-through, write-back, write-allocate

2,373 words11 min readBack to topic

Before we start, the two independent axes (from the parent), restated so nothing is used before it's named:

  • On a write HITwrite-through (update cache and memory now) or write-back (update cache only, set the dirty bit, tell memory later).
  • On a write MISSwrite-allocate (fetch the block into cache first, then write) or no-write-allocate (write straight to memory, leave cache alone).

The dirty bit is one extra bit per cache line meaning "this cached copy has been changed and memory does not know yet." dirty=0 means cache and memory agree; dirty=1 means memory is stale.


The scenario matrix

Every write question is one cell of this grid. Our job: make sure every cell has a worked example.

Cell Case class What it stresses
C1 Write HIT, write-back Does memory stay untouched? Does dirty flip to 1?
C2 Write HIT, write-through Does memory get written every time?
C3 Write MISS, write-allocate Block fetched, then written as a hit
C4 Write MISS, no-write-allocate Straight to memory, cache untouched
C5 Eviction of a dirty block The one forced memory write-back
C6 Eviction of a clean block Silent discard, zero memory writes
C7 Zero / degenerate input (, or ) Limiting behaviour of the cost formula
C8 Limiting input (, or ) Worst case, when write-back loses its edge
C9 Real-world word problem (memset streaming) Why no-write-allocate exists
C10 Exam twist (mixed WT+write-allocate) The "unnatural" pairing, counting both costs

The cost model we reuse (from the parent) — every symbol earned:


The worked examples

C1 + C2 — a HIT under both hit-policies


C3 + C4 — a MISS under both allocate-policies


C5 + C6 — eviction of dirty vs clean

The following figure shows both eviction paths on one cache line.

Figure — Write policies — write-through, write-back, write-allocate

C7 — degenerate inputs to the cost formula


C8 — worst-case limit, where write-back loses its edge

The next figure plots against as the miss rate sweeps from good to terrible.

Figure — Write policies — write-through, write-back, write-allocate

C9 — real-world word problem


C10 — the exam twist: the unnatural pairing


One consolidated trace (ties C1, C3, C5 together)


Recall

Recall Every cell, one line each

HIT + write-back memory writes for one write ::: 0 (dirty bit set instead) HIT + write-through memory writes for one write ::: 1 (every write hits DRAM) MISS + write-allocate: block cached afterward? ::: Yes (fetched then written) MISS + no-write-allocate: block cached afterward? ::: No (written straight to memory) Eviction of a dirty block costs ::: 1 memory write-back Eviction of a clean block costs ::: 0 memory writes when miss rate ::: (memory term vanishes) Crossover miss rate for (WB vs WT) ::: Why memset prefers no-write-allocate ::: avoids fetching blocks it will fully overwrite

See also: Cache Memory Fundamentals, Cache Replacement Policies, Memory Hierarchy and AMAT, Write Buffers and Store Buffers, Cache Coherence — MESI, DMA and I/O Consistency.