What is Write-through?

A write policy that writes to the level below (such as main memory) at the same time as the cache. The lower level stays up to date, but write traffic is heavy, so it is paired with a write buffer.

Field: Memory Hierarchy

Japanese name: ライトスルー方式

How a write-through cache handles a store

On a store hit, a write-through cache updates its own copy and also sends the write to the next level, such as an L2 cache or main memory. Lines are therefore never dirty: no dirty bit is needed, and an evicted line can simply be discarded because the level below already holds the same data. On a store miss, write-through caches usually use no-write-allocate, sending the write straight down without loading the line, since even if the line were loaded, every later write would still be sent down and the number of writes would not fall.

The write buffer

Waiting for every store to reach memory would stall the CPU constantly, so writes go into a write buffer that drains to the lower level in the background while the CPU continues. The CPU stalls only when the buffer fills, which happens if stores arrive faster than memory can absorb them. Loads that miss must check the buffer, or wait for it to drain, so they do not read stale data from memory. Buffers often merge several writes to the same line into one transfer.

Write-through vs. write-back

Write-back updates only the cache and writes a dirty line to memory once, when it is evicted, so repeated writes to the same line collapse into one transfer. That saves bandwidth and power, which is why most CPU L1 to L3 caches are write-back. Write-through generates traffic on every store but keeps the lower level always current, which simplifies coherence with other cores and with DMA, and makes recovery easy: an L1 that is write-through can protect its data with simple parity and refetch a clean copy on an error.

Where it is used

Write-through appears in small first-level caches backed by a write-back L2, in simple embedded processors, and in memory regions where the lower level must see every write promptly, which many architectures let the operating system select per page through memory-type attributes. It is less suited to the last cache level before DRAM, where store traffic would consume memory bandwidth that a write-back policy would save.

Try it: questions about Write-through

What is the main purpose of a write buffer in a write-through cache?

  1. ATo let the CPU continue without waiting for writes to main memory to complete
  2. BTo keep the data in the cache newer than in main memory
  3. CTo always fetch the line from main memory into the cache first on a write miss, then write it
Show answer and explanation

Answer: A. To let the CPU continue without waiting for writes to main memory to complete

A write-through cache also writes to main memory on every store, so waiting for each write to finish would stall the CPU constantly. A write buffer holds writes temporarily, letting the CPU move on immediately while the buffer drains to memory in the background. Keeping the cache newer than memory characterizes write-back caches; with write-through the two stay consistent. Whether to load a line on a write miss is the write-allocate decision, separate from the write buffer.

For code that writes to the same line many times, why is a write-back cache more advantageous than write-through?

  1. AWrites complete within the cache, and memory is written only once when the line is evicted
  2. BMemory is updated on every write, so no work is needed at eviction
  3. CCache and memory always match, so no coherence management is needed
Show answer and explanation

Answer: A. Writes complete within the cache, and memory is written only once when the line is evicted

A write-back cache absorbs repeated writes to the same line within the cache and writes the dirty line back just once on eviction, greatly reducing memory traffic and power. Updating memory on every write is the write-through behavior, which generates traffic each time the line is written. Cache and memory always matching is also write-through; with write-back they differ for a while.

FAQ

What is the difference between write-through and write-back cache?

Write-through writes to the lower level on every store, keeping it always up to date. Write-back writes only the cache and updates the lower level once when the modified line is evicted, cutting traffic.

Why does a write-through cache need a write buffer?

Without one, the CPU would have to wait for every store to complete in slower memory. The buffer queues writes so the CPU can continue while they drain in the background.

Does a write-through cache need a dirty bit?

No. Since every write is propagated immediately, a line never differs from the lower level, so it can be evicted without writing anything back.

Questions that mention Write-through (2)

Write-through appears in 4 practice questions across 2 topics, including Memory Hierarchy, CPUs and architecture.

  1. Which correctly describes the write-back policy for caches?
  2. Which policy, on a write miss, writes directly to the lower level without loading the line into the cache?

Books on Memory Hierarchy Ad

As an Amazon Associate I earn from qualifying purchases.

Comparisons that include this term

This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.

Back to the glossary