Course: Computer Architectures

Professor: E. Sanchez, Politecnico di Torino, ASE 2026/27. Source: Cache memories, 67 PDF pages, local file 08 - caches.pdf. Number 08 follows the filename, not a stated lecture date. The source remains local; redistribution permission is uncertain.

How to study this lecture

The lecture answers one question in stages: how can a small memory give the processor fast access to a much larger memory? Start with why a copied block is likely to be useful, then follow how the cache finds, replaces and updates it. The detailed examples and self-check answers are in Cache Memory Fundamentals.

  1. Locality and hits: repeated or nearby accesses can use a block fetched earlier. Trace the array example before trying formulas.
  2. Placement: distinguish a block (data), line (slot), set (group of slots), and way (position within a set). A set can be full while another is empty.
  3. Lookup: the index selects a set, the tag identifies the block through comparison, and the offset selects a byte. The address does not prescribe the way.
  4. Replacement and writes: if a set is full, select a victim. If a write-back victim is dirty, save its changes before reusing the line.
  5. Coherence and levels: other cores can have old copies, even with write-through. Multiple cache levels trade capacity for speed.
  6. Calculations: count lines and sets first, then derive offset, index and tag bits. Keep data capacity separate from metadata.

The slide exercises, worked in order

Direct mapping (pages 53–54)

The source gives 64 KiB of data, 4-byte blocks and 32-bit byte addresses. There are 65,536 / 4 = 16,384 = 2^14 lines. Direct mapping has one line per set, so the index has 14 bits. Four bytes per block require 2 offset bits. The tag has 32 − 14 − 2 = 16 bits.

Each line stores 32 data bits plus 16 tag bits: 2^14 × 48 bits = 96 KiB. This source figure excludes valid and other control bits. The index is implicit in the line’s position rather than stored as part of every tag.

Two-way cache (pages 55–67)

The source gives 4 KiB of data, 32-byte blocks, two ways and 32-bit byte addresses. 4,096 / 32 = 128 lines; 128 / 2 = 64 sets. The byte offset is 5 bits and set index 6 bits, leaving 32 − 5 − 6 = 21 tag bits. The 128 tags occupy 128 × 21 / 8 = 336 bytes. That is in addition to 4 KiB of data and excludes valid and replacement bits. Compare the two-way and four-way examples.

Recall route

Before consulting the detailed note, sketch: address → set → compare tags → choose byte. Then explain what happens on a miss, how a full set chooses a victim, and when a modified victim must be saved. Finally explain why a second core’s cached copy may still be stale. These connections make the formulas meaningful rather than isolated rules.

PDF page map

PagesTopic
2–6Cache hierarchy, locality and access time
7–12Lines, tags, hit/miss and early restart
13–18Cache position; instruction/data caches and Harvard vs von Neumann
19–30Capacity, blocks, direct, set-associative and fully associative mapping
31–43Replacement policies and tree pseudo-LRU
44–48Write-back, write-through, coherence and valid bits
49–52L1/L2/L3 and historical processor examples
53–54Direct-mapped sizing exercise
55–67Two-way sizing exercise

Source examples and qualifications

Page 6 models average time as h*C + (1-h)*M, where M is the total miss access time. If M instead denotes an additional miss penalty, use C + (1-h)*M. The printed numerical example has a unit/arithmetic inconsistency; do not use its result without recalculation.

Pages 12–18 introduce early restart, split instruction/data caches and Harvard versus von Neumann organization. Separate L1 instruction and data caches can be part of a modified Harvard design with unified lower memory. Instruction data can change in systems that support code modification, requiring appropriate synchronization.

Page 31 lists LRU, FIFO, LFU and random. LFU removes the least frequently used item; its claimed theoretical superiority depends on workload and assumptions. Pages 33–43 present tree pLRU. The source’s processor examples on pages 51–52 are historical, not current product specifications.

Page 54 counts data and tags but excludes valid and other control bits. Page 67 similarly counts 336 bytes of tags in addition to 4 KiB of data; valid and replacement bits add overhead. The addressing examples assume byte addresses and standard power-of-two indexing.

Revision questions

  • Why does spatial locality make fetching a block useful, and when might fetched bytes be wasted?
  • Explain how tag, set index and offset work together. Why is a way number not an address field?
  • Trace A, B, A, C in a two-way set under LRU and FIFO.
  • When must a write-back cache write an evicted block to memory? Why is coherence needed even with write-through?
  • Calculate line count and address fields for a 4 KiB, 32-byte, 4-way cache with 32-bit addresses.