Lecture 16 - Input/Output, Disks
- I got a rock. - Charlie Brown, It's the Great Pumpkin, Charlie Brown.
- Announcements
- Input/Output
- Disks
We will not spend much time in class going over the background - just
highlights. Read Chapter 5 if you're not comfortable with some of the
background.
The OS provides I/O instructions to control devices. Control may be
by
Accessing devices
Either way, how do we know when the device needs the attention of the
CPU? Remember that "I/O Wait" means the process is not in the ready
queue or on the CPU, ideally.
Application I/O Interface
I/O system calls encapsulate device behaviors using a common interface
for a wide variety of devices
Device drivers hide differences among I/O controllers from
kernel - same kernel routines can call functions in specific device
drivers without worrying about the details of the device
Device characteristics
Block devices
Character devices
Network Devices
Similar to block and character, but different enough to be unique
Blocking vs. Nonblocking I/O
Kernel I/O Subsystem
Beyond just the interface, the kernel manages devices to improve
efficiency
Scheduling
some I/O request ordering via per-device queue
consider a series of disk access requests - what order to
use? efficiency? priorities?
Buffering - may be needed because of
device speed mismatch (disk to printer, modem to disk)
device transfer size mismatch (gather network packets)
Caching - fast memory holding copy of data
always just a copy
key to performance
has come up before and will come up again
Spooling - hold output for a device
if device can serve only one request at a time
printing, maybe tape I/O
Device reservation - provides exclusive access to a device
system calls for allocation and deallocation
deadlock avoidance/detection/recovery
Error Handling
OS can recover from disk read, device unavailable,
transient write failures (retry)
switch to another device, if possible
return failure code when I/O request fails
error logs
Bookkeeping and Kernel Data Structures
state info (open files, network connections, etc.)
complex data structures (i.e., Unix buffer cache)
Performance
I/O performance is a critical factor in overall system performance:
reduce number of context switches
reduce data copying
reduce interrupts by using large transfers, smart
controllers, polling
use DMA
balance CPU, memory, bus, and I/O performance for highest
throughput
We will consider disks and file structures in much more detail than
most of the other types of I/O devices.
The data is written to the surface of the disk. How can it be arranged?
CD/DVD is arranged in a "spiral" for a continuous stream.
We'll concentrate on magnetic disks (floppy disk, hard disk). A hard
disk may have multiple surfaces, or platters. For simplicity, assume
there is only one disk, or platter, involved.
A read/write head is needed for each platter.
The data on a disk is arranged in concentric rings called cylinders or tracks.
Each cylinder of the disk is divided into chunks called sectors
that contain blocks, the minumum allocatable and addressable
unit on the disk. Since there is more space on the outside of the
disk, there may be more blocks in outer cylinders than there are on inner
cylinders.
The particular configuration of cylinders, sectors and the number of
platters is the drive geometry. The actual drive geometry may
be difficult to determine, as modern disk drives lie, controllers lie,
and by the time you get the numbers they may be completely
meaningless.
So to read or write data on the disk, a cylinder and sector must be
specified. The read/write head must be positioned over the desired
cylinder and sector. The read/write heads are typically connected to the
end of a moveable arm. This arm is moved to position the head at the
correct cylinder. When the disk rotates and the desired sector reaches
the read-write head, the read or write operation can proceed.
The speed of this operation depends on two major factors:
seek time - the time it takes to move the read/write head to
the correct cylinder
rotational latency - the time it takes for the correct
sector to rotate under the read/write head
We can minimize seek time by minimizing the distance the read/write
head has to move in order to service the incoming requests.