Facebook Pixel

LOOK and C-LOOK Disk Scheduling

When multiple read/write requests pile up for a disk, the system needs a smart way to handle them. LOOK and C-LOOK are two algorithms that do this well, both building on the ideas behind SCAN but trimming away the wasteful parts.

LOOK Disk Scheduling

LOOK works like a smart elevator that stops at the last floor someone requested rather than riding all the way up to the top or down to the basement.

The disk arm sweeps in one direction, serving every request it encounters, and turns around the moment it hits the furthest pending request. There is no reason to travel all the way to the disk boundary if no one is waiting there.

Worked Example (LOOK)

Suppose a disk has cylinders numbered 0 to 299. The head sits at cylinder 90, moving right. Pending requests are at: 45, 120, 200, 60, 260, 150.

MovementCalculationDistance
90 to 120|90 - 120|30
120 to 150|120 - 150|30
150 to 200|150 - 200|50
200 to 260|200 - 260|60
260 to 60|260 - 60| (Reverses at last request)200
60 to 45|60 - 45|15

Total Head Movement = 30 + 30 + 50 + 60 + 200 + 15 = 385 cylinders.

Notice the efficiency: the head turned around at 260, not at the boundary 299. That saved 39 unnecessary cylinders of travel compared to a standard SCAN algorithm.

C-LOOK Disk Scheduling

C-LOOK (Circular LOOK) takes the same logic a step further. Instead of reversing direction after the last request, the head jumps straight to the furthest request on the opposite end and continues scanning in the same original direction.

This keeps wait times more consistent. No track region sits idle for long because the head cycles through the disk in one continuous direction.

Same Example with C-LOOK

Starting at 90, moving right. Same requests: 45, 120, 150, 200, 260, 60.

MovementCalculationDistance
90 to 120|90 - 120|30
120 to 150|120 - 150|30
150 to 200|150 - 200|50
200 to 260|200 - 260|60
260 to 45|260 - 45| (Jump to furthest request on left)215
45 to 60|45 - 60| (Continue right)15

Total Head Movement = 30 + 30 + 50 + 60 + 215 + 15 = 400 cylinders.

While the total movement is slightly higher than LOOK because of the reset jump, the benefit is that all requests get serviced with a more uniform and predictable delay.

LOOK vs C-LOOK Trace Graph

Comparing LOOK (left) and C-LOOK (right). Unlike SCAN/C-SCAN, these algorithms turn around or jump immediately after the last request instead of going to the disk edges.

C++ Implementation

cpp
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int look_disk_scheduling(vector<int> requests, int head, string direction) {
    sort(requests.begin(), requests.end());
    int total_head_movement = 0;
    int index = 0;

    for (int i = 0; i < (int)requests.size(); i++) {
        if (head < requests[i]) {
            index = i;
            break;
        }
        index = requests.size();
    }

    vector<int> left(requests.begin(), requests.begin() + index);
    vector<int> right(requests.begin() + index, requests.end());

    if (direction == "right") {
        for (int r : right) {
            total_head_movement += abs(head - r);
            head = r;
        }
        reverse(left.begin(), left.end());
        for (int r : left) {
            total_head_movement += abs(head - r);
            head = r;
        }
    } else {
        reverse(left.begin(), left.end());
        for (int r : left) {
            total_head_movement += abs(head - r);
            head = r;
        }
        for (int r : right) {
            total_head_movement += abs(head - r);
            head = r;
        }
    }

    return total_head_movement;
}

int clook_disk_scheduling(vector<int> requests, int head, string direction) {
    sort(requests.begin(), requests.end());
    int total_head_movement = 0;
    int index = 0;

    for (int i = 0; i < (int)requests.size(); i++) {
        if (head < requests[i]) {
            index = i;
            break;
        }
        index = requests.size();
    }

    vector<int> left(requests.begin(), requests.begin() + index);
    vector<int> right(requests.begin() + index, requests.end());

    if (direction == "right") {
        for (int r : right) {
            total_head_movement += abs(head - r);
            head = r;
        }
        if (!left.empty()) {
            total_head_movement += abs(head - left[0]);
            head = left[0];
            for (int r : left) {
                total_head_movement += abs(head - r);
                head = r;
            }
        }
    } else {
        reverse(left.begin(), left.end());
        for (int r : left) {
            total_head_movement += abs(head - r);
            head = r;
        }
        if (!right.empty()) {
            total_head_movement += abs(head - right.back());
            head = right.back();
            reverse(right.begin(), right.end());
            for (int r : right) {
                total_head_movement += abs(head - r);
                head = r;
            }
        }
    }

    return total_head_movement;
}

int main() {
    vector<int> requests = {45, 120, 200, 60, 260, 150};
    int head = 90;
    string direction = "right";

    cout << "Total head movement using LOOK:   "
         << look_disk_scheduling(requests, head, direction)
         << " cylinders" << endl;

    cout << "Total head movement using C-LOOK: "
         << clook_disk_scheduling(requests, head, direction)
         << " cylinders" << endl;

    return 0;
}

Strengths and Limitations

LOOK and C-LOOK both outperform SCAN and C-SCAN on average seek time because they skip the 'dead travel' to disk boundaries. Neither wastes movement on empty stretches at the ends of the disk.

However, they both share a potential weakness: requests sitting far from the current head location can wait longer than necessary under extremely heavy load.

In practice, C-LOOK is often preferred in systems where uniform response time is critical, as the one-way circular sweep ensures no part of the disk is neglected for too long.

SCAN vs LOOK Efficiency

Question 1 of 1

Test your understanding of the difference between SCAN and LOOK.

What is the primary technical difference between the SCAN algorithm and the LOOK algorithm?
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.