Disk Scheduling
Disk Scheduling
Outline
Looping
• I/O Devices
• Organization of I/O functions
• Operating System Design issues
• I/O Buffering
• Disk Arm Scheduling Algorithm
• FCFS/FIFO
• SSTF
• SCAN
• C-SCAN
• LOOK
• C-LOOK
• RAID
• Disk Cache
1
4/10/2024
Section - 1
I/O devices
External devices that engage in I/O with computer systems can be grouped into 3 categories:
1. Human readable, suitable for communicating with the computer user.
Examples: printers, terminals, video display, keyboard, mouse
2. Machine readable, suitable for communicating with electronic equipment.
Examples: disk drives, USB keys, sensors, controllers
3. Communication, suitable for communicating with remote devices.
Examples: modems, digital line drivers
Devices differ in a number of areas:
1. Data Rate: there may be differences of magnitude between the data transfer rates
2. Application: the use to which a device is put has an influence on the software
3. Complexity of Control: the effect on the operating system is filtered by the complexity of the I/O module
that controls the device
4. Unit of Transfer: data may be transferred as a stream of bytes or characters or in larger blocks
5. Data Representation: different data encoding schemes are used by different devices
6. Error Conditions: the nature of errors, the way in which they are reported, their consequences, and the
available range of responses differs from one device to another
2
4/10/2024
Section - 2
3
4/10/2024
• The I/O module is enhanced to become a separate processor, with a specialized instruction set tailored for
5 I/O
• The I/O module has a local memory of its own and is, in fact, a computer in its own right
6
4
4/10/2024
Bus
Step 1: First the CPU programs the DMA controller by setting its registers so it knows what to
transfer where.
It also issues a command to the disk controller telling it to read data from the disk into its
internal buffer and verify the checksum.
When valid data are in the disk controller’s buffer, DMA can begin.
10
5
4/10/2024
2. DMA
requests
DMA transfer to Disk Main
CPU Controller memory Controller Memory
Bus
Step 2: The DMA controller initiates the transfer by issuing a read request over the bus to the
disk controller.
This read request looks like any other read request, and the disk controller does not know (or
care) whether it came from the CPU or from a DMA controller.
11
2. DMA
requests
DMA transfer to Disk 3. Data Main
CPU Controller memory Controller transferred Memory
Bus
Typically, the memory address to write to is on the bus’ address lines, so when the disk
controller fetches the next word from its internal buffer, it knows where to write it.
Step 3: The write to memory is another standard bus cycle.
12
6
4/10/2024
2. DMA
requests
DMA transfer to Disk 3. Data Main
CPU Controller memory Controller transferred Memory
Bus
Step 4: When the write is complete, the disk controller sends an acknowledgement signal to the
DMA controller, also over the bus.
The DMA controller then increments the memory address to use and decrements the byte
count.
If the byte count is still greater than 0, steps 2 to 4 are repeated until it reaches 0.
13
2. DMA
requests
DMA transfer to Disk 3. Data Main
CPU Controller memory Controller transferred Memory
Bus
At that time, the DMA controller interrupts the CPU to let it know that the transfer is now
complete.
When the OS starts up, it does not have to copy the disk block to memory; it is already there.
14
7
4/10/2024
Section - 3
15
16
8
4/10/2024
Section - 4
17
Buffering
Perform input transfers in advance of requests being made and perform output transfers
some time after the request is made is called buffering.
Types of I/O devices:
Block oriented: A block-oriented device stores information in blocks that are usually of fixed size, and
transfers are made one block at a time.
Generally, it is possible to reference data by its block number.
Hard disks, floppy disks and optical drives such as DVD-ROM and CD-ROM are examples of block oriented
devices.
Stream oriented: A stream-oriented device transfers data in and out as a stream of bytes, with no block
structure.
Terminals, printers, communications ports, keyboard, mouse and other pointing devices, and most other
devices that are not secondary storage are stream oriented.
18
9
4/10/2024
I/O buffering
Operating System User Process
Without a buffer, Operating system directly accesses the
IN
I/O
Device
device when it needs
Operating System User Process Double buffer, Operating system use two system buffers
IN
instead of one, also known as buffer swapping. A
I/O MOVE
process can transfer data to or from one buffer while the
Device
operating system empties or fills the other buffer
Operating System User Process Circular buffer, Operating system uses two or more
buffers. Each individual buffer is one unit in a circular
IN MOVE
I/O .. buffer. Used when I/O operation must keep up with
Device
process
19
Section - 5
20
10
4/10/2024
21
22
11
4/10/2024
23
24
12
4/10/2024
25
LOOK
Keep moving in the same direction until there are no more outstanding requests pending in
that direction, then algorithm switches the direction.
After switching the direction the arm will move to handle any request on the way. Here first it
moves in up direction then goes in down direction.
In this algorithm, the software maintains 1 bit: the current direction bit, which takes the value
either UP or DOWN.
26
13
4/10/2024
LOOK
Here first it moves in up direction then goes in down direction
0 1 9 12 16 34 36 50
11 1,
36,
12
16,
16 34,
34 9,
12
36
9
1
27
C-LOOK
Keep moving in the same direction until there are no more outstanding requests pending in that
direction, then algorithm switches direction.
When switching occurs the arm goes to the lowest numbered cylinder with pending requests
and from there it continues moving in upward direction again.
28
14
4/10/2024
C-LOOK
Here first it moves in up direction then goes in down direction
0 1 9 12 16 34 36 50
11 1,
36,
12
16,
16 34,
34 9,
12
36
1
9
29
SCAN
From the current position disk arm starts in up direction and moves towards the end, serving
all the pending requests until end.
At that end arm direction is reversed (down) and moves towards the other end serving the
pending requests on the way.
This is also called as elevator algorithm.
30
15
4/10/2024
SCAN
Here first it moves in up direction then goes in down direction
0 1 9 12 16 34 36 50
11 1,
36,
12
16,
16 34,
34 9,
12
36
9 50
1
Disk movement will be 11, 12, 16, 34, 36, 50, 9 and 1.
Total cylinder movement: (12-11) + (16-12) + (34-16) +(36-34) +(50-36) + (50-9) + (9-1) = 88
31
C-SCAN
From the current position disk arm starts in up direction and moves towards the end, serving
request until end.
At the end the arm direction is reversed (down), and arm directly goes to other end and again
continues moving in upward direction.
32
16
4/10/2024
C-SCAN
Here first it moves in up direction then goes in down direction
0 1 9 12 16 34 36 50
11 1,
12 36,
16,
16
34,
34 9,
12
36
0 50
1
9
Disk movement will be 11, 12, 16, 34, 36, 50, 0, 1 and 9.
Total cylinder movement: (12-11) + (16-12) + (34-16) +(36-34) +(50-36) + (50-0) + (1-0)+ (9-1) =
98
33
34
17
4/10/2024
Section - 6
35
RAID
RAID (Redundant Array of Independent Disks)
RAID is a data storage virtualization technology that combines multiple physical disk drive
components into a single logical unit for the purposes of data redundancy, performance
improvement, large storage capacity or all.
Data is distributed across the drives in one of several ways, referred to as RAID levels,
depending on the required level of redundancy and performance.
All RAID have the property that the data are distributed over drives, to allow parallel operation.
There are 7 levels of RAID.
36
18
4/10/2024
RAID 0 (Striping)
It splits data (file) into blocks of data.
Stripe the blocks across disks in the system.
In the diagram to the right, the odd blocks are written to disk 1
and the even blocks to disk 2.
It is easy to implement.
No parity calculation overhead is involved.
It provides good performance by spreading the load across
many channels and drives.
It provides no redundancy or error detection.
Not true RAID because there is no fault tolerance. The failure of
just one drive will result in all data in an array being lost.
After certain amount of drives, performance does not increase
significantly.
It requires minimum 2 drives to implement.
37
RAID 1 (Mirroring)
A complete file is stored on a single disk.
A second disk contains an exact copy of the file.
It provides complete redundancy of data.
Read performance can be improved
same file data can be read in parallel
Write performance suffers
must write the data out twice
Most expensive RAID implementation.
It requires twice as much storage space.
In case a drive fails, data do not have to be rebuild, they just
have to be copied to the replacement drive.
The main disadvantage is that the effective storage capacity
is only half of the total drive capacity because all data get
written twice.
38
19
4/10/2024
39
40
20
4/10/2024
41
42
21
4/10/2024
43
Section - 7
44
22
4/10/2024
Disk Cache
A disk cache is a mechanism for improving the time it takes to read from or write to a hard disk.
A disk cache can also be a specified portion of random access memory (RAM) for disk sectors.
The disk cache holds data that has recently been read and, in some cases, adjacent data areas that
are likely to be accessed next.
45
Questions
1. Write a short note on DMA.
2. Briefly describe all Disk Arm Scheduling Algorithm.
3. Write short note on RAID.
4. Suppose Disk drive has 300 cylinders. The current position of head is 90. The queue of
pending request is 36,79,15,120,199,270,89,170 Calculate head movement for the following
algorithms. 1. FCFS 2. SSTF
5. Suppose that a disk drive has 200 cylinders from 0 to 199. The drive is currently at cylinder 53
and previous request at 43. The queue of pending requests in FIFO order is 98, 183, 37, 122,
14, 124, 65, [Link] from the current head position what is the total distance (in cylinder )
that the disk arm moves to satisfy all the pending requests for each of the following disk
scheduling algorithms: FCFS, SSTF, SCAN, LOOK, CLOOK, CSCAN.
46
23
4/10/2024
Questions
6. Define seek time and rotational latency. Assume that a disk drive has 200 cylinders,
numbered 0 to 199. The drive is currently serving a request at cylinder 100. The queue of
pending requests is 23, 89, 132, 42, 189. Calculate seek time for FCFS and SSTF disk
scheduling algorithm.
7. Suppose that a disk drive has 5000 cylinders, numbered 0 to 4999. The drive is currently
serving a request at cylinder 143,. The queue of pending requests, in FIFO order,86, 1470, 913,
1774, 948, 1509, 1022, 1750, 130Starting from current head position what is total distance (in
cylinders) that disk arm moves to satisfy all the pending request for FCFS and SSTF disk
scheduling algorithm?
47
24