9.3 Elevator Algorithms: SCAN & C-SCAN Disk Scheduling
💡 Core Intuition
🍳 The Everyday Analogy: The Skyscraper Elevator
Imagine a 50-story commercial skyscraper with hundreds of passengers waiting on diverse floors:
The Skyscraper Elevator Sweep Pipeline
Contrasting chaotic passenger hopping with structured directional sweeps
Chaotic Passenger Hopping
The elevator stops on floor 10, then hops to floor 11, then back to floor 9.
The Upward Sweep
The elevator moves strictly upward, picking up everyone who wants to go up until it reaches the top floor.
Express Return to Ground
The elevator sweeps all the way to Floor 50, then rides non-stop express back to the Lobby without opening doors.
- SCAN (Elevator Algorithm): Sweeps back and forth across the disk surface, servicing requests along its current trajectory until it hits the physical extremity.
- C-SCAN (Circular SCAN): Sweeps in one direction, then immediately returns to the opposite boundary without servicing requests on the return journey, guaranteeing uniform wait times.
💻 Bridging to Computer Science
While Shortest Seek Time First (SSTF) achieves impressive seek reduction, its susceptibility to starvation renders it unacceptable for general-purpose multi-user operating systems.
Computer architects resolved this by implementing Elevator Algorithms:
- SCAN: Prevents starvation by maintaining a continuous sweep across cylinders.
- C-SCAN: Eliminates the density bias of SCAN by treating the cylinder tracks as a continuous circular loop.
📚 Core Deep-Dive & Concepts
1. The SCAN (Elevator) Algorithm
Algorithm Mechanics
- The read/write head begins at its current position and travels in a designated direction (e.g., towards lower cylinders or towards higher cylinders).
- It services all pending requests in its path as it encounters their cylinders.
- Crucially, the arm continues traveling until it reaches the physical extremity of the disk (Cylinder or Cylinder ), even if the last request occurred earlier!
- At the boundary, the actuator motor reverses direction, and the arm travels across the disk in the opposite direction, servicing pending requests.
2. Step-by-Step Mathematical Trace: SCAN
- Initial Head Position:
53 - Current Direction: Moving towards lower cylinders (towards
0). - Request Queue:
[ 98, 183, 37, 122, 14, 124, 65, 67 ]
SCAN (Elevator) Disk Head Trajectory
Actuator sweeps down to boundary (0), reverses, and sweeps up: 53 → 37 → 14 → 0 (Boundary) → 65 → 67 → 98 → 122 → 124 → 183
Total Head Movement Calculation
Because the motion consists of two monotonic linear sweeps, the calculation simplifies elegantly:
(Notice that the individual differences sum to the exact same cylinders).
Evaluation of SCAN
- Strengths: Completely eliminates starvation. Every request is serviced within at most two full sweeps of the disk.
- Weaknesses:
- Boundary Waste: Travels all the way to Cylinder even though the last requested track was .
- Unequal Wait Times: When the head reverses at Cylinder , the cylinders near have the lowest density of new requests (they were just visited!). Meanwhile, cylinders near have been waiting the longest.
3. Circular-SCAN (C-SCAN) Scheduling
Why C-SCAN Was Invented: Uniform Wait Times
Under SCAN, cylinders at the extremities enjoy an unfair advantage: when the head reaches an end, it reverses and immediately revisits adjacent cylinders. In contrast, cylinders in the middle of the disk must wait for the head to travel to the extremity, reverse, and travel all the way back!
C-SCAN resolves this by treating cylinders as a continuous ring:
Algorithm Mechanics
- The head moves in one direction (e.g. towards higher tracks), servicing requests along the way.
- Upon reaching the end of the disk (Cylinder ), the head immediately returns to the opposite end (Cylinder ) without servicing any requests on the return trip.
- Once at Cylinder , it resumes servicing requests in the original forward direction.
4. Step-by-Step Mathematical Trace: C-SCAN
- Initial Head Position:
53 - Current Direction: Moving towards higher cylinders (towards
199). - Request Queue:
[ 98, 183, 37, 122, 14, 124, 65, 67 ]
C-SCAN (Circular Elevator) Disk Head Trajectory
Monotonic upward sweep to 199 followed by express return to 0: 53 → 65 → 67 → 98 → 122 → 124 → 183 → 199 ⇢ 0 → 14 → 37
Total Head Movement Calculation
(Note: In modern disk controllers with high-speed voice coil slewing, the return trip from 199 to 0 is an uninterrupted high-velocity seek that completes in a fraction of normal stepped seek time).
5. Architectural Comparison Matrix
| Architectural Feature | First-Come First-Served (FCFS) | Shortest Seek Time First (SSTF) | SCAN (Elevator) | Circular-SCAN (C-SCAN) |
|---|---|---|---|---|
| Total Head Movement | Very High ( cyl) | Lowest ( cyl) | Moderate ( cyl) | Moderate ( cyl) |
| Starvation Potential | Zero () | Severe Risk | Zero () | Zero () |
| Wait-Time Uniformity | Moderate | Very Poor | Moderate (Favors ends) | Maximum (Optimal) |
| Boundary Reversal | Reverses on demand | Reverses on proximity | Reverses at disk edge | Resets to opposite edge |
| Implementation Complexity | Trivial () | Greedy scan () | Ordered sweep () | Ordered sweep () |
🏭 In The Real World: Production Case Study
Linux I/O Schedulers: Anticipatory, Deadline, and BFQ
Modern enterprise Linux servers run specialized disk scheduling frameworks inside the block I/O layer:
🎯 Exam & Interview Pitfall Check
Question 1: Why does C-SCAN generate more total cylinder movements than SCAN on the same benchmark, yet is often preferred in production systems? Answer:
- C-SCAN incurs the additional seek distance of returning from the highest cylinder () back to the lowest cylinder () without servicing requests. In our trace, this increased total movement from to cylinders.
- However, C-SCAN provides strictly uniform waiting times:
- In SCAN, requests arriving just behind the head must wait for a full double-sweep across the entire disk before the head returns.
- In C-SCAN, every request enjoys an almost identical expected waiting time because the head sweeps across the cylinder space cyclically in one direction.
- Furthermore, on physical hard drives, an uninterrupted full-stroke reset across platters executes significantly faster than multiple stop-and-start seeks.
Question 2: Under what specific scenario does SCAN travel to a cylinder that contains NO pending request? Answer:
- SCAN always travels to the physical extremity of the disk (Cylinder or Cylinder ) before reversing direction.
- In our benchmark, the lowest requested cylinder was .
- Despite no request existing at Cylinder , SCAN still forced the actuator arm to travel all the way from down to before reversing direction. This unnecessary boundary traversal was the exact motivation for inventing the LOOK algorithm.
- The Missing Boundary Trap in SCAN: When tracing SCAN on an exam, never forget to include the boundary cylinder ( or )! If the head is moving toward , it must travel to before reversing. Stopping at the lowest request () is the LOOK algorithm, not SCAN!
- Direction Specification Matters: Always verify the initial direction stated in the problem statement. Tracing SCAN moving toward produces completely different intermediate steps and seek totals than tracing toward .