Operating
Systems:
Internals Chapter 11
and
Design I/O Management
Principles and Disk Scheduling
Ninth Edition
By William Stallings
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Categories of I/O Devices
External devices that engage in I/O with computer
systems can be grouped into three categories:
Human readable
• Suitable for communicating with the computer user
• Printers, terminals, video display, keyboard, mouse
Machine readable
• Suitable for communicating with electronic equipment
• Disk drives, USB keys, sensors, controllers
Communication
• Suitable for communicating with remote devices
• Modems, digital line drivers
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Differences in I/O Devices
Devices differ in a number of areas:
Data Rate
• There may be differences of magnitude between the data transfer rates
Application
• The use to which a device is put has an influence on the software
Complexity of Control
• The effect on the operating system is filtered by the complexity of the I/O module that controls the device
Unit of Transfer
• Data may be transferred as a stream of bytes or characters or in larger blocks
Data Representation
• Different data encoding schemes are used by different devices
Error Conditions
• The nature of errors, the way in which they are reported, their consequences, and
the available range of responses differs from one device to another
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Organization of the I/O
Function
Three techniques for performing I/O are:
Programmed I/O
The processor issues an I/O command on behalf of a process to an I/O module; that
process then busy waits for the operation to be completed before proceeding
Interrupt-driven I/O
The processor issues an I/O command on behalf of a process
If non-blocking – processor continues to execute instructions from the process that
issued the I/O command
If blocking – the next instruction the processor executes is from the OS, which will put
the current process in a blocked state and schedule another process
Direct Memory Access (DMA)
A DMA module controls the exchange of data between main memory and an I/O
module
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Table 11.1
I/O Techniques
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Evolution of the I/O
Function
• Processor directly controls a peripheral device
1
• A controller or I/O module is added
2
• Same configuration as step 2, but now interrupts are employed
3
• The I/O module is given direct control of memory via DMA
4
• The I/O module is enhanced to become a separate processor, with a
5 specialized instruction set tailored for I/O
• The I/O module has a local memory of its own and is, in fact, a
6 computer in its own right
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Design Objectives
Efficiency Generality
Major effort in I/O design Desirable to handle all devices in a
uniform manner
Important because I/O operations
often form a bottleneck Applies to the way processes view
I/O devices and the way the
Most I/O devices are extremely operating system manages I/O
slow compared with main devices and operations
memory and the processor
Diversity of devices makes it
The area that has received the difficult to achieve true generality
most attention is disk I/O
Use a hierarchical, modular
approach to the design of the I/O
function
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Buffering
To avoid overheads and inefficiencies, it is sometimes convenient to perform
input transfers in advance of requests being made, and to perform output
transfers some time after the request is made
Block-oriented device Stream-oriented device
• Stores information in blocks • Transfers data in and out as a
that are usually of fixed size stream of bytes
• Transfers are made one block • No block structure
at a time • Terminals, printers,
• Possible to reference data by communications ports, mouse
its block number and other pointing devices,
• Disks and USB keys are and most other devices that
examples are not secondary storage are
examples
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Without a buffer, the OS
directly accesses the device
No Buffer when it needs
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
The simplest type of support that
the operating system can provide
Single Buffer When a user process issues an
I/O request, the OS assigns a
buffer in the system portion of
main memory to the operation
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Single Buffer
Input transfers are made to the system buffer
Reading ahead/anticipated input
Is done in the expectation that the block will eventually be needed
When the transfer is complete, the process moves the block into user space and
immediately requests another block
Approach generally provides a speedup compared to the lack of system buffering
The user process can be processing one block of data while the next block is being read in
The OS is able to swap the process out because the input operation is taking place in
system memory rather than user process memory
Disadvantages:
Complicates the logic in the operating system
Swapping logic is also affected
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Assigning two system buffers to
the operation
Double Buffer
A process now transfers data to or
from one buffer while the
operating system empties or fills
the other buffer
Also known as buffer swapping
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
When more than two buffers
are used, the collection of
buffers is itself referred to as a
Circular Buffer
circular buffer
Each individual buffer is one
unit in the circular buffer
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
The actual details of disk I/O
Disk
operation depend on the:
Computer system
Performance
Operating system
Nature of the I/O channel
Parameters and disk controller
hardware
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Disk Performance
Parameters
When the disk drive is operating, the disk is rotating at constant speed
To read or write the head must be positioned at the desired track and at the
beginning of the desired sector on that track
Track selection involves moving the head in a movable-head system or
electronically selecting one head on a fixed-head system
On a movable-head system the time it takes to position the head at the
track is known as seek time
The time it takes for the beginning of the sector to reach the head is
known as rotational delay
The sum of the seek time and the rotational delay equals the access time
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Seek Time
The time required to move the disk arm to the required track
Consists of two key components:
The initial startup time
The time taken to traverse the tracks that have to be crossed once the access
arm is up to speed
Settling time
Time after positioning the head over the target track until track identification is
confirmed
Much improvement comes from smaller and lighter disk components
A typical average seek time on contemporary hard disks is under
10ms
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Disk Performance
Rotational delay
The time required for the addressed area of the disk to rotate into a
position where it is accessible by the read/write head
Disks rotate at speeds ranging from 3,6000 rpm (for handheld devices
such as digital cameras) up to 15,000 rpm
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Table 11.3 Disk Scheduling Algorithms
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
First-In, First-Out (FIFO)
Processes in sequential order
Fair to all processes
Approximates random scheduling in performance if
there are many processes competing for the disk
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Priority (PRI)
Control of the scheduling is outside the control of disk management
software
Goal is not to optimize disk utilization but to meet other objectives
Short batch jobs and interactive jobs are given higher priority
Provides good interactive response time
Longer jobs may have to wait an excessively long time
A poor policy for database systems
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Shortest Service
Time First
(SSTF)
Always choose the minimum
seek time
Select the disk I/O request
that requires the least
movement of the disk arm
from its current position
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
SCAN
Also known as the elevator algorithm
Arm moves in one direction only
Satisfies all outstanding requests until it
reaches the last track in that direction then
the direction is reversed
Favors jobs whose requests are for tracks
nearest to both innermost and outermost
tracks and favors the latest-arriving jobs
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Restricts scanning to one direction
C-SCAN only
When the last track has been
(Circular SCAN) visited in one direction, the arm is
returned to the opposite end of the
disk and the scan begins again
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
N-Step-SCAN
Segments the disk request queue into subqueues of length N
Subqueues are processed one at a time, using SCAN
While a queue is being processed new requests must be added to some
other queue
If fewer than N requests are available at the end of a scan, all of them
are processed with the next scan
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
FSCAN
Uses two subqueues
When a scan begins, all of the requests are in one of the queues, with
the other empty
During scan, all new requests are put into the other queue
Service of new requests is deferred until all of the old requests have
been processed
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.