Lecture 5: Memory 1

Section 1: Physical Memory Technologies — From Core to SRAM and 1-T DRAM

In our pipelined RISC-V processor, both Instruction Fetch and Memory stages assumed that Instruction Cache and Data Cache return words effortlessly in a single short clock cycle. In reality, building memory that is simultaneously large, fast, and cheap is one of the hardest physical problems in computer engineering. Every memory technology forces a tradeoff among density, speed, volatility, and cost.

In the 1950s and 1960s, after early experimental storage like Williams CRT tubes and mercury delay lines proved fragile or non-random-access, Magnetic Core Memory (invented by Jay Forrester at MIT for the Whirlwind project) became the first large-scale reliable main memory. Each bit was stored as the magnetic polarity of a tiny ferrite ring threaded onto a 2D grid of X and Y copper wires. Coincident half-current pulses on an X and Y wire flipped the core at their intersection, while a sense wire detected the induced voltage pulse—meaning reads were destructive (reading a bit erased it, so the hardware had to immediately write it back). Core memory was non-volatile and rugged, but threading cores onto wires limited access times to roughly 1\text{ }\mu\text{s} (1,000\text{ ns}).

In the early 1970s, semiconductor memory built on silicon wafers rapidly replaced magnetic cores in two distinct forms:

Because a 1-T DRAM cell uses 1 transistor and a vertical capacitor whereas a 6-T SRAM cell uses 6 planar transistors, DRAM is roughly 10\times denser than SRAM in the same process generation (for instance, in a 0.5\text{ }\mu\text{m} process, a standard DRAM cell measures 3.2\text{ }\mu\text{m}^2 versus 43\text{ }\mu\text{m}^2 for a standard 6-T SRAM cell).

DRAM Array Architecture

Whether inside an SRAM or DRAM chip, bits are organized hierarchically from system board down to silicon cell: \text{DIMM} \longrightarrow \text{Rank} \longrightarrow \text{Chip} \longrightarrow \text{Bank} \longrightarrow \text{Array} \longrightarrow \text{Cell} The Bank is the “atomic unit” that gets independently activated on a memory access (modern DRAM chips contain roughly 4–8 logical banks, each physically subdivided into smaller arrays to keep wire capacitances manageable).

Inside a single 2D memory array storing 2^{N+M} bits:

Because DRAM relies on tiny stored charges and destructive reads, we cannot simply store all memory in fast SRAM—nor can we run a modern CPU directly out of dense DRAM without hitting a massive performance wall.

[Editor Note: removed duplicate slides of 18th–19th-century punched cards/Babbage wheels/Williams tubes covered in earlier lectures, Core Memory space-shuttle/production trivia, Gate-Array SRAM table rows, and the Chip War book slide.]

✎ Check Your Understanding

  1. Comparison check: Give two physical reasons why a 1-T DRAM cell is slower and requires more control overhead than a 6-T SRAM cell, even though both are built from silicon CMOS. Answer: DRAM reads are destructive (charge sharing drains the storage capacitor, requiring sense amplifiers to restore it), and capacitor charge leaks over time, forcing periodic refresh cycles every few milliseconds (plus DRAM multiplexes row and column address pins).

  2. Array calculation: A single DRAM array has N = 10 row address bits and M = 10 column address bits, outputting D = 1 bit at a time. How many memory cells sit on a single horizontal word line, and how many total bits does the array store? Answer: Each word line enables 2^{10} = 1,024 cells (columns), and the array stores 2^{10+10} = 2^{20} = 1\text{ Mebibit} (1,048,576 bits).


Section 2: The CPU–Memory Bottleneck, DRAM Operation, and Packaging for Bandwidth

High-speed processors are almost always bottlenecked by memory latency, bandwidth, and occupancy:

Why can’t we just make one giant memory that is also fast? Physics dictates that physical size hurts latency: in a big memory compared to a small memory, electrical signals must travel across longer RC wires and fan out to far more bit/word-line locations.

How DRAM Accesses Work (RAS, CAS, Precharge) and DDR

