Disk scheduling
About this lesson
A hard disk can only read a track after its arm swings the head there, and that seek takes milliseconds. When many programs are waiting, the order the operating system serves their requests decides how far the head travels. Follow one queue of eight requests, head on track 53, served three ways: first come first served (640 tracks), shortest seek time first (236, but it can starve a far request) and the elevator, SCAN (236, and nobody waits forever). The Hardware lesson on interrupts and I/O covers how a request reaches the device and how the device says it is done.
Why order matters
A hard disk keeps data on rings called tracks. To read one, an arm must move the head to that track first: a seek. Seeks are slow, about 4 to 9 ms on average, so less arm travel means faster reads.
time for one read = seek + rotation + transfer seek move the arm to the right track rotation wait for the data to spin under the head transfer read the bytes average seek (OSTEP, Fig. 37.5): Cheetah 15K.5 15,000 RPM 4 ms Barracuda 7,200 RPM 9 ms Below, the tracks are laid out in a straight line: track 0 at the outer edge, track 199 at the inner edge.
Read the lesson step by step
Why order matters
A hard disk keeps data on rings called tracks. To read one, an arm must move the head to that track first: a seek. Seeks are slow, about 4 to 9 ms on average, so less arm travel means faster reads.
time for one read = seek + rotation + transfer seek move the arm to the right track rotation wait for the data to spin under the head transfer read the bytes average seek (OSTEP, Fig. 37.5): Cheetah 15K.5 15,000 RPM 4 ms Barracuda 7,200 RPM 9 ms Below, the tracks are laid out in a straight line: track 0 at the outer edge, track 199 at the inner edge.A queue of requests
Many programs ask for data at once, so the operating system keeps a queue of requests, each naming a track. Eight wait here: 98, 183, 37, 122, 14, 124, 65, 67. The head is on track 53. Which one should go next?
head track 53 queue 98 183 37 122 14 124 65 67 (arrival order) disk tracks 0 .. 199 the disk scheduler picks the order; we score each order by the total tracks the head movesFirst come, first served
FCFS serves requests in arrival order. That is fair, but the head zigzags across the whole disk: 53 to 98, out to 183, back to 37. In total it moves 640 tracks.
FCFS (also called FIFO) 53 -> 98 45 98 -> 183 85 183 -> 37 146 37 -> 122 85 122 -> 14 108 14 -> 124 110 124 -> 65 59 65 -> 67 2 --- total 640 tracksShortest seek first
SSTF always serves the request nearest the head. From 53 it goes to 65 and 67, then down to 14, then up to 183. The head moves only 236 tracks instead of 640.
SSTF: shortest seek time first 53 -> 65 12 65 -> 67 2 67 -> 37 30 37 -> 14 23 14 -> 98 84 98 -> 122 24 122 -> 124 2 124 -> 183 59 --- total 236 tracks An OS sees block numbers, not tracks, so it does the same thing by block number: nearest-block-first.The catch: starvation
SSTF has a flaw. Say the head is on 65 and 183 is waiting. If new requests keep arriving near the head, each one is nearer, so it jumps ahead. Track 183 can wait forever: it starves.
head 65, waiting: 183 (118 tracks away) new 90 25 away -> SSTF picks 90 new 115 25 away -> SSTF picks 115 new 75 40 away -> SSTF picks 75 new 130 55 away -> SSTF picks 130 183 is never the nearest while the stream lastsThe elevator: SCAN
SCAN sweeps like a lift: one way to the edge, serving everything it passes, then back. Down from 53: 37, 14, the edge, then up to 183. 236 tracks, and nobody waits forever.
SCAN, the elevator algorithm (heading down first) 53 -> 37 16 37 -> 14 23 14 -> 0 14 edge: turn round 0 -> 65 65 65 -> 67 2 67 -> 98 31 98 -> 122 24 122 -> 124 2 124 -> 183 59 --- total 236 tracks a request behind the head waits for the way back, but never longer than that C-SCAN sweeps one way only, then jumps back to the start: fairer to the outer and inner tracks.Comparing the three
FCFS moved 640 tracks, SSTF 236, SCAN 236. SSTF and SCAN both cut the travel by more than 60 percent. Of those two fast ones, only SCAN also promises that every request gets served: no starvation.
the three orders as a Python simulation: def fcfs(head, q): moved = 0 for t in q: moved += abs(t - head); head = t return moved def sstf(head, q): q, moved = list(q), 0 while q: t = min(q, key=lambda t: abs(t - head)) q.remove(t); moved += abs(t - head); head = t return moved def scan_down(head, q): # to track 0, then up return head + max([t for t in q if t > head], default=0) queue = [98, 183, 37, 122, 14, 124, 65, 67] for f in (fcfs, sstf, scan_down): print(f.__name__, f(53, queue)) prints: fcfs 640 sstf 236 scan_down 236Who schedules today
Modern disks know their exact head position, so the OS hands them several requests and the drive orders them itself. Linux still offers schedulers such as mq-deadline. Solid-state drives (SSDs) have no moving head, so there is often less to gain.
see (and change) the scheduler for a disk on Linux: $ cat /sys/block/sda/queue/scheduler [mq-deadline] kyber bfq none the same with open() and read() in C (C99, POSIX): #define _POSIX_C_SOURCE 200809L #include <fcntl.h> #include <stdio.h> #include <unistd.h> /* print the I/O schedulers Linux offers for a disk */ int main(int argc, char *argv[]) { char path[256], buf[256]; snprintf(path, sizeof path, "/sys/block/%s/queue/scheduler", argc > 1 ? argv[1] : "sda"); int fd = open(path, O_RDONLY); if (fd < 0) { perror(path); return 1; } ssize_t n = read(fd, buf, sizeof buf - 1); close(fd); if (n < 0) { perror("read"); return 1; } buf[n] = '\0'; fputs(buf, stdout); /* e.g. [mq-deadline] kyber bfq none */ return 0; }
5 quick questions
Choose one answer per question. You can change your choices before checking them.
01Why does the order of disk requests matter on a hard disk?
A read waits for a seek (moving the arm), then for the data to spin round, then the transfer. Average seeks are milliseconds (4 ms and 9 ms for the two drives in OSTEP), so less arm travel means faster service.
02Head on track 53, queue 98, 183, 37, 122, 14, 124, 65, 67. Which request does SSTF serve first?
SSTF always picks the nearest track: 65 is 12 tracks away, closer than 37 (16) or 98 (45). FCFS would pick 98, the oldest request.
03For that queue, how many tracks does the head move in total under FCFS?
45 + 85 + 146 + 85 + 108 + 110 + 59 + 2 = 640. SSTF needs only 236, and SCAN heading down first also needs 236 (53 down to 0, then up to 183).
04What is starvation in SSTF?
SSTF only looks at distance. A steady stream of requests near the head always wins, so a request on a far track can wait forever. SCAN fixes this by sweeping across the disk, serving everything it passes.
05Why does SSD scheduling look so different from hard disk scheduling?
With no moving parts there is no seek or rotational delay, so reordering by position saves little. Linux lets you pick a scheduler per disk, including none, in /sys/block/<disk>/queue/scheduler.
Glossary
- Track
- One ring of data on a disk platter. The head reads one track at a time.
- Seek
- Moving the disk arm so the head sits over the right track. One of the slowest parts of a hard disk read.
- Disk scheduler
- The part of the operating system that picks the order of waiting disk requests.
- FCFS
- First come, first served (also FIFO): serve requests in arrival order. Fair, but the head can zigzag.
- SSTF
- Shortest seek time first: always serve the request nearest the head. Little travel, but far requests can starve.
- SCAN (elevator)
- Sweep the head one way across the disk serving every request it passes, then sweep back. C-SCAN sweeps one way only.
- Starvation
- A request that waits forever because other requests always get picked before it.
- SPTF
- Shortest positioning time first: pick the request with the least seek plus rotation time. Modern drives do this inside the drive.
Notes and sources
- The figure lays the tracks out in a straight line, from track 0 at the outer edge to track 199 at the inner edge, and pretends each request names a track. A real OS sees numbered blocks instead, and nearby block numbers usually sit on nearby tracks, so it orders requests by block number (nearest-block-first).
- Only seek distance is counted here. A real read also waits for the data to spin under the head; a drive that knows both can use shortest positioning time first (SPTF), which modern drives run internally.
- This lesson's SCAN heads toward track 0 first and goes all the way to the edge before turning. Heading the other way would give a different total. A variant that turns at the last request instead of the edge is often called LOOK.
- If two requests were equally near, our SSTF would pick the one that arrived first. This example has no ties.
- On Linux the scheduler is chosen per disk in /sys/block/<disk>/queue/scheduler; the list printed depends on the kernel and the device. mq-deadline gives each request a deadline so none waits too long, and sorts the rest by sector.
- R. and A. Arpaci-Dusseau, Operating Systems: Three Easy Pieces, ch. 37: Hard Disk Drives
- Berkeley CS162 (Fall 2026), Lecture 19: Device Drivers, Storage Devices, Performance (disk scheduling, SSDs)
- Linux kernel documentation: Switching Scheduler
- Linux kernel documentation: Deadline IO scheduler tunables
- Linux man-pages: open(2)
- Linux man-pages: read(2)
Quiz Unlocks after the last step.