OS_3141601_Unit7_IO_Management
OS_3141601_Unit7_IO_Management
Blocked Character
Bus
Disk read-write without a DMA
• Then the controller causes an
Drive
interrupt, so that OS can read the
block from controller’s buffer (a Disk Main
byte or a word at a time) by CPU Controller Buffer Memory
executing a loop.
• After reading every single part of
the block from controller device
register, the operating system will
store them into the main memory.
Bus
Disk read-write using DMA
Drive
1. CPU
programs DMA Disk Main
CPU DMA Controller Controller Memory
Buffer
controller
Address
Count
Control
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.
Disk read-write using DMA
Drive
1. CPU
programs DMA Disk Main
CPU DMA Controller Controller Memory
Buffer
controller
Address 2. DMA
Count requests
transfer to
Control
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.
Disk read-write using DMA
Drive
1. CPU
programs DMA Disk Main
CPU DMA Controller Controller Memory
Buffer
controller
Address 2. DMA
Count requests
transfer to 3. Data
Control
memory transferred
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.
Disk read-write using DMA
Drive
1. CPU
programs DMA Disk Main
CPU DMA Controller Controller Memory
Buffer
controller 4. ACK
Address 2. DMA
Count requests
transfer to 3. Data
Control
memory transferred
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.
Disk read-write using DMA
Drive
1. CPU
programs DMA Disk Main
CPU DMA Controller Controller Memory
Buffer
controller 4. ACK
Address 2. DMA
Count requests
transfer to 3. Data
Control
memory transferred
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.
Modes of bus operation
The buses can be operated in two modes
1. Word-at-a-time mode: Here the DMA requests for the transfer
of one word and gets it.
• If CPU wants the bus at same time then it has to wait.
• This mechanism is known as Cycle.
2. Block mode: Here the DMA controller tells the device to acquire
the bus, issues a series of transfer and then releases the bus.
• This form of the operation is called Burst mode.
• It is more efficient then cycle stealing.
Goals of I/O Software
1. Device independence
• It should be possible to write programs that can access any I/O
devices without having to specify device in advance.
• For example, a program that reads a file as input should be able to
read a file on a floppy disk, on a hard disk, or on a CD-ROM,
without having to modify the program for each different device.
2. Uniform naming
• Name of file or device should be some specific string or number. It
must not depend upon device in any way.
• All files and devices are addressed the same way: by a path name.
Goals of I/O Software
3. Error handling
• Error should be handled as close to hardware as possible.
• If any controller generates error then it tries to solve that error
itself. If controller can’t solve that error then device driver should
handle that error, perhaps by reading all blocks again.
• Many times when error occurs, error is solved in lower layer. If
lower layer is not able to handle error then problem should be
told to upper layer.
• In many cases error recovery can be done at a lower layer without
the upper layers even knowing about error.
Goals of I/O Software
4. Synchronous vs. asynchronous transfers
• Most of devices are asynchronous device. CPU starts transfer and
goes off to do something else until interrupt occurs.
• I/O Software needs to support both the types of devices.
5. Buffering
• Data comes in main memory cannot be stored directly.
• For example data packets come from the network cannot be
directly stored in physical memory.
• Packets have to be put into output buffer for examining them.
• Some devices have several real-time constraints, so data must be
put into output buffer in advance to decouple the rate at which
buffer is filled and the rate at which it is emptied, in order to avoid
buffer under runs.
Device driver
I/O devices which are plugged with computer have some specific
code for controlling them. This code is called the device driver.
Each device driver normally handles one device type, or at most
one class of closely related devices.
Generally device driver is delivered along with the device by
device manufacturer.
Device drivers are normally positioned below the rest of Operating
System.
Logical positioning of device drivers
User User
Space Programs
Rest of
Operating System
Kernel
Space
Printer CD-Rom
Driver Driver
Printer CD-Rom
Hardware
Controller Controller
Device
Functions of device drivers
1. Device driver accept abstract read and write requests from
device independent software.
2. Device driver must initialize the device if needed.
3. It also controls power requirement and log event.
4. It also checks statues of devices. If it is currently in use then
queue the request for latter processing. If device is in idle state
then request can be handled now.
5. Pluggable device can be added or removed while the computer is
running. At that time the device driver inform CPU that the user
has suddenly removed the device from system.
Device Independent I/O Software
Exact boundary between the drivers and the device independent
I/O software is system dependent.
Function of device independent I/O Software
1. Uniform interfacing for device drivers.
2. Buffering.
3. Error Reporting.
4. Allocating and releasing dedicated devices.
5. Providing a device-independent block size.
Uniform interfacing for device drivers
A major issue of an OS is how to make all I/O devices and drivers
look more or less the same.
One aspect of this issue is the interface between the device
drivers and the rest of the OS.
Uniform interfacing for device drivers
• Figure shows situation in
which each device driver has
a different interface to OS, it
means that interfacing each
new driver requires a lot of
new programming effort.
Uniform interfacing for device drivers
• Figure shows a different
design in which all drivers
have the same interface.
• Now it becomes much easier
to plug in a new driver.
Buffering
Buffering is also issue, both for block and character devices.
In case of a process, which reads the data from the modem,
without buffering the user process has to be started up for every
incoming character.
We have four different options:
1. Unbuffered input
2. Buffering in user space
3. Buffering in kernel followed by user space
4. Double buffering in kernel space
Unbuffered input
• No buffer available in user space or
kernel space. User User
Space Programs
• Allowing a process to run many
times for short runs is inefficient, so
this design is not a good one. Kernel
Space
Modem
Buffering in user space
• Buffer in users pace: here user
process provides an n-character User
buffer in user space and does a read Space
of n-characters.
Kernel
Space
Modem
Buffering in kernel space followed by user space
• Buffer inside kernel: to create the
buffer inside the kernel and User
interrupt handler is responsible to Space
Modem
Double buffering in kernel space
• Two buffers in kernel: the first buffer
is used to store characters. When it User
is full, it is being copied to user Space
Modem
Error Reporting
Errors are far more common in the context of I/O than in other
context. When they occur, the OS must handle them as best it can.
One class of I/O errors is programming errors. These occur when a
process asks for something impossible, such as writing to an input
device or reading from an output device.
The action taken for these errors is, to report an error code back
to the caller.
Another class of error is the class of actual I/O errors, for example
trying to write a disk block that has been damaged.
In this case, driver determines what to do and if it does not know
the solution then the problem may be passed to the device
independent software.
Allocating and releasing dedicated devices
Some devices such as CD-ROM recorders can be used only by a
single process at any given moment.
A mechanism for requesting and releasing dedicated devices is
required.
An attempt to acquire a device that is not available blocks the
caller instead of failing.
Blocked processes are put on a queue, sooner or later the
requested device becomes available and the first process on the
queue is allowed to acquire it and continue execution.
Providing a device-independent block size
Different disks may have different sector sizes.
It is up to the device independent I/O software to hide this fact
and provide a uniform block size to higher layers.
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.
RAID 0
• 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.
RAID 0
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.
RAID 1
• 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
RAID 1
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.
RAID 1
Software RAID 1 solutions do not always allow a hot swap of a
failed drive.
That means the failed drive can only be replaced after powering
down the computer it is attached to.
For servers that are used simultaneously by many people, this may
not be acceptable. Such systems typically use hardware controllers
that do support hot swapping.
RAID 2
It stripes data at bit level (rather than block level) with dedicated
Hamming-code parity.
It uses ECC (Error Correcting Code) to monitor correctness of
information on disk.
A parity disk is then used to reconstruct corrupted or lost data.
RAID 2
Imagine splitting each byte into a pair of 4-bit nibbles, then
adding Hamming code to each one to form a 7-bit word, of which
bit 1, 2 and 4 were parity bits.
In this RAID level 2 each of seven drives needs synchronized in
terms of arm position and rotational position, and then it would
be possible to write the 7-bit Hamming coded word over the
seven drives.
Here, losing one drive did not cause problem, which can be
handled by Hamming code on the fly.
Big problem is performance
• must have to read data plus ECC code from other disks
• for a write, must have to modify data, ECC, and parity disks
RAID 3
This technique uses striping and dedicates one drive for storing
parity information.
Here single parity bit is computed for each data word and written
to a parity drive.
The embedded ECC information is used to detect errors.
As in RAID level 2 the drives must be exactly synchronized.
RAID 4
This level uses large stripes (block level striping), which means
you can read records from any single drive.
They do not require synchronization of drives.
RAID 4
RAID level 4 is like RAID level 0, with strip-for-strip parity written
onto an extra drive, for example, if each strip is k bytes long, all
strips are EXCLUSIVE ORed together, resulting in a parity strip k
bytes long.
If a drive crashes, the lost bytes can be recomputed from the
parity drive by reading the entire set of drives.
This design protects against the loss of a drive but performs poorly
for small updates, if one sector is changed, it is necessary to read
all the drives in order to recalculate the parity.
It creates heavy load on parity drive.
RAID 5
This level is based on block-level striping with parity.
The parity information is striped across each drive.
RAID 5
As with RAID level 4, there is a heavy load in the parity drive, it
may become bottleneck.
This bottleneck can be eliminated in RAID level 5 by distributing
the parity bits uniformly over all the drives.
Definitions
Seek time: The time to move the arm to the proper cylinder.
Rotational delay: The time for the proper sector to rotate under
the head.
Disk Arm Scheduling Algorithm
Various types of disk arm scheduling algorithms are available to
decrease mean seek time.
1. FCSC (First come first serve)
2. SSTF (Shorted seek time first)
3. SCAN
4. C-SCAN
5. LOOK (Elevator)
6. C-LOOK
Example for Disk Arm Scheduling Algorithm
Consider an imaginary disk with 51 cylinders. A request comes in
to read a block on cylinder 11. While the seek to cylinder 11 is in
progress, new requests come in for cylinders 1, 36, 16, 34, 9, and
12, in that order.
Starting from the current head position, what is the total distance
(in cylinders) that the disk arm moves to satisfy all the pending
requests, for each of the following disk scheduling Algorithms?
FCSC (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
9 50
1
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
Examples for Disk Arm Scheduling Algorithm
Consider an imaginary disk with 45 cylinders. A request comes in
to read a block on cylinder 20. While the seek to cylinder 20 is in
progress, new requests come in for cylinders 10, 22, 20, 2, 40, 6,
and 38 in that order.
Starting from the current head position, what is the total distance
(in cylinders) that the disk arm moves to satisfy all the pending
requests and how much seek time is needed for, for each of the
disk scheduling algorithms if a seek takes 6 msec per cylinder
moved?
Assignment-5
1. Write a short note on DMA.
2. Explain storage structure.
3. Which are the major goals of I/O software?
4. Explain the use of Controller in I/O transfer.
5. Define following 1) Interrupt
6. Briefly describe all Disk Arm Scheduling Algorithm.
7. 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
8. 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, 67.Starting 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
9. 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?
10. 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.