Accessing a single DRAM bank proceeds in three sequential steps, each taking roughly 15\text{–}20\text{ ns} in modern DRAMs:

  1. Row access (RAS / ACT): Decode the row address and activate one word line (often several kilobits wide). Cell capacitors share charge with bit lines; sense amplifiers detect the tiny voltage shift, latch the entire row of bits, and drive the bit lines full-rail to recharge (restore) the storage cells.
  2. Column access (CAS / READ or WRITE): Decode the column address to select 4, 8, 16, or 32 bits from the sense-amplifier latches and drive them to the chip pins (or overwrite the latches on a write). Crucially, once a row is open in the sense amplifiers, the controller can issue multiple column accesses on that same row without another row access—called burst mode.
  3. Precharge (PRE): Equalize and recharge the bit lines back to the mid-rail reference voltage before the next row can be activated.

Notice how Double-Data Rate (DDR) DRAM doubles pin data rate without speeding up internal array physics: while commands clock on one edge, DQ data pins transfer on both the rising and falling edges of the clock (e.g., a 200\text{ MHz} clock yields a 400\text{ Mb/s} per-pin data rate).

Packaging Memory for Higher Bandwidth

Since single DRAM chips only have narrow data buses (4, 8, 16, or 32 bits), architects scale memory bandwidth through packaging:

For scale, the HBM interface on an NVIDIA Blackwell B300 GPU is 7,680 bits wide, against 6 \times 1{,}024 = 6{,}144 bits for the SX-Aurora’s six HBM2 stacks.

Yet even 1.2\text{ TB/s} of bandwidth does not shrink the \sim 50\text{–}100\text{ ns} raw latency of opening a DRAM row. To bridge that latency gap, we must exploit how real programs actually access memory.

[Editor Note: removed NEC SX-Aurora marketing package dimensions/stiffener details while keeping the HBM2 2.5D interposer bandwidth math.]

✎ Check Your Understanding

  1. Quick computation: In a RISC-V program where 30\% of all instructions are loads or stores (m = 0.30), how many memory references per cycle must the memory system sustain to achieve \text{CPI} = 1? Answer: 1 + m = 1 + 0.30 = 1.3 memory references per cycle (1 instruction fetch plus 0.3 data accesses on average).

  2. Mechanism check: Why can a DRAM controller serve a burst of sequential column reads faster than random reads scattered across different rows? Answer: Once a row access (RAS) latches an entire multi-kilobit row into the sense amplifiers, subsequent column accesses (CAS) to that same open row skip both Precharge and RAS.


Section 3: Memory Reference Patterns, Locality, and Cache Organization

If programs accessed memory uniformly at random, hiding a 100-ns DRAM latency would be hopeless. Fortunately, plotting real program execution traces (Memory Address on the vertical axis vs. Time on the horizontal axis, one dot per access—such as Hatfield and Gerald’s classic 1971 study) reveals striking structure:

These patterns express two fundamental, predictable properties of programs:

The Memory Hierarchy and Caches

To exploit both locality properties, we arrange memory as a small/fast \rightarrow big/slow pyramid: \text{CPU} \Longleftrightarrow \text{Small, Fast Memory (Register File, SRAM)} \Longleftrightarrow \text{Big, Slow Memory (DRAM)} Across this hierarchy:

On every memory access: if \text{data} \in \text{fast memory}, the CPU gets a low-latency SRAM access; if \text{data} \notin \text{fast memory}, it suffers a high-latency DRAM access (and brings the data into the fast memory).

A Cache is a hardware-managed SRAM structure sitting between the CPU and main memory that is completely invisible to software (unlike registers, the programmer does not name cache locations in the ISA):

Anatomy of a Cache and Basic Read Flow

Inside a cache, each Line stores two things: an Address Tag (identifying which main-memory address currently occupies this slot, e.g., 100, 304, 6848, 416) and a Data Block holding multiple contiguous data bytes (e.g., copies of main memory locations 100, 101, …).

On a processor read:

  1. Look at the processor address and search the relevant cache tag(s) for a match.
  2. HIT (found in cache): Return the requested copy of data directly from fast SRAM.
  3. MISS (not in cache): Read the full block of data from lower-level memory (Wait…), return the requested data to the CPU, and install the block into the cache—which raises an immediate design question: where in the cache can an incoming block be placed, and which existing line should it replace?

✎ Check Your Understanding

  1. Locality classification: Accessing elements A[0], A[1], A[2], A[3] sequentially in a loop primarily exhibits which type of locality, and why? Answer: Spatial locality, because accessing A[i] is immediately followed by accessing nearby memory addresses A[i+1].

  2. Concept check: Why are caches considered microarchitectural rather than architectural? Answer: Because caches are invisible to software—the programmer cannot address them directly in the ISA, and changing cache size or layout does not alter program correctness.


