Random I/O is brutally expensive β so, given a batch of pending requests, the OS (and the drive) can reorder them to minimize positioning cost.
37.5 Disk Scheduling
Unlike CPU jobs (whose length is unknown), a disk requestβs cost is estimable from its seek and rotation β so disk scheduling disk scheduling Choosing which of several pending disk I/O requests to service next (by the OS and/or the drive). Unlike CPU jobs, a disk request's cost is estimable from its seek and rotation, so schedulers approximate SJF by servicing the cheapest-to-reach request first. defined in ch. 37 β open in glossary can greedily approximate SJF, servicing the cheapest request first. Step through the classic policies:
1SSTF: two pending requests
The head is over the INNER track. Two requests wait: 21 (middle track) and 2 (outer track). Which should the disk serve first?
SSTF shortest seek time first SSTF: a disk-scheduling policy that services the request on the nearest track first (at the OS level, approximated as nearest-block-first, NBF). Fast, but a steady stream of near-track requests can starve requests to far-away tracks. defined in ch. 37 β open in glossary serves the nearest track first (the OS, lacking geometry, approximates it as nearest-block-first). Itβs fast but can starve far tracks. The elevator (SCAN) elevator algorithm SCAN: a disk-scheduling policy that sweeps the head back and forth across the disk, servicing requests in track order per sweep and deferring requests that arrive behind the head to the next sweep β which avoids the starvation of pure SSTF. Like an elevator that keeps going one direction rather than always serving the nearest floor. Variants: C-SCAN (one-way sweeps, fairer) and F-SCAN (freeze the queue during a sweep). defined in ch. 37 β open in glossary fixes that by sweeping back and forth in track order, deferring requests behind the head to the next sweep β like an elevator that keeps going one way instead of always serving the nearest floor. But SSTF and SCAN both ignore rotation; SPTF shortest positioning time first SPTF (a.k.a. SATF, shortest access time first): a disk-scheduling policy that accounts for BOTH seek and rotation, servicing whichever request has the shortest total positioning time. It beats SSTF/SCAN (which ignore rotation) when seek and rotation are comparable, but needs exact head position and track layout β so it is usually performed inside the drive. defined in ch. 37 β open in glossary (a.k.a. SATF) accounts for seek and rotation, winning when the two are comparable.
| how it picks next | starvation? | accounts for rotation? | |
|---|---|---|---|
| SSTF (shortest seek time first) | the request on the nearest track (OS approximates as nearest-block-first) | yes β far tracks can starve | no (seek only) |
| SCAN / elevator | sweep the head back and forth across tracks, serving in order per sweep | no | no (seek only) |
| SPTF / SATF (shortest positioning time first) | the request with the shortest total seek + rotation time | possible (greedy) | YES |
Tip: It Always Depends (Livnyβs Law)
Should the disk serve the nearer track or seek further to catch a sector thatβs about to arrive? βIt dependsβ β on the ratio of seek time to rotation. Almost any systems question can be answered βit dependsβ; the skill is knowing why it depends. (Use with caution, though: answer too many questions this way and people stop asking.)Where scheduling happens, and two more tricks
On modern systems, scheduling is split. The OS picks its best few requests (say 16) and hands them to the drive; the drive β which alone knows exact head position and track layout β does the final SPTF ordering internally. Two related tricks: I/O merging combines adjacent-block requests (e.g. read 33 and 34 β one two-block request), cutting overhead; and instead of always issuing work immediately (work-conserving), an anticipatory scheduler may briefly wait β a better (nearby) request might be about to arrive.
37.6 Summary
Weβve built a functional model of the disk: its geometry, the seek + rotation + transfer of every request, the huge sequential-vs-random gap, and how scheduling minimizes positioning cost. It skips the physics and materials science β but itβs enough to build real systems on. Next: gluing many disks together for capacity and reliability β RAID.
Check yourself: disk scheduling
1.Why can a disk scheduler approximate SJF, when a CPU scheduler generally can't?
2.What does SSTF (shortest-seek-time-first) do, and what's its danger?
3.How does the elevator algorithm (SCAN) avoid SSTF's starvation?
4.What does SPTF (shortest-positioning-time-first) add over SSTF and SCAN?
5.Why is SPTF usually performed inside the drive rather than by the OS?
6.What is I/O merging, and why does it help?