先决条件 – 磁盘调度算法
1. FCFS 磁盘调度算法:
先到先得,顾名思义,该算法按照任务到达磁盘队列的顺序来处理任务。它是最简单易懂的磁盘调度算法。在这种情况下,头部或指针向任务到达的方向移动,并移动直到所有请求都得到服务。 FCFS 提供更多的平均等待时间和响应时间。然而,FCFS 算法在处理即将到来的请求方面有更公平的策略。
例子:
考虑一个有 200 个磁道 (0-199) 的磁盘,磁盘队列的 I/O 请求顺序如下:
98, 183, 40, 122, 10, 124, 65
Read\Write 磁头当前磁头位置为 53。使用 FCFS 算法计算 Read/Write 磁头的磁道移动总数。
总的头部运动,
= (98-53)+(183-98)+(183-40)+(122-40)+(122-10)+(124-10)+(124-65)
= 640
2. SSTF 磁盘调度算法:
SSTF 代表 Shortest Seek Time First,顾名思义,它服务于最接近当前头部或指针位置的请求。在这个算法中,头指针的方向很重要。如果不知何故,我们遇到请求之间的联系,则头部将在其正在进行的方向上为请求提供服务。与 FCFS 相比,SSTF 算法在寻道时间上非常有效。
例子:
考虑一个有 200 个磁道 (0-199) 的磁盘,磁盘队列的 I/O 请求顺序如下:
98, 183, 40, 122, 10, 124, 65
Read\Write 磁头的当前磁头位置为 53,将向右移动。使用SSTF算法计算读/写磁头的磁道移动总数。
总的头部运动,
= (65-53)+(65-40)+(40-10)+(98-10)+(122-98)+(124-122)+(183-124)
= 240
FCFS和SSTF磁盘调度算法的区别:
FCFS SCHEDULING ALGORITHM | SSTF SCHEDULING ALGORITHM | |
---|---|---|
1. | FCFS is not efficient in seek movements. | SSTF is very effective/efficient in seek movements. |
2. | It results in increased total seek time. | It reduces the total seek time as compared to FCFS. |
3. | It provides more average waiting time and response time. | This algorithm provides less average response time and waiting time. |
4. | In this algorithm direction of head does not matters much, which we can clearly see in above example. | But here direction of head plays an important role, in order to break tie between requests and above example is a proof of it. |
5. | This algorithm is the easy to understand and implement. | Here, there is an overhead of finding out the closest request. |
6. | FCFS does not cause starvation to any request (but may suffer from Convoy effect.). | Here, the request which are far from head will suffer starvation. |
7. | In FCFS algorithm there is decrement in Throughput. | Here in SSTF there is increment in Throughput. |