devutils/ATFQ/book ATFQ git

Part I · How it works

4.1 Hard drives, SSDs and NVMe

alsohard drivehard diskspinning disksolid state driveflash storagesatam.2pcie ssdahcirotationaldisk types

TL;DR

  • A hard drive (HDD) reads magnetic platters with a moving head: fine at long sequential reads, slow at jumping around (a few milliseconds per seek, about a hundred random reads per second).
  • An SSD stores data in flash chips, with nothing moving: random reads take tens of microseconds, so it's thousands of times better at them.
  • SATA SSDs are capped by their interface at about 550 MB/s. NVMe SSDs talk to the CPU over PCIe: several GB/s, and many requests in parallel.
lsblk -d -o NAME,ROTA,TRAN,MODEL,SIZE     # ROTA 1: spinning

On your machine

alice@laptopexample
$ atfq 4.1
  nvme0n1   Samsung SSD 980 PRO 500GB: NVMe flash, 476.9 GiB · scheduler
            none · 8 hardware queues · volatile write cache · TRIM
  sda       USB DISK 3.0: USB drive, 30.0 GiB · scheduler mq-deadline · no
            volatile write cache

An example: Alice's laptop, one of the test machines. In your terminal, this block shows your own machine, read live.

Pitfalls

Deep dive 2 questions

Why is NVMe faster than SATA with the same flash?

SATA and its AHCI protocol were designed for hard drives: one queue of 32 commands, and an interface limited to 6 Gb/s. NVMe was designed for flash: up to 65,535 queues of 65,535 commands, usually one queue per CPU, so cores send requests without waiting on each other. A PCIe 4.0 x4 link carries about 8 GB/s, and the protocol costs less CPU per request.

Are hard drives still useful?

For size per euro, yes: large archives, backups, media and NAS boxes mostly stream big files, which suits them. For an operating system, databases or build directories, anything with many small random accesses, an SSD makes a far bigger difference than a faster CPU.

Commands
lsblk
Paths
/sys/block/
See also
14. Disk
4.2 Inside an SSD: flash, TRIM and wear
4.4 IOPS, throughput and latency: how fast is a disk?