Section 4: Cache Lookup, Placement Policies, and the Hash-Table Analogy

When Main Memory holds many blocks (say, blocks 0 through 31) and our Cache holds only 8 blocks, Placement Policy determines where a given memory block—say Block 12—is allowed to live:

  1. Fully Associative: Block 12 can be placed anywhere among all 8 cache blocks (1 set of 8 ways).
  2. Set Associative (e.g., 2-way): The 8 blocks are grouped into 4 sets (Set 0..3) of 2 blocks each. Block 12 maps to Set 12 \bmod 4 = 0, and can sit in either slot inside Set 0.
  3. Direct Mapped: Block 12 maps to only Block 4 (12 \bmod 8 = 4).

Cache = Hardware-Optimized Hash Table

A helpful mental model is to view a cache as a hardware-optimized hash table:

Hardware Walkthrough: Direct-Mapped, 2-Way, and Fully Associative

  1. Direct-Mapped Cache:
    • Address bits split into Tag (t bits) | Index (k bits) | Block Offset (b bits).
    • The k-bit Index selects 1 out of 2^k cache lines.
    • That line outputs its Valid bit V, its stored t-bit Tag, and its Data Block.
    • An = comparator checks Stored Tag == Address Tag, ANDed with V == 1, producing HIT. Meanwhile, the b-bit Block Offset drives a multiplexer across the words/bytes in Data Block to select the exact Data Word or Byte.
    • Preempting a Critical Addressing Misconception: You might think we could put Index in the highest-order bits ([31 : 32-k]) and Tag in the middle! That breaks spatial locality horribly. If Index used the top bits, every contiguous address in a typical program (which shares the same upper address bits!) would hash into the exact same cache line and constantly evict each other, leaving the rest of the cache empty. Placing Index in the lower-order block-address bits just above Block Offset guarantees consecutive memory blocks spread cleanly across different cache lines!

Inline Worked Example — Address Bit Slicing: Suppose we have a 16 KB Direct-Mapped Cache with 64-byte blocks on a 32-bit byte-addressed CPU:

  1. 2-Way Set-Associative Cache:
    • Now 256 total blocks with 2 ways means 256 / 2 = 128 = 2^7 sets (\mathbf{k = 7} Index bits, \mathbf{t = 19} Tag bits, \mathbf{b = 6} Offset bits).
    • The k-bit Index reads both ways in parallel. Two separate = comparators + V AND gates check both stored tags against Address Tag. Each way drives a tri-state buffer onto a shared data mux bus, and an OR gate combines the two way-hit signals into HIT.
  2. Fully Associative Cache:
    • There is zero Index (k = 0); the entire upper 32 - b bits form the Tag. Every line in the cache has its own = comparator checking Address Tag in parallel, feeding a wide OR gate for HIT. (Fast for small tables, too power-hungry and area-expensive for large caches!)

Replacement Policy (and Pseudo-LRU)

In an associative cache, when a set is full and a miss arrives, which way gets evicted?

Block Size Tradeoffs

Recall that a block (line) of size 2^b bytes splits the 32-bit address into block address (32-b bits) | offset (b bits). Making b larger has clear hardware advantages: less tag overhead (fewer tags per KB of data) and exploiting fast DRAM bursts and wide buses. However, for a fixed total cache size, larger blocks mean fewer total lines in the cache, which causes more conflict misses and can waste memory bandwidth if the CPU only reads 4 bytes out of a 256-byte block!

✎ Check Your Understanding

  1. Quick address split: A 32 KB, 4-way set-associative cache has 32-byte blocks on a 32-bit byte-addressed machine. Compute the bit widths of Block Offset (b), Index (k), and Tag (t). Answer: Block size = 32\text{ B} = 2^5 \implies b = 5 bits. Total lines = 32\text{ KB} / 32\text{ B} = 1,024; with 4 ways, sets = 1,024 / 4 = 256 = 2^8 \implies k = 8 bits. Thus t = 32 - 8 - 5 = 19 bits.

  2. Design check: Why must a direct-mapped cache use lower-order block-address bits (immediately above Block Offset) for Index instead of the highest-order bits [31 : 32-k]? Answer: Sequential addresses share the same highest-order bits; using them as Index would force consecutive blocks of an array or loop to collide in the exact same cache line, destroying spatial locality.