CS 152 Computer Architecture and Engineering CS252A Graduate Computer Architecture
Lecture 6 - Memory II
Chris FletcherUC Berkeley, Spring 2026
CPU–Cache Interaction (5-Stage Pipeline)
I-cache miss (hit? = 0)
Deassert PCen, inject a bubble into IR while memory control refills
D-cache miss
Stall the entire CPU until the refill block returns
Average Memory Access Time
$$\text{AMAT} = \text{Hit time} + \text{Miss rate} \times \text{Miss penalty}$$
Hit time : cycles to look up and return data on a hit
Miss rate : fraction of accesses that miss
Miss penalty : extra cycles to fetch from the next level
Hit time hurts 100% of accesses; miss penalty only the misses
Best L1 for a 5-stage pipeline: the biggest cache that keeps hit time at 1 cycle
Deep OoO cores accept longer hits: Zen 5 (~5 GHz) L1D 48 KB at 4 cycles, L2 ~14, L3 ~50–55
Causes of Cache Misses: The 3 C's
Miss type Cause Test
Compulsory (cold start)First reference to a line Happens even in an infinite cache
Capacity Working set too big Happens even in a fully associative cache of the same size
Conflict Collisions from limited associativity Would not happen fully associative
Effect of Cache Parameters
Parameter ↑ Helps Hurts
Cache size Capacity + conflict misses Hit time
Associativity Conflict misses (1 → 2-way removes most; 4/8-way diminishing) Possibly hit time (comparators, mux)
Line size Compulsory + capacity (reload) misses Conflict misses, miss penalty
SPEC92: 4 KB → 256 KB drops total miss rate from ~9.5% toward 1%
Miss rate vs. block size (16–256 B) is U-shaped for small caches (4 KB, 16 KB)
Falls to 64 B, rises at 128 B and 256 B: too few lines left
Sub-Block Placement (Sector Caches)
Tag V V V V
100 1 1 0 0
300 1 1 1 1
204 0 1 0 1
Problem: tags take too much area; bigger lines raise miss penalty
One tag covers a large line split into sub-blocks, each with its own valid bit
On a miss, fetch only the missing sub-block
Tag match ≠ hit. Check tag match AND sub-block valid .
Multilevel Caches
CPU ⇄ L1$ ⇄ L2$ ⇄ (L3$) ⇄ DRAM
Local miss rate = misses in cache $i$ / accesses to cache $i$
Global miss rate = misses in cache $i$ / total CPU accesses
$\text{Global}_{L2} = \text{Miss rate}_{L1} \times \text{Local miss rate}_{L2}$
Misses per instruction = misses in cache $i$ / instructions
$$\text{AMAT} = \text{Hit}_{L1} + \text{MR}_{L1} \times \left(\text{Hit}_{L2} + \text{MR}_{L2} \times \text{Penalty}_{L2}\right)$$
Miss rates here are local. The L2 term is L1's miss penalty.
Example: Two-Level AMAT
$\text{Hit}_{L1} = 1$, $\text{MR}_{L1} = 5\%$, $\text{Hit}_{L2} = 10$, $\text{MR}_{L2} = 20\%$, $\text{Penalty}_{L2} = 100$
$\text{Penalty}_{L1} = 10 + 0.20 \times 100 = 30$ cycles
$\text{AMAT} = 1 + 0.05 \times 30 = 2.5$ cycles
Global L2 miss rate $= 0.05 \times 0.20 = 1\%$ of accesses go to DRAM
L1 filters 95% of accesses: L2 capacity matters more than L2 latency
Alpha 21264 sims: L2 8 MB → 256 KB more than doubles run time; L2 latency 8 → 16 cycles changes it by a few percent
Inclusion Policy
Inclusive : every L1 line is also in L2 (and L3)
Coherence snoops check only the outer cache; L1 undisturbed
Costs duplicate capacity; L2 evictions must back-invalidate L1
Exclusive : inner lines are not in the outer cache
L1 miss that hits L2: the caches swap lines
AMD Athlon: 64 KB L1 + 256 KB L2 = 320 KB of distinct capacity
Check Your Understanding
1.
Computation: $\text{Hit}_{L1} = 1$, $\text{MR}_{L1} = 4\%$, $\text{Hit}_{L2} = 12$, local $\text{MR}_{L2} = 25\%$, $\text{Penalty}_{L2} = 200$. AMAT and global L2 miss rate?
$\text{Penalty}_{L1} = 12 + 0.25 \times 200 = 62$; AMAT $= 1 + 0.04 \times 62 = 3.48$ cycles; global L2 $= 0.04 \times 0.25 = 1\%$.
2.
Concept: why is 1-way → 2-way much more impactful than 4-way → 8-way, and which C does it reduce?
Conflict misses. Most collisions involve just two blocks competing for one set, so 2-way removes most of them.
Write Performance
Reads can be speculative
Direct-mapped: read data and compare tag in the same cycle; ignore data if HIT = 0
Writes cannot be done in parallel with the tag check
Writing data before HIT is known overwrites another block's valid data on a miss
Data-array WE must wait for HIT:
2-cycle tag-check-then-write, or
Pipeline the write behind the previous store's tag check
Write Policy Choices
Option Behavior
On hit Write-through Write cache and memory; simpler, more write traffic
Write-back Write cache only; memory updated on eviction; dirty bit skips clean lines
On miss No-write-allocate Send the write straight to memory
Write-allocate Fetch the block, then write (fetch-on-write)
Common pairs: write-through + no-allocate (simple L1s); write-back + allocate (modern L1/L2/L3)
Write-back: 0, 1, or 2 memory accesses per load/store (hit, clean miss, dirty miss)
Write Buffer to Reduce Read Miss Penalty
CPU
Data cache
Write buffer (FIFO)
L2 / DRAM
read misses bypass pending writes
CPU drops writes (write-through stores or dirty victims) into the buffer and keeps going
RAW hazard: a read miss to X while a write to X is still buffered reads stale data
Fixes:
Simple: on a read miss, wait for the buffer to drain
Fast: compare the miss address with buffered addresses; no match → go ahead; match → return the buffered value
Check Your Understanding
1.
Hazard: why can a direct-mapped cache read data in parallel with the tag compare, but not assert write enable in parallel?
A speculative read on a miss is just discarded; writing before HIT = 1 corrupts another block's data on a write miss.
2.
Worst case: how can one
LW or
SW in a write-back, write-allocate cache cause two memory block transfers?
On a miss whose victim is dirty: first write the dirty victim back, then fetch the requested block.