CS 152 Computer Architecture and Engineering
CS252A Graduate Computer Architecture Lecture 6 - Memory II

Chris Fletcher
UC Berkeley, Spring 2026

CPU–Cache Interaction (5-Stage Pipeline)

Average Memory Access Time

$$\text{AMAT} = \text{Hit time} + \text{Miss rate} \times \text{Miss penalty}$$

Causes of Cache Misses: The 3 C's

Miss typeCauseTest
Compulsory (cold start)First reference to a lineHappens even in an infinite cache
CapacityWorking set too bigHappens even in a fully associative cache of the same size
ConflictCollisions from limited associativityWould not happen fully associative

Effect of Cache Parameters

Parameter ↑HelpsHurts
Cache sizeCapacity + conflict missesHit time
AssociativityConflict misses (1 → 2-way removes most; 4/8-way diminishing)Possibly hit time (comparators, mux)
Line sizeCompulsory + capacity (reload) missesConflict misses, miss penalty

Sub-Block Placement (Sector Caches)

TagVVVV
1001100
3001111
2040101
  • 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

$$\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$

  1. $\text{Penalty}_{L1} = 10 + 0.20 \times 100 = 30$ cycles
  2. $\text{AMAT} = 1 + 0.05 \times 30 = 2.5$ cycles
  3. Global L2 miss rate $= 0.05 \times 0.20 = 1\%$ of accesses go to DRAM

Inclusion Policy

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

Write Policy Choices

OptionBehavior
On hitWrite-throughWrite cache and memory; simpler, more write traffic
Write-backWrite cache only; memory updated on eviction; dirty bit skips clean lines
On missNo-write-allocateSend the write straight to memory
Write-allocateFetch the block, then write (fetch-on-write)

Write Buffer to Reduce Read Miss Penalty

CPU Data cache Write buffer (FIFO) L2 / DRAM read misses bypass pending writes

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.