The Memory Hierarchy & Caches

write-through

Back to editing the borrowed document — but this time you re-file a fresh copy in the archive every single time you change a sentence. It is more work, and slower, but the archive is always perfectly up to date: anyone who consults it sees your latest edit. Write-through is this eager approach for caches: every write updates BOTH the cache and the slower memory below, keeping them always in agreement.

On a write, a write-through cache forwards the data to the next level immediately as well as updating its own copy. There is no dirty bit to track and no deferred write-back on eviction, because memory never lags behind — evicting a line is trivial since memory already has the current value. The obvious downside is that every write incurs traffic to the slow level, so a hot variable updated in a tight loop would, naively, generate a flood of slow memory writes. This is tamed by a write buffer: a small queue that accepts the writes at cache speed and drains them to memory in the background, so the CPU usually need not stall waiting for each store to complete.

Write-through buys simplicity and an always-consistent view of memory, which is genuinely valuable when other agents read memory directly (some I/O and multiprocessor settings), but it pays in write bandwidth. The related orthogonal choice is what to do on a write that MISSES: write-allocate (fetch the line into the cache first, then write, betting more writes to that line are coming) versus no-write-allocate (write straight to memory, skipping the cache). Write-back caches usually pair with write-allocate; write-through caches often pair with no-write-allocate. The honest summary: write-through is simpler and safer for consistency but slower under heavy writes, which is why high-performance caches overwhelmingly choose write-back instead.

A store updates the cache line and is also pushed to memory; the CPU drops it into the write buffer and keeps running. If the buffer fills before memory drains it, the CPU must stall — which is the cost write-back avoids by deferring writes entirely.

Every write updates cache and memory together; a write buffer hides the latency of the memory write.

Write-through keeps memory always current but at the price of write bandwidth, so high-performance caches favour write-back. Don't confuse the write policy (through vs back) with the write-miss policy (write-allocate vs not) — they are independent choices that are often paired by convention.

Also called
store-through直寫