Unit-5 - Disk Scheduling IO MGMT
Unit-5 - Disk Scheduling IO MGMT
Operating System
Unit – 5
I/O Management & Disk
Scheduling
Unit-
Unit-57 I/O
I/O Management
Management &
& Disk
Disk Scheduling
Scheduling (Rashmi
(Rashmi rathi
rathi Upadhyay)
Upadhyay) 2
Principles of I/O Hardware: I/O device
Unit-
Unit-57 I/O
I/O Management
Management &
& Disk
Disk Scheduling
Scheduling (Rashmi
(Rashmi rathi
rathi Upadhyay)
Upadhyay) 3
Principles of I/O Hardware: I/O device
Two types of I/O • block, character
devices
Unit-
Unit-57 I/O
I/O Management
Management &
& Disk
Disk Scheduling
Scheduling (Rashmi
(Rashmi rathi
rathi Upadhyay)
Upadhyay) 4
Components of I/O devices
I/O devices have two components
1. Mechanical component - Device itself.
2. Electronic Component-
Known as device controller or adapter .
The controller card usually has a connector on it, into which a
cable leading to the device itself can be plugged
Unit-
Unit-57 I/O
I/O Management
Management &
& Disk
Disk Scheduling
Scheduling (Rashmi
(Rashmi rathi
rathi Upadhyay)
Upadhyay) 5
Device Controller
Unit-
Unit-57 I/O
I/O Management
Management &
& Disk
Disk Scheduling
Scheduling (Rashmi
(Rashmi rathi
rathi Upadhyay)
Upadhyay) 7
Device Controller
Each device controller has a few registers that are used for
communicating with the CPU.
By writing into these registers, the OS can command the device to
deliver data, accept data, switch itself on or off, or perform some
action.
By reading from these registers OS can learn what the device’s
status is, whether it is prepared to accept a new command and so
on.
There are two ways to communicate with control registers and the
device buffers:
1. I/O Port
2. Memory mapped I/O
Unit-
Unit-57 I/O
I/O Management
Management &
& Disk
Disk Scheduling
Scheduling (Rashmi
(Rashmi rathi
rathi Upadhyay)
Upadhyay) 8
Disk Architecture
Platter → Surface → Track → Sector → Data .
8*2*256*512*512KB
2(3)*2(1)*2(8)*2(9)*2(9)2(10)
2(40)
1TB
Unit-
Unit-57 I/O
I/O Management
Management &
& Disk
Disk Scheduling
Scheduling (Rashmi
(Rashmi rathi
rathi Upadhyay)
Upadhyay) 9
Disks
It is relatively permanent and can hold large quantities of data. Its
access time is slow compared with that of main memory and
magnetic disk. provide the bulk of secondary storage for modern
computer system.
disk platter: has a flat circular shape, like a CD. The two surfaces of
a platter are covered with a magnetic material. We store
information by recording it magnetically on the platters.
The surface of a platter is logically divided into circular tracks
which are subdivided into sectors. The set of tracks that are at one
arm position makes up a cylinder.
Unit-
Unit-57 I/O
I/O Management
Management &
& Disk
Disk Scheduling
Scheduling (Rashmi
(Rashmi rathi
rathi Upadhyay)
Upadhyay) 10
Disk Access time
Seek time – the time taken by r/w head to reach desired track.
Rotation time – the time for one full rotation (360◦).
Unit-
Unit-57 I/O
I/O Management
Management &
& Disk
Disk Scheduling
Scheduling (Rashmi
(Rashmi rathi
rathi Upadhyay)
Upadhyay) 11
Direct Memory Access
CPU could request data one byte at a time from I/O controller,
Big waste of time. So other schema can be used DMA.
DMA controller can access system bus independent of CPU. DMA
contains serval registers that can be written and read by CPU.
Memory address register
Byte count register
Control registers-I/O port, direction of transfer, transfer
units (byte/word), number of bytes to transfer in a burst.
Unit-
Unit-57 I/O
I/O Management
Management &
& Disk
Disk Scheduling
Scheduling (Rashmi
(Rashmi rathi
rathi Upadhyay)
Upadhyay) 12
How Disk read occurs when DMA is not used??
First the controller reads the block (one or more sectors) from the
drive serially, bit by bit, until the entire block is in the controller’s
internal buffer.
Next, it computes the checksum to verify that no read errors
have occurred. Then the controller causes an interrupt.
When the operating system starts running, it can read the disk
block from the controller’s buffer a byte or a word at a time by
executing a loop, with each iteration reading one byte or word
from a controller device register and storing it in main memory.
Unit-
Unit-57 I/O
I/O Management
Management &
& Disk
Disk Scheduling
Scheduling (Rashmi
(Rashmi rathi
rathi Upadhyay)
Upadhyay) 13
How Disk read occurs when DMA is not used??
Unit-
Unit-57 I/O
I/O Management
Management &
& Disk
Disk Scheduling
Scheduling (Rashmi
(Rashmi rathi
rathi Upadhyay)
Upadhyay) 15
How does DMA work?
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.
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.
Unit-
Unit-57 I/O
I/O Management
Management &
& Disk
Disk Scheduling
Scheduling (Rashmi
(Rashmi rathi
rathi Upadhyay)
Upadhyay) 16
How does DMA work?
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.
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.
Unit-
Unit-57 I/O
I/O Management
Management &
& Disk
Disk Scheduling
Scheduling (Rashmi
(Rashmi rathi
rathi Upadhyay)
Upadhyay) 17
Disk Arm Scheduling Algorithm
Various types of disk arm scheduling algorithms are available to
decrease mean seek time.
1. FCFS (First come first serve)
2. SSTF (Shorted seek time first)
3. SCAN
4. C-SCAN
5. LOOK (Elevator)
6. C-LOOK
Unit-
Unit-57 I/O
I/O Management
Management &
& Disk
Disk Scheduling
Scheduling (Rashmi
(Rashmi rathi
rathi Upadhyay)
Upadhyay) 18
Unit- 7 I/O Management & Disk Scheduling (Rashmi rathi Upadhyay) 19
FCFS (First come first serve)
Here requests are served in the order of their arrival.
0 1 9 12 16 34 36 50
11 1,
36,
1 16,
36 34,
9,
16 12
34
9
12
Unit-
Unit-57 I/O
I/O Management
Management &
& Disk
Disk Scheduling
Scheduling (Rashmi
(Rashmi rathi
rathi Upadhyay)
Upadhyay) 21
SSTF (Shortest seek time first)
We can minimize the disk movement by serving the request closest to the
current position of the head.
0 1 9 12 16 34 36 50
11 1,
36,
12 16,
9 34,
16 9,
12
1
34
36
Unit-
Unit-57 I/O
I/O Management
Management &
& Disk
Disk Scheduling
Scheduling (Rashmi
(Rashmi rathi
rathi Upadhyay)
Upadhyay) 23
LOOK (Elevator)
0 1 9 12 16 34 36 50
11 1,
36,
12
16,
16 34,
34 9,
12
36
9
1
Unit-
Unit-57 I/O
I/O Management
Management &
& Disk
Disk Scheduling
Scheduling (Rashmi
(Rashmi rathi
rathi Upadhyay)
Upadhyay) 25
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.
Unit-
Unit-57 I/O
I/O Management
Management &
& Disk
Disk Scheduling
Scheduling (Rashmi
(Rashmi rathi
rathi Upadhyay)
Upadhyay) 26
C-LOOK
0 1 9 12 16 34 36 50
11 1,
36,
12
16,
16 34,
34 9,
12
36
1
9
Unit-
Unit-57 I/O
I/O Management
Management &
& Disk
Disk Scheduling
Scheduling (Rashmi
(Rashmi rathi
rathi Upadhyay)
Upadhyay) 28
SCAN
0 1 9 12 16 34 36 50
11 1,
36,
12
16,
16 34,
34 9,
12
36
9 50
1
Unit-
Unit-57 I/O
I/O Management
Management &
& Disk
Disk Scheduling
Scheduling (Rashmi
(Rashmi rathi
rathi Upadhyay)
Upadhyay) 30
C-SCAN
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,9.
Total cylinder movement: (12-11) + (16-12) + (34-16) +(36-34) +(50-36) +
(50-0) + (1-0)+ (9-1) = 98
Unit-
Unit-57 I/O
I/O Management
Management &
& Disk
Disk Scheduling
Scheduling (Rashmi
(Rashmi rathi
rathi Upadhyay)
Upadhyay) 31
Disk Scheduling Algorithm
Q- Track no given= 55,58,39,18,90,160,150,38,184
A disk contains 0-199 tracks
Current position of r/w head is 100 and direction is towards larger
value of track
Calculate the total no of track movement of your r/w head for
FCFS, SSTF, SCAN,C-SCAN, LOOK AND C-LOOK?
Unit-
Unit-57 I/O
I/O Management
Management &
& Disk
Disk Scheduling
Scheduling (Rashmi
(Rashmi rathi
rathi Upadhyay)
Upadhyay) 32
Disk Scheduling Algorithm
Solution
FCFS=498
SSTF=248
SCAN= 280
C-SCAN=388
LOOK=250
C-LOOK=322
Unit-
Unit-57 I/O
I/O Management
Management &
& Disk
Disk Scheduling
Scheduling (Rashmi
(Rashmi rathi
rathi Upadhyay)
Upadhyay) 33
Unit- 7 I/O Management & Disk Scheduling (Rashmi rathi Upadhyay) 34