Skip to main content

Cache write policy and replacement algorithm

Short answer

Write policies: write-through updates cache and memory together; write-back writes only to cache, marking the line dirty, and updates memory on eviction. Replacement algorithms select a victim when the set is full: random, FIFO, LRU (least recently used), LFU (least frequently used). A dirty block under write-back is first written back to memory.

Describe write policy and replacement algorithm used in cache memory.

Write policy

When the processor writes data that is in the cache, the cache and main memory must remain consistent.

  • Write-through: write to cache and main memory together. Memory is always up to date and the design is simple, but every write takes memory time and increases bus traffic.
  • Write-back: write only to cache and mark the line dirty. The block is written to memory when it is evicted. Faster and less traffic, but memory is temporarily inconsistent and control is more complex.
  • On a write miss: write-allocate (fetch block into cache, then write) or no-write-allocate (write directly to memory).

Replacement algorithm

On a miss with the cache (set) full, a block must be removed to make room. Direct mapping has only one choice, but associative and set-associative caches need an algorithm:

  • Random: simplest, selects any line.
  • FIFO: removes the oldest-loaded block.
  • LRU: removes the block unused for the longest time; usually best, as it uses temporal locality.
  • LFU: removes the least frequently used block. If the victim is dirty (write-back), it is first written back to memory.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Embedded System chapter 4 questions →