---
title: DRAM
heading: Banks, rows and the row buffer, timing parameters, bandwidth, refresh and memory controllers
eyebrow: S4 · Lesson 26 · DRAM
xp: 50
---

::: hook
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.
:::

::: play
- Average DRAM access latency against the row-buffer hit rate h. A hit needs only the column access, $t_{CL}$; a miss to a bank with another row open needs a precharge, an activate and the column access, $t_{RP} + t_{RCD} + t_{CL}$.
- 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.
:::
:::

```sim plot
view: graph
x: h = 0..1
y: t = 0..60 ns
slider: C = 10..20 = 13.75 ns
slider: R = 10..20 = 13.75 ns
slider: P = 10..20 = 13.75 ns
slider: M = 1600..8000 = 3200 MT/s
plot: h*C + (1 - h)*(P + R + C) | label: average latency, ns
readout: peak bandwidth per 64-bit channel, GB/s = M*8/1000
```

::: predict
## A DDR4-3200 channel is 64 bits wide. What's its peak bandwidth?

- [ ] 3.2 GB/s
- [ ] 6.4 GB/s
- [x] 25.6 GB/s
- [ ] 204.8 GB/s

::: reveal
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.
:::
:::

::: nameit
## 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: $t_{RCD}$ before a column command can follow.
- **Read/write** (CAS) moves data from the open row: $t_{CL}$ to the first data, then a **burst** of BL transfers (8 in DDR4, 16 in DDR5).
- **Precharge** (PRE) closes the row: $t_{RP}$ before another activate. A row must stay open at least $t_{RAS}$.

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:** $t_{CL}$.
- **Row empty** (bank precharged): $t_{RCD} + t_{CL}$.
- **Row conflict** (another row open): $t_{RP} + t_{RCD} + t_{CL}$.

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 $t_{REFI}$ (7.8 µs) that blocks the rank for $t_{RFC}$ (hundreds of ns), losing a fraction $t_{RFC}/t_{REFI}$ of the time.
:::

::: 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)?

::: solution
1. **One timing in nanoseconds.** The clock is 1600 MHz, so
   $$22\ \text{cycles} = 13.75\ \text{ns}$$
2. **Hit and conflict.** A row hit takes 13.75 ns, and a conflict takes
   $$3 \times 13.75 = 41.25\ \text{ns}$$
3. **Moving the line.** The burst of 8 transfers at 3200 MT/s takes 2.5 ns.
4. **Average at h = 0.6.**
   $$\begin{aligned} t &= 0.6 \times 13.75 + 0.4 \times 41.25 \\ &= 24.75\ \text{ns} \end{aligned}$$
   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).
:::
:::

::: example
## With $t_{REFI}$ = 7.8 µs and $t_{RFC}$ = 350 ns, what fraction of time does refresh take, and how many refresh commands cover the 64 ms retention period?

::: solution
1. **Refresh overhead.**
   $$350/7800 = 4.5\%$$
   of the rank's time.
2. **Refresh commands.**
   $$64\ \text{ms}/7.8\ \text{µs} = 8205$$
   so each refresh covers about 1/8192 of the rows.
3. **Density.** Larger chips need longer $t_{RFC}$, 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.
:::
:::

::: 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?

::: solution
1. **Chip capacity.**
   $$\begin{aligned} C &= 16 \times 65\,536 \times 1024 \times 8 \\ &= 8.6 \times 10^9\ \text{bits} \end{aligned}$$
   which is 8 Gb.
2. **The rank.** Eight chips side by side fill a 64-bit channel, each supplying 8 bits of every transfer:
   $$8 \times 8\ \text{Gb} = 64\ \text{Gb}$$
   an 8 GB rank.

**Answer:** each chip holds 8 Gb, and the rank of eight holds 64 Gb, 8 GB.
:::
:::

::: check
given: M = 2400 | 3200 | 4800 | 6400; c = 1 | 2 | 8
answer: M*8*c/1000
unit: GB/s
tolerance: 0.5%

## A system has {c} channels of 64-bit DRAM at {M} MT/s. What's its peak bandwidth?

::: right
Right. MT/s × 8 bytes × channels = {answer} GB/s.
:::

::: misses
- [M*64*c/1000] Convert the 64 bits to 8 bytes.
- [M/2*8*c/1000] MT/s already counts both edges of the clock.
- [any] Not yet. Transfers per second × bytes per transfer.
:::
:::

::: check
given: h = 0.3 | 0.55 | 0.8; C = 12 | 15; R = 13 | 16; P = 14 | 17
answer: h*C + (1 - h)*(P + R + C)
unit: ns
tolerance: 0.5%

## A row hits {h} of the time; every miss is a conflict. With $t_{CL}$ = {C}, $t_{RCD}$ = {R} and $t_{RP}$ = {P} ns, what's the average latency to the first data?

