I/O Management and Disk Structure Introduction to Operating Systems: Module 14
Operating System Design Objectives u I/O is extremely slow compared to main memory, CPU u Use of multiprogramming allows for some processes to be waiting on I/O while another process executes u Efficiency and generality are important u Try to handle all I/O devices in a uniform manner u 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 Device I/O Scheduling & Control Scheduling & Control Local peripheral deviceCommunications portFile System Device I/O Device I/O Hardware User Processes User Processes User Processes User Processes User Processes User Processes Logical I/O Comm. Architecture Directory Management File System Physical Organization
I/O Buffering u 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 u Block-oriented information is stored in fixed sized blocks transfers are made a block at a time used for disks and tapes u 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 SystemUser Process No buffering I/O Device In
Single Buffer u Operating system assigns a buffer in main memory for an I/O request u Block-oriented input transfers made to buffer block moved to user space when needed another block is moved into the buffer read ahead Operating SystemUser Process Single buffering I/O Device InMove
Single Buffer u 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 u 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 u Use two system buffers instead of one u 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 SystemUser Process Double buffering
Circular Buffer u More than two buffers are used u Each individual buffer is one unit in a circular buffer u Used when I/O operation must keep up with process I/O Device InMove Operating SystemUser Process Circular buffering..
Disk Structure u Disk drives are addressed as large 1-dimensional arrays of logical blocks, where the logical block is the smallest unit of transfer u 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 u All of the sectors that can be accessed without moving the read/write heads belong to the same cylinder u This disk has 12 surfaces u A sector is, like a pie slice, a small angular displacement
Disk Data Layout Inter-sector gap SectorsTracks Inter-track gap
Disk Layout: Constant Angular Velocity Track 2, Sector 7 Track 0, Sector 0
Disk Management u Low-level formatting, or physical formatting — Dividing a disk into sectors that the disk controller can read and write u 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” u Boot block initializes system. The bootstrap is stored in ROM Bootstrap loader program u Methods such as sector sparing used to handle bad blocks
Disk Reliability u Several improvements in disk-use techniques involve the use of multiple disks working cooperatively u Disk striping uses a group of disks as one storage unit u 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) f 0 (b) b2b2 b1b1 b0b0 b2b2 f 1 (b) f 2 (b)
RAID 3 (bit-interleaved parity) P(b) b2b2 b1b1 b0b0 b2b2
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 Physical Disk 0 Physical Disk 1 Physical Disk 2 Physical Disk 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 Array Management Software
Disk Cache u Buffer in main memory for disk sectors u Contains a copy of some of the sectors on the disk
Least Recently Used u The block that has been in the cache the longest with no reference to it is replaced u The cache consists of a stack of blocks u Most recently referenced block is on the top of the stack u When a block is referenced or brought into the cache, it is placed on the top of the stack
Least Recently Used u The block on the bottom of the stack is removed when a new block is brought in u Blocks don’t actually move around in main memory u A stack of pointers is used
Least Frequently Used u The block that has experienced the fewest references is replaced u A counter is associated with each block u Counter is incremented each time block accessed u Some blocks may be referenced many times in a short period of time and then not needed any more
Disk Scheduling u The operating system is responsible for using hardware efficiently — for the disk drives, this means having a fast access time and high disk bandwidth. u 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. u Minimize seek time u Seek time seek distance u 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 u Several algorithms exist to schedule the servicing of disk I/O requests. u We illustrate them with a request queue (0-199). 98, 183, 37, 122, 14, 124, 65, 67 Head pointer 53
FCFS Illustration shows total head movement of 640 cylinders
SSTF u Selects the request with the minimum seek time from the current head position u SSTF scheduling may cause starvation of some requests u Illustration shows total head movement of 236 cylinders
SSTF
SCAN u 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 u Sometimes called an elevator algorithm u Illustration shows total head movement of 236 cylinders
SCAN
C-SCAN u Provides a more uniform wait time than SCAN u 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 u Treats the cylinders as a circular list that wraps around from the last cylinder to the first one
C-SCAN
C-LOOK u Version of C-SCAN u 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