Unit 5
Unit 5
Unit 5
I/O Systems:
Overview of I/O Systems:
Categories of I/O Devices are
Storage Devices Or Machine Readable:
It is suitable for communicating with electronic equipment.Such as Disks and Tapes.
Transmission Devices or Communication:
It is suitable with communicating with remote devices.Such as Network Card and
Modems.
Human Interface Devices:
It is suitable with communicating with the computer user.Such as Screen, Keyboard
and Mouse.
Difference between I/O Devices:
Data rate:There may be differences of several orders of size (Magnitude) between
the data transfer rates.
Application:Different devices have different use in the system
Complexity of control:A disk is much more complex whereas printer requires simple
control interfaces.
Unit if transfer:Data may be transferred as a stream of bytes or characters or in
larger block
Data representation:Different data encoding schemes are used for different devices.
Error Conditions: The nature of errors differs widely from one device to another
device.
I/O Hardware:
A device is communicated along with a system by passing the signals through a cable or by
air, port or bus.
A connection point or port is used to communicate the device with the machine.
Example: Serial Port.
Given Below the Figure: Typical Structure of PCI bus:
Bus: If one or more devices use a common set of wires, the connection is called as bus.
PC Bus System: It is used to connect the processor memory subsystem to the fast
devices.Here an expansion bus is used to connect the slow devices like keyboard, serial and
parallel ports. With the SCSI bus, four disks are connected and this is plugged into the SCSI
controller.
T.Krishnakumar Lecture/IT Operating System Notes Unit
2 5
Control Register: This can be used by a host for starting a command or change the
device made.
Data-in Register: It is read by the host to get input.
Data-out Register: It is written by the host to send output.
1. Polling:
The processors inform the operating system of events such as program execution or changes
in devices.A processor can do so by repeatedly requesting the status of each device, a
technique called polling or also called as busy waiting.
Hand shaking:
The interaction between the host and the controller can be done using hand shaking concept.
This can be done the following steps. They are:
i. The busy bit is read by the host repeatedly until is cleared.
ii. The host sets the write bit in the command register and writes a byte into the data out
register.
iii. If the command bit ready is set sets the busy bit.
iv. The controller also reads the command register and it looks the write command.
It reads the data out register to have the byte and it does the I/O to the devices.
v. To represent the I/O is successfully completed, the controller
Clears the command ready bit
Clears the error bit in the status register
Clears the busy bit
This loop is repeated for each byte.
2. Interrupts:
The CPU hardware has a wire called the interrupt request line which is sensed by the CPU at
the end of the execution of every instruction.
When the CPU detects that controller has open a signal on the interrupt request wire, the CPU
saves the current state and jumps to the interrupt- handler routine at a fixed addresses in
memory.
The interrupt handler defines the reason of the interrupt, performs the necessary processing
and execution a return from interrupt instruction to return the CPU to the execution earlier to
the interrupt.
T.Krishnakumar Lecture/IT Operating System Notes Unit
4 5
If the data transfer is wholly completed then the DMA controller interrupts the CPU.
The system performance can be achieved by unloading the data transfer work to a DMA
controller.
Direct Virtual Memory Access (DVMA):
It uses virtual addresses which perform virtual to physical memory address translation.
The data transfer is done in-between the two memory mapped devices by the DVMA without
getting any help from the CPU or main memory.
___________________________________________________________________________
Application I/O Interface:
Sequential or random-access:
A sequential device transfer data in a fixed order determined by the device, whereas
the user of a random access device can instruct the device to search for to any of the
available data storage locations.
Synchronous or Asynchronous:
A synchronous device is one that performs data transfer with predictable response
times.An asynchronous device exhibits irregular or unpredictable response time.
Sharable or dedicated;
A sharable device can be used concurrently by several processes or threads; a
dedicated device cannot.
Speed of operation:
Device speeds range from a few bytes per second to a few gigabytes per second.
read-write, read only, or write only:
Some devices perform both input and output, but others support only one data
direction.
Charactertics of IO devices:
__________________________________________________________________________
This is the innermost layer of the operating system close to the hardware and controlling the
actual hardware.
It is the heart of the operating system.
Kernel I/O subsystem provides following services:
Scheduling
Buffering
Caching
Spooling andDevice reservation
Error Handling
I/O Scheduling:
It is a process in which a good order is found to execute the set of I/O requests.
Generally scheduling
Can increases the overall system performance
Can share the device access fairly below the operation.
May minimize the average waiting time for I/O to complete.
Operating system developers implement scheduling by maintaining a queue of request for
each device.
When an application issues a blocking I/O system call, the request is placed on the queue for
that device.
The I/O scheduler rearranges the order of the queue to improve the overall efficiency and the
average response time.
Buffering:
It is a technique by which the device manager can keep slower I/O devices busy during times
when a process is not demanding I/O operations.
Reasons for Buffering:
1. Speed mismatch in between the producer and consumer of a data stream.
Example:
A file has to be obtained through a modem for storage on the hard disk.
But the modem is 100 times slower than hard disk.
i.e... Why a buffer is introduces to have the bytes which come from the modem.
Process
T.Krishnakumar Lecture/IT Operating System Notes Unit
11 5
Double Buffering:
There are two buffers in the system.
One buffer is for the driver or controller to store data while waiting for it to be
retrieved by higher level of the hierarchy.
Other buffer is to store data from the lower level module
It is also called as buffer swapping
Process
A B
A B
Device
2. The second reason for buffering is to adapt between the devices which holds different
data transfer size.
T.Krishnakumar Lecture/IT Operating System Notes Unit
12 5
This is mostly used in case of computer networking for the purpose of fragmentation
and reassembly of messages.
So a large message splitted into smaller fragments at the sender side.
Then these are passed through the communication network.
3. Buffering is needed for supporting the copy semantics for application I/O.
A simple strategy for copy semantics is for the write ( ) system call inorder to copy
the application data within the kernel buffer before returning the control to
application.
Caching:
To improve the performance, most systems perform caching by placing copies of information
that processes location in faster storage.
Due to the high cost of fast storage, caches can contain only a small portion of the
information contained in slower storage.
Caches can contain only a small portion of the information contained in slower storage.
Spooling and Device reservation:
It is a technique in which an intermediate device like a disk, it is cut in between a process and
a low speed or buffer limited I/O device.
Error Handling:
Generally the device and I/O transfers may fair in many ways.
They are
Transmit reasons: Example: Network becoming overloaded
Permanent reasons: Example: a disk controller becoming effective.
Operating system can frequently compensate effectively for temporary failure.
Stream:
T.Krishnakumar Lecture/IT Operating System Notes Unit
13 5
Low cost is the defining characteristic of tertiary storage. Generally, tertiary storage is built
using removable media. Common examples of removable media are floppy disks and CD-
ROMs; other types are available.
1. Removable Disks
Floppy disk — thin flexible disk coated with magnetic material, enclosed in a
protective plastic case.
Most floppies hold about 1 MB; similar technology is used for removable disks that
hold more than 1 GB.
Removable magnetic disks can be nearly as fast as hard disks, but they are at a greater
risk of damage from exposure.
A magneto-optic disk records data on a rigid platter coated with magnetic material.
Laser heat is used to amplify a large, weak magnetic field to record a bit.
Laser light is also used to read data (Kerr effect).
The magneto-optic head flies much farther from the disk surface than a
magnetic disk head, and the magnetic material is covered with a protective
layer of plastic or glass; resistant to head crashes.
Optical disks do not use magnetism; they employ special materials that are altered by
laser light.
2. WORM Disks
The data on read-write disks can be modified over and over.
WORM (“Write Once, Read Many Times”) disks can be written only once.
Thin aluminum film sandwiched between two glass or plastic platters.
To write a bit, the drive uses a laser light to burn a small hole through the aluminum;
information can be destroyed by not altered.
Very durable and reliable.
Read only disks, such as CD-ROM and DVD, com from the factory with the data pre-
recorded.
3. Tapes
Compared to a disk, a tape is less expensive and holds more data, but random access
is much slower.
Tape is an economical medium for purposes that do not require fast random access,
e.g., backup copies of disk data, holding huge volumes of data.
Large tape installations typically use robotic tape changers that move tapes between
tape drives and storage slots in a tape library.
T.Krishnakumar Lecture/IT Operating System Notes Unit
16 5
By using a remote procedure call interfaces like NFS and UNIX systems, the clients
gets the access of network attached storage.
But, the remote procedure calls are used through a TCP or UDP across the IP
network.
The network attached storage is implemented as a RAID array with the software
which implements the RPC interface.
Advantages:
It is easy to share a pool of storage.
Disadvantages:
Less efficient
Lower performance
Increased possible of communication. Because it consume bandwidth on the
data network.
3. Storage Area Network:
It is a private network in between the servers and storage units.
Also this is separate from the LAN or WAN
More number of hosts and storage arrays can be connected with a same SAN.
Also the storage is allocated dynamically to hosts.
Example: when a host is running low on disk space, in order to provide more storage to that
host, the storage area N/W can be arranged.
___________________________________________________________________________
T.Krishnakumar Lecture/IT Operating System Notes Unit
18 5
Disk Management:
Operating system is responsible for disk management.
Following are some activities discussed.
Disk Formatting:
1. Low-level formatting, or physical formatting:
Disk must be formatted before storing a disk.
Dividing a disk into sectors that the disk controller can read and write
Low level formatting files the disk with a special data structure for each sector.
Data structures consist of three fields:
Header
Data Area
Trailer
Header and trailer contain information used by the disk controller.
Sector number and Error Correcting Codes (ECC) contained in the Header and Trailer
For writing data to the sector – ECC is updated.
For reading data from the sector – ECC is recalculated
If there is mismatch in stored and calculated value then data area is corrupted.
Low level formatting is done at factory.
2. Logical formatting or “making a file system”.
After disk is partitioned, logical formatting used
Operating system stores the initial file system data structures onto the disk.
Boot Block:
The system requires an initial program to begin its running.
Example: when the computer system is powered up or rebooted, it needs a program
This program should be very simple.
Problem-solving check is done first
Stage 0 boot program is executed
Boot program reads the first sector form the boot device into main memory.
Boot sector is the first sector of the boot device and contains stage 1 boot program.
May be boot sector will not contain a boot program.
PC booting from hard disk, the boot sector also contains a partition table
The code in the boor ROM instructs the disk controller to read the boot blocks into memory
and then starts executing that code.
Full boot strap program is more sophisticated than the bootstrap loader in the boot ROM.
T.Krishnakumar Lecture/IT Operating System Notes Unit
19 5
Bad blocks:
Data that resided on the bad blocks usually are lost.
The controller maintains a list of bad blocks on the disk.
The list is initialized during the low level format at the factory, and is updated over the life of
the disk.
Low level formatting also sets aside spare sectors not visible to the operating system.
The controller can be told to replace each bad sector logically with one of the spare sectors.
This scheme is known as sector sparing or forwarding
A typical bad sector transaction might be as follows;
The OS tries to read logical block 90
The controller calculates the ECC and finds that the sector is bad. It reports this finding to the
OS
The next time that the system is rebooted, a special command is run to tell the SCSI
controller to replace the bad sector with a spare
After that whether the system requests the logical block 90, the request is translated into the
replacement sectors address by the controller.
___________________________________________________________________________
Swap-Space Management:
T.Krishnakumar Lecture/IT Operating System Notes Unit
20 5
Swap space can be created in a separate disk partition. No file system or directory structure is
placed on this space. A separate swap space storage manager is used to allocate and
deallocate the blocks. This manager uses algorithms optimized for speed.
Internal fragmentation may increase. Some OS are flexible and can swap both in raw
partition and in file system space. Solaris 2 is an example
Swap-space management
1. 4.3BSD allocates swap space when process starts; holds text segment (the
program) and data segment.
2. Kernel uses swap maps to track swap-space use.
3. Solaris 2 allocates swap space only when a page is forced out of physical memory,
not when the virtual memory page is first created.
__
________________________________________________________________________
T.Krishnakumar Lecture/IT Operating System Notes Unit
22 5
RAID:
Redundant Array of Inexpensive (or "Independent") Disks is a series (RAID0 to
RAID5) of increasing reliable and expensive ways of organising multiple physical hard disks
into groups ("arrays") that work as a single logical disk.
Each logical drive appears to the operating system as a single physical drive, thanks to the
efforts of the RAID controller.
There are hardware and software RAID controllers, but the software version adds pressure to
the CPU and is slower than a hardware controller.
RAID comes in several flavors, levels zero through five (if you want to get particular, there
are others: 0, 1, 2, 3, 4, 5)
Different flavours let you choose between performance, protection, and storage capacity.
A hot-spare drive is a hard disk drive in a server that is defined for automatic use in the
event of a drive failure.
If a drive fails, the system can automatically switch to the hot-spare drive, and the data from
the dead drive is reconstructed on the hot-spare drive.
Each level is optimized for various capabilities, including improved performance of read or
writeoperations, and improved data availability through redundant copies or parity
(consistency) checking.
Features of different RAID levels can be combined to get the benefits of both.
If one disk in the array happens to fail, all data in the array is unavailable.
Striping spreads data across each disk in the array for improved performance.
STRIPING
Striping is the practice of spreading data over multiple disk drives.
It allows greater performance because drives can find and deliver data simultaneously, rather
than one drive having to do all the work by itself.
If one disk fails, all data is lost, and all disks must be reformatted.
Protection Poor Data could be restored across the array from a tape or diskette backup,
if available.
RAID-1:
It is a disk-mirroring strategy for high performance.
All data is written twice to separate drives. The cost per megabyte of storage is higher, of
course, but if one drive fails, normal operations can continue with the duplicate data.
If the RAID device permits hot-swapping of drives, the bad drive can be replaced without
interruption.
T.Krishnakumar Lecture/IT Operating System Notes Unit
24 5
Mirroring and Duplexing: Disk mirroring duplicates the data from one disk onto a second
disk using a single disk controller. Disk duplexing is the same as mirroring, except that the
disks are attached to separate disk controllers, such as two SCSI adapters.
If either disk fails, a copy of the data is still available on the other
Protection good disk. - If a disk controller fails while duplexing, the data can still
be accessed through the other controller and disk.
Data Disks- stores data strips Parity Disk- stores parity strips
RAID-3:
It uses data striping, generally at the byte level and uses one disk to store parity information.
Striping improves the throughput of the system, and using only one disk per set for parity
information reduces the cost per megabyte of storage.
Striping data in small chunks provides excellent performance when transferring large
amounts of data, because all disks operate in parallel.
Two disks must fail within a set before data would become unavailable.
Bit interleave data striping with parity - Access to all drives to retrieve on record - Best for
large sequential reads - Poor for random transactions - Faster than a single disk but
significantly slower than RAID 0 or RAID 1 in random environments
RAID-4:
Itstripes data in larger chunks, which provides better performance than RAID-3 when
transferring small amounts of data. Block interleave data striping with one parity disk - Best
for large sequential I/O, but poor write performance-Faster than a single drive but
significantly slower than RAID 0 or RAID 1.
RAID-5:
Itstripes data in blocks sequentially across all disks in an array and writes parity data on all
disks as well.
By distributing parity information across all disks, RAID-5 eliminates the bottleneck
sometimes created by a single parity disk.
RAID-5 is increasingly popular and is well suited to transaction environments.
If any disk fails, the data can be recovered by using the data
Protection Good
from the other disks along with the parity information.
Parity is interleaved with data information rather than stored on a dedicated drive
RAID 5E:
It uses a distributed hot spare disk, so it works with a minimum of four disks. Protection: very
good.
Capacity: N-2.
Where N is the number of disks, the capacity is N-2 (one for parity and one for spare).
Spanned Arrays (RAID x0):
Spanned arrays (or composite RAID levels) are RAID arrays that are joined together to form
larger RAID arrays.
T.Krishnakumar Lecture/IT Operating System Notes Unit
28 5
Disk Scheduling
1. The operating system is responsible for using hardware efficiently — for the disk
drives, this means having a fast access time and disk bandwidth.
2. Access time has two major components
Seek time is the time for the disk are to move the heads to the cylinder containing
the desired sector.
Rotational latency is the additional time waiting for the disk to rotate the desired
sector to the disk head.
3. Minimize seek time
4. Seek time seek distance
5. Disk bandwidth is the total number of bytes transferred, divided by the total time
between the first request for service and the completion of the last transfer.
6. Several algorithms exist to schedule the servicing of disk I/O requests.
7. We illustrate them with a request queue (0-199).
Example: 98, 183, 37, 122, 14, 124, 65, 67. Head pointer 53
FCFS
Illustration shows total head movement of 640 cylinders.
SSTF
1. Selects the request with the minimum seek time from the current head position.
2. SSTF scheduling is a form of SJF scheduling; may cause starvation of some requests.
3. Illustration shows total head movement of 236 cylinders.
T.Krishnakumar Lecture/IT Operating System Notes Unit
29 5
SCAN
1. The disk arm starts at one end of the disk, and moves toward the other end, servicing
requests until it gets to the other end of the disk, where the head movement is reversed and
servicing continues.
2. Sometimes called the elevator algorithm.
3. Illustration shows total head movement of 208 cylinders.
T.Krishnakumar Lecture/IT Operating System Notes Unit
30 5
C-SCAN
1. Provides a more uniform wait time than SCAN.
2. The head moves from one end of the disk to the other. servicing requests as it goes. When
it reaches the other end, however, it immediately returns to the beginning of the disk, without
servicing any requests on the return trip.
3. Treats the cylinders as a circular list that wraps around from the last cylinder to the first
one.
C-LOOK
1. Version of C-SCAN
2. Arm only goes as far as the last request in each direction, then reverses direction
immediately, without first going all the way to the end of the disk.
T.Krishnakumar Lecture/IT Operating System Notes Unit
31 5