Week7
磁盘调度
What is a Disk?
1.A disk is a magnetic storage device which has a number of platters( or surfaces ).
2.The entire assembly of platters rotates as a unit at high speeds (typically 5000-10000 RPM for a fixed disk. )
3.The surface of each platter is organized as a concentric group of magnetic tracks which data can be stored.
4.Each track is divided into a number of blocks of fixed size ( typically 1024 bytes ) which the data is stored.
5.A block is the smallest amount of data that can be read from or written to the disk in a single I/O operation.
6.Each disk surface has a read/write head which can move linearly across the surface.
7.Data from the disk is requested by block number.
8.The disk controller moves the head to the correct track and then waits for the correct block to pass underneath it for access.
Seek time:
The slowest part of accessing a disk block is physically moving the head to the track.
Disk scheduling:
1.First Come First Served(FCFS)
2.Shortest Seek Time First(SSTF)
3.SCAN Algorithm
4.C-SCAN Algorithm
5.Look Algorithm(Elevator Algorithm)
Example Case:
1.First Come First Served(FCFS)
先来先服务
Order:
53 -> 98 -> 183 -> 37 -> 122 -> 14 -> 124 -> 65 -> 67
Seek Time = 45 + 85 + 156 + 85 + 108 + 110 + 59 + 2 = 650
2.Shortest Seek Time First(SSTF)
最短访问时间优先
在我所有的要访问的磁道里,我先访问理我目前位置最近的。
Order:
53 -> 65 -> 67 -> 37 -> 14 -> 98 ->122 -> 124 -> 183
Seek Time = 12 +2 + 30 +23 + 84 + 24 + 2 + 59 = 236
3.SCAN Algorithm
磁头选定一个方向,会一直朝那个方向移动,直到那个方向再没有磁道。之后再反方向顺序移动。一般是从外往里扫,(从大往小),这里是规定扫到0.
会提示你寻道方向,然后按照起始方向移动磁头,直到最小,然后再往大处走,直到最大再往回走,直到完成。往返移动
(一直到头)
前提条件加上轨道数从0到200并且正在往轨道数编号增加的方向移动
Order:
53 -> 65 -> 67 -> 98 -> 122 -> 124 -> 183 -> 200 -> 37 -> 14
Seek Time = 12 + 2 +31 + 24 +2 + 59 + 17 + 163 + 23 = 333
4.C-SCAN Algorithm
循环扫描
直到没有更外的磁道要扫描时,回到最里道从头开始扫描
类似于SCAN,但是它不来回移动,而是磁头移动方向是单向的,比如从大往小移动,那么达到最小值后,瞬间移动到后面的最大磁道处,再往小处移动,以此类推直到完成。
Order:
53 -> 65 -> 67 -> 98 -> 122 -> 124 -> 183 -> 200 -> 0 -> 14 -> 37
Seek Time = 12 + 2 +31 + 24 +2 + 59 + 17 + 200 + 37 = 384
5.Look Algorithm(Elevator Algorithm)
朝里(0)扫,扫到头再返回方向,与SCAN不同的是它这次不用非得到0,到最小的那个需求就可以了。
(SCAN加强版 )不需要走到头
Order:
53 -> 65 -> 67 -> 98 -> 122 -> 124 -> 183 -> 37 -> 14
Seek Time = 12 + 2 +31 + 24 +2 + 59 + 146 + 23 = 299
Summary - Algorithms
- Random scheduling ( RSS )
- First In, First Out ( FIFO ) , also known as First Come First Served ( FCFS )
- Last In, First Out ( LIFO )
- Shortest seek first , also know as Shortest Seek / Servie Time First ( SSTF )
- Elevator algorithm , also known as SCAN ( including its variants, C - SCAN, LOOK, and C - LOOK )
- N - Step - SCAN SCAN of N records at a time
- FSCAN, N - Step - SCAN where N equals queue size at start of the SCAN cycle