1. Home
  2. Operating Systems
  3. Disk Scheduling (FCFS, SSTF, SCAN, C-SCAN, LOOK, C-LOOK)

Disk Scheduling (FCFS, SSTF, SCAN, C-SCAN, LOOK, C-LOOK)

Choose the order of disk requests so the read/write head travels as little as possible. Six algorithms race on the same queue.

Interactive 3DIntermediate12 min readOSUpdated

Drag to rotate · Right-drag to pan · Click, then scroll to zoom · Space play · Left arrowRight arrow step

What's happening

A hard disk has to move its read/write head to the right cylinder for every request, and moving the head (seeking) is the slowest part. The disk scheduler picks the order. Choose an algorithm and press Run, then Compare all.

Pseudocode

  1. while requests are pending:
  2. next ← the pending request closest to the head
  3. total += |next − head|; head ← next
Read this model as text · 11 steps

One run of the model above, written out step by step. Useful with a screen reader, on a slow connection, or for quick revision. The values may differ from the run on your screen.

  1. A hard disk has to move its read/write head to the right cylinder for every request, and moving the head (seeking) is the slowest part. The disk scheduler picks the order. Choose an algorithm and press Run, then Compare all.
  2. SSTF (shortest seek time first). The head is at cylinder 53. Requests: 98, 183, 37, 122, 14, 124, 65, 67. Goal: serve them all with as little head movement as possible.
  3. 53 → 65: 12 cylinders — the closest pending request (12 away).
  4. 65 → 67: 2 cylinders — the closest pending request (2 away).
  5. 67 → 37: 30 cylinders — the closest pending request (30 away).
  6. 37 → 14: 23 cylinders — the closest pending request (23 away).
  7. 14 → 98: 84 cylinders — the closest pending request (84 away).
  8. 98 → 122: 24 cylinders — the closest pending request (24 away).
  9. 122 → 124: 2 cylinders — the closest pending request (2 away).
  10. 124 → 183: 59 cylinders — the closest pending request (59 away).
  11. All 8 requests served. Total head movement = 236 cylinders (average seek 29.5 per request). Press Compare all to see every algorithm on the same queue.

Try this in the 3D model

  • Run FCFS on the textbook queue, then SSTF. How much shorter is the head's path?
  • Run SCAN and then LOOK. Find the exact step where they behave differently.
  • Switch the direction to ← Towards lower and press Compare all. Does the winner change?
  • Press Random queue a few times and compare. Is SSTF always the best?

Why the order of requests matters

A hard disk stores data on spinning platters. To read a block, the read/write head must first move to the right cylinder (track). This movement is the seek, and it is by far the slowest part of a disk access: milliseconds, while everything else in the computer works in nanoseconds.

Many programs send requests at once, so the operating system keeps a queue of cylinders to visit. The disk scheduler decides the order. A good order means a short total head movement, which means faster programs.

Think of a courier with eight parcels for houses along one long road. Delivering them in the order they were ordered sends the van back and forth along the road. Delivering them in the order of the houses saves a lot of driving.

The textbook example

The classic exam question uses a disk with cylinders 0–199, the head at 53 moving towards higher cylinders, and this queue:

98, 183, 37, 122, 14, 124, 65, 67

Algorithm Order of service Total head movement
FCFS 98, 183, 37, 122, 14, 124, 65, 67 640
SSTF 65, 67, 37, 14, 98, 122, 124, 183 236
SCAN 65, 67, 98, 122, 124, 183, (199), 37, 14 331
C-SCAN 65, 67, 98, 122, 124, 183, (199 → 0), 14, 37 382 (183 without the return jump)
LOOK 65, 67, 98, 122, 124, 183, 37, 14 299
C-LOOK 65, 67, 98, 122, 124, 183, 14, 37 322

If the head were moving towards lower cylinders, SCAN would be 236 and LOOK only 208. The direction matters, which is why exam questions always state it. Try both in the 3D model with Compare all.

The six algorithms

FCFS (First Come, First Served): serve requests in arrival order. It is simple and fair, but the head zig-zags wildly.

SSTF (Shortest Seek Time First): always go to the closest pending request. It is greedy and usually gives a short path. The danger is starvation: a request at the far end can wait forever if new requests keep arriving near the head.

