How computers work

Storage: SSDs and hard drives

A storage drive keeps files when the power is off. In an SSD, data is stored as charges in billions of NAND flash memory cells; in a hard drive, as magnetized regions on a spinning platter. Hence their different characters: an SSD responds in tens of microseconds but cannot overwrite data in place; a hard drive spends milliseconds on mechanics but stores tens of terabytes cheaply.

Open in 3D →

M.2 NVMe SSD: controller, DRAM, NAND

An M.2 2280 drive is a 22 × 80 mm board with a PCIe x4 connector. It carries three kinds of chips. The controller is essentially a specialized computer: several ARM cores, hardware encryption and error-correction blocks, a PCIe interface on one side and 4–8 channels to the flash memory on the other. The NAND chips are the memory itself, each package containing a stack of several dies. The DRAM buffer — usually 1 GB per terabyte of capacity — holds the address table.

Where does the “gigabyte per terabyte” ratio come from? The controller keeps a “logical block → physical page” table at 4 KB granularity. A terabyte is ≈ 250 million 4 KB blocks; at 4 bytes per entry that comes to ≈ 1 GB. The table is kept in DRAM so that it does not have to be read from slow flash memory on every access. Cheap DRAM-less drives keep only part of the table in their SRAM and borrow a chunk of the computer’s main memory over PCIe (Host Memory Buffer).

An SSD’s speed is the result of parallelism. A single NAND die reads a page in ≈ 50 µs and writes it in hundreds of microseconds — that is slow. But there are dozens of dies, each with 4–6 independent planes, and the controller works with all of them at once: 8 channels × 4 dies × 4 planes means 128 operations simultaneously. That is how drives reach 7 GB/s on PCIe 4.0 and 12–14 GB/s on PCIe 5.0 in sequential reads, and more than a million operations per second in random ones.

The controller does more than it seems: it corrects errors (they are normal for flash memory, so powerful LDPC codes are used), spreads wear, encrypts data on the fly, monitors temperature and slows down when overheating, and after a sudden power loss rebuilds the address table from a journal.

Reading a file step by step: the path through NVMe

The NVMe protocol was designed specifically for flash memory. Communication is built on queues in the computer’s main memory: a submission queue for commands and a completion queue for responses. There can be up to 65,535 queues, each with up to 65,536 commands. The operating system usually sets up a pair of queues for each processor core, so different programs do not wait for each other on locks.

1. A program asks to read a piece of a file. The file system translates “file and offset” into logical block addresses (LBAs) — the drive itself knows nothing about files. 2. The NVMe driver places a 64-byte command in the queue — “read such-and-such LBAs and put the data at such-and-such memory address” — and writes the new queue tail number to the drive’s doorbell register: a single write over the PCIe bus.

3. The SSD controller fetches the command from main memory on its own via DMA. 4. It looks in the FTL table: this LBA is located, say, in die 5, block 812, page 37. 5. It sends the die a read command; inside the die ≈ 50 µs are spent reading the page from the cells into its register. 6. The page travels over the NAND channel (2–3.6 GB/s per channel) to the controller, which corrects errors with its LDPC decoder and decrypts the data if necessary.

7. The controller writes the data directly into the computer’s main memory via DMA, places an entry in the completion queue and sends an interrupt. 8. The driver sees the response, and the OS wakes up the program. A single random 4 KB read takes 60–100 µs, and most of that is reading the cells inside the die. The processor spends only a few microseconds of all this time.

This shows why queue depth matters. If a program waits for each read before asking for the next one (a queue depth of 1), the SSD delivers only 10–20 thousand operations per second — its dozens of dies sit idle. If there are many requests in the queue, the controller spreads them across the dies in parallel, and the count goes into hundreds of thousands and millions of operations.

The NAND die: cells, pages and blocks

A flash memory cell is a transistor with an extra insulated layer between the gate and the channel: in older ones a floating gate of polysilicon, in modern 3D NAND a layer of silicon nitride that “traps” charge. Electrons driven there by a strong field (≈ 20 V) stay for years without power. The charge shifts the transistor’s turn-on threshold, and during a read this threshold tells what has been written.

One cell stores several bits: it distinguishes not two charge levels but 8 (TLC, 3 bits) or 16 (QLC, 4 bits). The more levels, the cheaper the gigabyte, but the closer together the levels: reads are slower, writes more delicate, wear faster. Most modern SSDs are TLC; cheap high-capacity models are QLC.

