Disk Scheduling Algorithms

Let us assume a simple disk model:

Diagram of disk model

The cost of a reading the data at track b is |b - h|, ignoring latency, waiting for the disk to rotate to the data, and acceleration of the disk head.


1) First-Come, First-Serve

Handles requests in a simple queue.

Assuming that the data is uniformly distributed, the average cost of random access for each h can be graphed as such:

Graph of average cost

Integrating the graph gives us the average cost of random access:

cost of random access = 1/3

This is pretty expensive!


2) Shortest Seek Time First

Always schedules closest request to disk head.


Now we seek inspiration from elevators. After all, elevator operators have handled the same problem long before OS programmers...

3) Elevator Algorithm

Tries to keep going in the same direction until we run out of jobs in that direction.


4) Circular Elevator Algorithm

Like the Elevator Algorithm, but it keeps going in the positive direction and immediately goes back to the lowest job when it reaches the end.


Example

Assume that the disk head is currently at cylinder 100, and cylinders 101, 98, 200, 96 requested in that order.
Here's what the algorithms above will do, and why:

Step FCFS SSTF Elevator Circular Elevator
1 101
1st job
101
closest job
101
closest job
101
closest job
2 98
2nd job
98
closest job
200
same direction
200
positive direction
3 200
3rd job
96
closest job
98
closest job in other direction
96
lowest job
4 96
4th job
200
closest job
96
same direction
98
positive direction
Total Cost 210 110 204 206

Problem With The Above Algorithms

They can't see the future! Suppose we have two processes that read files starting at cylinders 100 and 200, respectively:

OS Process 1 Process 2
Waiting for request Request cylinder 100 Request cylinder 200
Go to cylinder 100, queued request for cylinder 200 Request cylinder 101 Waiting for OS
Go to cylinder 200, queued request for cylinder 101 Waiting for OS Request cylinder 201
Go to cylinder 101, queued request for cylinder 201 Request cylinder 102 Waiting for OS
Go to cylinder 201, queued request for cylinder 102 Waiting for OS Request cylinder 202

And so on...All of the algorithms above will go back and forth because they don't know that the processes will request more cylinders close by.


5) Anticipatory Scheduling

After fulfulling a request, wait (for ~0.1 ms) in case the process wants to request more accesses close by.

We can easily solve the starvation problem by limiting the number of times we wait for a process.


Other File Systems

File systems don't have to be made from disks. They can be made from flash or from the network (LAN and cloud). However, they face similar problems of scheduling limited resources, whether it be seek time, IOPS, latency, bandwidth, etc.

File System Design

A file system is a data structure that lives on disk and provides and abstraction of a set of organized files.


1) Simple File System Created by Eggert in 1974 before he know any better.

Diagram of SFS

Features:


2) FAT (File Allocation Table)

Diagram of FAT

Features:

Super Block:

File Allocation Table:

Diagram of FAT on FAT filesystem

Directories in FAT:

Diagram of a directory entry

Pros and Cons:


3) UFS (Unix File System)

Diagram of UFS

Features:

inodes:

Diagram of inode entry

Directories in UFS:

Diagram of FAT

Compared to FAT:


Made by Jeff Chien and Ze (Albert) Yuan.