Ref: Chap 12 Secondary Storage and I/O Systems Applied Operating System Concepts 12.1
Part 1 - Secondary Storage Secondary storage typically: is anything that is outside of primary memory does not permit direct execution of instructions or data retrieval via machine load/store instructions Characteristics: it s large: 30-60GB it s cheap: 40GB ~ 130. 0.3 cents per megabyte (wow!) it s persistent: data survives power loss it s slow: milliseconds to access why is this slow?? Applied Operating System Concepts 12.2
Typical time for computer components Item Processor cycle Time 0.5 [ns] (2 GHz) Scaled to human terms (2 billion times slower) 1 second Cache access 1 ns (1 GHz) 2 seconds Memory access 15 60 ns 30 sec 2min Context Switch Disk access 5,000 ns (5 usec) 7,000,000 ns (7 ms) ~3 hrs (167 mins) 51/2 months (162 days) Quantum 100,000,000 ns (100 ms) 6.3 years 1 ns = 10-9 seconds 1 usec = 10-6 seconds Applied Operating System Concepts 12.3
Size and Access Time Applied Operating System Concepts 12.4
Disks and the OS Disks are messy devices errors, bad blocks, missed seeks, etc. Job of OS is to hide this mess from higher-level software low-level device drivers (initiate a disk read, etc.) higher-level abstractions (files, databases, etc.) OS may provide different levels of disk access to different clients physical disk block (surface, cylinder, sector) disk logical block (disk block #) file logical (filename, block or record or byte #) Applied Operating System Concepts 12.5
Physical Disk Structure IBM Ultrastar 36XP drive form factor: 3.5 capacity: 36.4 GB rotation rate: 7,200 RPM (120 RPS) platters: 10 surfaces: 20 sector size: 512 to 732 bytes cylinders: 11,494 cache: 4MB transfer rate: 17.9 MB/s (inner) 28.9 MB/s (outer) full seek: 14.5 ms head switch: 0.3 ms Applied Operating System Concepts 12.6
Platter Applied Operating System Concepts 12.7
Interacting with Disks In the old days OS would have to specify cylinder #, sector #, surface #, transfer size I.e., OS needs to know all of the disk parameters Modern disks are even more complicated not all sectors are the same size, sectors are remapped, disk provides a higher-level interface, e.g. SCSI exports data as a logical array of blocks [0 N] maps logical blocks to cylinder/surface/sector OS only needs to name logical block #, disk maps this to cylinder/surface/sector as a result, physical parameters are hidden from OS both good and bad Applied Operating System Concepts 12.8
Disk Performance Performance depends on a number of steps seek: moving the disk arm to the correct cylinder depends on how fast disk arm can move seek times aren t diminishing very quickly rotation: waiting for the sector to rotate under head depends on rotation rate of disk rates are increasing, but slowly transfer: transferring data from surface into disk controller, and from there sending it back to host depends on density of bytes on disk increasing, and very quickly When the OS uses the disk, it tries to minimize the cost of all of these steps particularly seeks and rotation Applied Operating System Concepts 12.9
Disk Scheduling (1) Seeks are very expensive, so the OS attempts to schedule disk requests that are queued waiting for the disk FCFS (do nothing) reasonable when load is low long waiting time for long request queues * requests served in order of arrival * simplest and fairest policy * works well when few processes, each accessing sectors that are clustered together * poor when many processes compete for access to disk SSTF (shortest seek time first) minimize arm movement (seek time), maximize request rate unfairly favors middle blocks * scheduler needs to know current track position * chooses request involving nearest track => method for tie-breaking also needs to be adopted * not optimal, but likely to be better than FIFO * starvation problem Applied Operating System Concepts 12.10
Disk Scheduling (2) SCAN (elevator algorithm) arm moves in one direction only until it reaches last track (or until no further requests in that direction, also known as LOOK), servicing requests as it goes * reverses direction after each scan * no starvation * upon reversal, tracks with highest density of requests likely to be furthest away! skews wait times non-uniformly C-SCAN like scan, but only go in one direction (typewriter) uniform wait times arm flies back to beginning instead of reversing direction upon reaching last track or no further requests in that direction (C- LOOK) Applied Operating System Concepts 12.11
Head Movement Current position: track 100 Requested tracks ( in order received) 55, 58, 39, 18, 90, 160, 150, 38, 184 FIFO: move 45 tracks to track 55; move 3 tracks to track 58; etc. SSTF: move 10 tracks to track 90; move 32 tracks to track 58; etc. SCAN, C-SCAN (moving in direction of increasing track number): move 50 tracks to track 150; move 10 tracks to track 160; etc. Applied Operating System Concepts 12.12
Part 2 - I/O Subsystems I/O hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests to Hardware Operations Performance Applied Operating System Concepts 12.13
I/O Hardware Incredible variety of I/O devices Common concepts Port Bus (daisy chain or shared direct access) Controller (host adapter) I/O instructions control devices Devices have addresses, used by Direct I/O instructions Memory-mapped I/O Applied Operating System Concepts 12.14
Polling Determines state of device command-ready busy error Busy-wait cycle to wait for I/O from device Applied Operating System Concepts 12.15
Interrupts CPU Interrupt request line triggered by I/O device Interrupt handler receives interrupts Maskable to ignore or delay some interrupts Interrupt vector to dispatch interrupt to correct handler Based on priority Some unmaskable Interrupt mechanism also used for exceptions Applied Operating System Concepts 12.16
Interrupt-driven I/O Cycle Applied Operating System Concepts 12.17
Direct Memory Access Used to avoid programmed I/O for large data movement Requires DMA controller Bypasses CPU to transfer data directly between I/O device and memory Applied Operating System Concepts 12.18
Six step process to perform DMA transfer Applied Operating System Concepts 12.19
Application I/O Interface I/O system calls encapsulate device behaviors in generic classes Device-driver layer hides differences among I/O controllers from kernel Devices vary in many dimensions Character-stream or block Sequential or random-access Sharable or dedicated Speed of operation read-write, read only, or write only Applied Operating System Concepts 12.20
Block and Character Devices Block devices include disk drives Commands include read, write, seek Raw I/O or file-system access Memory-mapped file access possible Character devices include keyboards, mice, serial ports Commands include get, put Libraries layered on top allow line editing Applied Operating System Concepts 12.21
Network Devices Varying enough from block and character to have own interface Unix and Windows/NT include socket interface Separates network protocol from network operation Includes select functionality Approaches vary widely (pipes, FIFOs, streams, queues, mailboxes) Applied Operating System Concepts 12.22
Clocks and Timers Provide current time, elapsed time, timer if programmable interval time used for timings, periodic interrupts ioctl (on UNIX) covers odd aspects of I/O such as clocks and timers Applied Operating System Concepts 12.23
Blocking and Nonblocking I/O Blocking - process suspended until I/O completed Easy to use and understand Insufficient for some needs Nonblocking - I/O call returns as much as available User interface, data copy (buffered I/O) Implemented via multi-threading Returns quickly with count of bytes read or written Asynchronous - process runs while I/O executes Difficult to use I/O subsystem signals process when I/O completed Applied Operating System Concepts 12.24
Kernel I/O Subsystem Scheduling Some I/O request ordering via per-device queue Some OSs try fairness Buffering - store data in memory while transferring between devices To cope with device speed mismatch To cope with device transfer size mismatch To maintain copy semantics Applied Operating System Concepts 12.25
Kernel I/O Subsystem Caching - fast memory holding copy of data Always just a copy Key to performance Spooling - hold output for a device If device can serve only one request at a time i.e., Printing Device reservation - provides exclusive access to a device System calls for allocation and deallocation Watch out for deadlock Applied Operating System Concepts 12.26
Error Handling OS can recover from disk read, device unavailable, transient write failures Most return an error number or code when I/O request fails System error logs hold problem reports Applied Operating System Concepts 12.27
Kernel Data Structures Kernel keeps state info for I/O components, including open file tables, network connections, character device state Many, many complex data structures to track buffers, memory allocation, dirty blocks Some use object-oriented methods and message passing to implement I/O Applied Operating System Concepts 12.28
I/O Requests to Hardware Operations Consider reading a file from disk for a process Determine device holding file Translate name to device representation Physically read data from disk into buffer Make data available to requesting process Return control to process Applied Operating System Concepts 12.29
Life Cycle of an I/O Request Applied Operating System Concepts 12.30
Performance I/O a major factor in system performance Demands CPU to execute device driver, kernel I/O code Context switches due to interrupts Data copying Network traffic especially stressful Applied Operating System Concepts 12.31
Intercomputer communications Applied Operating System Concepts 12.32
Improving 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 Applied Operating System Concepts 12.33