computer-architecture memory

Definition

Cache Write-Hit

A cache write-hit occurs when a write access targets data that is already present in the cache.

So the processor can update the cached copy directly, according to the chosen cache write policy.

A cache write-hit is the write analogue of a cache hit for a read.

Policies

Write-Through

Write-through

On a write-hit, the processor updates both the cache and main memory immediately.

This keeps the cached value consistent with main memory at all times.

Pros

  • simple;
  • guarantees consistency with main memory, which is useful for I/O and multiprocessor settings.

Cons

  • causes frequent writes to main memory;
  • can reduce performance.

Copy-Back

Copy-back

On a write-hit, the processor updates the cache and marks the block as dirty.

Main memory is updated only later, when the dirty block is removed from the cache. This approach is also called write-back.

Pros

  • a write-hit is much faster;
  • accesses to main memory are less frequent.

Cons

  • the cached value may temporarily differ from main memory;
  • a read miss can be slower, because a dirty block may first have to be copied back;
  • a dirty block must be synchronised before it is replaced.

Write-Buffer

Buffered write-through

A write-buffer can be used together with write-through to combine data consistency with faster write operations.

On a write-hit, the new value is written into the cache and also entered into the write-buffer. The processor can then continue while the buffered write is propagated to main memory.

This gives some of the simplicity and consistency of write-through, while reducing the immediate delay of each write.

If the write-buffer becomes full, however, the processor must wait until buffered writes have been written out.