Cache mapping and hierarchy performance
Caches exploit temporal reuse and spatial proximity. Solve a cache problem in this order: convert the block size to address units, split the address, identify the candidate set, then apply the replacement and write policy. A hit requires a valid matching tag.
5.1 Cache address fields
Past papers · CS 2014–2026 (23 papers): 15 questions, 25 marks
A direct-mapped cache offers one location per memory block. A -way cache offers candidate lines in one set. A fully associative cache allows any line and has no set-index bits. Cache capacity below means data capacity, excluding metadata.
The offset selects a byte, the index selects one set, and the tag is compared across that set's ways.
Increasing ways by a factor of two at fixed data capacity and block size reduces index width by one and increases tag width by one. It does not change the processor–memory data-bus width. Increasing block size at fixed capacity and associativity decreases index width and increases offset width by the same amount: tag width stays unchanged.
5.2 Tags, valid bits and replacement storage
Past papers · CS 2014–2026 (23 papers): 1 question, 2 marks
A data-capacity statement usually excludes tags and status. A tag match on an invalid line is still a miss. Write-back caches need a way to record whether a valid line has been modified; write-through caches do not require dirty bits for this purpose.
5.3 Replacement, locality and miss classification
Past papers · CS 2014–2026 (23 papers): 5 questions, 10 marks
Maintain a separate ordered list for each set. For LRU, a hit moves its block to most recent; on a miss use an invalid line first, otherwise evict least recent. FIFO changes insertion order on a miss, not on a hit. Random replacement needs its stated random model; a deterministic answer cannot assume it behaves like LRU.
| Miss class | Operational test |
|---|---|
| Compulsory | First reference to a block in an initially empty cache |
| Capacity | Non-first reference that also misses in a fully associative LRU cache of the same line capacity |
| Conflict | Non-first reference that misses in the actual cache but hits in that fully associative reference cache |
Use this reference-cache definition for the standard three-C classification. Write-policy bypasses, coherence invalidations and prefetch effects need extra categories or explicit assumptions. Temporal locality is reuse of the same block; spatial locality is access to nearby data. Larger blocks may exploit spatial locality but reduce line count and increase transfer cost, so they do not guarantee a lower miss rate.
For array traces, first obtain byte addresses from Section 1.5, then map them to blocks. A single aligned streaming read of elements of bytes, with no eviction/revisit effects, incurs one compulsory miss per touched block. Do not multiply by element count when several adjacent elements share a line. A column traversal of a row-major array uses a row-size stride and may conflict repeatedly.
5.4 Write policies and inclusion
Past papers · CS 2014–2026 (23 papers): 3 questions, 5 marks
| Decision | Choice | Consequence |
|---|---|---|
| Write hit | Write-through | Update cache and send the store to the next level; a write buffer may hide delay |
| Write hit | Write-back | Update cache, mark dirty; defer lower-level write until required |
| Write miss | Write-allocate | Fetch/allocate the block, then update it |
| Write miss | No-write-allocate | Send the store downward without allocating the missed block |
The hit policy and miss-allocation policy are separate decisions. Write-back with write-allocate and write-through with no-write-allocate are common pairings, not mandatory rules. A read miss can evict a dirty write-back line. A clean victim needs no data writeback. A write-through victim needs no dirty writeback, although queued stores may still be draining.
Inclusive L2 contains every L1 block, so an L2 eviction may require L1 invalidation. Exclusive levels avoid storing the same block in both by design. Inclusion concerns block presence; it does not imply that lower-level data is already current when an upper-level write-back copy is dirty. DMA coherence requirements appear in Section 7.3.
5.5 Average memory access time
Past papers · CS 2014–2026 (23 papers): 9 questions, 14 marks
Decide whether a quoted miss time is the entire miss path or an extra penalty after the lookup. Most AMAT errors come from mixing those two conventions. A lower-level local miss rate is conditional on accesses that actually reach that level.
If a program makes memory accesses per instruction and L2 misses per instruction, then the local L2 miss fraction is . The denominator is L2 accesses per instruction. For an optimisation, compare complete AMAT expressions; a better hit ratio can be offset by a longer hit time.
5.6 Cache stalls in processor time
Past papers · CS 2014–2026 (23 papers): 1 question, 2 marks
A fetch is a memory access even when an instruction has no data operand. Separate instruction-cache misses from load/store misses, and ensure the base CPI does not already contain the penalties being added.
Last-minute recall
- Cache capacity normally means data capacity; metadata is extra.
- Tag, set index and block offset exhaust the physical address bits.
- At fixed capacity and line size, doubling ways adds one tag bit.
- LRU reuse is a hit only when distinct intervening same-set blocks are fewer than the ways.
- A read miss can cause a dirty writeback.
- A local L2 miss rate is conditional on reaching L2.
- Use total miss time or incremental miss penalty consistently.
- Include instruction fetches when calculating memory stalls.