write up 10
write up 10
10
Aim: To implement I/O scheduling algorithms (FCFS, LOOK and SSTF).
Theory: In operating systems, seek time is very important. Since all device requests are linked in
queues, the seek time is increased causing the system to slow down. Disk Scheduling Algorithms
are used to reduce the total seek time of any request. There are following disk scheduling
algorithms:
First Come-First Serve (FCFS)
Shortest Seek Time First (SSTF)
Elevator (SCAN)
Circular SCAN (C-SCAN)
LOOK
C-LOOK
Given the following queue -- 95, 180, 34, 119, 11, 123, 62, 64 with the Read-write head initially
at the track 50 and the tail track being at 199 let us now discuss the different algorithms.
1. First Come -First Serve (FCFS): All incoming requests are placed at the end of the queue.
Whatever number that is next in the queue will be the next number served.
Using this algorithm doesn't provide the best results. To determine the number of head
movements you would simply find the number of tracks it took to move from one request to the
next. For this case it went from 50 to 95 to 180 and so on. From 50 to 95 it moved 45 tracks. If
you tally up the total number of tracks you will find how many tracks it had to go through before
finishing the entire request. In this example, it had a total head movement of 640 tracks. The
disadvantage of this algorithm is noted by the oscillation from track 50 to track 180 and then
back to track 11 to 123 then to 64. As you will soon see, this is the worse algorithm that one can
use.
2. LOOK: The Look Disk Scheduling Algorithm is similar to the SCAN algorithm. In the
LOOK algorithm, the disk head moves to the last request (and not the end of the disk as is the
case for the SCAN algorithm) to be serviced in front of the head, then it reverses its direction and
services all the requests behind the disk head. This algorithm addresses the limitation of the
SCAN algorithm by preventing the extra delay used in traversing to the end of the disk when
there are no requests to be serviced.
1. Shortest Seek Time First (SSTF): In this case request is serviced according to next
shortest distance. Starting at 50, the next shortest distance would be 62 instead of 34 since it is
only 12 tracks away from 62 and 16 tracks away from 34. The process would continue until all
the process are taken care of. For example the next case would be to move from 62 to 64 instead
of 34 since there are only 2 tracks between them and not 18 if it were to go the other way.
Although this seems to be a better service being that it moved a total of 236 tracks, this is not an
optimal one. There is a great chance that starvation would take place. The reason for this is if
there were a lot of requests close to eachother the other requests will never be handled since the
distance will always be greater.
Algorithm
1. FCFS
Pseudo code for disk head movement: Move the head to the next requested cylinder in the queue.
No queue sorting is necessary.
2. LOOK:
3. SSTF:
1. Let the Request array represents an array storing indexes of tracks that have been requested.
‘head’ is the position of the disk head.
1. Find the positive distance of all tracks in the request array from the head.
2. Find a track from the requested array which has not been accessed/serviced yet and has a
minimum distance from the head
3. Increment the total seek count with this distance.
4. Currently serviced track position now becomes the new head position.
5. Go to step 2 until all tracks in the request array have not been serviced.