0% found this document useful (0 votes)
2 views

6Chapter Six - Input Output Management(0)

Chapter 6 discusses I/O management in operating systems, covering principles of I/O hardware and software, device controllers, and the role of device drivers. It explains the importance of I/O for user-computer communication, the categorization of I/O devices, and various I/O software layers and algorithms for efficient data transfer. Additionally, it addresses disk management, including access times and scheduling algorithms, as well as techniques like RAID and disk caching to enhance performance.

Uploaded by

jamsibro140
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

6Chapter Six - Input Output Management(0)

Chapter 6 discusses I/O management in operating systems, covering principles of I/O hardware and software, device controllers, and the role of device drivers. It explains the importance of I/O for user-computer communication, the categorization of I/O devices, and various I/O software layers and algorithms for efficient data transfer. Additionally, it addresses disk management, including access times and scheduling algorithms, as well as techniques like RAID and disk caching to enhance performance.

Uploaded by

jamsibro140
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 35

Chapter 6

I/O Management

Operating System
1
Memory Management

• Principles of I/O Hardware


• Principles of I/O Software
• I/O Software Layers
• Disks

2
Introduction

• Input Output is important for communication between the user and


computer.
• The operating system controls all the computer’s I/O devices.
 It issue commands to I/O devices, catch interrupts and handle
errors.
 It provides an interface between the device and the rest of the
system.

3
Principles of I/O Hardware: I/O
Devices
I/O devices can be roughly divided into two categories:
• Block devices: A block device is one that stores information in Fixed-
size blocks, each one with its own address.
 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.
• Character devices: 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.
 Printers, network interfaces, mice (for pointing), and most other
devices that are not disk-like can be seen as character devices.

4
Device Controllers

• I/O units often consist of a mechanical component and an electronic


component.
• The electronic component is called the device controller or adapter.
• On personal computers, it often takes the form of a chip on the
parent board or a printed circuit card that can be inserted into a
(PCIe) expansion slot.
• The mechanical component is the moving parts.

5
Device Controllers (Cont.)

6
Memory-Mapped I/O

• Each controller has a few registers that are used for communicating
with the CPU. By writing into these registers, the operating system
can command the device to perform some action.
• In addition to the control registers, many devices have a data buffer
that the operating system can read and write.
• The issue thus arises of how the CPU communicates with the control
registers and also with the device data buffers.
• Two approaches:
• In the first approach, each control register is assigned an I/O port
number, an 8- or 16-bit integer. The set of all the I/O ports form the
I/O port space,

7
I/O Addresses

8
Memory-Mapped I/O (Cont.)

• The second approach, is to map all the control registers into the
memory space. Each control register is assigned a unique memory
address to which no memory is assigned. This system is called
memory-mapped I/O.

9
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:
 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.

10
DMA (Cont.)

Primary
Primary Memory
Memory

CPU
CPU

Controller Controller

Device Device
Traditional I/O DMA

11
DMA (Cont.)

12
Principles of I/O Software

Goals of the I/O Software:


• Device Independence: we should be able to write programs that can
access any I/O device without having to specify the device in advance.
• Uniform Naming: The name of a file or a device should simply be a string
or an integer and not dependent 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
• Transfer: There are two types of transfer modes – Synchronous (Blocking)
and Asynchronous (interrupt –driven).
• Synchronous transfer: the program requesting I/O transfer will be
suspended until the transfer is completed.
• Asynchronous transfer: the CPU starts the transfer and goes off to do
something until the interrupt that shows the completion of the transfer
arrives.
13
Goals of the I/O Software
(Cont.)
• Buffering: Often data that come off a device cannot be stored directly
in their final destination. For example, when a packet comes in off
the network, the operating system does not know where to put it
until it has stored the packet somewhere and examined it.
• Device types: There are two device types,
 Sharable - such as disks, can be 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 - such as printers, have to be dedicated to a single
user until that user is finished. Then another user can have the
printer. Having two or more users writing characters intermixed
at random to the same page will definitely not work.

14
I/O Software Layers

15
Interrupt Handler

• Interrupts are unpleasant facts of program or process and cannot be


avoided. They should be hidden.
• 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.

16
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.

17
Device Driver (Cont.)

• 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 everything 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.

18
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 writes half a block, the OS will normally
keep the data in buffer(a part of RAM used for temporary storage of
data that is waiting to be sent to a device; used to compensate for
differences in the rate of flow of data between components of a
computer system ) until the rest of the data are written. Keyboard
inputs that arrive before it is needed also require buffering. 19
Device Independent I/O
Software (Cont.)
• Functions of the device-independent I/O software:
 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.

20
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.

21
I/O Software Layers (Cont.)

User-Process Make I/O call, Format I/O; spooling

Device-independent Naming, protection, blocking, buffering,


software allocation

Device Drivers Setup devices registers, check status

Interrupt Handlers Wakeup driver when I/O completed

Hardware Perform I/O operation

22
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. 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

23
SWAP – Space Management
(Cont.)
• 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.

24
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).
Disk Access Time
• The time required to read or write a disk block is determined by three
factors
 Seek time: the time to move the arm to the proper cylinder or track.
 Rotational delay: the time for the proper sector to rotate under the
head.
 The actual data transfer time: The transfer time of the disk depends
on the rotation speed of the disk.
• 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.
25
Disk Arm Scheduling Algorithm

• 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.
• The OS maintains queue of requests for each I/O operation.
• It uses disk scheduling algorithm.

26
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.

27
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)

28
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
29
C-SCAN (Modified Elevator)
Algorithm
• It restricts scanning to one direction only.
• 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.
• 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

30
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.

31
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.

32
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).

33
Quiz

1. Queue=98, 183, 37,122,14,124,65,67


• Head starts at 53
 SSTF Algorithm
 SCAN Algorithm
 C-SCAN Algorithm
2. Mention at least two functions of the operating system as an I/O
manager.

34
Thank you

35

You might also like