::: right
Right. $ht_{CL} + (1 - h)(t_{RP} + t_{RCD} + t_{CL})$ = {answer} ns.
:::

::: misses
- [h*C + (1 - h)*(R + C)] A conflict also needs a precharge.
- [any] Not yet. Weighted average of hit and conflict times.
:::
:::

::: check
given: n = 16 | 22 | 40; f = 1200 | 1600 | 2400
answer: n/f*1000
unit: ns
tolerance: 0.5%

## A DRAM timing is {n} cycles at a {f} MHz clock. How many nanoseconds is that?

::: right
Right. {answer} ns.
:::

::: misses
- [n/(2*f)*1000] The timing counts clock cycles, not transfers.
- [any] Not yet. Cycles ÷ clock frequency.
:::
:::

::: check
given: F = 260 | 350 | 550; I = 3.9 | 7.8
answer: 100*F/(I*1000)
unit: %
tolerance: 0.5%

## Each refresh blocks a rank for {F} ns, once every {I} µs. What fraction of time is lost?

::: right
Right. $t_{RFC}/t_{REFI}$ = {answer}%.
:::

::: misses
- [100*F/I] Convert microseconds to nanoseconds.
- [any] Not yet. Blocked time over the interval.
:::
:::

::: check
given: b = 8 | 16 | 32; r = 32768 | 65536; c = 1024; w = 4 | 8 | 16
answer: b*r*c*w/2^30
unit: Gbit
tolerance: 0.5%

## A DRAM chip has {b} banks of {r} rows, each row with {c} columns of {w} bits. What's its capacity?

::: right
Right. {answer} Gbit.
:::

::: misses
- [b*r*c*w/1e9] A gigabit here is $2^{30}$ bits.
- [any] Not yet. Banks × rows × columns × width.
:::
:::

::: check
given: B = 8 | 16; M = 3200 | 4800 | 6400
answer: B/(M*1e6)*1e9
unit: ns
tolerance: 0.5%

## A burst of {B} transfers runs at {M} MT/s. How long does it take?

::: right
Right. {answer} ns, moving {B} × 8 bytes on a 64-bit bus.
:::

::: misses
- [B/(M*1e6)*1e9*2] MT/s already counts transfers.
- [any] Not yet. Transfers ÷ transfer rate.
:::
:::

::: check
kind: parts
given: R = 2400 | 3200 | 4800; c = 16 | 22 | 40; B = 8 | 16

## A DRAM runs at {R} MT/s with CL = tRCD = tRP = {c} clock cycles and bursts of {B} transfers on a 64-bit bus.

::: part
answer: c/(R/2)*1000
unit: ns
tolerance: 0.5%

### What is a row hit's latency?

::: misses
- [c/R*1000] The clock runs at half the transfer rate.
- [any] CL ÷ clock frequency.
:::
:::

::: part
answer: 3*c/(R/2)*1000
unit: ns
tolerance: 0.5%

### And a row conflict's?

::: misses
- [any] $t_{RP} + t_{RCD} + t_{CL}$.
:::
:::

::: part
answer: B/R*1000
unit: ns
tolerance: 0.5%

### How long does one burst take on the bus, and so how often can the bus carry {B} × 8 bytes?

::: misses
- [any] Transfers ÷ transfer rate.
:::
:::
:::

::: check
kind: derivation
vars: h = 0..1, a = 10..20, b = 10..20, c = 10..20, R = 100..500, F = 3000..10000

## 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
answer: h*a + (1 - h)*(a + b + c)

### What is the average latency?
:::

::: step
answer: R/F

### What fraction of time does refresh take?
:::

::: right
Right. Row hits and bank parallelism, not raw timings, set most of a memory system's effective speed.
:::
:::

::: explain
## Why do memory controllers reorder requests instead of serving them in the order they arrive?

::: model
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

::: check
given: M = 2933 | 5600; c = 2 | 4
answer: M*8*c/1000
unit: GB/s
tolerance: 0.5%

## Peak bandwidth: {c} channels at {M} MT/s?

::: misses
- [any] MT/s × 8 B × channels.
:::
:::

::: check
given: h = 0.4 | 0.7; C = 13 | 16; R = 14 | 16; P = 14 | 18
answer: h*C + (1 - h)*(P + R + C)
unit: ns
tolerance: 0.5%

## Average latency: hit rate {h}, timings {C}, {R}, {P} ns?

::: misses
- [any] $ht_{CL} + (1 - h)(t_{RP} + t_{RCD} + t_{CL})$.
:::
:::

::: check
given: F = 295 | 410; I = 3.9 | 7.8
answer: 100*F/(I*1000)
unit: %
tolerance: 0.5%

## Refresh overhead: {F} ns every {I} µs?

::: misses
- [any] $t_{RFC}/t_{REFI}$.
:::
:::
:::
