All episodes · From One Switch to a CPU · Episode 16

How Hard Disks and SSDs Keep Your Files

Pressing play loads the video from YouTube.

Turn the power off and memory forgets everything, yet your files are still there. Where?
We look inside a hard disk (spinning platters, a moving head, milliseconds of waiting), then flash SSDs: why they can't overwrite a page in place, why they erase whole blocks, and how the controller spreads the writes evenly. Then the whole memory hierarchy, from registers down to disk.

Every animation in this video is drawn by code, and the narration is an AI voice.

Transcript

Turn off your computer, and everything in its memory is gone. Turn it back on, and your files are still there. So where were they? In storage that keeps data without power. Today: hard disks, SSDs, and how all the memories fit together.

A hard disk stores bits on spinning platters, coated with a magnetic layer. Each bit is a tiny patch magnetized one way or the other. A head on a moving arm reads and writes them, floating just above the surface. The platters spin about seven thousand times a minute. To read something, the arm swings to the right track, then waits for the data to spin around. That takes a few milliseconds, millions of times longer than a cache. But once the head is in place, long runs of data stream off quickly.

An SSD has no moving parts. It's made of flash cells: the trapped electrons from episode eight. Reading takes tens of microseconds: much faster than a spinning disk, though still far slower than memory. Flash has a strange rule: you can't overwrite a page. You first have to erase it, and erasing only works on a whole block of pages at once. So the SSD's little controller writes new data to fresh pages, and keeps a table of where everything really lives. Sound familiar? It's like the page table from last time. And since each block can only be erased a few thousand times, the controller spreads the writes around, so no block wears out early.

Now put every kind of memory from this season together. At the top: registers, the fastest and the smallest. Then the caches. Then main memory. Then SSDs and hard disks at the bottom. Each step down is bigger and cheaper per byte, but slower. The whole trick is keeping what you need right now near the top.

So: hard disks spin and seek, SSDs trap electrons and remap their pages, and the hierarchy keeps the right data in the right place. But how does the CPU even talk to a disk, a keyboard, or a screen? Next time: buses and interrupts. See you there.

Next episode: how the CPU notices when you press a key. Buses, polling, interrupts and DMA.

Buy the Developer a Coffee

Entirely up to you: it works the same either way.

Every cup turns into the next update.

WeChat Pay QR code
WeChat Pay
Alipay QR code
Alipay
PayPal QR code
PayPal