SCAN (the elevator algorithm): move in one direction serving every request on the way, go all the way to the edge of the disk, then reverse. Like a lift that goes to the top floor and then comes down. No request starves.

C-SCAN (Circular SCAN): like SCAN, but after reaching the edge the head jumps back to the other edge and serves only in one direction. Waiting times become more uniform, because the disk is treated like a circle.

LOOK: SCAN without the wasted trip. The head reverses at the last request in the current direction instead of at the edge of the disk.

C-LOOK: C-SCAN without the wasted trip. After the last request it jumps straight to the farthest request on the other side.

Comparison

Total movement Starvation? Waiting time
FCFS High No Fair but slow
SSTF Low Yes Very uneven
SCAN Medium No Middle cylinders favoured
C-SCAN Medium–high No Most uniform
LOOK Low–medium No Like SCAN
C-LOOK Medium No Like C-SCAN

In practice, LOOK and C-LOOK are the usual choices: they are almost as efficient as SSTF but never starve a request.

Code

def fcfs(reqs, head):
    total = 0
    for r in reqs:
        total += abs(r - head)
        head = r
    return total

def sstf(reqs, head):
    pending, total = list(reqs), 0
    while pending:
        nxt = min(pending, key=lambda r: abs(r - head))   # closest request
        total += abs(nxt - head)
        head = nxt
        pending.remove(nxt)
    return total

# The sweeping algorithms, with the head moving towards higher cylinders.
def scan(reqs, head, max_cyl=199):
    up = sorted(r for r in reqs if r >= head)
    down = sorted((r for r in reqs if r < head), reverse=True)
    return fcfs(up + ([max_cyl] if down else []) + down, head)

def c_scan(reqs, head, max_cyl=199):
    up = sorted(r for r in reqs if r >= head)
    low = sorted(r for r in reqs if r < head)
    return fcfs(up + ([max_cyl, 0] if low else []) + low, head)

def look(reqs, head):
    up = sorted(r for r in reqs if r >= head)
    down = sorted((r for r in reqs if r < head), reverse=True)
    return fcfs(up + down, head)

def c_look(reqs, head):
    up = sorted(r for r in reqs if r >= head)
    low = sorted(r for r in reqs if r < head)
    return fcfs(up + low, head)

queue, head = [98, 183, 37, 122, 14, 124, 65, 67], 53
for f in (fcfs, sstf, scan, c_scan, look, c_look):
    print(f.__name__, f(queue, head))
# fcfs 640, sstf 236, scan 331, c_scan 382, look 299, c_look 322

What about SSDs?

Solid-state drives have no moving head, so every block is equally fast to reach and seek order hardly matters. Operating systems still schedule SSD requests, but for other reasons: merging neighbouring requests and keeping things fair between programs. Linux, for example, often uses the simple none or mq-deadline schedulers for SSDs. Disk scheduling algorithms remain important for hard disks, which still store most of the world’s data in data centres.

Common mistakes

  • Forgetting the trip to the edge in SCAN. SCAN goes to cylinder 199 (or 0) before reversing. LOOK does not.
  • Ignoring the direction. SCAN and LOOK give different totals depending on which way the head is moving.
  • Counting (or not counting) C-SCAN’s return jump without saying so. Textbooks differ, so state which one you use.
  • Starting the sum from the first request instead of from the head’s starting position.

Complexity at a glance

Case / operationTimeWhy
FCFSO(n)Serve the requests in arrival order.
SSTFO(n²)n times, search the pending requests for the nearest one.
SCAN, C-SCAN, LOOK, C-LOOKO(n log n)Sort the requests once, then sweep across them.
Head movement of one SCAN sweep≤ 2 × disk sizeOut to one edge and back across the disk.
Extra spaceO(n)

Quick check

Test yourself — pick an answer to see if you got it.

1. The head is at cylinder 50 and the queue is 45, 70, 10. In what order does SSTF serve them?

2. Which algorithm can make a request far from the head wait forever?

3. What is the difference between SCAN and LOOK?

4. Why does C-SCAN give more even waiting times than SCAN?

Saved in this browser.
Spotted a mistake or a bug in the 3D model?

Report a mistake

in Disk Scheduling (FCFS, SSTF, SCAN, C-SCAN, LOOK, C-LOOK). Thank you — every report makes the lesson better for the next reader.

We'll also include a link to the step of the 3D model you're on and your browser type, so we can reproduce it.