LECTURE-12 Disk Scheduling

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 44

SECONDARY STORAGE

STRUCTURE

P.Ray@HIT-CSE 1
The Memory Hierarchy

P.Ray@HIT-CSE 2
• Disks provide the bulk of secondary storage.
• All disks can be visualised as a large one
dimensional array of logical blocks.
• The block is the basic unit of data Transfer. The
size of all blocks is the same usually 512-bytes
but an option exists for choosing a different
block size.

P.Ray@HIT-CSE 3
Disk Structure
• A disk consists of sectors, tracks and cylinders.
• The one-dimensional array of logical blocks is
mapped on through all sectors in a track, then
through all tracks of a cylinder and through all
cylinders of a disk sequentially.
• This mapping converts a logical block address or
number into a physical block address consisting of
a cylinder number, a track number within that
cylinder and a sector number within the at track.
P.Ray@HIT-CSE 4
Organization of Hard Disk Structure of a platter
P.Ray@HIT-CSE 5
• Disk Access: Disk access time has two main
parts:
1. Seek time
2. Latency time

P.Ray@HIT-CSE 6
Seek Time:
• Seek time is the time needed for the disk arm to move
the head to the cylinder containing the desired sector.
• The seek time is dependent on the size of the disk
platter. Larger the platter, greater is the distance and
time.
• But the traversal time is not a uniform function of
distance only.
• It depends on the initial startup time and final settling
time.
• The typical average seek time is 10 ms.
P.Ray@HIT-CSE 7
Latency Time:
• Latency time is the time required for the disk
to rotate the desired sector under the disk
head.
• If r is the rotational speed, then the latency is
1/2r.

P.Ray@HIT-CSE 8
Transfer time:
• The Transfer time is the actual time taken to
transfer b-bytes from or to disk.

Ta (Total access time) = Seek Time + Latency + Transfer time

P.Ray@HIT-CSE 9
Disk Scheduling
• First-Come-First-Served (FCFS) Scheduling:
The first-cum-first-served (FCFS) disk
scheduling algorithm is the simplest of all the
algorithms.
• It is fair to all requests but does not guarantee
the fastest service.
P.Ray@HIT-CSE 10
• On a disk with 1000 cylinders, numbered 0 to 999,
compute the number of tracks the disk arm move
to satisfy all requests in the disk queue.
• Assume the last request serviced was at track 345
and the head is moving towards track 0. The disk
queue contains request for the following tracks:
123, 874, 692, 475, 105, 376
• Trace the path taken by FCFS scheduling and also
compute the total number of head movement.

P.Ray@HIT-CSE 11
• Ans: The disk head is initially positioned at
cylinder 345.
• Then according to the FCFS scheduling algorithm
the disk head will move from 345 to 123 and
then to 123, 874, 692, 475, 105 and finally to
376 in that order as shown in Figure.
• The total Head movement is
222+751+182+217+370+271 = 2013.
P.Ray@HIT-CSE 12
P.Ray@HIT-CSE 13
• A disk queue has the following requests to
tracks.
• The disk head is initially at cylinder 60.
• 87, 170, 40, 150, 36, 72, 66, 15

P.Ray@HIT-CSE 14
P.Ray@HIT-CSE 15
P.Ray@HIT-CSE 16
• Advantages of FCFS disk scheduling
– It is a very simple algorithm to implement.
– Improved response time as a request gets response in fair
amount of time.
• Disadvantages of FCFS disk scheduling
– It involves a lot of random head movements and disk
rotations.
– Throughput is not efficient.
– It is used in small systems only where VO efficiency is not
very important.
– FCFS is acceptable when the load on a disk is light. As the
load grows, FCFS tends saturate the device and the response
time becomes longer.
P.Ray@HIT-CSE 17
Shortest-Seek-Time-First (SSTF) Scheduling:
• To overcome the disadvantage in FCFS algorithm,
I/O requests close to the disk head need to be
serviced together before moving the head far away
for other requests.
• This assumption is the basis for the shortest-seek-
time-first (SSTF) algorithm.
• The algorithm selects the next request for service
as that request which will involve the minimum
seek time from the current disk position.
P.Ray@HIT-CSE 18
Shortest Seek Time Flrst (SSTF)
• This algorithm works on this principle. "When a disk
operation finishes, choose the request that is closest to
the current head position or choose the request that has
minimum seek time from the current head position."
• Consider again the previous example with the disk queue
as follows
(87, 170, 40, 150, 36, 72, 66, 15)
• The initial head position is say, 60. Now, closest to the
head position is the request at cylinder 66.
• Then, the closest to 66 is 72, closest request to 72 is 87
and so on. This is shown in Figure.
P.Ray@HIT-CSE 19
P.Ray@HIT-CSE 20
P.Ray@HIT-CSE 21
• Advantages of SSTF scheduling
– It minimizes latency.
– Better throughput than FIFO method.