The cells are connected in series strings, like the transistors in a NAND gate — hence the name NAND. Modern dies are built upward: 200–300 layers of cells stacked on top of each other, with a string being a vertical channel through all the layers. A terabit die the size of a fingernail is possible precisely because of this “multistory” construction.

Organization: a page of ≈ 16 KB is the unit of reading and writing; a block of hundreds to thousands of pages — megabytes to tens of megabytes — is the unit of erasure. Only a whole block can be erased: erasure pulls the charge out of all the block’s cells at once with a strong field through the shared substrate, and it is physically impossible to select an individual page. A page can be written (programmed) only in an erased block, and usually in order.

Typical TLC timings: page read ≈ 50 µs, programming ≈ 300 µs or more, block erase ≈ 3 ms. Each erase slightly damages the insulating layer, so a cell has a limited endurance: on the order of 1000–3000 cycles for TLC, fewer for QLC. In the model the die is three blocks of four pages: this makes the rule “write in pages, erase in blocks” easy to see.

FTL and garbage collection

The operating system treats the drive as an array of numbered blocks and, for example, rewrites LBA 5 in place. Flash memory cannot do that. So the controller maintains a translation layer, the FTL (Flash Translation Layer): the new version of LBA 5 is written to any free page, an entry “LBA 5 is now here” appears in the table, and the old page is marked stale. In the demo you can see this by color: green pages are valid, gray ones are stale, empty ones are free.

Stale pages take up space until their block is erased. When free blocks run low, garbage collection kicks in: the controller picks the block with the most stale pages, copies the remaining live pages to free space, updates the table and erases the block. The demo shows that garbage collection is many times more expensive than an ordinary write: moving each live page is a read plus a write, and the erase costs another 3 ms.

Because of garbage collection, the drive writes more to flash than it was sent — this is write amplification. If blocks are almost entirely filled with live data, many old pages have to be moved for every new one. That is why every SSD has a hidden capacity reserve (over-provisioning), and a drive filled “to the brim” writes more slowly.

The TRIM command is a hint from the OS. When a file is deleted, the file system tells the drive: “these LBAs are no longer needed.” The controller marks the pages stale in advance and will not drag dead data around during garbage collection. Without TRIM it would learn that the data is no longer needed only when the OS overwrites the same LBAs.

The same FTL levels wear: the controller tracks the erase count of each block and from time to time moves long-resting “cold” data so that lightly worn blocks also get used. Without this, frequently rewritten blocks — for example, those holding the file system journal — would exhaust their endurance within months.

Writing step by step and the SLC cache

1. The OS sends a write command with LBA numbers and the address of the data in memory. 2. The controller fetches the data via DMA into its buffer and often replies “done” right away — the data is for now in the controller’s memory. 3. It chooses free pages, spreading the write across different dies so that programming proceeds in parallel. 4. It programs the pages, updates the FTL table and marks the old copies stale.

Programming TLC is a slow and delicate operation: the cell is brought to one of 8 levels by a series of pulses with a verification after each. To make writes seem fast, almost all consumer SSDs use an SLC cache: some free blocks temporarily operate in “1 bit per cell” mode, which is several times faster. Later, at idle, the controller rewrites the data from the SLC blocks into dense TLC blocks.

Hence the familiar picture: a large file is copied at 5–10 GB/s, and after tens or hundreds of gigabytes the speed suddenly drops to 1–2 GB/s, and on cheap QLC drives to hundreds of megabytes per second. The cache has run out, and the drive writes directly to TLC while freeing up SLC in parallel. The cache size depends on free space: on an almost full drive it is small.

What happens on a sudden power loss? Data that has already been acknowledged but is still sitting in the buffer may be lost. For important writes — the file system journal, databases — the OS sends a Flush command: “push everything to flash.” Server SSDs have capacitors with enough energy to finish writing the buffer. The controller rebuilds the FTL table from the journal and the pages’ metadata, so the drive itself usually survives a failure intact.

Wear and service life

SSD endurance is specified in TBW — how many terabytes can be written under warranty. A typical 1 TB drive is rated at about 600 TBW, which is ≈ 330 GB per day for five years. An ordinary user writes 10–50 GB per day, so the endurance rarely runs out before the drive becomes obsolete.

A cell wears out because each program and erase drives electrons through a thin insulator and leaves defects in it. The charge starts leaking faster, the levels blur, and errors become more frequent. The controller compensates: it adjusts the read thresholds, re-reads with different thresholds, strengthens error correction. When a block can no longer hold data reliably, it is retired and replaced with a spare.

The drive’s health is visible in SMART: endurance used as a percentage, the amount of data written, the remaining spare blocks, errors. Wear is not the only cause of failure: drives more often fail because of the controller or power, so you need a backup regardless of TBW.

