Disk Scheduling — FCFS & SSTF With Head-Movement Traces
The Problem — An Elevator's Dilemma
The single slowest step in a disk read is seek time — physically moving the arm to the right cylinder. It's the only part the OS can control, and it does so by choosing which pending request to serve next. That choice is disk scheduling.
Inside a Hard Disk
A spinning platter is divided into concentric tracks, each split into sectors (512 B or 4 KB — the smallest unit). The same track across all stacked platters forms a cylinder. The head moves radially to a cylinder while the spindle spins the platters at 5400 or 7200 RPM.
Access Time — Three Costs
Rotational latency is fixed by RPM and transfer by the interface — the OS can't change them. But seek time depends on how far the arm travels, and that's set entirely by the order requests are served. Minimising total head movement is the whole job of disk scheduling.
FCFS — Serve in Arrival Order
FCFS serves strictly in arrival order, so the arm lurches from 98 out to 183, all the way back to 37, out again to 122… Those wild swings add up to 640 cylinders of travel. Simple and perfectly fair — but the head crosses the disk again and again.
FCFS — Fair but Wasteful
On a lightly loaded system or a batch queue, few requests are pending at once, so there's little to reorder — and FCFS's fairness and zero overhead win. Its weakness only shows under heavy, scattered load.
SSTF — Always the Nearest Request
At each step SSTF picks the closest pending cylinder: from 53 it takes 65, then 67, sweeps down through 37 and 14, then climbs steadily to 98, 122, 124, 183. The path barely doubles back — 236 cylinders versus FCFS's 640, a 63% reduction.
SSTF — Fast, but It Can Starve
SSTF is not globally optimal: always grabbing the nearest request can miss a shorter overall path — the same greedy pitfall as SJF in CPU scheduling. It also costs O(n) per step to scan the queue. Production systems bolt on deadlines to stop the edges from starving.
Same Queue, Two Totals
On the identical queue, SSTF moves the arm less than 40% as far as FCFS. On a disk averaging 5 ms per seek, that gap is real wall-clock time saved — and less mechanical wear on the arm. The cost is fairness, which SSTF gives up.
Worked Example — Head at 50
Head starts at 50; queue 82, 170, 43, 140, 24, 16, 190. Disk 0–199.
| FCFS path | Move | SSTF path | Move | |
|---|---|---|---|---|
| 50 → 82 | 32 | 50 → 43 | 7 | |
| 82 → 170 | 88 | 43 → 24 | 19 | |
| 170 → 43 | 127 | 24 → 16 | 8 | |
| 43 → 140 | 97 | 16 → 82 | 66 | |
| 140 → 24 | 116 | 82 → 140 | 58 | |
| 24 → 16 | 8 | 140 → 170 | 30 | |
| 16 → 190 | 174 | 170 → 190 | 20 | |
| Total | 642 | Total | 208 |
FCFS crosses 642 cylinders; SSTF, always taking the nearest, needs just 208 — about 3.1× less. On a 5 ms/seek disk that's roughly 2.2 seconds saved on this one batch of requests.
Practice — Head at 50, New Queue
Head starts at 50; queue 176, 79, 34, 60, 92, 11, 41, 114. Disk 0–199.
| FCFS order | Total | SSTF order (nearest each step) | Total | |
|---|---|---|---|---|
| 50 → 176 → 79 → 34 → 60 → 92 → 11 → 41 → 114 | 510 | 50 → 41 → 34 → 11 → 60 → 79 → 92 → 114 → 176 | 204 |
# SSTF, step by step — pick the nearest remaining cylinder 50 →41 (9) →34 (7) →11 (23) →60 (49) →79 (19) →92 (13) →114 (22) →176 (62) Total = 9 + 7 + 23 + 49 + 19 + 13 + 22 + 62 = 204 cylinders
For FCFS, sum the gaps in arrival order (510). For SSTF, at each step pick the smallest distance from the current head and add it up (204). The first nearest request from 50 is 41 (distance 9) — and SSTF again more than halves the travel.
FCFS vs SSTF at a Glance
| Property | FCFS | SSTF |
|---|---|---|
| Selection rule | Head of queue (arrival) | Nearest pending request |
| Total seek distance | High — 2–5× worse | Much lower |
| Implementation cost | O(1) — dequeue | O(n) — scan queue |
| Starvation possible | No — strict FIFO | Yes — edge cylinders |
| Fairness | Perfect | None |
| Predictable latency | Yes — bounded wait | No — depends on arrivals |
| Best for | Light load, batch queues | Heavy random-access |
FCFS trades speed for guaranteed fairness; SSTF trades fairness for speed. Neither is globally optimal, which is why real schedulers add directional sweeps (SCAN, C-SCAN) and deadlines to get most of SSTF's speed without the starvation.
Disk Scheduling in the Real World
Eight Rules for Disk Scheduling
Choosing What the Head Does Next
From disk anatomy and the access-time breakdown to tracing FCFS and SSTF cylinder-by-cylinder and totalling their head movement — you can work either algorithm by hand and explain the fairness-versus-speed trade at the heart of disk scheduling.
SSTF's starvation is exactly what the directional algorithms fix. Next come SCAN, C-SCAN, LOOK and C-LOOK — the "elevator" schedulers that sweep the disk in one direction — completing the disk-scheduling family.
💿 End of tutorial · Press ← to review, or click Restart