29/32 · 5 min
The order requests reach the disk
On a spinning disk, the arm must move to the right track and the platter must rotate to the right sector. Moving the arm is by far the most expensive thing the disk does, so the order of requests decides throughput.
The numbers
seek time ~ 5 to 10 ms moving the arm
rotational ~ 2 to 4 ms waiting for the sector
transfer ~ 0.1 ms reading the dataThe data transfer is almost free. Everything is positioning, which is why sequential access is roughly a hundred times faster than random access on a spinning disk.
The algorithms
FCFS: service in arrival order. The arm wanders across the disk.
SSTF, shortest seek time first: always the nearest request. Better throughput, and it starves requests at the edges while activity continues in the middle.
SCAN, the elevator: sweep from one end to the other, servicing everything on the way, then reverse. No starvation, and the middle gets served twice as often as the edges.
C-SCAN: sweep in one direction only, then jump back without servicing. Uniform waiting time, which is fairer at a small throughput cost.
head at 53, queue: 98, 183, 37, 122, 14, 124, 65, 67
FCFS total head movement 640
SSTF 236
SCAN 208Solid state changes the question
An SSD has no arm and no platter. Access time is the same wherever the data is, so seek optimisation is meaningless and SCAN buys nothing.
Different concerns replace it:
Write amplification. An SSD erases in large blocks and writes in small pages, so modifying one page can require rewriting a whole block.
Wear levelling. Each cell tolerates a limited number of erases, so the controller spreads writes across the device. Overwriting the same logical block repeatedly does not wear one physical spot.
TRIM. The drive cannot tell which blocks the filesystem considers free unless told, and without that knowledge it preserves data nobody wants, performing worse over time.
| Spinning disk | SSD | |
|---|---|---|
| Random vs sequential | 100x difference | small difference |
| Scheduling | matters a lot | reorder to merge, little else |
| Wears out | mechanically | by erase count |
The practical consequence is that a database index layout tuned for sequential access on spinning disks is far less critical on flash, and that "random reads are slow" is advice with an expiry date on it.