devutils/ATFQ/book ATFQ git

Part I · How it works

4. How storage works

  1. 4.1Hard drives, SSDs and NVMeA 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).
  2. 4.2Inside an SSD: flash, TRIM and wearFlash can't overwrite in place: it writes pages of a few KiB, but only erases whole blocks of many pages. The SSD's controller writes new data elsewhere and cleans up old blocks in the background.
  3. 4.3From write() to the disk: the block layerA write() goes into the page cache and returns. Later, the filesystem turns dirty pages into block requests ("write these sectors").
  4. 4.4IOPS, throughput and latency: how fast is a disk?Three numbers describe a disk: latency (time for one request), IOPS (requests per second) and throughput (bytes per second). Throughput = IOPS × request size.
  5. 4.5fsync: when is data really on disk?write() returning means the data reached the kernel's memory, not the disk. Linux writes it out later, usually within 30 seconds.