---
title: "Cache write policy and replacement algorithm"
subject: "Embedded System"
chapter: 4
key: "semester_6/embedded_system:cache-write-policy-replacement"
source: https://www.bctengineer.com/q/semester_6/embedded_system/cache-write-policy-replacement
site: BCT Engineering
---

# Cache write policy and replacement algorithm

Embedded System · Chapter 4: Memory

- Asked in: 2079 Asoj, 5 marks
- Video: [Cache Design - An Overview](https://www.youtube.com/watch?v=1tvW8kzOpSA) — Neso Academy
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_6/embedded_system/cache-write-policy-replacement
- Whole chapter: https://www.bctengineer.com/md/semester_6/embedded_system/chapter-4

## Question

Describe write policy and replacement algorithm used in cache memory.

## 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.

## Answer

#### 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.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. In a write-back cache, when is a modified block written to main memory?
   A. On every write
   B. When the block is evicted
   C. Never
   D. Only on a read hit
   Answer: B. Write-back marks the line dirty and writes it to memory when it is replaced. (Key point: Write-back)

2. What does write-allocate do on a write miss?
   A. Writes directly to memory without loading
   B. Discards the write
   C. Fetches the block into cache, then writes
   D. Evicts the whole cache
   Answer: C. Write-allocate loads the block first and then writes; no-write-allocate writes straight to memory. (Key point: Write miss handling)

3. Which cache organisation needs no replacement algorithm?
   A. Fully associative
   B. Set-associative
   C. Direct mapped
   D. All need one
   Answer: C. Direct mapping gives only one choice of line, so no algorithm is needed. (Key point: Replacement need)

4. If the block chosen for replacement is dirty in a write-back cache, what must happen first?
   A. It is written back to memory
   B. It is simply discarded
   C. It is moved to another set
   D. The cache is flushed fully
   Answer: A. A dirty victim holds the only up-to-date copy so it must be written back before being replaced. (Key point: Dirty victim)

## Related in Embedded System

- [Cache replacement policies](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3Acache-replacement-policies) — Embedded System, chapter 4
- [Cache memory mapping techniques](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3Acache-mapping-techniques) — Embedded System, chapter 4, asked 3×
- [Which cache is better (4KB vs 12KB)](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3Acache-comparison-4kb-12kb) — Embedded System, chapter 4, asked 2×
- [Which cache is better (2KB vs 8KB)](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3Acache-comparison-2kb-8kb) — Embedded System, chapter 4, asked 2×

## Related in other subjects

- [Need for replacement algorithm in cache](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_organization_and_architecture%3Areplacement-why) — Computer Organization and Architecture, chapter 6
- [Cache write policy techniques](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_organization_and_architecture%3Awrite-policy) — Computer Organization and Architecture, chapter 6
- [Memory characteristics and LRU replacement](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_organization_and_architecture%3Amemory-char-lru) — Computer Organization and Architecture, chapter 6
- [Direct mapping with 32-block memory, 8-block cache](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_organization_and_architecture%3Adirect-mapping-example) — Computer Organization and Architecture, chapter 6, asked 3×
