Worked examples — Write-allocate vs no-allocate
This page is the practice ground for Write-allocate vs no-allocate. The parent explained the idea; here we grind through every kind of situation a write miss can put you in and count the memory traffic each time.
Before anything else, let us pin down the words so no symbol is used unearned.

The scenario matrix
Every write-miss situation this topic can throw at you falls into one of these cells. The examples that follow are each tagged with the cell they cover, and together they hit all of them.
| # | Case class | What makes it special | Policy that shines | Example |
|---|---|---|---|---|
| A | Single isolated write, reused soon | temporal locality present | write-allocate + write-back | Ex 1 |
| B | Single isolated write, never reused | zero temporal locality | no-allocate + write-through | Ex 2 |
| C | Cluster of writes to one block, then read | spatial locality | write-allocate | Ex 3 |
| D | Streaming writes across many blocks | data larger than cache | no-allocate / Streaming Stores | Ex 4 |
| E | Degenerate: write the same address twice | is the 2nd a hit? | either — tests hit logic | Ex 5 |
| F | Boundary: write straddling a block edge | offset near line size | reveals block granularity | Ex 6 |
| G | Eviction / dirty writeback | line already dirty, conflict | write-back cost accounting | Ex 7 |
| H | Word-problem (real workload) | pick a policy & justify | decision framework | Ex 8 |
| I | Exam twist: forbidden combo | write-back + no-allocate | shows why it's illegal | Ex 9 |
Cache used throughout unless stated: 4 lines, 8 bytes/line, direct-mapped, initially empty.
Cell A — isolated write, reused soon
Cell B — isolated write, never reused
Cell C — cluster to one block, then read (spatial locality)

Cell D — streaming across many blocks
Statement. Write once to each of 8 addresses 0x00, 0x08, 0x10, 0x18, 0x20, 0x28, 0x30, 0x38 (8 distinct blocks), never read them. Cache holds only 4 lines. Compare policies.
Forecast: with only 4 lines and 8 blocks, does write-allocate even keep anything useful?
Write-allocate + write-back:
- Blocks
0x00,0x08,0x10,0x18map to indices : 4 fetches (4 reads), 4 dirty lines. 0x20→ index : conflict — evicts dirty line 0 → 1 write-back, then 1 read to fetch. Same for0x28(idx1),0x30(idx2),0x38(idx3): each is 1 writeback + 1 read. Why so bad? We keep no data (never read), yet pay to fetch and to evict — pure overhead. → reads , writes (evictions) . Total = 12.
No-allocate + write-through:
- 8 writes bypass cache entirely → 8 writes, 0 reads. Total = 8.
Verify: no-allocate 8 vs write-allocate 12. Streaming has zero reuse, so allocating only adds fetch + eviction cost. This is exactly why Streaming Stores and Write Combining Buffers exist.
Cell E — degenerate: write same address twice
Statement. Write 0xAA then 0xBB to 0x28 under write-allocate + write-back. Is the 2nd write a hit?
Forecast: hit or miss on the second write?
- Write 1: miss → fetch block (1 read), write
0xAA, dirty. - Write 2: line 1 now valid → hit, overwrite to
0xBB, still dirty (0 traffic). Why a hit? Allocation from write 1 already brought the block in.
Verify: reads = 1, writes = 0. Total = 1. The block is written twice but hits memory once — the Dirty Bit tracks "needs saving later" without extra traffic per write.
Cell F — boundary: write straddling a block edge
Statement. A program writes a 2-byte value at address 0x07 (bytes 0x07 and 0x08) under write-allocate. How many blocks are touched?
Forecast: one block or two?
- Byte
0x07: block , index 0. - Byte
0x08: block , index 1. Why two?0x08is the first byte of the next line; the 2-byte write straddles the boundary. - Both are misses → 2 fetches (2 reads), both lines allocated & dirtied. Why fetch both? Each byte lives in a different line, and the cache moves whole lines only.
Verify: reads = 2. A single small store cost two block fetches purely because it crossed the line edge — the classic misalignment penalty.
Cell G — eviction of a dirty line
Statement. Under write-allocate + write-back: write 0x28 (index 1), then write 0x48. What is the total traffic?
Forecast: 0x48's index — and does the old dirty line cost us?
- Write
0x28: index 1, miss → fetch (1 read), dirty line 1. - Write
0x48: , index . Same slot, occupied by a dirty line. Why conflict? Different block, same index — direct-mapped has only one slot per index. - Evict line 1: it is dirty ⇒ write it back (1 write), then fetch block for
0x48(1 read), write, dirty. Why write back first? Write-back never lost the earlier0x28change; it must be saved before the slot is reused, or data corrupts.
Verify: reads = 2, writes = 1. Total = 3. Contrast with write-through, which would have paid the 0x28 write immediately and never needed a dirty writeback.
Cell H — real-world word problem
Statement. A logging system appends 64-byte records to a file buffer sequentially, flushed to disk and never re-read by the CPU. Records total 100 MB; cache is 1 MB. Which policy, and estimate the relative traffic?
Forecast: allocate or not?
- Access pattern: pure sequential writes, no reads ⇒ zero temporal, and data (100 MB) ≫ cache (1 MB) ⇒ no line survives to be reused. Why it matters: this is the streaming signature (Cell D at scale).
- Apply the framework from the parent: use write-allocate only if is high. Here it is ≈ 0.
- Decision: no-allocate (non-temporal stores). One write per 64-byte record.
- Write-allocate would additionally read each 64-byte block (100 MB of pointless fetch) and later evict it.
- So write-allocate traffic ≈ no-allocate (a fetch + a writeback per useful write).
Verify: no-allocate ≈ 100 MB written; write-allocate ≈ 100 MB read + 100 MB written = 200 MB. Ratio 2:1 in favour of no-allocate — matches the "streaming ⇒ bypass cache" rule and avoids Cache Pollution of the 1 MB cache.
Cell I — exam twist: the forbidden combination
Statement. A student proposes write-back + no-allocate. Trace one write miss and show the contradiction.
Forecast: where does it break?
- Write miss to
A. - No-allocate says: don't put
Ain cache. - Write-back says: only touch memory when a dirty cached line is evicted. Why this is a deadlock: the data isn't in cache (step 2), so write-back has nothing to defer — yet write-back forbids writing memory now.
- The only escape is to write memory immediately — but that is literally write-through behaviour.
Verify: the combination collapses into write-through, so it is not a distinct valid policy. This is why the parent's identity holds. See Write-back vs Write-through.
Recap
Recall Which cell wins for pure streaming writes?
No-allocate — zero reuse means allocation only adds fetch + eviction cost. (Cell D / Ex 4)
Recall In Ex 3, why did write-allocate cost 2 reads, not 1?
0x100–0x10C spanned two blocks (0x20 and 0x21), each fetched once.
Traffic count for write-allocate hit, given prior allocation
Why does a dirty line cost extra on eviction
Allocate for Again (reuse), Around for Away-forever (streaming).