Skip to guide

Part 2 · Cache hierarchy

Cache mapping, misses, VIPT, and MSHRs

Decompose addresses, compare associativity and write policies, classify miss causes, and reason about VIPT and non-blocking cache structures.

Reason cycle by cycle, calculate the cost of misses and stalls, and explain why each implementation choice changes performance or correctness.

Updated July 20261 connected chaptersInteractive labs + worked examples

Memory hierarchy

Keep the common case close to the core.

Registers, SRAM caches, DRAM, and storage trade capacity for latency and cost. Caches work because access patterns exhibit temporal and spatial locality.

Registerssmallest · fastestL1SRAM · core localL2 / L3larger · slowerDRAMmain memorySSD / storagelargest · slowest
Temporal locality

Recently used data is likely to be used again. Loops and accumulators are common examples.

Spatial locality

Nearby addresses are likely to be used. A cache line fetches a neighborhood, often 64 bytes.

Tag

Identifies which memory block currently occupies the selected way.

Index

Selects a set, reducing the number of tag comparisons.

Offset

Selects the byte or word within the cache line.

Cache address explorer

Split a physical address and size the tag array.

PIPT cache
Tag17 bitsSet index11 bitsBlock offset6 bits
Cache lines16,384
Sets2,048
Tag + valid storage288 Kibit
Storage in bytes36 KiB

Address 0x1234ABCD selects set 687 of 2,048, byte offset 13, and compares tag 0x91A against 8 ways.

Accuracy note: PIPT tags use the physical address width. The source gives a 32-bit virtual address but not the physical width. Its requested 17-bit tag and 288 Kibit tag array imply a 34-bit physical address. If the physical address is 32 bits, the correct result is a 15-bit tag and 256 Kibit, or 32 KiB, including one valid bit per line.

1-way

Direct mapped

One possible line per index. Fast and compact, but vulnerable to conflicts.

N-way

Set associative

N candidate ways in one set. Parallel tag checks trade power for fewer conflicts.

Any line

Fully associative

Best placement freedom, but every tag may need comparison. Practical for small structures.

Compulsory miss

Cause: The block has never been fetched.

Response: Prefetch useful streams or use a larger line when spatial locality justifies it.

Larger lines can waste bandwidth and pollute the cache.

Conflict miss

Cause: Active blocks compete for the same set even while other sets have space.

Response: Increase associativity or improve placement and indexing.

More ways add tag comparisons, power, mux delay, and replacement state.

Capacity miss

Cause: The working set exceeds the cache's usable capacity.

Response: Increase cache capacity or reduce the software working set.

A larger cache costs area and can lengthen hit latency.

Coherence miss

Cause: Another agent's write invalidates the local copy.

Response: Reduce writable sharing and false sharing; use an appropriate coherence protocol.

This miss reflects inter-core communication, not only local placement.
Cache design choices move miss rate, hit time, bandwidth, power, and area together.
ParameterChoicePerformance benefitCost and complexity
CapacitySmall ↔ largeLarger capacity reduces capacity misses and holds a bigger working set.More area and leakage; longer wires can increase hit time.
AssociativityDirect ↔ N-way ↔ fully associativeMore ways reduce conflict misses.More comparators, replacement metadata, mux delay, power, and verification.
Line size16 B ↔ 64 B ↔ 128 BLarger lines exploit spatial locality, amortize refill overhead, and need fewer tag entries.Longer refill latency, more bandwidth, pollution, and false sharing.
Write policyWrite-through ↔ write-backWrite-through simplifies lower-level visibility; write-back bundles repeated writes.Write-through needs bandwidth and usually a write buffer. Write-back needs dirty state and reliable eviction.

VIPT L1 cache

Index while translation runs.

A virtually indexed, physically tagged cache uses page-offset bits to select a set in parallel with the TLB lookup, then compares translated physical tags. This removes serial TLB-plus-cache latency.

The synonym problem

Two virtual addresses can map to one physical page. If their index bits differ, duplicate copies could occupy different sets. Keep index plus offset within the page offset, commonly expressed as cache capacity divided by associativity no larger than page size. Page coloring and explicit alias handling cover designs that exceed this constraint.

Non-blocking cache

Keep independent work moving.

MSHRs record each outstanding line, request type, destination, and waiting consumers. They enable hit-under-miss, merge requests to the same line, and allow multiple independent misses.

Where it matters

A long DRAM miss need not block an unrelated L1 hit. Several concurrent misses can overlap until MSHRs, fill buffers, memory-level parallelism, or bandwidth become the new limit. When all MSHRs are occupied, new misses must stall.

Parallel lookup

A VIPT cache spends the page offset twice.

One branch translates the VPN. The other uses untranslated page-offset bits to start the SRAM read. They meet at the physical-tag comparison, so no data becomes valid before translation and permission checks finish.

VIPT
Fast path

Use virtual page-offset bits to index the set while the TLB produces the physical tag.

Invariant

Every index bit used before translation must be unchanged by translation.

Failure signature

Synonyms create duplicate physical lines in different sets, producing stale copies.

MSHR
Fast path

Track an outstanding line and let independent hits or misses continue.

Invariant

Every waiter links to one fill, and same-line requests merge without a duplicate refill.

Failure signature

A lost waiter never wakes; a premature free misroutes data; full MSHRs apply backpressure.

1Lookup missesline address2Allocate or mergewaiters + destination3Issue lower readone request per line4Install and wakefill + replay5Retire MSHRafter consumers resolve

AMAT calculator

Price every miss at the level where it occurs.

Average latency
AMAT = tL1 + mL1 × (tL2 + mL2 × tDRAM)

2 + 0.1 × (10 + 0.2 × 60)

4.2 ns

AMAT is 4.2 ns. L1 contributes 2 ns, L2 contributes 1 ns, and DRAM contributes 1.2 ns. L1 lookup is the largest contribution.

What happens on a cache read miss?

Allocate miss-tracking state, select a victim, write back a dirty victim if needed, request the line from the next level, install data and tag, update replacement state, then wake or replay the waiting load.

How does associativity reduce conflict misses?

Blocks with the same index can coexist in different ways. It does not remove compulsory or capacity misses, and the extra ways increase lookup cost.

Continue the system

Connect the adjacent layer.