Key features of storage:
non-volatile (keep data when power off)
slow (compared to memory)
block oriented (read/write blocks by blocks)
Address Space:
Ancient Times: (C, H, S) cylinder, head, sector
Modern Times: LBA (logical block address) from 0 to N, 512 bytes per block, 2TB max (with 48-bit LBA)
Reading/writing:
Read-block(N) => give block N or failure (you can retry when fail)
Write-block(N, data) => "ok?" or failure ("ok?" doesn't guarantee success, must re-read to verify)
Power buffer: in case of power failure, we want to guarantee write operation either completes or has no effect (no partial write)
Tagged command queueing: OS can issue multiple requests, each with a tag, disk can return in any order with the given tag
Note: hardware only guarantee "atomic" with respect to requests. If OS needs some storage to be atomic (resilient to power failure), it needs to pack them in one request. OS can further disable write-cache or "flush all pending writes".

Historical Cylinder Layout: Although each sector has different physical size, they store the same amount of data (512 bytes).
So important data is stored in outer cylinders.
Swap may be stored in the middle, so time to access may be faster.
Polarization of magnetic field stores data.
Modern Cylinder Layout: amount of data scales with physical size.
To select a position:
move head to track
wait until desired sector rotates


Typical speed:
random seek: 25 KBytes/s
sequential: hundreds of MBytes/s
Solid state: no moving parts (as supposed to "no vacuum tubes" for "solid state" in electronics)
RAM backed by battery
"NOR flash": used to boot embedded devices, store configuration
"NAND flash": read/write 512B, erase 16KB (most SSDs today)
other stuff: "Phase-change" memory (melting), magnetic RAM, "Memristor" memory, "3D XPoint" / "Optane"
NAND flash:
read is faster than write
write must erase first
erase damages the block, and must be in block size
erase is slow
Strategy dealing with erase:
FTL (Flash Translation Layer): map logical block to physical block, and do wear leveling (avoid using the same block too much)
over-provisioning: have more physical blocks than logical blocks, so we can have spare blocks to replace damaged blocks
group unrelated "disk block" writes into flash blocks
Note that "TRIM" command might not actually erase all data in SSD, security issue
If SSD has to erase every time, it might not be faster than disk. But in the future, there will be more SSD and disks.
Table of Content