Without power, flash memory is not eternal either: charge slowly leaks away, especially from worn cells and at high temperatures. A new drive holds data for years; a heavily worn one left on a shelf in the heat, noticeably less. For long-term archives, hard drives and tapes are better suited, and they are also cheaper per terabyte.

The hard drive: platter, head, arm

A hard drive is mechanics with nanometer precision. On the spindle sit platters of glass or aluminum with a magnetic layer tens of nanometers thick; high-capacity 3.5″ drives have up to 10 of them, and the case is filled with helium — it drags less on the platters and shakes the heads less. The spindle rotates at 7200 rpm: one revolution takes 8.33 ms, and the edge of the platter moves at ≈ 130 km/h.

A bit is the direction of magnetization of a tiny region. The regions run along concentric tracks a few tens of nanometers wide, and the tracks are divided into 4 KB sectors. The outer tracks are longer and hold more sectors — which is why data at the beginning of the disk reads faster than at the end.

The head is a pair of elements on a slider: a write element (a tiny electromagnet) and a read element (a magnetoresistive sensor whose resistance changes with the field beneath it). The slider is an aerodynamic wing: the oncoming gas flow holds it above the surface at a height of a few nanometers — smaller than a smoke particle. That is why drives are assembled in clean rooms and sealed. When the drive stops, the arm moves the heads onto a plastic parking ramp at the edge.

The arm is rotated by a voice coil (VCM) between strong magnets — the same idea as in a loudspeaker: current in the coil, force, rotation. The head’s position is held by a servo system: service marks are written on the platters at the factory, the head reads them hundreds of times per revolution, and the controller constantly steers to keep the head on the track.

The controller board is screwed to the bottom of the case: the drive’s processor, the motor and voice coil drivers, the read channel that turns the head’s analog signal into bits using digital signal processing and error correction, and a DRAM cache. The drive communicates with the outside world over SATA.

Why a hard drive needs to read sequentially

The time of a single access consists of three parts. Seek — the arm moves the head to the needed track: from ≈ 1 ms to an adjacent track to ≈ 10 ms across the whole platter. Rotational latency — the drive waits for the needed sector to come under the head: from zero to a full revolution, on average half a revolution — 4.17 ms. Transfer — the actual reading: at 250 MB/s, 4 KB is read in 16 µs.

For a small random read, transfer is nothing: almost all the time goes to mechanics, ≈ 10 ms per access, about 100 accesses per second. The demo shows four cases: a random read (seek plus rotational latency), the next sector on the same track (almost instant), a distant track (a long seek) and 1 MB in a row — no seek needed, the time goes only to transfer.

So a disk has two faces: sequentially it reads 200–280 MB/s, but in random 4 KB blocks less than 1 MB/s. An SSD is thousands of times faster at random reads and 25–50 times faster at sequential ones. File systems try to lay files out contiguously, and the drive’s command queue (NCQ) reorders requests so that the head moves across the platter like an “elevator” rather than darting back and forth.

Why hard drives today? Price and capacity: 20–30 TB in a single case, with a terabyte several times cheaper than on an SSD. New technologies — shingled recording (SMR, where tracks partially overlap) and heat-assisted magnetic recording (HAMR) — keep raising density. At home a hard drive is an archive and backups; in data centers it holds huge volumes of rarely read data.

Common misconceptions

“SSDs die quickly; you can’t write much to them.” The endurance of modern drives is hundreds of terabytes of writes, which lasts many years with ordinary use. Disabling the page file or moving temporary files elsewhere “to save endurance” is pointless.

“A deleted file can be recovered from an SSD just like from a hard drive.” After TRIM the controller may erase the blocks in the background, and the data physically disappears. With a hard drive it is the opposite: deletion only marks the space as free, and the data stays there until it is overwritten.

“Defragmentation speeds up an SSD.” An SSD spreads data across its dies anyway, and logical contiguity means almost nothing to it — defragmentation only wastes endurance. For SSDs, the operating system periodically sends TRIM instead. Defragmentation does help a hard drive — for the sake of sequential reads.

“The speed in the specs is the speed you always get.” 14 GB/s is sequential reading at a deep queue. Launching a program means thousands of small reads, and there what matters is latency and random-read speed at a shallow queue, where the difference between PCIe 4.0 and 5.0 SSDs is small.

Open in 3D →

All articles

Overviews

Logic: from transistor to arithmetic

Processor

Computer

Servers and data centers

Networks and the internet

Software