6Chapter Six - Input Output Management(0)
6Chapter Six - Input Output Management(0)
I/O Management
Operating System
1
Memory Management
2
Introduction
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
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)
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
14
I/O Software Layers
15
Interrupt Handler
16
Device Driver
17
Device Driver (Cont.)
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
21
I/O Software Layers (Cont.)
22
SWAP – Space Management
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
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
31
RAM Disk
32
Disk Cache
33
Quiz
34
Thank you
35