Download 12io.pdf

Document related concepts
Transcript
Operating Systems
CSE 410, Spring 2004
I/O Management and Disk Scheduling
Stephen Wagner
Michigan State University
Categories of I/O Devices
• Human readable
• Machine readable
• Communications
Human Readable I/O Devices
• Used to communicate with the user
• Printers
• Video Terminal
• Keyboard
• Mouse
• Speakers
Machine Readable I/O Devices
• Used to communicate with electronic devices
• Disk and tape drives
• Sensors
• Controllers
Communication I/O Devices
• Networks
• Digital Line Drivers
• Modems
Differences in I/O Devices
• Data Rate
• Application
• Complexity of Control
Data Rate Differences
• Different I/O devices will have different data rates.
• There may be several orders of magnitude difference
between the data rates
• The data rate affects how the OS communicates with
the I/O
Gigabit Ethernet
Graphics display
Hard disk
Ethernet
Optical disk
Scanner
Laser printer
Floppy disk
Modem
Mouse
Keyboard
101
102
103
104
105
106
107
Data Rate (bps)
Figure 11.1 Typical I/O Device Data Rates
108
109
Application Differences
• Disk used to store files requires file management
software
• Disk used to store virtual pages needs special hardware
and software
• A Terminal used by an administrator may be given
higher priority
Complexity Differences
• Unit of Transfer
– Data may be transferred as a stream of bytes for a
terminal or in larger blocks for a disk
• Data representation
• Error conditions
Techniques for Performing I/O
• Programmed I/O
– Processor busy waits for the I/O to complete
– Even the fastest I/O devices are slow compared to the
processor
• Interrupt-driver I/O
– I/O command is issued
– Processor continues executing another process
– I/O module sends an interrupt when it is done
Direct Memory Access (DMA)
• DMA module controls exchange of data between main
memory and I/O device
• Processor interrupted only after entire block has been
transferred
• Processor does not have to be involved in moving every
piece of data
Evolution of I/O
• Processor directly controls a peripheral device
• Controller or I/O module added
– Programmed I/O used
– Processor does not need to handle the details of
external devices
Evolution of I/O
• Interrupt Driven I/O used
– Processor does not have to spend time waiting for an
I/O operation to be performed
– Processor is still busy moving data
• Direct Memory Access
– Blocks of data are moved in and out of memory
without involving the processor
– Processor is only involved at beginning and end
Evolution of I/O
• I/O module is a separate processor
• I/O processor
– I/O module has its own memory
– Its a computer in its own right
• Local disk → NetApp
Details of DMA
• Processor sends the following information to the DMA
– Whether a read or write is requested
– The address of the I/O device involved
– The starting location in memory to read or write from
(physical address)
– The number of words to be read or written
Details of DMA
Data
Count
Data Lines
Data
Register
Address Lines
Address
Register
DMA Request
DMA Acknowledge
Interrupt
Read
Write
Control
Logic
Figure 11.2 Typical DMA Block Diagram
Details of DMA
• Goal: the I/O and memory communicate directly so
that the processor can work on other things
• How to do this without interfering with the processor?
• Answer depends on the hardware
• How do the I/O and memory physically communicate?
Simple Bus Architecture
Processor
DMA
I/O
• • •
I/O
Memory
(a) Single-bus, detached DMA
Processor
DMA
Memory
DMA
I/O
I/O
(b) Single-bus, Integrated DMA-I/O
I/O
DMA: Cycle Stealing
• DMA takes control of the system from the CPU to transfer data
to and from memory over the system bus
• A cycle is “stolen” from the CPU. The CPU does not have to do
any work, but it cannot use the bus while the DMA is using it
• The instruction cycle is suspended so data can be transferred
• The CPU pauses one bus cycle
• No interrupts occur
Time
Instruction Cycle
Processor
Cycle
Processor
Cycle
Processor
Cycle
Processor
Cycle
Processor
Cycle
Processor
Cycle
Fetch
Instruction
Decode
Instruction
Fetch
Operand
Execute
Instruction
Store
Result
Process
Interrupt
DMA
Breakpoints
Interrupt
Breakpoint
Figure 11.3 DMA and Interrupt Breakpoints During an Instruction Cycle
DMA: Cycle Stealing
• Cycle stealing causes the CPU to execute more slowly
• Number of required busy cycles can be cut by integrating
the DMA and I/O functions
• Hardware can provide a path between DMA module and
I/O module that does not include the system bus
• DMA can talk to I/O without interfering with processor
Simple Bus Architecture
Processor
DMA
I/O
• • •
I/O
Memory
(a) Single-bus, detached DMA
Cycle stolen so DMA can make I/O transfer request, and
another Processor
cycle stolen
Memory
DMA so DMA can
DMAtransfer data.
I/O
I/O
(b) Single-bus, Integrated DMA-I/O
I/O
Processor
DMA
Memory
DMA
I/O
I/O
I/O
(b) Single-bus, Integrated DMA-I/O
System bus
Processor
Memory
DMA
I/O bus
I/O
I/O
I/O
(c) I/O bus
Alternatives
Figure 11.4 Alternative DMA Configurations
Operating System Design Issues
• Efficiency
– Most I/O devices are extremely slow compared to
main memory and the CPU
– Use of multiprogramming allows for some processes to
be waiting on I/O while another process executes
– I/O cannot keep up with processor speed
– Swapping is used to bring in additional processes
Operating System Design Issues
• Generality
– Desirable 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 see devices in general terms
such as read, write, open, close, lock, unlock
User
Processes
User
Processes
User
Processes
Directory
Management
Logical
I/O
Communication
Architecture
File
System
Physical
Organization
Device
I/O
Device
I/O
Device
I/O
Scheduling
& Control
Scheduling
& Control
Scheduling
& Control
Hardware
Hardware
Hardware
(a) Local peripheral device
(b) Communications port
(c) File system
Figure 11.5 A Model of I/O Organization
I/O Buffering
• Block-oriented
– Information is stored in fixed size 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
I/O Buffering
• DMA transfers do not involve the OS
• DMA works with physical addresses
• Certain pages must remain in memory during I/O
• Processes waiting for I/O are blocked, and are
candidates for being swapped out
I/O Buffering
• Operating System assigns a buffer in main memory for
an I/O request
• This allows the OS to evict the pages of a process
waiting on I/O
• Block-Oriented
– Input transfers made to buffer
– Block moved to user space when needed
– Another block is moved into the buffer
Operating System
I/O Device
User Process
In
(a) No buffering
Operating System
I/O Device
In
User Process
Move
(b) Single buffering
Operating System
I/O Device
In
User Process
Move
Double Buffering
• With a single buffer the user process must copy the data
from the buffer before the I/O reads the next block into
the buffer
• This may prevent us from efficiently using the processor
and I/O
• Solution is to use two buffers
• A process can transfer data to one buffer while the
operating system empty or fills another buffer
Circular Buffering
• Generalization of double buffering
• 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 the process
Operating System
I/O Device
In
User Process
Move
(c) Double buffering
Operating System
I/O Device
In
User Process
Move
•
•
(d) Circular buffering
Figure 11.6
I/O Buffering Schemes (input)
Disks
Sectors
Tracks
Inter-sector gap
• •
•
S6
Inter-track gap
• • •
S6
S5
SN
S5
SN
S4
S1
S4
S1
S2
S2
S3
S3
Figure 11.17 Disk Data Layout
Disk Performance Parameters
• To read or write, the disk head must be positioned at
the desired track and at the beginning of the desired
sector
• Seek time
– The time it takes to position the head at the desired
track
• Rotational delay or latency
– The time it takes for the beginning of the sector to
reach the head.
Timing of Disk I/O Transfer
Wait for
Device
Wait for
Channel
Seek
Rotational
Delay
Device Busy
Figure 11.7 Timing of a Disk I/O Transfer
Data
Transfer
Disk Performance Parameters
• Access time
– Sum of seek time and rotational delay
– The time it takes to get in position to read or write
• Data transfer occurs at the sector moves under the head
Disk Scheduling Policies
• Seek time is the reason for differences in performance
• We have little control over rotational delay
• For a single disk there will be a number of I/O requests
• If requests are selected randomly, we will get poor
performance
Timing Comparison
• A file occupies all 320 sectors on 8 adjacent tracks
Sequential Access
Random Access
–
–
–
–
–
–
–
–
–
Avg. seek: 10ms
Rot. Delay: 3ms
Read 1st Track: 6ms
Read next track: 3+6=9ms
Total Time = 19+7*9=82ms
Avg. seek: 10ms
Rot. Delay: 3ms
Read One Sector: .01875ms
Total Time=8*320*.01875ms
33,328 ms
Disk Scheduling Policies
• FIFO
• Process requests sequentially
• Fair to all processes
• Approaches random scheduling in performance if there
are many processes
Disk Scheduling Policies
• Priority
– Goal is not to optimize disk usage but to meet other
objectives
– Short batch jobs may have higher priority
– Provide good interactive response time
Disk Scheduling Policies
• Last in, First out
– Minimizes seek time, assuming a process tends to read
from similar areas of the disk
– May lead to starvation
Disk Scheduling Policies
• Shortest Service Time First (SST)
– Select the request that requires the least amount of
movement of the disk head
– May lead to starvation
Disk Scheduling and Elevators
• Moving a disk head is kind of like moving an elevator
• Which floor should an elevator head to next?
• In FIFO, you would go to your floor, not stopping to
pick people up or let them off on the way.
• In SST, the elevator may bounce around the middle
floors, and only rarely make it to the top or bottom
Disk Scheduling Policies
• SCAN ( Elevator Algorithm)
– Head moves in one direction only, server all requests
it encounters in the order encountered
– When it reaches the last track, or the last track with
any requests on it, it reverses direction
Disk Scheduling Policies
• C SCAN ( Elevator Algorithm)
– Head moves in one direction only, server all requests
it encounters in the order encountered
– When it reaches the last track, or the last track with
any requests on it, it returns to the first track.
– It only serves requests while going in the “forward”
direction
Disk Scheduling Policies
• SCAN policies will favor new requests if they are on the
same track as an older request
• We can modify scan slightly to favor older requests
–
–
–
–
–
F SCAN.
Requests are put into two queues
One queue is serviced using the SCAN algorithm
New requests are added to the other queue
A new request will not be serviced until all requests in the old
queue are serviced
RAID
• RAID: Redundant Array of Independent (Inexpensive)
Disks
• Improvement rat in secondary storage is slow
• Uses multiple disks to improve efficiency and reliability
RAID 0
strip 0
strip 1
strip 2
strip 3
strip 4
strip 5
strip 6
strip 7
strip 8
strip 9
strip 10
strip 11
strip 12
strip 13
strip 14
strip 15
(a) RAID 0 (non-redundant)
strip 0
strip 1
strip 2
strip 3
strip 0
strip 1
strip 4
strip 5
strip 6
strip 7
strip 4
strip 5
strip 8
strip 9
strip 10
strip 11
strip 8
strip 9
strip 12
strip 13
strip 14
strip 15
strip 12
strip 13
Logical Disk
Physical
Disk 0
Physical
Disk 1
Physical
Disk 2
Physical
Disk 3
strip 0
strip 0
strip 1
strip 2
strip 3
strip 1
strip 4
strip 5
strip 6
strip 7
strip 2
strip 8
strip 9
strip 10
strip 11
strip 3
strip 12
strip 13
strip 14
strip 15
strip 4
strip 5
strip 6
strip 7
strip 8
strip 9
Array
Management
Software
strip 10
strip 11
strip 12
strip 13
strip 14
strip 15
Figure 11.10 Data Mapping for a RAID Level 0 Array [MASS97]
strip 0
strip 1
strip 2
strip 3
strip 4
strip 5
strip 6
strip 7
strip 8
strip 9
strip 10
strip 11
strip 12
strip 13
strip 14
strip 15
RAID 1 (Mirrored)
(a) RAID 0 (non-redundant)
strip 0
strip 1
strip 2
strip 3
strip 0
strip 1
strip 2
strip 3
strip 4
strip 5
strip 6
strip 7
strip 4
strip 5
strip 6
strip 7
strip 8
strip 9
strip 10
strip 11
strip 8
strip 9
strip 10
strip 11
strip 12
strip 13
strip 14
strip 15
strip 12
strip 13
strip 14
strip 15
b2
b3
f0(b)
f1(b)
f2(b)
(b) RAID 1 (mirrored)
b0
b1
(c) RAID 2 (redundancy through Hamming code)
Figure 11.9
RAID Levels (page 1 of 2)
strip 0
strip 1
strip 2
strip 3
strip 0
strip 1
strip 2
strip 3
strip 4
strip 5
strip 6
strip 7
strip 4
strip 5
strip 6
strip 7
strip 8
strip 9
strip 10
strip 11
strip 8
strip 9
strip 10
strip 11
strip 12
strip 13
strip 14
strip 15
strip 12
strip 13
strip 14
strip 15
b3
f0(b)
f1(b)
f2(b)
RAID 2
(b) RAID 1 (mirrored)
b0
b1
b2
(c) RAID 2 (redundancy through Hamming code)
Figure 11.9
RAID Levels (page 1 of 2)
RAID 3
b0
b1
b2
b3
P(b)
(d) RAID 3 (bit-interleaved parity)
block 0
block 1
block 2
block 3
P(0-3)
block 4
block 5
block 6
block 7
P(4-7)
block 8
block 9
block 10
block 11
P(8-11)
b0
b1
b
RAID
4
2
b3
P(b)
(d) RAID 3 (bit-interleaved parity)
block 0
block 1
block 2
block 3
P(0-3)
block 4
block 5
block 6
block 7
P(4-7)
block 8
block 9
block 10
block 11
P(8-11)
block 12
block 13
block 14
block 15
P(12-15)
(e) RAID 4 (block-level parity)
block 0
block 1
block 2
block 3
P(0-3)
block 4
block 5
block 6
P(4-7)
block 7
block 8
block 9
P(8-11)
block 10
block 11
block 12
P(12-15)
block 13
block 14
block 15
block 8
block 9
block 10
block 11
P(8-11)
block 12
block 13
block 14
block 15
P(12-15)
RAID 5
(e) RAID 4 (block-level parity)
block 0
block 1
block 2
block 3
P(0-3)
block 4
block 5
block 6
P(4-7)
block 7
block 8
block 9
P(8-11)
block 10
block 11
block 12
P(12-15)
block 13
block 14
block 15
P(16-19)
block 16
block 17
block 18
block 19
(f) RAID 5 (block-level distributed parity)
block 0
block 1
block 2
block 3
P(0-3)
Q(0-3)
block 4
block 5
block 6
P(4-7)
Q(4-7)
block 7
block 8
block 9
P(8-11)
Q(8-11)
block 10
block 11
block 12
P(12-15)
Q(12-15)
block 13
block 14
block 15
block 12
P(12-15)
block 13
block 14
block 15
P(16-19)
block 16
block 17
block 18
block 19
RAID 6
(f) RAID 5 (block-level distributed parity)
block 0
block 1
block 2
block 3
P(0-3)
Q(0-3)
block 4
block 5
block 6
P(4-7)
Q(4-7)
block 7
block 8
block 9
P(8-11)
Q(8-11)
block 10
block 11
block 12
P(12-15)
Q(12-15)
block 13
block 14
block 15
(g) RAID 6 (dual redundancy)
Figure 11.9 RAID Levels (page 2 of 2)
Disk Cache
• Buffer in main memory used to store disk sectors
• Contains a copy of some of the sectors that are stored
on disk
• Similar to virtual memory. Reads and writes to memory
are much faster than writes to disk.
• Not all sectors can be stored in memory, so we
sometimes have to evict sectors.
Replacement Policies for Disk Caches
• Least Recently Used
• Least Frequently Used
UNIX SRV4 I/O
File Subsystem
Buffer Cache
Character
Block
Device Drivers
Figure 11.14 UNIX I/O Structure
W2K
I/O Manager
Cache
Manager
File System
Drivers
Network
Drivers
Hardware
Device Drivers
Figure 11.16 Windows 2000 I/O Manager
W2K
• Cache Manager: Used by entire I/O subsystem. Caches
file data in memory. Uses lazy writes.
• File system drivers: the I/O manager treats a file system
like any other device driver and routes message to the
appropriate software driver
• Network drivers: W2K includes integrated networking
capabilities
• Hardware device drivers: low level drivers that access
the hardware registers of the peripheral devices