MTU
5. INPUT/OUTPUR MANAGEMENT
INTRODUCTION:
Input Output is important for communication between the user and computer. The following
are functions of the operating system as I/O manager:
Control all the computer I/O devices.
Issue commands to I/O devices, catch interrupts and handle errors.
Provide an interface between the device and the rest of the system.
PRINCIPLES OF I/O HARDWARE
I/O devices have three sections:
1. I/O devices: - Concerns with the way data are handled by the I/O device. There are two
types of I/O devices blocked and character.
Blocked devices (such as disks) - A block device is one that stores information in
Fixed-size blocks, each one with its own address. Common block size range from
512bytes to 32,768bytes. The essential property of a block device is that it is possible
to read or write each block independently of all the other ones. Disks are the most
common block devices. A disk is a block addressable device because no matter where
the arm currently is, it is always possible to seek to another cylinder and then wait for
the required block to rotate under the head.
Character devices (such as printers, mouse and NIC) - The other type of I/O
device is the character device. A character device delivers or accepts stream of
character, without regard to any block structure. It is not addressable and does not
have any seek operation.
2. Device controller: Indicates the hardware components. There are two major components
– Electronic Component (Device controller/Adapter) and the Mechanical Component (the
moving parts).
CPU Memory Disk Printer Other
Controller Controller Controller
s
System
Bus
3. Direct Memory Access (DMA): DMA is a technique for moving a data directly between
main memory and I/O devices without the CPU’s intervention. In the absence of DMA
reading from a disk is done with the following steps.
Input and output Management Page: 1
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.
The controller computes the checksum to verify that no read errors have occurred.
The controller causes an interrupt.
The OS reads the disk block from the controller’s buffer a byte or a word at a time and
stores it on memory.
Primary Primary
Memory
Memory
CPU
CPU
Controller Controller
Device Device
Traditional I/O DMA
PRINCIPLES OF I/O SOFTWARE
1. Goals and issues of I/O software.
2. Layered technique is used (Layers of I/O software)
1. Goals and issues of I/O software:
Device Independence: It should be possible to write programs that can read files on
a floppy disk, on hard disk, or on a CD-ROM, without having to modify the program
for each different device types. It is up to the operating system to take care of the
problems caused by the fact that these devices are really different.
Uniform Naming: The name of a file or a device should simply be a string or an
integer and not dependant on the device in any way.
Error handling: In general, errors should be handled as close to the hardware as
possible (at the device controller level). Many errors are transient, such as read errors
caused by specks of dust on the read head, and will go away if the operations are
repeated.
Transfer: There are two types of transfer modes – Synchronous (Blocking) and
Asynchronous (interrupt –driven). In the case of synchronous transfer the program
requesting I/O transfer will be suspended until the transfer is completed. In the case
Input and output Management Page: 2
of Asynchronous transfer the CPU starts the transfer and goes off to do something
until the interrupt that shows the completion of the transfer arrives.
Device types: There are two device types
Sharable (such as disk) - Used by many users at the same time. No problems are
caused by multiple users having open files on the same disk at the same time.
Dedicated (tape drives) - Have to be dedicated to a single user until that user is
finished. Having two or more users writing blocks intermixed at random to the same
tape will definitely not work.
2. Layers of I/O software:
The following are the I/O software layers
Interrupt handler (bottom)
Device driver
Device independent I/O software
User-level software (top)
Interrupt Handler
Interrupts are unpleasant facts of program or process and cannot be avoided. They
should be hidden away.
The best way to hide them is to have every process starting an I/O operation block
until the I/O has completed and the interrupt occurs.
When the interrupt happens, the interrupt procedure does whatever it has to in order
to unblock the process that started it.
Device Driver
All devices – Dependent code goes in the device driver.
Each device driver handles one device type, or at most, one class of closely related
devices.
Each controller has one or more device registers used to give it command.
The device driver issues the commands and check that they are carried out properly.
Thus, the disk driver is the only part of the OS that knows how many registers that disk
controller has and what they are used for.
In general terms, the job of a device driver is to accept requests form the device
independent software above it and sees to it that the request is executed.
Steps in carrying out I/O requests
Translate it from abstract to concrete terms.
Write into the controller’s device registers.
The device driver blocks itself until interrupt comes.
The blocked driver will be awakened by the interrupt.
Device driver checks for errors.
If every thing is all right, the driver may have data to pass to the device independent
software.
If nothing is queued, the driver blocks waiting for the next request.
Input and output Management Page: 3
Device Independent I/O Software
It is large fraction of I/O software.
Functions of the device-independent I/O software.
Uniform interfacing for device drivers – Perform I/O function common to all drives.
Device Naming – Responsible for mapping symbolic devices names onto the proper driver.
Device protection – Prevent users from accessing devices that they are not entitled to
access.
Providing device-independent block size – Provide uniform block size to higher layers
hiding differences in block sizes.
Buffering: If a user process write half a block, the OS will normally keep the data in buffer
until the rest of the data are written. Keyboard inputs that arrive before it is needed also
require buffering.
Storage allocation on block devices: When a file is created and filled with data, new disk
blocks have to be allocated to the file. To perform this allocation, the OS needs a list of free
blocks and used some algorithms for allocation.
Allocating and releasing dedicated devices: It is up to the OS to examine requests for
devices usage and accept or reject them.
Error reporting: Errors handling, by and large, is done by drivers. Most errors are device
dependent. After the driver tries to read the block a certain number of times, it gives up and
informs the device-independent software. It then reports to the caller.
User Space I/O Software
A small portion of the I/O software is outside the OS.
System calls, including the I/O system calls, are normally made by library
procedures. E.g. when a C program contains the call count=write (fd, buffer,
nbytes); the library procedure write will be linked with the program and contained
in the binary program present in memory at run time.
Formatting of input and output is done by library procedures.
User-Process Make I/O call, Format I/O; spooling
Device-independent software Naming, protection, blocking, buffering, allocation
Device Drivers Setup devices registers, check status
Interrupt Handlers Wakeup driver when I/O completed
Hardware Perform I/O operation
SWAP – SPACE MANAGEMENT
It is the low-level task of operating system. Implementation of swap-space is to provide the
best throughput for the virtual memory system.
Swap-Space Use The Operating System needs to release sufficient main memory to
bring in a process that is ready to execute. Operating system uses this swap space in various
ways. Paging systems may simply store pages that have been pushed out of main memory.
Input and output Management Page: 4
These swap space are usually put on separate disks, so the load placed on the I/O system by
paging and swapping can be spread over the systems I/O devices.
Swap-Space Location Swap space can reside in two places
Normal file system: If the swap space is simply a large file within the file system,
normal file system routines can be used to create it, name it and allocate its space.
This is easy to implement but also inefficient. External fragmentation can greatly
increase swapping times. Catching is used to improve the system performance.
Block of information is cached in the physical memory, and by using special tools to
allocate physically contiguous blocks for the swap file.
Separate Disk Partition: 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
operating systems are flexible and can swap both in raw partitions and file system
space.
DISKS:
All real disks are organized into cylinders, each one containing many tracks. Each of the
tracks then will be divided into sectors (equal number of sectors or different number of
sectors).
In the case of equal number of sectors
The data density as closer to the center (hub) is high.
The speed increases as the read/write moves to the outer tracks.
Modern large hard drives have more sectors per track on outer tracks e.g. IDE drives.
Many controllers can read or write on one drive while seeking on one or more other
drives, but floppy disk controller cannot do that.
Disk Access Time
The time required to read or write a disk block is determined by three factors
The seek time (the time to move the arm/disk to the proper cylinder or track).
The rotational delay (the time for the proper sector to rotate under the head).
The actual data transfer time (The transfer time form the disk depends on the
rotation speed of the disk).
For most disks, the seek time dominates the other two times, so reducing the mean seek
time can improve system performance substantially.
While the arm is seeking on behalf of one request, other disk requests may be generated
by other process. Many disk drivers maintain a table, indexed by cylinder number, with
all the pending requests for each cylinder chained together in a linked list headed by the
table entries.
Input and output Management Page: 5
DISK SCHEDULING ALGORITHM
The OS maintains queue of requests for each I/O operation.
It uses disk scheduling algorithm.
1. First Come First Served (FCFS):
Accept a request one at a time and carries them out in that order. Service requests in the
order they are received.
E.g. Track initial position: 11
Track request: 1,36,16,34,9,12
Service order: 1,36,16,34,9,12
The simplest and the fairest of all, but it doesn’t improve performance
2. Shortest Seek Time First (SSTF):
It handles the closest (the least disk arm movement) request next, to minimize seek time.
E.g. Track initial position: 11
Track request: 1,36,16,34,9,12
Service order: 12,9,16, 1, 34, 36
Performance (efficiency), provides better performance
Possibility of starvation (it lacks fairness)
3. SCAN (Elevator) Algorithm:
The disk arm keeps moving in the same direction until there are no more outstanding
requests in that direction, and then it switches direction.
It has the head start at track 0 and move towards the highest numbered track, servicing all
requests for a track as it passes the track.
SCAN algorithm is guaranteed to service every request in one complete pass through the
disk.
E.g. Track initial position: 11
Track request: 1,36,16,34,9,12
Direction bit: 1
Service order: 12, 16, 34, 36, 9, 1
It provides better service distribution.
4. C-SCAN (Modified Elevator) Algorithm (Circular-SCAN):
It restricts scanning to one direction only. A slight modification of elevator algorithm that
has smaller variance in response times is always scans in the same direction. When the
highest numbered cylinder with a pending request has been serviced, the arm goes to the
lowest-numbered cylinder with a pending request and then continues moving in an upward
direction. In effect, the lowest-numbered cylinder is thought of as being just above the
highest-numbered cylinder.
Input and output Management Page: 6
It reduces the maximum delay experienced by new request.
E.g. Track initial position: 11
Track request: 1,36,16,34,9,12
Direction bit: 1
Service order: 12, 16, 34, 36, 1, 9
RAID - Redundant array of independent disks may be used to increase disk reliability.
In a RAID system, a single large file is stored in several separate disk units by
breaking the file up into a number of smaller pieces and storing these pieces on
different disks.
When a file is accessed for a read, all disks deliver their data in parallel.
RAID may be implemented in hardware or in the operating system.
RAM Disk
A RAM (Random Access Memory) disk has the advantage of having instant access.
UNIX support mounted file system but DOS and Windows do not support.
The RAM disk is split up into ‘n’ blocks each with a size equal to the real disk.
Finally the transfer will be done.
A RAM disk driver may support several areas of memory used as RAM disk.
Disk Cache
Memory cache – To narrow the distance between the processor and memory.
Disk cache – To narrow the distance between the processor, memory and I/O.
It uses a buffer kept in main memory that functions as a cache of disk memory and
the rest of the main memory.
It contains a copy of some of the sectors on the disk.
It improves performance (by minimizing Block transfer and Disk memory).
Design issue
Data transfer - Memory-to-memory
- using shared memory (pointer).
Replacement algorithm - Least Recently used
- Least Frequently Used.
Input and output Management Page: 7
Queue=98, 183, 37,122,14,124,65,67
Head starts at 53
1. FCFS ALGO
2. SSTF ALGO
3. SCAN ALGO
4. C-SCAN ALGO
Which one is best? And why?
Input and output Management Page: 8