Lesson 1 · Storage and I/O

FCFS Disk Scheduling: Order, Cost and Fairness

First come, first served: the disk serves requests in the order they arrive and never reorders them. It is the simplest disk scheduling policy, the only one that is fair by construction, and usually the most expensive.

FCFS Disk Scheduling: Order, Cost and Fairness concept diagramA visual explanation of the layout and operations shown in this lesson.arrival order only — the head crosses the platter five times05010015019914376594122140183cylinder37891468510812675head 57total head movement: 666 cylinders
1

How FCFS Disk Scheduling Works

  1. Keep pending requests in a FIFO queue, in arrival order
  2. Take the request at the front
  3. Move the head there and add |request − head| to the total
  4. Repeat until the queue is empty

First come first serve disk scheduling (FCFS, sometimes called FIFO) is the simplest of the disk scheduling algorithms. The head serves requests in exactly the order they reached the queue. It never looks at where a request is on the disk, so it needs no sorting and no knowledge of the disk's layout.

The number exams ask for is total head movement: the sum of the distances the head travels, measured in cylinders. FCFS also fixes the order of service, so each request's waiting time is easy to predict.

  • The cost of one move is |next − current|
  • Do not confuse it with FCFS CPU scheduling, the same rule applied to processes
2

FCFS Disk Scheduling Example

The head is at cylinder 57 and the queue, in arrival order, is 94, 183, 37, 122, 14, 140, 65, on a disk with cylinders 0 to 199. FCFS serves them in that order:

Total = |94 − 57| + |183 − 94| + |37 − 183| + |122 − 37| + |14 − 122| + |140 − 14| + |65 − 140| = 37 + 89 + 146 + 85 + 108 + 126 + 75 = 666 cylinders. The average seek per request is 666 / 7 ≈ 95 cylinders, almost half the disk every time.

  • Order served: 94, 183, 37, 122, 14, 140, 65
  • Longest single move: 183 → 37, 146 cylinders
3

Why It Costs So Much

Arrival order has nothing to do with where requests sit on the disk. Two requests that arrive one after the other may be at opposite ends, and FCFS crosses the whole disk to serve them, then crosses back for the next one.

In the example the head changes direction five times in seven moves, and those five moves account for 540 of the 666 cylinders. Serving the same requests in one sweep up and one sweep down (LOOK) costs 295; serving the nearest one each time (SSTF) costs 228.

There is also no upper limit. Requests that alternate between cylinder 0 and cylinder 199 make FCFS pay the full width of the disk on every request, however many are queued, because it never looks past the front of the queue.

  • Five reversals cost 540 of the 666 cylinders
  • Alternating far requests make the cost as bad as possible
Implementation

FCFS disk scheduling on the standard queue

def fcfs(requests, head):
    """Serve requests in arrival order. Returns (order, total head movement)."""
    order, total, position = [], 0, head
    for cylinder in requests:
        total += abs(cylinder - position)   # seek cost of this leg
        position = cylinder
        order.append(cylinder)
    return order, total


order, total = fcfs([94, 183, 37, 122, 14, 140, 65], 57)
print(*order, "|", total, "cylinders")
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;

// Returns total head movement in cylinders; `order` receives the service order.
int fcfs(const vector<int>& requests, int head, vector<int>& order) {
    int total = 0, position = head;
    for (int cylinder : requests) {          // arrival order, no reordering
        total += abs(cylinder - position);   // seek cost of this leg
        position = cylinder;
        order.push_back(cylinder);
    }
    return total;
}

int main() {
    vector<int> requests = {94, 183, 37, 122, 14, 140, 65}, order;
    int total = fcfs(requests, 57, order);
    for (int c : order) cout << c << " ";
    cout << "| " << total << " cylinders" << endl;
}
import java.util.ArrayList;
import java.util.List;

class Main {
    // Returns total head movement in cylinders; `order` receives the service order.
    static int fcfs(int[] requests, int head, List<Integer> order) {
        int total = 0, position = head;
        for (int cylinder : requests) {               // arrival order, no reordering
            total += Math.abs(cylinder - position);   // seek cost of this leg
            position = cylinder;
            order.add(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 = fcfs(requests, 57, order);
        StringBuilder sb = new StringBuilder();
        for (int c : order) sb.append(c).append(' ');
        System.out.println(sb + "| " + total + " cylinders");
    }
}
Watch it run

Step through it

Running on head at 57; requests 94, 183, 37, 122, 14, 140, 65

head at 57; cylinders 0-199arrival queue9418337122141406501501995794183371221414065headFCFS0no reordering: queue order is service order
Step 1

The queue and the head

Seven requests sit in the disk queue in the order they arrived, and the head is at cylinder 57. FCFS will serve them in exactly this order. The cost of each move is the distance |next − current|, and the answer is the sum of all seven.

Output
1 / 12
4

Advantages and Disadvantages

FCFS's one real strength is fairness. Every request waits only for the requests that arrived before it, so no request can starve, which SSTF cannot promise. When the queue rarely holds more than one request, there is nothing to reorder anyway, so a smarter algorithm would only add code. That is why FCFS is also the baseline the other algorithms are measured against.

  • Advantage: simple, a plain FIFO queue
  • Advantage: fair and starvation-free, with predictable waiting
  • Disadvantage: highest head movement on most queues
  • Disadvantage: long seeks mean low throughput under heavy load
5

Where FCFS Still Runs Today

FCFS aged better than the seek-saving algorithms, because the thing it refuses to do, reordering, stops mattering when seeks cost nothing. An SSD has no arm, so reading block 9 after block 4,000 costs about the same as reading block 5.

Linux's default I/O scheduler for NVMe drives is none: requests are passed to the drive in arrival order, and the drive's own controller spreads them across its flash chips. For hard disks Linux uses mq-deadline, which sorts requests by position but gives each one an expiry time so none waits too long, or bfq, which shares disk time fairly between processes.

  • SSDs and NVMe: arrival order is good enough
  • Hard disks: sorted order plus deadlines (mq-deadline) beats plain FCFS