0 · Recall Warm-up
Answer from memory first. Answers are in the Answer Vault at the bottom.
- Which replacement policy can show Belady's anomaly? from Lesson 4.2.5
- What does the dirty bit in a tag directory record? from Lesson 4.2.3
- Hierarchical AMAT? from Lesson 4.1.2
1 · The Hook
🎣
Reads only copy data up the hierarchy. Writes create a problem: after the CPU writes to the cache, the cache and memory disagree. Either update memory every time (simple, slow) or later, when the line leaves the cache (fast, needs bookkeeping). That choice changes both the access time and the memory traffic, and GATE asks about both.
2 · Predict First
🤔
A loop writes the variable sum 100 times; its block stays in the cache the whole time. With "write to memory on every write", how many memory writes happen? With "write only when the line is evicted"?
Make a guess in your head. The answer opens Section 3.
3 · Core Concept
💡
Predict First — the answer
Every-write policy: 100 memory writes. Write-on-evict: 1 block write (when the dirty line finally leaves).
On a write hit
- Write-through: write the cache and memory. Memory is always up to date; every write costs memory time (unless a write buffer absorbs it).
- Write-back (copy-back): write only the cache and set the line's dirty bit. When a dirty line is evicted, the whole block is written back to memory first. Fewer memory writes; a miss that evicts a dirty line costs an extra block write.
On a write miss
- Write-allocate (fetch on write): bring the block into the cache, then write it.
- No-write-allocate (write around): write straight to memory; don't load the block.
Usual pairs: write-back + write-allocate; write-through + no-write-allocate.
Average access time, write-back
On a miss, the victim is dirty with probability d: the miss costs a block fetch plus, with probability d, a block write-back. T = t_c + (1 − h)(t_block + d·t_block) = t_c + (1 − h)(1 + d)·t_block (hierarchical).
Example: t_c = 1 ns, t_block = 50 ns, h = 0.95, d = 0.2: T = 1 + 0.05 × 60 = 4 ns.
Average access time, write-through (no-write-allocate, no buffer)
Model: a read behaves as before; every write takes t_m (cache and memory written in parallel, the CPU waits for memory). T = f_read × [t_c + (1 − h)·t_m] + f_write × t_m
Example: t_c = 2 ns, t_m = 20 ns, read hit ratio 0.9, 80% reads: T = 0.8 × (2 + 0.1 × 20) + 0.2 × 20 = 0.8 × 4 + 4 = 7.2 ns.
Questions vary in exactly what a write costs; always use their description.
Memory traffic
- Write-through: every write sends a word (or more) to memory.
- Write-back: only dirty evictions send a block.
Consistency in one line
With write-back, memory can hold stale data; a DMA device (Phase 6) or another processor reading memory directly must be kept consistent (cache coherence), which write-through makes easier.
4 · Visual
Write hit to block X (in cache)
write-through: CPU --> cache[X] updated
\-> memory[X] updated (every time)
write-back: CPU --> cache[X] updated, dirty = 1
later, when X is evicted: cache[X] --> memory (once)
| Write-through | Write-back | |
|---|---|---|
| Memory up to date | always | only after eviction |
| Dirty bit | not needed | needed |
| Memory traffic | every write | dirty evictions only |
| Miss cost | fetch | fetch + write-back if dirty |
| Usual miss policy | no-write-allocate | write-allocate |
5 · Worked Examples
Example 1 Easy
A write-through cache sees 600 writes; 90% hit. How many memory writes?
Solution
All 600: write-through writes memory on hits too (no-write-allocate misses also go to memory).
Example 2 Medium
Write-back, hierarchical: t_c = 2 ns, block fetch 80 ns, h = 0.9, 30% of evicted lines dirty. Average access time?
Solution
2 + 0.1 × (80 + 0.3 × 80) = 2 + 0.1 × 104 = 12.4 ns.
Example 3 GATE
Write-through, no-write-allocate, no write buffer. Reads: t_c = 5 ns, t_m = 50 ns, hit ratio 0.8, hierarchical. Every write takes 50 ns. 75% of accesses are reads. Average access time?
Solution
Read: 5 + 0.2 × 50 = 15 ns. T = 0.75 × 15 + 0.25 × 50 = 11.25 + 12.5 = 23.75 ns.
6 · GATE Traps
⚠️
- Write-through writes memory on hits too.
- Write-back's extra cost appears only on misses that evict dirty lines.
- Multiply the dirty fraction by the block write time.
- Read the question's model of a write: parallel write, write buffer, or sequential.
7 · Memory Hook
🧠
"Through = now, back = later." Write-through pays every write; write-back pays at eviction, if dirty.
8 · Connect the Dots
Chapter 4.2 placed blocks; this lesson decided when memory hears about writes. Next: how long a miss really takes (moving a whole block over the bus) and how misses raise the CPI.
9 · Self-Test
GATE format. Try every question before opening the vault.
Q1NAT2 marksWrite-back AMAT
Write-back, hierarchical: t_c = 1 ns, block transfer 40 ns, h = 0.95, half of the evicted blocks are dirty. Average access time (ns)?
Numerical answer: ________
Q2NAT2 marksWrite-through AMAT
Write-through, no buffer: reads hierarchical with t_c = 2 ns, t_m = 40 ns, read hit ratio 0.95; every write takes 40 ns. 70% reads. Average access time (ns)?
Numerical answer: ________
Q3MCQ1 markPairing
Which pairing is the usual one?
- (A) Write-back with write-allocate
- (B) Write-through with write-allocate only
- (C) Write-through needs a dirty bit
- (D) Write-back with no-write-allocate
Q4NAT1 markTraffic
A program performs 5,000 writes, all hits, to 10 distinct blocks that stay in a write-back cache and are evicted once at the end. How many block writes reach memory?
Numerical answer: ________
Q5MSQ2 marksPolicies
Which are true?
- (A) A write-through cache never sends writes to memory on a hit.
- (B) Write-back reduces memory write traffic when a block is written many times.
- (C) Write-back needs a dirty bit per line.
- (D) Write-through keeps memory always up to date.
10 · Rule Card
- Write hit: write-through (cache + memory) vs write-back (cache only, dirty bit, write block on eviction).
- Write miss: write-allocate vs no-write-allocate. Pairs: WB + WA; WT + NWA.
- Write-back: T = t_c + (1−h)(1 + d)·t_block.
- Write-through (writes take t_m): T = f_r[t_c + (1−h)t_m] + f_w·t_m.
11 · Concept Ledger
Unlocked in this lesson. From here on, these terms may be used.
write-throughwrite-back (copy-back)dirty bit usewrite-allocateno-write-allocate (write around)write bufferdirty fraction dmemory write trafficcache coherence (one-line)
12 · Answer Vault
Answer Vault
Try the questions first. Open when you are ready to check.
Recall Warm-up
- FIFO.
- That the line was written since it was loaded (needed for write-back).
- t_c + (1 − h)·t_m.
Self-Test
Q1 Answer: 42 marks
1 + 0.05 × (40 + 0.5 × 40) = 1 + 0.05 × 60 = 4.
Re-read: Lesson 4.3.1 — Write policies: write-through vs write-back, dirty bit, write-allocate
Q2 Answer: 14.82 marks
Read: 2 + 0.05 × 40 = 4 ns. T = 0.7 × 4 + 0.3 × 40 = 2.8 + 12 = 14.8 ns.
Re-read: Lesson 4.3.1 — Write policies: write-through vs write-back, dirty bit, write-allocate
Q3 Answer: (A)1 mark
A write-back cache benefits from keeping written blocks.
- (B) is wrong: Write-through usually pairs with no-write-allocate.
- (C) is wrong: Write-through keeps memory current; no dirty bit needed.
- (D) is wrong: Possible but unusual.
Re-read: Lesson 4.3.1 — Write policies: write-through vs write-back, dirty bit, write-allocate
Q4 Answer: 101 mark
One per dirty block at eviction.
Re-read: Lesson 4.3.1 — Write policies: write-through vs write-back, dirty bit, write-allocate
Q5 Answer: (B) (C) (D)2 marks
Write-through writes memory on every write.
- (A) is wrong: That describes write-back.
Re-read: Lesson 4.3.1 — Write policies: write-through vs write-back, dirty bit, write-allocate