LOOK Disk Scheduling: Turn at the Last Request
Move the head in its current direction, serve each request it reaches, and reverse as soon as nothing is left ahead instead of running on to the end of the disk.
How the LOOK Algorithm Works
- Split the requests into those ahead of the head and those behind it
- Sort the ones ahead in the direction of travel
- Serve them in that order
- When none are left ahead, reverse
- Serve the rest in the new direction, nearest first
The LOOK disk scheduling algorithm moves the read/write head in one direction and serves each pending request as it reaches it. Before each move it looks further along that direction. When nothing is waiting there, it reverses and serves the rest on the way back.
It is SCAN without the empty run to cylinder 0 or the last cylinder. The head only travels between the lowest and highest requests in the queue, so the disk size never enters the sum.
- Needs the head position, the direction and the queue
- A request at the head's own cylinder costs 0 and is served at once
- The answer changes with the starting direction
LOOK Disk Scheduling Example: 295 Cylinders
This is the queue every disk scheduling lesson here uses: requests 94, 183, 37, 122, 14, 140, 65 on a disk of cylinders 0 to 199, head at 57 and moving up.
Going up, the head serves 65, 94, 122, 140 and 183: 8 + 29 + 28 + 18 + 43 = 126. Nothing waits above 183, so it reverses there. Going down it serves 37 (146) and 14 (23). Total head movement: 295 cylinders. Average seek per request: 295 / 7 ≈ 42.1.
Had the head been moving down at 57, the order would be 37, 14, then 65 up to 183: 20 + 23 + 51 + 29 + 28 + 18 + 43 = 212. Always state the direction before working the answer; it is part of the question.
- Order moving up: 65, 94, 122, 140, 183, 37, 14
- Up: 126, then one long move of 146, then 23
- Moving down first: 212, because the short side is served first
LOOK vs SCAN
Both serve the same requests in the same order. The only difference is where the head turns. SCAN continues from 183 to cylinder 199 and comes back, so it pays 16 cylinders twice: 327 against LOOK's 295.
That gives a quick check for any answer: the saving is twice the gap between the outermost request and the disk edge in the starting direction. If a request sits at cylinder 199 the gap is 0 and the two totals match.
The gap can be most of the trip. With the head at 57 moving up and only 37 and 14 waiting, LOOK reverses at once and moves 43 cylinders. SCAN still goes up to 199 and back: 327 for two requests.
| SCAN | LOOK | |
|---|---|---|
| Turns at | Cylinder 199, the disk edge | 183, the highest request |
| Ends at | 14 | 14 |
| Total head movement | 327 | 295 |
| Needs the disk size | Yes | No |
| Longest possible wait | About two full-disk sweeps | About two sweeps of the request range |
- Same order, different turning point
- Saving = 2 × (edge − outermost request)
- Equal totals when a request sits on the edge
LOOK on the head-57 queue
def look(requests, head):
above = sorted(c for c in requests if c >= head)
below = sorted((c for c in requests if c < head), reverse=True)
# No disk edge: the head turns at the outermost pending request.
order = above + below
total, position = 0, head
for cylinder in order:
total += abs(cylinder - position)
position = cylinder
return order, total
order, total = look([94, 183, 37, 122, 14, 140, 65], 57)
print(*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 look(const vector<int>& requests, int head, vector<int>& order) {
// No disk edge: the head turns at the outermost pending request.
vector<int> above, below;
for (int c : requests) (c >= head ? above : below).push_back(c);
sort(above.begin(), above.end());
sort(below.rbegin(), below.rend());
for (int c : above) order.push_back(c);
for (int c : below) order.push_back(c);
int 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 = look(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 look(int[] requests, int head, List<Integer> order) {
// No disk edge: the head turns at the outermost pending request.
List<Integer> above = new ArrayList<>(), below = new ArrayList<>();
for (int c : requests) (c >= head ? above : below).add(c);
Collections.sort(above);
below.sort(Collections.reverseOrder());
order.addAll(above);
order.addAll(below);
int 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 = look(requests, 57, order);
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
Waiting Times and Edge Cases
LOOK cannot starve a request. The head reverses only when nothing is left ahead, so every request is reached within one trip out and one trip back. That is the difference from SSTF, which totals less here (228) but can leave a far request waiting while near ones keep arriving.
The waits are uneven, though. A request that arrives just behind the head as it turns waits the longest. On the example, a request for 175 arriving as the head leaves 183 waits 146 + 23 + 161 = 330 cylinders, while one arriving just ahead would wait 8. Cylinders in the middle are passed twice per round trip; the ends only once. C-LOOK serves in one direction only to even this out.
Two smaller cases come up in exams. If no request is ahead, the head reverses straight away. If every request is ahead, LOOK never reverses at all and the total is just the distance to the furthest one.
- No starvation: a request waits at most one trip out and back
- Just behind the turn is the worst place to arrive
- Middle cylinders get served more often than the ends
Where LOOK Is Used
Kernel elevators for hard disks behaved like LOOK rather than SCAN: they sorted pending requests by block number and turned when the sorted list ran out, because a seek to an empty edge buys nothing. Linux's bfq, its usual choice for rotational drives, still sorts and merges requests by position beneath its fairness rules.
On SSDs and NVMe drives there is no head to move, so the order saves nothing and Linux sets these devices to the none scheduler.
- Hard disks: request order by position, turning at the last request
- SSDs: no seek cost, so no reordering