Skip to content

30/32 · 5 min

Why the disk is the slowest thing you own

Every performance problem in this subject comes back to one table.

OperationTimeIf a processor cycle were one second
Processor cycle0.3 ns1 second
L1 cache1 ns3 seconds
Main memory100 ns5 minutes
SSD read150 us6 days
Disk seek10 ms1 year
Network round trip150 ms15 years

A disk seek is a billion times slower than an instruction. Nothing you do to your code matters if it causes one you could have avoided.

What the operating system does about it

Buffering. Read a whole block even when asked for a byte, because the next byte is almost certainly wanted and the seek is already paid for.

Caching. Keep recently used blocks in RAM. This is why the second read of a file is instant, and why a machine with plenty of free memory feels faster: the memory is not idle, it is full of disk.

Reordering. Given several pending reads, serve them in an order that minimises head movement rather than in the order they arrived.

Scheduling the disk arm

For requests at cylinders 98, 183, 37, 122, 14, 124, 65, 67 with the head at 53:

  • FCFS serves them in order and travels 640 cylinders.
  • SSTF always takes the nearest next, travels 236, and can starve a distant request forever.
  • SCAN sweeps to one end and back, like a lift. About 236 as well, and no starvation.