Presentation is loading. Please wait.

Presentation is loading. Please wait.

Silberschatz, Galvin, and Gagne  1999 12.1 Applied Operating System Concepts Ref: Chap 12 Secondary Storage and I/O Systems.

Similar presentations


Presentation on theme: "Silberschatz, Galvin, and Gagne  1999 12.1 Applied Operating System Concepts Ref: Chap 12 Secondary Storage and I/O Systems."— Presentation transcript:

1 Silberschatz, Galvin, and Gagne  1999 12.1 Applied Operating System Concepts Ref: Chap 12 Secondary Storage and I/O Systems

2 Silberschatz, Galvin, and Gagne  1999 12.2 Applied Operating System Concepts 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??

3 Silberschatz, Galvin, and Gagne  1999 12.3 Applied Operating System Concepts Typical time for computer components 6.3 years100,000,000 ns (100 ms)‏Quantum 51/2 months (162 days)‏7,000,000 ns (7 ms)‏Disk access ~3 hrs (167 mins)‏5,000 ns (5 usec)‏ Context Switch 30 sec– 2min15 – 60 nsMemory access 2 seconds1 ns (1 GHz)‏Cache access 1 second0.5 [ns] (2 GHz)‏Processor cycle Scaled to human terms (2 billion times slower)‏ TimeItem 1 ns = 10 -9 seconds 1 uSec = 10 -6 seconds

4 Silberschatz, Galvin, and Gagne  1999 12.4 Applied Operating System Concepts Size and Access Time

5 Silberschatz, Galvin, and Gagne  1999 12.5 Applied Operating System Concepts 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 #)‏

6 Silberschatz, Galvin, and Gagne  1999 12.6 Applied Operating System Concepts 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

7 Silberschatz, Galvin, and Gagne  1999 12.7 Applied Operating System Concepts Platter

8 Silberschatz, Galvin, and Gagne  1999 12.8 Applied Operating System Concepts 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

9 Silberschatz, Galvin, and Gagne  1999 12.9 Applied Operating System Concepts 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

10 Silberschatz, Galvin, and Gagne  1999 12.10 Applied Operating System Concepts 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

11 Silberschatz, Galvin, and Gagne  1999 12.11 Applied Operating System Concepts 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)

12 Silberschatz, Galvin, and Gagne  1999 12.12 Applied Operating System Concepts 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.

13 Silberschatz, Galvin, and Gagne  1999 12.13 Applied Operating System Concepts New Hard-Drive Preparation See notes on formatting hard-drives

14 Silberschatz, Galvin, and Gagne  1999 12.14 Applied Operating System Concepts I/O hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests to Hardware Operations Performance Part 2 - I/O Subsystems

15 Silberschatz, Galvin, and Gagne  1999 12.15 Applied Operating System Concepts 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

16 Silberschatz, Galvin, and Gagne  1999 12.16 Applied Operating System Concepts Polling Determines state of device –command-ready –busy –error Busy-wait cycle to wait for I/O from device

17 Silberschatz, Galvin, and Gagne  1999 12.17 Applied Operating System Concepts 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

18 Silberschatz, Galvin, and Gagne  1999 12.18 Applied Operating System Concepts Interrupt-driven I/O Cycle

19 Silberschatz, Galvin, and Gagne  1999 12.19 Applied Operating System Concepts Direct Memory Access Direct memory access (DMA) is a feature of modern computers that allows certain hardware subsystems within the computer to access system memory for reading and/or writing independently of the central processing unit –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 Many hardware systems use DMA including disk drive controllers, graphics cards, network cards, and sound cards. Computers that have DMA channels can transfer data to and from devices with much less CPU overhead than computers without a DMA channel.

20 Silberschatz, Galvin, and Gagne  1999 12.20 Applied Operating System Concepts DMA on ISA and PCI bus A DMA transfer essentially copies a block of memory from one device to another. While the CPU initiates the transfer, it does not execute it. For so-called "third party" DMA, as is normally used with the ISA bus, the transfer is performed by a DMA controller which is typically part of the motherboard chipset. More advanced bus designs such as PCI typically use bus mastering DMA, where the device takes control of the bus and performs the transfer itself –More precisely, a PCI component requests bus ownership from the PCI bus controller (usually the southbridge in a modern PC design), which will arbitrate if several devices request bus ownership simultaneously, since there can only be one bus master at one time. –When the component is granted ownership, it will issue normal read and write commands on the PCI bus, which will be claimed by the bus controller and forwarded to the memory controller using a scheme which is specific to every chipset..

21 Silberschatz, Galvin, and Gagne  1999 12.21 Applied Operating System Concepts Six step process to perform DMA transfer

22 Silberschatz, Galvin, and Gagne  1999 12.22 Applied Operating System Concepts 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

23 Silberschatz, Galvin, and Gagne  1999 12.23 Applied Operating System Concepts 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

24 Silberschatz, Galvin, and Gagne  1999 12.24 Applied Operating System Concepts 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)‏

25 Silberschatz, Galvin, and Gagne  1999 12.25 Applied Operating System Concepts 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

26 Silberschatz, Galvin, and Gagne  1999 12.26 Applied Operating System Concepts 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

27 Silberschatz, Galvin, and Gagne  1999 12.27 Applied Operating System Concepts 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”

28 Silberschatz, Galvin, and Gagne  1999 12.28 Applied Operating System Concepts 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

29 Silberschatz, Galvin, and Gagne  1999 12.29 Applied Operating System Concepts 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

30 Silberschatz, Galvin, and Gagne  1999 12.30 Applied Operating System Concepts 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

31 Silberschatz, Galvin, and Gagne  1999 12.31 Applied Operating System Concepts 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

32 Silberschatz, Galvin, and Gagne  1999 12.32 Applied Operating System Concepts Life Cycle of an I/O Request

33 Silberschatz, Galvin, and Gagne  1999 12.33 Applied Operating System Concepts 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

34 Silberschatz, Galvin, and Gagne  1999 12.34 Applied Operating System Concepts Intercomputer communications

35 Silberschatz, Galvin, and Gagne  1999 12.35 Applied Operating System Concepts 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


Download ppt "Silberschatz, Galvin, and Gagne  1999 12.1 Applied Operating System Concepts Ref: Chap 12 Secondary Storage and I/O Systems."

Similar presentations


Ads by Google