← ⚡ Cache Memory
Subtopic 7 of 9

3.7Write policies

The idea

Write policies decide what happens on a store: update memory immediately (write-through) or only when the line is evicted (write-back).

Think of it like this: Write-through: update both the copy on your desk and the master in the library every time. Write-back: only scribble on your desk copy and mark it "changed" (dirty), returning it later.

Why it exists

Memory is slow. Write-back saves bandwidth when a value is written many times.

How it works

  1. Write-through: cache and memory updated together; simple, memory always current, often uses a write buffer.
  2. Write-back: only the cache is updated; a dirty bit marks the line.
  3. On eviction, a dirty line is written to memory; a clean one is just dropped.
  4. Misses on writes: write-allocate (bring block in) or no-write-allocate.

Worked example: CPU writes X twice (9 then 12)

Write-through: 2 memory writes. Write-back: 0 now, 1 later at eviction.

Now play with it

  • →Step through both tabs and watch the Memory X value and the Dirty bit.
CPU-
Cache X5
Memory X5
  • CPU writes X = 9
  • Cache line updated
  • Memory updated at the same time (via a write buffer)
  • CPU writes X = 12: again both are written, so memory traffic on every store

Check yourself

Which extra bit does a write-back cache need per line?

Remember: Write-back saves traffic, needs a dirty bit.
Exam notes (the dense version)

Write-through: update cache + memory every write (simple, slow, often no-write-allocate, uses write buffer). Write-back: write memory only on eviction; needs a dirty bit; usually write-allocate.

Previous year questions: Cache Memory (22)

PYQs are grouped by topic, so this is the full set for Cache Memory; try the ones that match this subtopic. Open all 22 on the topic page.