4.1.12 · D1Computer Architecture (Deep)

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

1,758 words8 min readBack to topic

Before you can read the parent note, you must own every word and letter it throws at you. Below, each item is built from nothing: what it means in plain words → the picture it maps to → why the topic needs it. They are ordered so each one leans only on the ones above it.


1. Memory vs cache — the two notebooks

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

Look at the figure: the CPU (left) talks to the small blue cache almost instantly; reaching the big gray memory on the right is a long slow trip. This distance-and-size difference is the entire reason write policies exist — we want to touch the far box as rarely as possible.

Prerequisite depth on this lives in Cache Memory Fundamentals.


2. Block (a.k.a. cache line) — the unit of copying


3. Hit and miss — did the copy exist?

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

The parent note splits the world into "write HIT" and "write MISS" and gives a different rule for each. So hit/miss is the first fork in every decision — it decides which column of the parent's tables you are in.


4. Read vs write — why writes are the hard one


5. The dirty bit — one flag per line

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

The picture shows two lines: a green clean one (0) and a red dirty one (1). The topic needs this bit because write-back delays the memory update — and the only way to later remember "this line owes memory an update" is to have flagged it. Write-through never delays, so it never needs this bit.


6. Eviction / replacement — making room


7. The cost letters — reading the formula alphabet

The parent's cost formula uses six symbols. Here is each, from zero.

Recall Why is

multiplied by in write-back but not in write-through? Because write-through hits memory on every write (so the coefficient is 1), while write-back only reaches memory on the misses (coefficient ), plus the occasional dirty write-back (). Small ⇒ big savings.

More on how these times chain into overall performance: Memory Hierarchy and AMAT.


8. Write buffer — the trick that rescues write-through


Prerequisite map

Memory vs Cache two notebooks

Block the copy unit

Locality

Hit or Miss

Read vs Write asymmetry

Stale data problem

Dirty bit flag

Eviction triggers write back

Cost letters h m tc tm d

Write policy formulas

Write buffer hides latency

Write Policies topic

Read the arrows top-to-bottom: nothing points into a box until everything it depends on is already built. That is the order this page introduced them.


Equipment checklist

Self-test: cover the right side and answer before revealing.

Where does the "true" value of a data location live?
In main memory (DRAM); the cache only holds copies.
What is a block / cache line?
A fixed-size chunk of neighbouring bytes (e.g. 64 B) — the smallest unit the cache copies at once.
What is locality and why does it matter?
The tendency to reuse nearby data soon; it makes caching (and write-back) pay off.
Hit vs miss in one line each?
Hit = the wanted data is already cached; miss = it is not, so we must reach memory.
Why are writes harder than reads?
A read changes nothing, but a write makes the cached copy disagree with memory (possible stale data).
What is stale data?
A copy that is out of date — it no longer matches the true value in memory.
What does the dirty bit record, and its two values?
Whether a line was written since load: 0 = clean (matches memory), 1 = dirty (memory is stale).
Which policy needs the dirty bit, and why?
Write-back, so it remembers which evicted lines still owe memory an update.
What event forces a dirty block's memory write in write-back?
Eviction (replacement) of that dirty line.
What do and mean and how are they related?
Hit rate and miss rate; .
What do and stand for?
Cache access time (small) and memory access time (large).
What does mean?
The fraction of evicted blocks that are dirty (they pay an extra write-back).
What does a write buffer do?
Queues memory-bound writes so the CPU need not stall waiting for slow DRAM.