S4 · Lesson 26 · DRAM
Banks, rows and the row buffer, timing parameters, bandwidth, refresh and memory controllers
Main memory is DRAM: each bit a capacitor and a transistor, packed so densely that a single chip holds billions of them. The density comes at a cost. Reading a row of cells drains them, so the whole row is copied into a row buffer first, and that copy takes time; the cells leak, so every row must be refreshed every few tens of milliseconds; and the interface runs far slower than the processor. A memory access that finds its row already open in the buffer costs about a third of one that doesn't, so memory controllers reorder requests to hit open rows, and good data layouts matter as much as raw bandwidth.
- Average DRAM access latency against the row-buffer hit rate h. A hit needs only the column access, ; a miss to a bank with another row open needs a precharge, an activate and the column access, .
- With DDR4-3200 timings of 22-22-22 cycles at 1600 MHz, each step is 13.75 ns: a hit costs 13.75 ns and a miss 41.25 ns (plus the burst itself).
- The readout gives the channel's peak bandwidth: transfers per second times 8 bytes.
Predict
A DDR4-3200 channel is 64 bits wide. What's its peak bandwidth?
25.6 GB/s: 3200 million transfers a second (two per clock of the 1600 MHz bus) times 8 bytes. That's peak: real streams lose some to row misses, refresh, bus turnarounds between reads and writes, and bank conflicts. A desktop with two channels has 51.2 GB/s; a server with eight DDR5-4800 channels about 300 GB/s; a GPU with HBM, several TB/s.
Name it
Organization
A DRAM chip has several banks (16 in DDR4, 32 in DDR5), each an array of rows. A rank of chips works in lockstep to fill a 64-bit channel; capacity = banks × rows × columns × bits per column.
- Activate (ACT) copies a row into the bank's row buffer: before a column command can follow.
- Read/write (CAS) moves data from the open row: to the first data, then a burst of BL transfers (8 in DDR4, 16 in DDR5).
- Precharge (PRE) closes the row: before another activate. A row must stay open at least .
Timings are quoted in clock cycles, CL-tRCD-tRP (such as 22-22-22); in nanoseconds, cycles ÷ clock frequency, where the clock is half the transfer rate.
Hits, misses and conflicts
- Row hit: .
- Row empty (bank precharged): .
- Row conflict (another row open): .
An open-page policy leaves rows open, betting on locality; closed-page precharges at once, betting against it. Controllers schedule ready row hits first (FR-FCFS) and spread consecutive lines across banks and channels so their activations overlap.
Bandwidth and refresh
- Peak bandwidth = transfers per second × bus width × channels. One burst of BL transfers moves BL × 8 bytes, a 64-byte line in DDR4.
- Every row must be refreshed within 64 ms. The controller issues a refresh command every (7.8 µs) that blocks the rank for (hundreds of ns), losing a fraction of the time.
Worked example
DDR4-3200 with 22-22-22 timings: what are the hit and conflict latencies, the time to move a 64-byte line, and the average latency at a 60% hit rate (all misses conflicts)?
Show the solution
- One timing in nanoseconds. The clock is 1600 MHz, so
- Hit and conflict. A row hit takes 13.75 ns, and a conflict takes
- Moving the line. The burst of 8 transfers at 3200 MT/s takes 2.5 ns.
- Average at h = 0.6. before the burst, against 35.75 ns at h = 0.2.
Answer 13.75 ns for a hit and 41.25 ns for a conflict, 2.5 ns to move the line, and 24.75 ns on average at a 60% hit rate (before the burst).
Worked example
With = 7.8 µs and = 350 ns, what fraction of time does refresh take, and how many refresh commands cover the 64 ms retention period?
Show the solution
- Refresh overhead. of the rank's time.
- Refresh commands. so each refresh covers about 1/8192 of the rows.
- Density. Larger chips need longer , which is why refresh overhead grows with density and why DDR5 can refresh banks individually.
Answer refresh takes 4.5% of the time, and about 8205 commands cover the 64 ms retention period.
Worked example
A DDR4 chip has 16 banks of 65 536 rows, each with 1024 columns of 8 bits. What is its capacity, and what does a rank of eight such chips hold?
Show the solution
- Chip capacity. which is 8 Gb.
- The rank. Eight chips side by side fill a 64-bit channel, each supplying 8 bits of every transfer: an 8 GB rank.
Answer each chip holds 8 Gb, and the rank of eight holds 64 Gb, 8 GB.
Check
A system has 1 channels of 64-bit DRAM at 3200 MT/s. What's its peak bandwidth?
Check
A row hits 0.55 of the time; every miss is a conflict. With = 12, = 16 and = 17 ns, what's the average latency to the first data?
Write units the way you normally would: 1.5 ns, 1500 ps and 0.0015 µs are the same answer.
Check
A DRAM timing is 22 cycles at a 1200 MHz clock. How many nanoseconds is that?
Write units the way you normally would: 1.5 ns, 1500 ps and 0.0015 µs are the same answer.
Check
Each refresh blocks a rank for 350 ns, once every 3.9 µs. What fraction of time is lost?
Check
A DRAM chip has 16 banks of 32768 rows, each row with 1024 columns of 16 bits. What's its capacity?
Write units the way you normally would: 1.5 Gbit, 1500 Mbit and 0.0015 Tbit are the same answer.
Check
A burst of 8 transfers runs at 3200 MT/s. How long does it take?
Write units the way you normally would: 1.5 ns, 1500 ps and 0.0015 µs are the same answer.
Check
A DRAM runs at 3200 MT/s with CL = tRCD = tRP = 16 clock cycles and bursts of 16 transfers on a 64-bit bus.
(a)
What is a row hit's latency?
Write units the way you normally would: 1.5 ns, 1500 ps and 0.0015 µs are the same answer.
(b)
And a row conflict's?
(c)
How long does one burst take on the bus, and so how often can the bus carry 16 × 8 bytes?
Check
A DRAM controller sees a row-hit rate h; misses are conflicts. tCL = a, tRCD = b, tRP = c (in ns). Refresh blocks the rank R ns every F ns.
Step 1
What is the average latency?
Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.
Step 2
What fraction of time does refresh take?
Explain why
Why do memory controllers reorder requests instead of serving them in the order they arrive?
A DRAM access is much cheaper when its row is already open in the bank's row buffer: only the column access is needed, about a third of the time of a precharge, activate and column access. Requests from a processor arrive interleaved from many sources, so serving them strictly in order would keep closing and reopening rows, paying the full cost again and again. A controller that looks over its queue and first serves the requests that hit open rows, while spreading others across banks so their activations overlap, gets far more of the channel's peak bandwidth and lowers the average latency. It has to bound how long any one request can be passed over, so none starves.
Practice
Keep practicing
10 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.