Write-Through vs Write-Back Cache: Differences Explained

A write policy decides what happens when the CPU writes to data that is in the cache. A write-through cache updates the cache and main memory at the same time, so memory is always current but every write costs memory traffic. A write-back cache updates only the cache, marks the line dirty, and writes it to memory later when the line is evicted. Write-back is faster and uses less bandwidth, but it is more complex to keep consistent.

AspectWrite-throughWrite-back
Write policyEvery write goes to both the cache and the next memory levelA write updates only the cache and sets the dirty bit; memory is updated on eviction
Memory trafficHigh: every write goes outLower: repeated writes to one line are merged into one write-back
Write speedSlower without help; a write buffer hides much of the delayFaster: writes complete at cache speed
Consistency with memoryMemory is always up to date, which simplifies sharing with DMA and other coresMemory can be stale until the line is written back, so coherence needs more care
ComplexitySimpleMore complex: dirty bits, write-back on eviction, coherence protocols
Cost of evictionCheap: nothing needs to be writtenEvicting a dirty line costs an extra write to memory
Usual write-miss policyNo-write-allocateWrite-allocate
Typical useSome L1 caches and simple or reliability-focused systemsMost modern CPU caches, especially L2 and L3

Figures are typical orders of magnitude and vary by process generation and product.

When to use which

Write-through
When simplicity and an always-current memory matter more than write bandwidth.
Write-back
When performance matters, especially for code that writes to the same lines many times.

FAQ

What is a dirty bit?

A bit on each cache line in a write-back cache that marks the line as modified. A dirty line must be written back to memory when it is evicted.

Why is write-back faster?

Repeated writes to the same line stay in the cache and are merged into a single write to memory, which reduces memory traffic.

What does a write buffer do?

In a write-through cache it queues the writes to memory, so the processor does not have to wait for them to finish.

Which is simpler for multiple cores?

Write-through, because memory is always up to date. Write-back needs more care, such as coherence protocols, because memory can be stale.

Check your understanding

Which correctly describes the write-back policy for caches?

  1. AWrites skip the cache and update only main memory
  2. BEvery write always updates both the cache and main memory
  3. COnly the cache is updated at first, and the data is written back to main memory when it is evicted from the cache
Show answer and explanation

Answer: C. Only the cache is updated at first, and the data is written back to main memory when it is evicted from the cache

Write-back caches update only the cache and write a dirty line to main memory when it is evicted. Many writes to the same location collapse into one write-back, drastically cutting memory traffic, so most CPU L1–L3 caches use it. Main memory and cache temporarily disagree, however, so coherence and consistency with DMA must be managed. Write-through updates both every time.

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.

In a write-back cache, what is the role of the dirty bit attached to each line?

  1. AIt shows whether the line's data is valid and can be read
  2. BIt shows the line was modified and differs from memory
  3. CIt shows the time the line was last accessed
Show answer and explanation

Answer: B. It shows the line was modified and differs from memory

A write-back cache completes writes in the cache alone, so some lines end up newer than main memory. The dirty bit marks such modified lines so that only dirty lines need to be written back on eviction; clean lines can simply be discarded, avoiding wasted writes. Validity is indicated by the valid bit, and access order is tracked by separate replacement information such as LRU state.

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

Practice Memory Hierarchy questions

Key terms explained

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.
Cache memory
Fast, small memory placed close to the CPU. It holds frequently used data to bridge the speed gap with main memory. Mostly built from SRAM.
Cache coherency
In a multicore CPU, the mechanism that keeps copies of the same address in different cores' caches consistent, for example by invalidating other copies when one core writes.
Cache line
The unit in which data moves between a cache and the level below, also called a cache block. Many CPUs use 64 bytes, and the low address bits give the position (offset) within the line.

Related comparisons