on every write (cache and memory updated together).
Write-back writes to memory
only when a dirty block is evicted.
What bit does write-back require per line and why
the dirty bit, to know if memory is stale and needs writing on eviction.
Does write-through need a dirty bit
No — memory is always current.
Write-allocate vs no-write-allocate apply on a
write MISS.
Write-allocate action on a write miss
fetch the block into cache, then write it (treat as hit).
No-write-allocate action on a write miss
write directly to memory, don't cache the block.
Most common modern pairing
write-back + write-allocate.
Common simple pairing
write-through + no-write-allocate.
Average write cost write-through
tc+tm.
Average write cost write-back
tc+mtm(1+d) where m=miss rate, d=dirty-eviction fraction.
Why is write-back faster for hot loops
repeated writes hit cache; the slow tm is only paid at rate m (eviction), not per write.
Best policy for a memset you never read back
no-write-allocate (avoids useless block fetch).
What hides write-through latency from the CPU
a write buffer.
On clean-block eviction in write-back, memory is
untouched (just discard the copy).
Recall Feynman: explain to a 12-year-old
Imagine your notebook (cache) is a copy of the class textbook (memory). When the teacher changes a fact, you can either immediately run and edit the textbook too (write-through — safe but lots of running) or just fix your notebook now and mark the page with a sticky note (write-back — the sticky note is the dirty bit). You only bother walking to fix the textbook when you need that notebook page for something else (eviction). And if a fact is brand-new and not in your notebook (a write miss), you decide: copy the whole page into your notebook first (write-allocate) because you'll probably use it again, or just scribble it straight into the textbook and don't bother (no-write-allocate) if it's a one-time thing.
Dekho, cache main memory ka ek chhota fast copy hota hai. Read karna easy hai, problem write par aati hai — kyunki write ke baad cache ki copy aur memory ka data alag (mismatch) ho sakta hai. Write policy basically rule hai ki yeh mismatch kaise handle karein.
Pehla sawaal: write HIT par. Write-through matlab har write pe cache aur memory dono update — safe hai, lekin DRAM slow hota hai, toh har baar slow write padta hai. Write-back matlab sirf cache update karo aur ek dirty bit = 1 set kar do (matlab "yeh page badla hua hai"). Memory ko update tabhi karte ho jab woh dirty block cache se nikalna (evict) padta hai. Loops mein same variable baar-baar likhte hain, isliye write-back kai writes ko ek hi memory write mein collapse kar deta hai — bahut fast.
Doosra sawaal: write MISS par (block cache mein hai hi nahi). Write-allocate matlab pehle pura block memory se cache mein le aao, phir likho — locality ka faida. No-write-allocate matlab seedhe memory mein likh do, cache mein dalo hi mat — agar woh data dobara nahi padhna (jaise memset se array initialize karna), toh fetch karna waste hai.
Yaad rakho do alag axes hain: HIT pe through-ya-back, MISS pe allocate-ya-no-allocate. Real CPU mostly write-back + write-allocate use karte hain (kam memory traffic), aur simple systems write-through + no-write-allocate. Isiliye yeh topic important hai — yahi cache coherence (MESI ka Modified state) aur performance ki neev hai.