P.Ray@HIT-CSE 22
Disadvantages of SSTF Seheduling
• Starvation may occur here. As we know that
requests arrive at random in a real system.
• Some process may have to wait for a long time until
its requests are satisfied, if new requests with
shorter seek time keep arriving. This may cause
starvation of some requests.
• SSTF services requests for those tracks which are
highly localized. So, the innermost and outermost
tracks receive poor service as compared to the
midrange tracks.
P.Ray@HIT-CSE 23
SCAN Elevator algorithm
• The principle used in this algorithm is as follows:
• "The disk head constantly moves from the most inner
cylinder to the outer cylinder and then it changes its
direction back towards the center.
• As the head moves, if there is a request for the current
disk position then it is satisfied.“
• This algorithm is sometimes called as the elevator
algorithm because the disk arm behaves just like an
elevator of a building, firstly it services all the request of
going up and then reaching at the top, it goes downward.
P.Ray@HIT-CSE 24
• The disk head progresses in a single direction ie.,
from the center of the disk to the edge or vice versa,
serving the closest request in that direction.
• When it runs out of requests in the direction it is
currently moving, it switches to the opposite
direction.
• This algorithm usually gives more equitable service
to all requests. In worst case, it can still lead to
starvation.
• While it is satisfying requests on one cylinder, other
requests for the same cylinder could arrive.
P.Ray@HIT-CSE 25
• Consider the previous disk queue again. That is,
• (87, 170. 40, 150, 36, 72, 66, 15). The head movement starts
from 60th cylinder.

Come at
last i.e. 180

P.Ray@HIT-CSE 26
P.Ray@HIT-CSE 27
• So, we observe here that if any request comes
on its way, it will be serviced immediately
while the request arriving just behind the head
will have to wait until disk head moves to the
end of the disk, reverses direction and returns
before being serviced.

P.Ray@HIT-CSE 28
• Advantages of SCAN algorithm
– The throughput is better then FIFO.
– It has been the basis of most disk scheduling
strategies.
– It eliminates the discrimination inherent in SSTF
Schemes.
– No starvation problems

P.Ray@HIT-CSE 29
Disadvantages of SCAN algorithm
• Because of the continuous scanning of disk from end to
end, the outer tracks are visited less often than the mid
range tracks.
• Also, as the disk arm keeps scanning between two
extremes, this may result in wear and tear of the disk
assembly.
• Certain requests arriving ahead of the arm position would
get immediate service but some other requests that arrive
behind the arm position will have to wait for the arm to
return back. So, this algorithm is not fair.

P.Ray@HIT-CSE 30
C-SCAN Algorithm/One-way Elevator Algorithm
• C-SCAN stands for circular-SCAN and is so called because
this algorithm treats the cylinder as a circular list.
• C-SCAN is similar to SCAN but I/O requests are only satisfied
when the drive head is moving in one direction across the
surface of the disk.
• Principle: The head sweeps from the innermost cylinder to
the outermost cylinder satisfying the waiting requests in
order of their locations.
• When it reaches the outermost cylinder, it sweeps back to
the innermost cylinder, without satisfying any requests and
then starts again.

P.Ray@HIT-CSE 31
Reach at
end, here it
is starting
point

Reach
at
end

P.Ray@HIT-CSE 32
• Advantages of C-SCAN algorithm
– It is more fair as compared to SCAN.
– It provides more uniform waiting time

P.Ray@HIT-CSE 33
Disadvantages of C-SCAN algorithm

• The time taken for the back swing has been


ignored.
• The average head movements in this algorithm
is more as compared to SCAN algorithm.
• This method increases the total seek time
because of the long seek from the edge back to
the hub.
P.Ray@HIT-CSE 34
LOOK/SEEK algorithm
• The principle of this algorithm is as follows
• "The drive sweeps across the surface of the
disk in alternating directions, satisfying
requests. But now, the drive makes use of the
information it has about the locations
requested by the waiting requests."
P.Ray@HIT-CSE 35
• Consider an example to understand it. Say,
disk queue has this request
• (87, 170, 40, 150, 36, 72, 66, 15) and starting
cylinder 60th (again).

P.Ray@HIT-CSE 36
Not
going at
the end

P.Ray@HIT-CSE 37
C-LOOK/ C-SEEK algorithm
• C-LOOK stands for circular - LOOK algorithm.
It is a variation of LOOK where requests are
satisfied only when the head moves
outwards, as in C-SCAN.
• Thus, no request is satisfied when the head
moves inwards after determining that no
requests are there beyond the current point.
P.Ray@HIT-CSE 38
• Consider an example to understand this. Say,
the I/O request queue is
• (23, 89, 132, 42, 187).
• The disk head starts at number 100.
• So, disk movement will be from 100 to 89 (as
89 comes on its way while moving to the other
end), (89 to 42), (42 to 23),. (23 to 187) and
(187 to 132). So, we draw a graph in next
figure.
P.Ray@HIT-CSE 39
(23, 89, 132, 42, 187).

P.Ray@HIT-CSE 40
P.Ray@HIT-CSE 41
P.Ray@HIT-CSE 42
P.Ray@HIT-CSE 43
P.Ray@HIT-CSE 44

You might also like