5.4.7 · D3Memory Hierarchy & Caches

Worked examples — Write-allocate vs no-allocate

2,467 words11 min readBack to topic

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.

Figure — Write-allocate vs no-allocate

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)

Figure — Write-allocate vs no-allocate

Cell D — streaming across many blocks


Cell E — degenerate: write same address twice


Cell F — boundary: write straddling a block edge


Cell G — eviction of a dirty line


Cell H — real-world word problem


Cell I — exam twist: the forbidden combination


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?

0x1000x10C spanned two blocks (0x20 and 0x21), each fetched once.

Traffic count for write-allocate hit, given prior allocation
Zero — the block is already valid, so a repeated write just flips the dirty bit.
Why does a dirty line cost extra on eviction
It must be written back to memory before its slot is reused, adding one memory write.