Lecture 02 · Main Memory & Caching

Keywords → one line each. Page numbers refer to ../lectures/Lecture_02_MemoryAndCache.pdf. Slides 13–15, 30–32 are mostly figures.

Memory technology

KeywordOne linep.
von Neumann memoryHolds both instructions and data. Registers (≤1 cycle) → main memory (10s of cycles, random access) → external (100s+ cycles, block access)4
ROM vs RAMNon-volatile (ROM, PROM, EPROM, Flash) vs volatile (SRAM, DRAM)5–6
static vs dynamicSRAM keeps data while powered; DRAM leaks and needs refresh6
access typesRandom (RAM), sequential (tape), associative (by tag, e.g. TCAM), stack7
UMA vs NUMAUniform access time vs access time depending on where the memory sits relative to the CPU7
cell / locationCell = 1 bit (flip-flop in SRAM, capacitor in DRAM); location = addressable group of 8/16/32 bits8
matrix organisationA location sits at the intersection of a row and a column; SRAM uses a decoder, cells and a data amplifier10–11
bank · chip · rank · DIMMRows×columns · several banks (capacity) · chips read at the same address (bandwidth) · module; ≤16 DIMMs per CPU; DDR4 12–25 GB/s per DIMM12
HBM3D-stacked, on-package, wide bus, >512-bit access unit, used on GPUs16

Virtual memory

KeywordOne linep.
virtual address spacePrivate and contiguous per process; can map to physical memory or to devices19
MMU + OSTranslate every access, one page at a time; the page table lives in memory19
lazy allocationAllocating touches no physical memory; the mapping is made on first access20
TLBAssociative cache of page-table entries, 1000s of entries, multi-level; a miss costs extra memory reads20–21
huge pagesMB or 1 GB instead of 4 KB → fewer TLB entries needed, contiguous memory for DMA; risk of fragmentation21

Caches

KeywordOne linep.
temporal / spatial localityReused soon / neighbours used soon. This is why the hierarchy exists23–24
inclusivityLower levels usually also hold the data of the higher levels25
replacement policyChooses which line to evict; “a crucial optimization”25
write-through / write-backWrite immediately / write when evicted (dirty line)25, 29
caching everywhereWeb or DBMS results → DDR in front of flash → OS page buffer → CPU caches. Common challenges: invalidation, sizing, constant-cost lookup, coherence26
prefetchingNext-line, stream, stride; kept simple; fails on pointer chasing; branch prediction plays this role for instructions27
storage prefetchingTransparent prefetching from storage costs too much when it guesses wrong; prefetch from the app instead (async, pipelining)28
cache line64 B; always loaded and evicted whole29
conflicts / cache coloringMany addresses map to the same slot; choose a data layout that avoids collisions30
multi-level pathReads fill L1; evicted lines move down to larger levels; dirty lines leaving the LLC go to DRAM; non-allocating loads skip the cache31
MESI / snoopingModified/Exclusive/Shared/Invalid; intentions broadcast on the interconnect (MOESI, MESIF in practice)33

Best practices p.34

Exam-style questions from the deck p.36

  1. T/F: transistors added to a CPU but not used directly inside a core are not very useful.
  2. T/F: in directory-based coherence, a write to an Exclusive line incurs no coherence messages.
  3. Example of an application or data structure that suffers from TLB misses.
  4. Example of one that benefits from prefetching in main memory.
  5. What issue(s) do huge pages solve?