Memory Hierarchy & Caches
Level: 4 (Application — novel problems, no hints) Time limit: 60 minutes Total marks: 60
Question 1 — Cache Organization & Address Decomposition (12 marks)
A system uses a byte-addressable 40-bit physical address space. The L1 data cache is 32 KiB, 4-way set-associative, with a 64-byte line size.
(a) Compute the number of sets, and the width (in bits) of the block-offset, index, and tag fields. (6)
(b) A program streams sequentially through a 1 MiB array exactly once (read-only), starting at a line-aligned address. Assuming the cache starts cold, compute the number of misses and the hit rate for this traversal. Classify the miss type(s) that occur. (4)
(c) If the cache were instead direct-mapped but kept at the same 32 KiB capacity and 64-byte lines, would the sequential traversal in (b) produce a different miss count? Justify. (2)
Question 2 — AMAT & Multi-Level Hierarchy (14 marks)
A processor has the following memory system parameters:
- L1: hit time 1 cycle, local miss rate 8%
- L2: hit time 12 cycles, local miss rate 25%
- L3: hit time 40 cycles, local miss rate 40%
- Main memory access: 200 cycles
(a) Compute the global miss rate at each of L2 and L3 (relative to all CPU memory references). (3)
(b) Compute the overall AMAT in cycles. (5)
(c) A proposed redesign doubles the L2 size, lowering its local miss rate from 25% to 15% but raising its hit time from 12 to 16 cycles. All other parameters unchanged. Determine whether this redesign reduces AMAT, and by how much. (4)
(d) State one reason why a lower L1 hit time might justify accepting a higher L1 miss rate in a real design. (2)
Question 3 — Replacement Policy Trace (10 marks)
A fully-associative cache holds 4 lines. The access stream (by line number) is:
(a) Trace the cache contents and count the hits under LRU replacement. (4)
(b) Trace and count the hits under FIFO replacement. (4)
(c) This particular stream exhibits a well-known counter-intuitive phenomenon when comparing FIFO caches of different sizes. Name it, and state briefly what it means. (2)
Question 4 — Write Policy & Traffic Analysis (12 marks)
A cache uses 64-byte lines. Consider a workload of 1000 memory operations: 700 reads and 300 writes. The read miss rate is 10% and the write miss rate is 20%. On a miss requiring line fetch, a full 64-byte line is transferred; a single word write-through is 4 bytes.
(a) For a write-through + no-write-allocate cache, compute the total bytes transferred to main memory (count both refill traffic and write-through traffic). Assume clean read-miss lines never need writeback. (5)
(b) For a write-back + write-allocate cache where 30% of all lines evicted are dirty and each writeback moves a full 64-byte line, estimate the total bytes transferred. Assume every miss (read or write) fetches a line, and assume the number of dirty evictions equals 30% of the total number of misses. (5)
(c) State one workload characteristic that would make write-through preferable despite higher bandwidth. (2)
Question 5 — Virtual Memory, Paging & TLB (12 marks)
A system uses 48-bit virtual addresses, 4 KiB pages, and a 4-level page table where each level indexes with an equal number of bits and each page-table entry is 8 bytes.
(a) Determine how many bits index each page-table level, and confirm the offset width. (4)
(b) A memory reference incurs a TLB miss followed by a page-table walk that is fully served from cache. TLB hit time is 1 cycle; each page-table level access on TLB miss costs 3 cycles; the final data access costs 1 cycle. If the TLB hit rate is 98%, compute the average address-translation-plus-access latency in cycles. (On a TLB hit, translation is 1 cycle then the 1-cycle data access.) (5)
(c) Explain, in terms of reach, why increasing page size can reduce TLB misses, and name one cost of doing so. (3)
Answer keyMark scheme & solutions
Question 1
(a) Capacity bytes. Line B ⇒ offset = 6 bits. (1) Number of lines . (1) 4-way ⇒ number of sets ⇒ index = 7 bits. (2) Tag bits. (2)
(b) 1 MiB B ⇒ number of lines touched . (1) Sequential streaming touches each line once; only the first access to each new line misses (compulsory). So misses = 16384, one per line. (1) Accesses = 16384 line-first accesses only? No — misses counted per line access. With one access per byte the hits come from spatial locality within a line: each 64-byte line has 64 accesses, 1 miss + 63 hits. Misses , total accesses . Hit rate . (1) All misses are compulsory (cold) — data never seen before; array (1 MiB) fits/streams without reuse so no capacity/conflict reuse effect. (1)
(c) No difference. Sequential first-touch traversal produces exactly the compulsory misses regardless of associativity — each line is loaded once and never re-referenced, so conflict misses cannot arise. Same 16384 misses. (2)
Question 2
(a) Global miss rate = product of local miss rates down the chain.
- L1 miss (global) = 8% = 0.08
- L2 global = (2%) (1.5)
- L3 global = (0.8%) (1.5)
(b) AMAT (in cycles), using local-miss-rate hierarchical form: (1) Inner: . (1) Next: . (1) Outer: cycles. (2)
(c) New: , . Next level: . (1) Outer: cycles. (2) Improvement cycles. Redesign reduces AMAT by 0.64 cycles — worthwhile. (1)
(d) L1 hit time is on the critical path of every memory reference and often sets the CPU clock period; a smaller/faster L1 (even with a slightly higher miss rate) can allow a higher clock frequency or shorter pipeline, and the modest extra misses are absorbed by a fast L2. (2)
Question 3
Cache = 4 lines, stream: 1 2 3 4 1 2 5 1 2 3 4 5
(a) LRU (MRU listed rightmost, evict leftmost):
| ref | hit? | contents after (LRU→MRU) |
|---|---|---|
| 1 | miss | 1 |
| 2 | miss | 1 2 |
| 3 | miss | 1 2 3 |
| 4 | miss | 1 2 3 4 |
| 1 | hit | 2 3 4 1 |
| 2 | hit | 3 4 1 2 |
| 5 | miss (evict 3) | 4 1 2 5 |
| 1 | hit | 4 2 5 1 |
| 2 | hit | 4 5 1 2 |
| 3 | miss (evict 4) | 5 1 2 3 |
| 4 | miss (evict 5) | 1 2 3 4 |
| 5 | miss (evict 1) | 2 3 4 5 |
LRU hits = 4. (4)
(b) FIFO (evict oldest-inserted):
| ref | hit? | queue (old→new) |
|---|---|---|
| 1 | miss | 1 |
| 2 | miss | 1 2 |
| 3 | miss | 1 2 3 |
| 4 | miss | 1 2 3 4 |
| 1 | hit | 1 2 3 4 |
| 2 | hit | 1 2 3 4 |
| 5 | miss (evict 1) | 2 3 4 5 |
| 1 | miss (evict 2) | 3 4 5 1 |
| 2 | miss (evict 3) | 4 5 1 2 |
| 3 | miss (evict 4) | 5 1 2 3 |
| 4 | miss (evict 5) | 1 2 3 4 |
| 5 | miss (evict 1) | 2 3 4 5 |
FIFO hits = 2. (4)
(c) Bélády's anomaly: under FIFO (and some non-stack policies) increasing the number of cache/frame slots can increase the number of misses rather than reduce it — miss count is not monotonic in cache size. (This classic stream is the standard example.) (2)
Question 4
Total ops = 1000; reads = 700, writes = 300. Read misses . Write misses . (1 — setup)
(a) Write-through + no-write-allocate:
- Read misses fetch a line: B. (1.5)
- No-write-allocate: write misses do not fetch; writes go straight through.
- Every write (hit or miss) writes 4 B through to memory: B. (1.5)
- Read hits/misses cause no writeback (clean). Total bytes. (1)
(b) Write-back + write-allocate:
- Every miss (read or write) fetches a line: total misses . Refill traffic B. (2)
- Dirty evictions of misses writebacks. Writeback traffic B. (2) Total bytes. (1)
(c) Any one: multiprocessor/coherence scenarios where memory (or other caches) must always see up-to-date data; simpler coherence; DMA/I/O consistency; write-through avoids the dirty-line tracking and coherence complexity — preferable when data must stay consistent with memory or when write bandwidth is not the bottleneck. (2)
Question 5
(a) Offset for 4 KiB page bits. (1) Remaining VA bits for indexing bits across 4 levels. (1) Per level bits. (1) (Check: each table has entries B B one page — consistent.) (1)
(b)
- TLB hit (98%): 1 (translation) + 1 (data) = 2 cycles. (1)
- TLB miss (2%): 4 levels 3 = 12 cycles walk + 1 (data) = 13 cycles. (Include TLB probe 1 cycle before miss detected → 14; here take walk+data = 13 as the miss path cost; if TLB probe added, 14. Accept either with consistent statement.) (2) Using 13: Average cycles. (2)
(If the 1-cycle initial TLB probe is added to the miss path (14): . Full marks for either consistent method.)
(c) TLB reach = (number of TLB entries) × (page size). Larger pages mean each TLB entry maps more memory, so a fixed-size TLB covers more of the working set ⇒ fewer TLB misses. Cost: internal fragmentation (wasted space within partially-used large pages) — also coarser protection/paging granularity and larger I/O on page faults. (3)
[
{"claim":"Q1 tag width = 27 bits","code":"offset=6; index=7; tag=40-index-offset; result=(tag==27)"},
{"claim":"Q1 hit rate = 63/64","code":"misses=2**14; acc=2**20; hr=1-Rational(misses,acc); result=(hr==Rational(63,64))"},
{"claim":"Q2 baseline AMAT = 4.36 cycles","code":"inner=40+Rational(4,10)*200; mid=12+Rational(25,100)*inner; amat=1+Rational(8,100)*mid; result=(amat==Rational(436,100))"},
{"claim":"Q2 redesign AMAT = 3.72 and improvement 0.64","code":"mid=16+Rational(15,100)*120; amat=1+Rational(8,100)*mid; result=(amat==Rational(372,100) and Rational(436,100)-amat==Rational(64,100))"},
{"claim":"Q4a write-through no-allocate = 5680 bytes","code":"rm=700*Rational(10,100); total=rm*64+300*4; result=(total==5680)"},
{"claim":"Q4b write-back write-allocate = 10816 bytes","code":"misses=70+60; refill=misses*64; wb=Rational(30,100)*misses*64; result=(refill+wb==10816)"},
{"claim":"Q5b average latency = 2.22 cycles (13-cycle miss path)","code":"avg=Rational(98,100)*2+Rational(2,100)*13; result=(avg==Rational(222,100))"}
]