Relatively speaking, retrieving data from hard disk drivers is always slow compared to CPU and memory access due to the mechanical nature of the magnetic disk. Disk arm movement is very expensive operation therefore operating systems use disk scheduling algorithms to reduce seek time. Below you can find a summary of some of the well known disk scheduling algorithms. The algorithm receives a queue of request positions (track numbers) and the current head position. The output of the algorithm is the order in which the requests are serviced.
First Come First Serve (FCFS)
- Requests are serviced in the order in which they arrive
- The algorithm is easy to implement
- Bad algorithm as it may involve lots of unnecessary seek distance
- Queue: 100, 175, 51, 133, 8, 140, 73, 77
- Head: 63
- Seek order: 100, 175, 51, 133, 8, 140, 73, 77
- Seek distance = (100-63) + (175-100) + (175-51) + (133-51) +
- (133-8) + (140-8) + (140-73) + (77-73)
- = 646
Here is an example assuming we have 200 cylinders:
Shortest Seek Time First (SSTF)
- Service request with the shortest seek time from the current head position
- May starve some requests
- Good algorithm for a small list of requests
- Queue: 100, 175, 51, 133, 8, 140, 73, 77
- Head: 63
- Seek order: 73, 77, 51, 8, 100, 133, 140, 175
- Seek distance = 10 + 4 + 26 + 43 + 92 + 33 + 7 + 35 = 250
Here is an example:
Scan or Elevator Algorithm
- Disk arm starts at one end of the disk and moves towards the other end
- It services the requests as it moves then reverses the direction when it hits the other end
- Scan algorithms are good for heavy loads and more fair
- Queue: 100, 175, 51, 133, 8, 140, 73, 77
- Head: 63
- Seek order: 51, 8, 0, 73, 77, 100, 133, 140, 175
- Seek distance = 12 + 43 + 8 + 73 + 4 + 23 + 33 + 7 + 35 = 238
Here is an example:
C-Scan
- Similar to scan algorithm but the head returns to cylinder 0 when it reaches the end of the disk
- Treats the cylinder list as a circular list that wraps around the disk
- Waiting time is more uniform for cylinders near the edge of the disk
- Queue: 100, 175, 51, 133, 8, 140, 73, 77
- Head: 63
- Seek order: 73, 77, 100, 133, 140, 175, 199, 0, 8, 51
- Seek distance = 10 + 4 + 23 + 33 + 7 + 35 + 24 + 199 + 8 + 43
- = 387
Here is an example:
C-Look
- Similar to C-Scan but the head only travels as far as the last request in each direction
- Queue: 100, 175, 51, 133, 8, 140, 73, 77
- Head: 63
- Seek order: 73, 77, 100, 133, 140, 175, 8, 51
- Seek distance = 10 + 4 + 23 + 33 + 7 + 35 + 167 + 43
- = 322
Here is an example:
No comments:
Post a Comment