The previous chapter built a working memory out of latches, decoders and read gates. It works, but at more than a dozen transistors per bit it would take a whole chip to store a few kilobytes. Real memory chips use much smaller cells, and each kind of cell makes a different trade between speed, density, cost and whether the bits survive a power cut. This chapter goes through the four families (SRAM, DRAM, ROM and flash) and how their cells are organized into chips and modules.
The machine this chapter was written on, an Apple M2 Ultra Mac Studio, has all four: SRAM caches inside the processor, 64 GB of DRAM, a read-only boot ROM, and a 1 TB flash drive.
Width × depth: how a chip is organized
A memory chip is described by its depth (how many words it holds) and its width (how many bits each word has). Capacity is quoted in bits, not bytes: a "16 Gbit" DRAM chip holds 2 GiB.
The same 16 Gbit of cells can be wired out in several ways:
| Organization | Words | Bits per word | Address bits |
|---|---|---|---|
| 4G × 4 | 4 Gi | 4 | 32 |
| 2G × 8 | 2 Gi | 8 | 31 |
| 1G × 16 | 1 Gi | 16 | 30 |
A narrow chip needs more address bits and fewer data pins; a wide one the reverse. The internal grid is the same; the organization only changes how many columns are delivered at once.
A computer needs words far wider than any single chip, so chips are used side by side. A DDR4 memory channel is 64 bits wide: eight ×8 chips, each supplying 8 of the 64 bits, all receiving the same address at the same time. Such a group is a rank. Eight 16 Gbit chips make a 16 GB rank. Server modules add a ninth chip for 8 extra bits of error-correcting code (72 bits in all), which lets the memory controller fix single-bit errors on the fly, the subject of the foundations chapter on error-correcting codes.
To add depth rather than width, a system uses more ranks and turns on only one at a time with chip select, exactly as the address-decoding chapter shows.
SRAM: six transistors that hold their value
A static RAM cell is a latch reduced to its essentials: two inverters connected in a loop, each feeding the other, which is the same feedback idea as the SR latch. Each inverter takes two transistors (the CMOS gates chapter shows why), and two more access transistors connect the loop to a pair of bit lines. That makes 6 transistors per bit (6T).
- To read, the row's word line turns on the access transistors, and the cell pulls one bit line slightly lower than the other. A sense amplifier at the bottom of the column detects the difference and turns it into a clean 0 or 1.
- To write, drivers force the bit lines to the new value, strongly enough to flip the loop.
The loop keeps its value as long as power is on, with no maintenance. That's what static means. SRAM is fast, and it is built on the same chip, with the same process, as the logic around it. That's why every register file and every cache is made of SRAM.
It is also expensive in area. On this Mac, sysctl reports the cache sizes:
$ sysctl hw.perflevel0.l2cachesize hw.perflevel0.cpusperl2 hw.perflevel1.l2cachesize hw.perflevel1.cpusperl2
hw.perflevel0.l2cachesize: 16777216
hw.perflevel0.cpusperl2: 4
hw.perflevel1.l2cachesize: 4194304
hw.perflevel1.cpusperl2: 4
The 16 performance cores share an L2 of 16 MiB per group of 4, and the 8 efficiency cores 4 MiB per group of 4: four 16 MiB caches and two 4 MiB ones, 72 MiB in all. At 6 transistors per bit, the bit cells of the L2 caches alone take 72 × 2²⁰ × 8 × 6 ≈ 3.6 billion transistors, before counting tags, error-correction bits and the decoders and sense amplifiers around them. Apple quotes 134 billion transistors for the whole M2 Ultra, so the storage for just one level of cache is a visible slice of the chip.
DRAM: one transistor, one capacitor
A dynamic RAM cell stores a bit as electric charge in a tiny capacitor, behind a single access transistor: 1T1C. That's six times fewer transistors than SRAM, and the capacitor is built vertically, so DRAM packs many more bits per square millimeter. It is used for main memory.
The price is paid in three ways.
Reading destroys the bit. The cell's charge is minute compared with the long bit line it is connected to. Opening the word line shares the charge with the bit line, which moves its voltage only a little, and a sense amplifier has to amplify that difference. By then, the cell has lost its charge, so the sense amplifier writes the value back. In practice a DRAM reads a whole row at once into its sense amplifiers (the row buffer) and then serves columns from it:
- ACTIVATE: open a row and copy it into the row buffer (the RAS step of the previous chapter).
- READ or WRITE: transfer columns from or to the row buffer (the CAS step). Several can follow each other while the row is open.
- PRECHARGE: write the row back, close it, and prepare the bit lines for the next ACTIVATE.
A DDR4 ×8 chip has 1 KB rows. Reading several columns of an open row is quick; reaching a different row of the same bank costs a precharge and an activate first. That's why chips are divided into banks that can each have a row open: a 16 Gbit DDR4 ×8 chip has 16 banks in 4 bank groups, and a DDR5 chip of the same size has 32. The memory controller spreads consecutive accesses over banks so that one can be activating while another transfers data. Bus timing shows what these commands look like on the wires.
The bank below runs these three commands on a tiny grid. Read a few addresses in order, then a few at random: in order, every read after the first finds its row already in the row buffer (until the 16 bytes of the row run out) and needs only the READ; at random, almost every read lands in another row and pays for a PRECHARGE and an ACTIVATE first, three times as long with these illustrative timings.
Try it: Click Next sequential read a few times: the first read opens row 0, the next ones are row hits and take a third of the time. Then click 8 random reads and watch every read pay for a precharge and an activate. You can also click any cell of the bank to read it.
Illustrative timings, of the order of a DDR4-3200 chip: tRP = tRCD = CL = 22 cycles of its 1600 MHz clock (half of 3200 MT/s), 0.625 ns each, so 13.75 ns per command; real chips differ by speed grade. Slowed down about 48 million times: one cycle lasts 30 ms here. The bank is drawn tiny, 8 rows of 16 one-byte columns (address = row × 16 + column); a real DDR4 ×8 row holds 1 KB, and a chip has 16 banks. Only the delay until the data appears is counted, and the controller leaves a row open until another row is needed.
The charge leaks. A capacitor holds its charge for only a limited time, so every row must be refreshed (read and written back) periodically. For DDR3 and DDR4, the standard requires every row to be refreshed within 64 ms, spread over 8192 refresh commands, one every 7.8 µs. DDR5 halves both, to 32 ms and 3.9 µs. During a refresh, the banks being refreshed can't answer, which costs a few percent of the memory's time. The physics chapter on storing a bit works out how little leakage a cell can afford.
Neighbors disturb each other. Cells are now so close that activating one row over and over, many thousands of times within one refresh window, can leak enough charge from the rows next to it to flip bits. This is Rowhammer, published in 2014, and it turned an electrical problem into a security one: carefully chosen memory accesses from one program can flip bits in memory it isn't allowed to touch. DRAM chips and memory controllers now track heavily activated rows and refresh their neighbors early.
From asynchronous DRAM to DDR5
The interface between the chip and the memory controller has changed far more than the cell.
The early chips were asynchronous: the controller raised RAS and CAS, and the chip answered when it was ready. Synchronous DRAM (SDRAM) put the chip on a clock, so that the controller knows exactly in which cycle the data will come. DDR (double data rate) SDRAM then transferred data on both edges of the clock. Each generation since has kept the cell and made the interface faster:
| Generation | Supply voltage | Data rates (JEDEC) | Module pins |
|---|---|---|---|
| DDR3 | 1.5 V (1.35 V for DDR3L) | 800–2133 MT/s | 240 |
| DDR4 | 1.2 V | 1600–3200 MT/s | 288 |
| DDR5 | 1.1 V | 4800–8800 MT/s | 288 |
Rates are in MT/s, millions of transfers per second. The clock runs at half that rate, since data moves on both edges. Figures such as 533 MHz for DDR2 and 1067 MHz for DDR3 are clock frequencies; the fastest DDR3 transferred 2133 MT/s. DDR3 is now two generations old. Today's desktop and server memory is DDR5. DDR5 also splits each module into two independent 32-bit subchannels, adds on-die ECC inside each chip, and moves the power regulator onto the module.
Peak bandwidth is width × transfer rate. A 64-bit DDR5-6400 module: 8 bytes × 6400 M/s = 51.2 GB/s, three times the 17 GB/s of the fastest DDR3.
Phones, tablets and many laptops use LPDDR (low-power DDR) instead: narrower 16-bit channels, lower voltages, and chips soldered next to the processor rather than on modules. This Mac is one of them:
$ system_profiler SPMemoryDataType
Memory:
Memory: 64 GB
Type: LPDDR5
Manufacturer: Hynix
$ sysctl hw.memsize
hw.memsize: 68719476736
68,719,476,736 bytes is exactly 2³⁶, 64 GiB: memory sizes are powers of two because each address bit doubles the number of words. In the M2 Ultra, the LPDDR5 packages sit on the processor's own package, on a 1024-bit bus. At 6400 MT/s that's 128 bytes × 6400 M/s = 819.2 GB/s, which Apple rounds to 800 GB/s. The CPU cores alone don't get near it: summing a 2 GiB array, one core read 50–54 GB/s, and 16 to 24 threads together 212–228 GB/s (two runs, best of three each). The rest of the bandwidth is there for the GPU and the other units that share the same memory.
ROM: memory fixed at manufacture
A read-only memory holds data that never changes. Its structure is simple enough to show completely. A ROM is an address decoder that drives one word line per word, plus a grid in which each data bit is the OR of the word lines that have a connection in its column. The contents are the pattern of connections:
Try it: Click an input switch in the circuit (or its button above) to toggle it. The gates and the truth table follow.
| A1 | A0 | D3 | D2 | D1 | D0 |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 0 | 1 | 1 |
| 1 | 0 | 0 | 1 | 1 | 0 |
| 1 | 1 | 1 | 0 | 0 | 1 |
A read-only memory is a decoder plus a fixed OR plane. The address lights one word line; each data bit is the OR of the word lines that have a connection in its column. Here word k stores 3 × k: 0000, 0011, 0110, 1001. Changing the contents means changing the connections: a mask in a factory ROM, a fuse in a PROM, a stored charge in EPROM and flash.
Unit-delay model: every gate takes one step to react. With auto off, toggle switches and press step to watch the change travel gate by gate.
This one stores 3 × A for each address A: words 0 to 3 hold 0000, 0011, 0110 and 1001. Set A1·A0 and read D3…D0. The truth table under the circuit is the entire contents of the chip. Note that word 0 is connected to nothing, since it stores only zeros, and that a ROM is just the lookup-table idea of the multiplexer chapter at a larger scale.
The variations differ in how and when the connections are made:
- Mask ROM: the pattern is part of the photographic masks used to make the chip. It's the cheapest per bit in large volumes, and it can never be changed. Every modern processor still has one: the boot ROM that runs first at power-on. When a flaw is found in it, it can't be fixed: the checkm8 exploit, published in 2019, attacked the boot ROM of Apple's A5 to A11 chips, and every iPhone with those chips will always be vulnerable to it.
- PROM (programmable ROM): every connection starts present, and the user blows fuses (or, in other designs, closes antifuses) with high-voltage pulses. It can be programmed once.
- EPROM (erasable PROM): each bit is a transistor with a floating gate, an island of conductor surrounded by insulator. Charge pushed onto it stays for years and changes whether the transistor conducts. Exposing the chip to ultraviolet light through a quartz window erases everything, and a programmer device writes it again.
- EEPROM (electrically erasable PROM): the same floating-gate idea, but erasable electrically, byte by byte, in the circuit. EEPROMs are small and slow to write, so they store configuration: every DDR memory module carries a small one, the SPD chip, from which the computer reads the module's size and timings at boot, and many microcontrollers have a few hundred bytes of it for settings.
Flash: EEPROM erased in blocks
Flash memory keeps the floating gate (or, in most current chips, a charge-trap layer that does the same job) but gives up erasing byte by byte. Cells are erased together in large blocks, which makes each cell smaller and cheaper. How the charge stays trapped is a subject for the physics chapter on storing a bit. Flash comes in two architectures.
NOR flash connects each cell directly to its bit line, in parallel, like a ROM. Any byte can be read at random, fast enough for a processor to execute code straight from it. It's used for firmware: a PC's UEFI firmware, for instance, lives in a small NOR chip on the motherboard, read over the SPI serial bus.
NAND flash connects cells in series strings. That saves most of the contacts and makes it far denser, but a cell can only be reached through its whole string. The rules are strict:
- data is read and programmed by pages, of a few KiB to 16 KiB;
- programming can only move bits in one direction; to rewrite a page, its whole block (hundreds of pages, several MiB in current chips) must first be erased;
- each block survives a limited number of program/erase cycles.
To pack more bits in, NAND stores several bits per cell by distinguishing more charge levels:
| Type | Bits per cell | Charge levels to tell apart |
|---|---|---|
| SLC (single-level cell) | 1 | 2 |
| MLC (multi-level cell) | 2 | 4 |
| TLC (triple-level cell) | 3 | 8 |
| QLC (quad-level cell) | 4 | 16 |
Each extra bit halves the voltage margin between levels, so reading gets slower, errors get more frequent and endurance drops: from around 100,000 program/erase cycles for SLC down to around a thousand for QLC. Most SSDs today use TLC, and cheaper high-capacity ones QLC. Since the 2010s, NAND has also been built in 3D: the cell strings run vertically through stacks of more than 200 layers.
Because pages can't be rewritten in place, an SSD never writes where the operating system thinks it does. A flash translation layer in the drive's controller maps each logical block to a fresh physical page, marks the old page as stale, and reclaims whole blocks in the background (garbage collection). It also spreads the writes over all the blocks so that none wears out early (wear leveling). The chapter on hard disks and SSDs follows that machinery from the drive's side.
This Mac's drive reports:
$ system_profiler SPNVMeDataType
APPLE SSD AP1024Z:
Capacity: 1 TB (1 000 555 581 440 bytes)
TRIM Support: Yes
$ diskutil info disk0
Protocol: Apple Fabric
Device Block Size: 4096 Bytes
The flash controller is part of the M2 Ultra itself, hence the "Apple Fabric" protocol, and the NAND chips sit on the board. The capacity is a decimal 1.0006 TB, not a power of two, unlike the DRAM. Flash chips are made in power-of-two sizes, and drives keep part of the raw flash hidden as spare area for the translation layer and for replacing worn blocks. If this drive holds 1 TiB of raw flash, a common configuration, about 99 GB, or 9%, is spare. TRIM is the command with which the operating system tells the drive which blocks no longer hold files, so that garbage collection doesn't copy dead data.
The families side by side
The main memory families, compared:
| Type | Cell | Volatile | Erase / rewrite | Typical use today |
|---|---|---|---|---|
| SRAM | 6 transistors | yes | any bit, any time | registers, caches |
| DRAM | 1 transistor + 1 capacitor | yes, and needs refresh | any bit, any time | main memory (DDR5, LPDDR5) |
| Mask ROM | a connection or not | no | never | boot ROMs, fixed tables inside chips |
| PROM | fuse or antifuse | no | program once | security keys, trimming values |
| EPROM | floating gate | no | whole chip, ultraviolet | legacy, mostly replaced by flash |
| EEPROM | floating gate | no | byte by byte, electrically | module SPD, microcontroller settings |
| NOR flash | floating gate, in parallel | no | block erase | firmware, code executed in place |
| NAND flash | floating gate or charge trap, in strings | no | page write, block erase | SSDs, phones, memory cards |
Flash cards have grown too: around 2011 they held up to 64 GB, and memory cards of a terabyte and more now exist, and flash has replaced the hard disk in almost every laptop and phone.
Takeaways
- A memory chip is depth × width: the same cells can be delivered as ×4, ×8 or ×16. Chips side by side form a rank as wide as the memory bus; chip select picks one rank among several.
- SRAM stores a bit in a 6-transistor loop: fast, static, and large. Registers and caches are SRAM: 72 MiB of L2 alone on the M2 Ultra.
- DRAM stores a bit as charge in a 1T1C cell: dense, but reads are destructive (rows are activated, read, then precharged), the charge must be refreshed every 64 ms (32 ms in DDR5), and dense rows can disturb each other (Rowhammer).
- The DRAM interface went from asynchronous RAS/CAS to DDR generations; DDR5 and LPDDR5 are current. Bandwidth = width × MT/s: 819.2 GB/s for the M2 Ultra's 1024-bit LPDDR5-6400, of which its CPU cores used up to about 228 GB/s.
- ROM is a decoder plus a fixed OR plane; PROM, EPROM and EEPROM make the connections programmable. Flash is EEPROM erased in blocks: NOR for firmware, NAND (SLC to QLC, in 3D stacks) for storage, managed by a translation layer that hides erase-before-write and wear.