Write-through vs Write-back

A Cache writing scheme can be defined in one of two-ways. Writes can update both the cache block and main memory or Writes can update just the cache block and main memory is updated when the block is replaced. The former is called write-through and the latter is called write-back.

Write-through

In a write-through scheme, writes always update both the cache and the next lower level of the memory hierarchy, ensuring that data is always consistent between the two.

Advantages

  • Read miss never results in writes to main memory
  • Easy to implement
  • Main memory always has current copy of data ensuring consistency

Disadvantages

  • Write is slower
  • Every write needs a memory access
  • Uses more memory bandwidth

Write-back

A write-back scheme handles writes by updating values only to the block in the cache, then writing the modified block to the lower level of the hierarchy when the block is replaced. To reduce the frequency of writing back blocks on replacement, a dirty bit is used. This bit indicates whether the block is dirty (modified while in the cache) or clean (not modified).

Advantages

  • Writes occur at the speed of the cache memory
  • Multiple writes within a block only require one write to main memory
  • Uses less memory bandwidth

Disadvantages

  • Harder to implement
  • Main memory is not always consistent with cache
  • Reads that result in replacement may cause writes of dirty blocks to main memory

Write Buffer

A write buffer is a queue that holds data while the data is waiting to be written to memory. After writing the data into the cache and the write buffer, the processor can continue execution. When a write to main memory completes, the entry in the write buffer is freed. if the write buffer is full, the processor must stall. To reduce the occurrence of stalls, the depth of the write buffer is greater than the size of a typical write burst.

Cycle Time

In a Write Back cache, since the block cannot be overwritten, stores either require two cycles (one cycle to check for hit, another cycle to perform the write) or require a write buffer (one cycle by pipelining). In a Write Through cache, writes can always be done in one cycle.

1 Comment Write-through vs Write-back

  1. Pingback: Write and No-Write Allocate

Leave a Reply

Your email address will not be published. Required fields are marked *