C-SCAN Disk Scheduling: One-Way Sweeps
Serve requests in one direction only. At the end of the disk, jump back to cylinder 0 without serving anything, and sweep the same way again.
How the One-Way Sweep Works
- Sort the pending requests by cylinder
- Serve every request at or above the head, lowest first
- Keep going to the last cylinder (199 on a 0-199 disk)
- Jump to cylinder 0 and serve nothing on the way
- Serve the remaining requests upward, lowest first
C-SCAN, short for circular scan, moves the disk arm in one direction only. It serves every pending request on the way up, runs on to the last cylinder, then jumps straight back to cylinder 0 without serving anything and starts the next upward sweep. The cylinders behave like a ring: after 199 comes 0.
It is SCAN with the downward pass removed. SCAN serves on the way back too; C-SCAN treats the way back as dead travel.
- One service direction, always the same one
- The jump is a reset, not a service pass
- If no request sits below the head, there is no jump
Worked Example: 378 Cylinders from Head 57
This is the same queue the disk scheduling and FCFS lessons use, so the totals compare directly. The head starts at 57 and moves toward higher cylinders.
Five requests sit above 57 and are served first, for 126 cylinders. The arm then runs on to 199 even though nothing is waiting there, jumps to 0, and climbs to 14 and 37. The service order is 65, 94, 122, 140, 183, 14, 37.
Of the 378 cylinders, 229 serve nothing: 16 to reach the edge, 199 for the jump and 14 from cylinder 0 up to the first request. Some textbooks leave the jump out of the total and give 179; say which convention you use in an answer.
| Move | Seek | Running total |
|---|---|---|
| 57 → 65 | 8 | 8 |
| 65 → 94 | 29 | 37 |
| 94 → 122 | 28 | 65 |
| 122 → 140 | 18 | 83 |
| 140 → 183 | 43 | 126 |
| 183 → 199 (no request) | 16 | 142 |
| 199 → 0 (jump) | 199 | 341 |
| 0 → 14 | 14 | 355 |
| 14 → 37 | 23 | 378 |
- Order: 65, 94, 122, 140, 183, then 14, 37
- Total 378 with the jump counted, 179 without
- FCFS needs 666 on this queue; SCAN 327
C-SCAN vs SCAN: Even Waiting
SCAN passes over the middle of the disk twice per round trip, once each way, but reaches each edge only once. With the arm sweeping steadily, a request at cylinder 100 waits about 100 cylinders of travel on average, while one at 199 can wait almost 400 and averages about 200. Edge requests wait twice as long.
C-SCAN fixes that by sweeping the same way every time. Each cylinder is passed once per cycle at the same interval, so the expected wait is about half a cycle wherever the request sits. Waits become even, not shorter: the middle cylinders give up what the edges gain. The cost in head movement is 378 cylinders here, against 327 for SCAN.
Counting cylinders also overstates the jump. A seek is mostly the arm speeding up, slowing down and settling on the track, so one 199-cylinder seek takes far less time than many short seeks adding up to 199.
| SCAN | C-SCAN | |
|---|---|---|
| Serves while moving | Both ways | Up only |
| Total head movement | 327 | 378 |
| Middle vs edge wait | Edge waits about twice as long | About the same everywhere |
| Way back | Serves requests | One jump, serves nothing |
- SCAN: lower total, uneven waits
- C-SCAN: higher total, even waits
- One long seek is cheaper in time than its cylinder count suggests
C-SCAN on the head-57 queue
def c_scan(requests, head, disk_size=200):
above = sorted(c for c in requests if c >= head)
below = sorted(c for c in requests if c < head)
# Both edges are visited: the top to finish the sweep, cylinder 0 to
# restart it. Neither serves a request.
order = above + [disk_size - 1, 0] + below if below else above
total, position = 0, head
for cylinder in order:
total += abs(cylinder - position)
position = cylinder
return order, total
order, total = c_scan([94, 183, 37, 122, 14, 140, 65], 57)
print(" ".join(map(str, order)), "|", total, "cylinders")#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;
// Returns total head movement in cylinders; `order` receives the service order.
int cScan(const vector<int>& requests, int head, vector<int>& order, int diskSize = 200) {
int total = 0, position = head;
// Up to the edge, jump to 0, then up again. Neither edge serves a request.
vector<int> above, below;
for (int c : requests) (c >= head ? above : below).push_back(c);
sort(above.begin(), above.end());
sort(below.begin(), below.end());
for (int c : above) order.push_back(c);
if(!below.empty()) {
order.push_back(diskSize - 1);
order.push_back(0);
}
for (int c : below) order.push_back(c);
total = 0;
position = head;
for (int cylinder : order) {
total += abs(cylinder - position);
position = cylinder;
}
return total;
}
int main() {
vector<int> requests = {94, 183, 37, 122, 14, 140, 65}, order;
int total = cScan(requests, 57, order);
for (int c : order) cout << c << " ";
cout << "| " << total << " cylinders" << endl;
return 0;
}import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Main {
// Returns total head movement in cylinders; `order` receives the service order.
static int cScan(int[] requests, int head, List<Integer> order, int diskSize) {
int total = 0, position = head;
// Up to the edge, jump to 0, then up again. Neither edge serves a request.
List<Integer> above = new ArrayList<>(), below = new ArrayList<>();
for (int c : requests) (c >= head ? above : below).add(c);
Collections.sort(above);
Collections.sort(below);
order.addAll(above);
if(!below.isEmpty()) {
order.add(diskSize - 1);
order.add(0);
}
order.addAll(below);
total = 0;
position = head;
for (int cylinder : order) {
total += Math.abs(cylinder - position);
position = cylinder;
}
return total;
}
public static void main(String[] args) {
int[] requests = {94, 183, 37, 122, 14, 140, 65};
List<Integer> order = new ArrayList<>();
int total = cScan(requests, 57, order, 200);
StringBuilder line = new StringBuilder();
for (int c : order) line.append(c).append(" ");
System.out.println(line + "| " + total + " cylinders");
}
}Step through it
Running on requests 94 183 37 122 14 140 65, head 57 moving up, disk 0-199
Edge Cases and Variants
Nothing below the head. If every request is at or above the head, the sweep ends at the last one and no jump happens: 126 cylinders on this queue without 14 and 37. The code checks for this.
A request just behind the head. A request for cylinder 56 that arrives once the arm has left 57 waits for the arm to reach 199, jump to 0 and climb back: 142 + 199 + 56 = 397 cylinders of travel, almost a full cycle. That is C-SCAN's worst wait, and it is the same for every cylinder, which is the point.
Direction. The sweep can run downward instead: serve down to 0, jump to 199, serve down again. The total changes, the idea does not. C-LOOK keeps the one-way sweep but turns at the last request and jumps only as far as the lowest one, which cuts this queue to 318.
On SSDs none of this applies: there is no arm, and Linux usually runs NVMe drives with the none scheduler. For hard disks, mq-deadline sorts by sector but adds expiry times, which gives the bounded wait C-SCAN aims for by a timer instead of by geometry.
- No requests below the head means no jump
- Worst wait: a request just behind the head, about one full cycle
- C-LOOK trims both edges: 318 here