Suppose that a disk drive has 200 cylinders, numbered 0 to 199. The work queue is: 23, 89, 132, 42, 187. Determine the total distance for the following disk scheduling algorithms. i. SCAN ii. LOOK
Q.) Suppose that a disk drive has 200 cylinders, numbered 0 to 199. The work queue is: 23, 89, 132, 42, 187. Determine the total distance for the following disk scheduling algorithms. i. SCAN ii. LOOK
Subject: Operating SystemTo calculate the total distance (also known as seek time) that the disk arm moves to access all the requested cylinders using the SCAN and LOOK disk scheduling algorithms, we need to know the initial position of the disk arm. For the purpose of this explanation, let's assume that the initial position of the disk arm is at cylinder 100 and that it is moving towards the higher numbered cylinders.
i. SCAN (also known as Elevator Algorithm)
The SCAN algorithm moves the disk arm towards one end of the disk, servicing all requests until it reaches the end, then reverses direction and services requests on the return trip. The arm continues to sweep back and forth across the disk, servicing requests as it reaches them.
Steps for SCAN:
- Move from the initial position towards the nearest end (in this case, towards cylinder 199 since we're initially closer to that end).
- Service all requests on the way.
- Once the end is reached, reverse direction.
- Service all remaining requests.
Calculation for SCAN:
- Initial position: 100
- Direction: Towards 199 (higher numbers)
- Requests: 23, 89, 132, 42, 187
The sequence of servicing requests will be: 100 -> 132 -> 187 -> 199 -> 89 -> 42 -> 23
Step | Current Position | Next Position | Distance Moved |
---|---|---|---|
1 | 100 | 132 | 32 |
2 | 132 | 187 | 55 |
3 | 187 | 199 | 12 |
4 | 199 (reverse) | 89 | 110 |
5 | 89 | 42 | 47 |
6 | 42 | 23 | 19 |
Total distance = 32 + 55 + 12 + 110 + 47 + 19 = 275 cylinders
ii. LOOK
The LOOK algorithm is similar to SCAN, but instead of going all the way to the end of the disk, the arm only goes as far as the last request in each direction, then reverses direction immediately without hitting the end of the disk.
Steps for LOOK:
- Move from the initial position towards the nearest end, servicing requests until the last request in that direction.
- Reverse direction before hitting the end of the disk.
- Service all remaining requests.
Calculation for LOOK:
- Initial position: 100
- Direction: Towards 199 (higher numbers)
- Requests: 23, 89, 132, 42, 187
The sequence of servicing requests will be: 100 -> 132 -> 187 -> 89 -> 42 -> 23
Step | Current Position | Next Position | Distance Moved |
---|---|---|---|
1 | 100 | 132 | 32 |
2 | 132 | 187 | 55 |
3 | 187 (reverse) | 89 | 98 |
4 | 89 | 42 | 47 |
5 | 42 | 23 | 19 |
Total distance = 32 + 55 + 98 + 47 + 19 = 251 cylinders
Summary Table
Algorithm | Total Distance |
---|---|
SCAN | 275 cylinders |
LOOK | 251 cylinders |
Conclusion
In this example, the LOOK algorithm results in a shorter total distance for the disk arm to travel compared to the SCAN algorithm. This is because LOOK does not waste movement going all the way to the end of the disk if there are no requests to service there.