Upload
roland-hensley
View
225
Download
1
Tags:
Embed Size (px)
Citation preview
I/O Management and Disk Structure
Introduction to Operating Systems: Module 14
Operating System Design Objectives I/O is extremely slow compared to main memory, CPU Use of multiprogramming allows for some processes to be
waiting on I/O while another process executes Efficiency and generality are important Try to handle all I/O devices in a uniform manner Hide most of the details of device I/O in lower-level
routines so that processes and upper levels see devices in general terms such as Read, Write, Open, and Close
A Model of I/O Organization
Scheduling& Control
DeviceI/O
Scheduling& Control
Scheduling& Control
Local peripheral device Communications port File System
DeviceI/O
DeviceI/O
HardwareHardware HardwareHardware HardwareHardware
UserProcesses
UserProcesses
UserProcesses
UserProcesses
UserProcesses
UserProcesses
LogicalI/O
Comm.Architecture
DirectoryManagement
FileSystem
PhysicalOrganization
I/O Buffering Reasons for buffering
Process responsiveness a writing processes must wait for I/O to complete before
proceeding A reading process cannot do other things while waiting for
data Pages must remain in main memory during I/O
I/O Buffering Block-oriented
information is stored in fixed sized blocks transfers are made a block at a time used for disks and tapes
Stream-oriented transfer information as a stream of bytes used for terminals, printers, communication ports,
mouse, and most other devices that are not secondary storage
No Buffering
Operating System User Process
No buffering
I/O DeviceIn
Single Buffer Operating system assigns a buffer in main memory
for an I/O request Block-oriented
input transfers made to buffer block moved to user space when needed another block is moved into the buffer
read ahead Operating System User Process
Single buffering
I/O DeviceIn Move
Single Buffer Block-oriented
user process can process one block of data while next block is read in
swapping can occur since input is taking place in system memory, not user memory
operating system keeps track of assignment of system buffers to user processes
output is accomplished by the user process writing a block to the buffer and later actually written out
Single Buffer Stream-oriented
used a line (or word, or char) at a time user input from a terminal is one line at a time with carriage
return signaling the end of the line output to the terminal is one line at a time
Double Buffer Use two system buffers instead of one A process can transfer data to or from one buffer
while the operating system empties or fills the other buffer
I/O Device In Move
Operating System User Process
Double buffering
Circular Buffer More than two buffers are used Each individual buffer is one unit in a circular
buffer Used when I/O operation must keep up with
process
I/O DeviceIn Move
Operating System User Process
Circular buffering
.
.
Disk Structure
Disk drives are addressed as large 1-dimensional arrays of logical blocks, where the logical block is the smallest unit of transfer
The 1-dimensional array of logical blocks is mapped into the 3-dimensional disk, where the 3 dimensions are cylinder, sector, surface Sector 0 is the first sector of the first track on the
outermost cylinder (top surface) Mapping proceeds in order through that track, then the
rest of the tracks in that cylinder, and then through the rest of the cylinders from outermost to innermost
Disk Structure
All of the sectors that can be accessed without moving the read/write heads belong to the same cylinder
This disk has 12 surfaces A sector is, like a pie slice, a
small angular displacement
Disk Data Layout
Inter-sector gap
Sectors Tracks
Inter-track gap
Disk Layout: Constant Angular Velocity
Track 2, Sector 7 Track 0, Sector 0
Disk Management
Low-level formatting, or physical formatting — Dividing a disk into sectors that the disk controller can read and write
To use a disk to hold files, the operating system still needs to record its own data structures on the disk Partition the disk into one or more groups of cylinders Logical formatting or “making a file system”
Boot block initializes system. The bootstrap is stored in ROM Bootstrap loader program
Methods such as sector sparing used to handle bad blocks
Disk Reliability
Several improvements in disk-use techniques involve the use of multiple disks working cooperatively
Disk striping uses a group of disks as one storage unit
RAID schemes improve performance and improve the reliability of the storage system by storing redundant data Mirroring or shadowing keeps duplicate of each disk Block interleaved parity uses much less redundancy
RAID 0 (non-redundant)
strip 0
strip 4
strip 8
strip 12
strip 1
strip 5
strip 9
strip 13
strip 2
strip 6
strip 10
strip 14
strip 3
strip 7
strip 11
strip 15
RAID 1 (mirrored)
strip 0
strip 4
strip 8
strip 12
strip 1
strip 5
strip 9
strip 13
strip 2
strip 6
strip 10
strip 14
strip 3
strip 7
strip 11
strip 15
strip 0
strip 4
strip 8
strip 12
strip 1
strip 5
strip 9
strip 13
strip 2
strip 6
strip 10
strip 14
strip 3
strip 7
strip 11
strip 15
RAID 2 (redundancy through Hamming code)
f0(b)b2b1b0 b2f1(b) f2(b)
RAID 3 (bit-interleaved parity)
P(b)b2b1b0 b2
RAID 4 (block-level parity)
block 0
block 4
block 8
block 12
block 1
block 5
block 9
block 13
block 2
block 6
block 10
block 14
block 3
block 7
block 11
block 15
P(0-3)
P(4-7)
P(8-11)
P(12-15)
RAID 5 (block-level distributed parity)
block 0
block 4
block 8
block 12
P(16-19)
block 1
block 5
block 9
P(12-15)
block 16
block 2
block 6
P(8-11)
block 13
block 17
block 3
P(4-7)
block 10
block 14
block 18
P(0-3)
block 7
block 11
block 15
block 19
Data Mapping for RAID Level 0 Array
strip 0
strip 4
strip 8
strip 12
strip 1
strip 5
strip 9
strip 13
strip 2
strip 6
strip 10
strip 14
strip 3
strip 7
strip 11
strip 15
PhysicalDisk 0
PhysicalDisk 1
PhysicalDisk 2
PhysicalDisk 3
strip 0
strip 1
strip 2
strip 3
strip 4
strip 15
strip 14
strip 13
strip 12
strip11
strip 10
strip 9
strip 8
strip 7
strip 6
strip 5
ArrayManagement
Software
Disk Cache Buffer in main memory for disk sectors Contains a copy of some of the sectors on the disk
Least Recently Used The block that has been in the cache the longest
with no reference to it is replaced The cache consists of a stack of blocks Most recently referenced block is on the top of the
stack When a block is referenced or brought into the
cache, it is placed on the top of the stack
Least Recently Used The block on the bottom of the stack is removed
when a new block is brought in Blocks don’t actually move around in main
memory A stack of pointers is used
Least Frequently Used The block that has experienced the fewest
references is replaced A counter is associated with each block Counter is incremented each time block accessed Some blocks may be referenced many times in a
short period of time and then not needed any more
Disk Scheduling The operating system is responsible for using hardware efficiently
— for the disk drives, this means having a fast access time and high disk bandwidth.
Access time has two major components Seek time is the time for the disk are to move the heads to the cylinder
containing the desired sector. Rotational latency is the additional time waiting for the disk to rotate the
desired sector to the disk head.
Minimize seek time Seek time seek distance Disk bandwidth is the total number of bytes transferred, divided by
the total time between the first request for service and the completion of the last transfer
Disk Scheduling
Several algorithms exist to schedule the servicing of disk I/O requests.
We illustrate them with a request queue (0-199).
98, 183, 37, 122, 14, 124, 65, 67
Head pointer 53
FCFSIllustration shows total head movement of 640 cylinders
SSTF
Selects the request with the minimum seek time from the current head position
SSTF scheduling may cause starvation of some requests
Illustration shows total head movement of 236 cylinders
SSTF
SCAN
The disk arm starts at one end of the disk, and moves toward the other end, servicing requests until it gets to the other end of the disk, where the head movement is reversed and servicing continues
Sometimes called an elevator algorithm Illustration shows total head movement of 236
cylinders
SCAN
C-SCAN
Provides a more uniform wait time than SCAN The head moves from one end of the disk to the
other, servicing requests as it goes When it reaches the other end, however, it immediately
returns to the beginning of the disk, without servicing any requests on the return trip
Treats the cylinders as a circular list that wraps around from the last cylinder to the first one
C-SCAN
C-LOOK
Version of C-SCAN Arm only goes as far as the last request in each
direction, then reverses direction immediately, without first going all the way to the end of the disk
C-LOOK