Β§37.5–37.6Disk Scheduling … Summary

Part III OSTEP pp. 442–446 Β· ~6 min read

  • disk scheduling
  • shortest seek time first
  • elevator algorithm
  • shortest positioning time first

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 can greedily approximate SJF, servicing the cheapest request first. Step through the classic policies:

Disk scheduling: pick the cheapest request next. SSTF minimizes seek; SPTF weighs seek AND rotation. (Amber = pending, green = chosen.)
01234567891011121314151617181920212223242526272829303132333435head

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?

step 1 / 5

SSTF 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) 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 (a.k.a. SATF) accounts for seek and rotation, winning when the two are comparable.

Three disk-scheduling policies. Each greedily approximates SJF, but differently.
how it picks nextstarvation?accounts for rotation?
SSTF (shortest seek time first)the request on the nearest track (OS approximates as nearest-block-first)yes β€” far tracks can starveno (seek only)
SCAN / elevatorsweep the head back and forth across tracks, serving in order per sweepnono (seek only)
SPTF / SATF (shortest positioning time first)the request with the shortest total seek + rotation timepossible (greedy)YES
Dotted-underlined cells have explanations β€” click one.

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?

6 questions