4.2.38 · D3Operating Systems

Worked examples — Disk scheduling — FCFS, SCAN, C-SCAN, LOOK

4,376 words20 min readBack to topic

Before we start, one reminder of the only rule that matters (built in the parent):


The scenario matrix

Every disk-scheduling problem is built from a few independent choices. This table lists each case class — the odd corners that trip people up — and the example below that nails it.

# Case class What makes it special Example
A Head in the middle, requests both sides the "normal" case, all 4 algos Ex 1
B Head at the low edge (0) no down-travel exists; SCAN reversal is trivial Ex 2
C Head at the high edge (max) starts already at the wall Ex 3
D All requests above the head direction down wastes a whole trip Ex 4
E Direction = down first mirror image; tests you didn't hard-code "up" Ex 5
F Degenerate: one request (and empty queue) limiting case, sum has one term or zero Ex 6
G Duplicate / tie at head or between requests $ h_i-h_{i-1}
H Word problem in milliseconds (seek-rate given) convert cylinders → time, real units Ex 8
I Exam twist: C-LOOK + "compare all four" wrap-jump to last request, ranking Ex 9
J Circular scans going DOWN first C-SCAN/C-LOOK jump upward on the wrap Ex 10
K Request sits exactly ON a wall (0 or 199) is the trip to the wall "free" or paid? Ex 11

We use a fresh, small queue so the arithmetic is checkable by hand: Queue = {90, 20, 150, 60, 10}, disk range 0–199, unless a case overrides it. Sorted for reference: 10, 20, 60, 90, 150.

The figure below draws exactly this setup. Keep it in view as you read Case A — the amber square is the head, the cyan dots are pending requests, and the two arrows show how the head position "cuts" the queue into an up-side and a down-side. Every algorithm below is just a different rule for combining those two sides.

Figure — Disk scheduling — FCFS, SCAN, C-SCAN, LOOK
Figure s01 — the standard scenario on a cylinder axis (0 to 199): amber square = head at 70, cyan dots = requests {10, 20, 60, 90, 150}. The amber arrow points to the up-side requests {90, 150}; the cyan arrow points to the down-side requests {60, 20, 10}.


Case A — head in the middle, requests on both sides


Why a SCAN reversal "doubles" wasted distance

Before the edge cases, let's nail down a fact we'll reuse. First, two names we'll keep using:

  • = the "end", i.e. the physical wall SCAN is heading toward (the high wall is , the low wall is ).
  • = the "last real request", i.e. the furthest cylinder in that direction that an actual request lives on.

Suppose SCAN is sweeping up, so the last real request is at cylinder , but SCAN insists on climbing to the wall . It travels the extra up to reach the wall, and then — because it reverses and comes back down through that same empty stretch — it travels down again before it meets any request. So the wasted distance for touching an unneeded wall is: That factor of 2 is the up-then-back-down round trip. LOOK avoids it entirely by turning around at . This is exactly the 98 in Case A (, so , ). Keep this "×2" in mind — it only appears when the head both goes to the wall and comes back through the same gap. When the head starts on a wall, there is no coming back through that gap, so the ×2 does not apply (see Case B).


Case B — head at the low edge (cylinder 0)


Case C — head at the high edge (cylinder max)


Case D — all requests above the head


Case E — direction = down first (mirror image)


Case F — degenerate inputs (one request, empty queue)


Case G — duplicates and ties


Case H — word problem: convert cylinders to milliseconds


Case I — exam twist: C-LOOK and rank all four


Case J — circular scans going DOWN first

So far C-SCAN and C-LOOK swept up and wrapped downward (to 0 or to the lowest request). The mirror case sweeps down first and therefore wraps upward — you must flip every "0/lowest" to "199/highest". This is the case textbooks omit and exams exploit.


Case K — a request sitting exactly ON a physical wall



Recall Self-test — one line each

Empty queue total head movement? ::: 0 (empty sum, head never moves). C-LOOK wraps back to which cylinder (up-first)? ::: The lowest pending request, not physical 0. C-SCAN going down-first jumps to which wall? ::: The high wall 199 (then keeps servicing downward). If a real request sits exactly on the wall, how do SCAN and LOOK compare? ::: They coincide, since makes the ×2 waste zero. Cost of choosing the empty direction first in SCAN? ::: distance to the near wall (wasted round trip). A request equal to the current head position adds how much travel? ::: 0 cylinders (it's free). To turn cylinders into milliseconds you multiply by? ::: The seek rate (ms per cylinder).


Connections

  • 4.2.38 Disk scheduling — FCFS, SCAN, C-SCAN, LOOK (Hinglish) — parent (Hinglish)
  • Seek time vs Rotational latency — the ms conversion in Case H
  • Hard Disk Drive structure (cylinders, tracks, sectors) — why cylinders are the unit
  • SSTF (Shortest Seek Time First) — the greedy cousin that can starve
  • Starvation and Fairness in OS — why C-SCAN/C-LOOK exist
  • Process Scheduling — FCFS, SJF, Round Robin — same ordering trade-offs
  • I/O Subsystem and Device Drivers