se350 operating systems
play

SE350: Operating Systems Lecture 13: I/O and Storage Devices - PowerPoint PPT Presentation

SE350: Operating Systems Lecture 13: I/O and Storage Devices Outline I/O subsystem Magnetic storage Flash memory Whats Next? So far in this course: We have learned how to manage CPU and memory What about I/O?


  1. SE350: Operating Systems Lecture 13: I/O and Storage Devices

  2. Outline • I/O subsystem • Magnetic storage • Flash memory

  3. What’s Next? • So far in this course: • We have learned how to manage CPU and memory • What about I/O? • Without I/O, computers are useless (disembodied brains?) • But … thousands of devices, each slightly different • How can we standardize interfaces to these devices? • Devices unreliable: media failures and transmission errors • How can we make them reliable? • Devices unpredictable and/or slow • How can we manage them if we don’t know what they will do or how they will perform?

  4. Operational Parameters for I/O • Data granularity: Byte vs. Block • Some devices provide single byte at a time (e.g., keyboard) • Others provide whole blocks (e.g., disks, networks, etc.) • Access pattern: Sequential vs. Random • Some devices must be accessed sequentially (e.g., tape) • Others can be accessed “randomly” (e.g., disk, cd, etc.) • Fixed overhead to start transfers • Notification mechanisms: Polling vs. Interrupt • Some devices require continual monitoring • Others generate interrupts when they need service

  5. Kernel Device Structure The System Call Interface Process Memory Device Filesystems Networking Management Management Control Concurrency, Files and dirs: Virtual TTYs and Connectivity multitasking the VFS memory device access File System Network Types Subsystem Architecture Memory Device Dependent Manager Control Block IF drivers Code Devices

  6. Modern I/O Systems network

  7. Goal of I/O Subsystem • Provide uniform interfaces, despite wide range of different devices • This code works on many different devices: FILE fd = fopen("/dev/something", "rw"); for (int i = 0; i < 10; i++) { fprintf(fd, "Count %d\n", i); } close(fd); • Why? Because device drivers implements standard interface • We will get a flavor for what is involved in controlling devices in this lecture • We can only scratch the surface!

  8. I/O Device Types • Character devices: e.g. keyboards, mice, serial ports, some USB devices • Access single characters at a time • Commands include get(), put() • Libraries layered to allow line editing • Block devices: e.g. disk drives, tape drives, DVD-ROM • Access blocks of data • Commands include open(), read(), write(), seek() • Network devices: e.g. Ethernet, Wireless, Bluetooth • Different enough from block/character to have its own interface • Unix and Windows include socket interface • Separates network protocol from network operation • Includes select() functionality • Usage: pipes, FIFOs, streams, queues, mailboxes

  9. I/O Standard Interfaces • Blocking interface: “Wait” • When request data (e.g. read() syscall), put to sleep until data is ready • When write data (e.g. write() syscall), put to sleep until device is ready • Non-blocking interface:“Don’t wait” • Return quickly from read or write with count of bytes successfully transferred • Read may return nothing, write may write nothing • Asynchronous interface: “Tell me later” • When request data, take pointer to user’s buffer, return immediately; later kernel fills buffer and notifies user • When send data, take pointer to user’s buffer, return immediately; later kernel takes data and notifies user

  10. I/O Transfer Rates • Transfer rates vary over 7 orders of magnitude! • System better be able to handle this wide range • Better not have high overhead/byte for fast devices! • Better not waste time waiting for slow devices

  11. I/O Data Access Processor Memory Bus Regular Memory CPU Bus Bus Adaptor Adaptor Device Controller Address + Data Other Devices Hardware Bus or Buses Interface Controller Interrupt Interrupt Request Controller read Addressable write Memory control status and/or Registers Queues (port 0x20) Memory Mapped Region: 0x8f008020 • Device controller (may) contains • Set of registers and memory buffers that can be read and written • CPU accesses registers/buffers in two ways • Port mapped I/O: in/out instructions • Example from Intel architecture: out 0x21,AL • Memory mapped I/O: load/store instructions • Registers/memory appear in physical address space and accessed by load/store instructions

  12. Memory Mapped I/O • Physical address space is shared between DRAM and I/O 0x00000000 • HW maps control registers and device memory into physical address space DRAM Physical • Set by HW jumpers or at boot time Address Ranges 0x7FFFFFFF • I/O-access instructions • load a1, (0xC00…) // To read 0xC0001000 Audio Controller • store (0xC00…), b2 . // To write 0xC0002000 Keyboard Controller 0xC0003000 • Example: writing to display memory Disk Controller (also called the “frame buffer”) changes image on screen = 2 32 -1 0xFFFFFFFF

  13. I/O Notification Mechanisms • I/O Interrupt • Device generates interrupt whenever it needs service • Pro: handles unpredictable events well • Con: interrupts have relatively high overhead • Polling • OS periodically checks device-specific status register • I/O device puts completion information in status register • Pro: low overhead • Con: may waste many cycles on polling if infrequent or unpredictable I/O operations • Actual devices combine both polling and interrupts • For instance – High-bandwidth network adapter • Interrupt for first incoming packet • Poll for following packets until hardware queues are empty

  14. I/O Data Transfer • Programmed I/O • Each byte transferred via processor in/out or load/store • Pro: Simple hardware, easy to program • Con: Consumes processor cycles proportional to data size • Direct Memory Access (DMA) • Give controller access to memory bus • Ask it to transfer data blocks to/from memory directly

  15. DMA Transfer 1 6 5 2 4 3

  16. Review: Performance Concepts • Response Time/Latency: Time to perform an operation • Bandwidth/Throughput: Rate of executing operations (op/s) • Files: MB/s, Networks: Mb/s, Arithmetic: GFLOP/s • Overhead: time to initiate an operation • Most I/O operations are roughly linear in n bytes • Latency(n) = Overhead + n/Bandwidth

  17. Example: Fast Network • Consider a 1 Gb/s link (B = 128 MB/s ) • With startup cost S = 1 ms • Latency(n) = S + n/B • Bandwidth = n/(S + n/B) = B x n/(B x S + n) = B/(B x S/n + 1) • Bandwidth = B/2 when n = S x B

  18. Example: Disk (10ms Startup) 18,000"" 50"" 45"" 16,000"" 40"" 14,000"" Bandwidth)(mB/s)) 35"" 12,000"" Latency)(us)) 30"" 10,000"" 25"" 8,000"" 20"" 6,000"" 15"" 4,000"" 10"" n = 1,280,000 bytes! 2,000"" 5"" 0"" 0"" 0"" 50,000""100,000"" 150,000"" 200,000"" 250,000"" 300,000"" 350,000"" 400,000"" 450,000"" 500,000"" Length)(b))

  19. What Determines Peak BW for I/O? • Bus speed (per lane) • Ultra Wide SCSI: 320 Mb/s • Serial Attached SCSI & Serial ATA & IEEE 1394 (firewire): 1.6 Gb/s • USB 3.0 – 5 Gb/s • PCI-X: > 8.5 Gb/s (1064 MB/s = 133 MHz x 64 bit) • Thunderbolt 3 – 40 Gb/s • PCI Express (v. 6, RS-544/514): 60 Gb/s • Device transfer bandwidth • Rotational speed of disk • Write/Read rate of NAND flash • Signaling rate of network link • Whatever is the bottleneck in the path…

  20. Storage Devices • Magnetic disks • Storage that rarely becomes corrupted • Large capacity at low cost • Block level random access (except for Shingled Magnetic Recording (SMR)) • Slow performance for random access • Better performance for sequential access • Flash memory • Storage that rarely becomes corrupted • Capacity at intermediate cost (5-20x disk) • Block level random access • Good performance for reads; worse for random writes • Erasure requirement in large blocks • Wear patterns issue

  21. The Amazing Magnetic Disk • Unit of transfer: Sector • Ring of sectors form track track t spindle • Stack of tracks form cylinder • Heads position on cylinders arm assembly sector s • Disk tracks ~ 1µm (micron) wide • Wavelength of light is ~ 0.5µm read-write cylinder c head • Resolution of human eye: 50µm • 100K tracks on a typical 2.5” disk platter arm • Separated by unused guard regions rotation • Reduces likelihood neighboring tracks are corrupted during writes (still small non-zero chance)

  22. The Amazing Magnetic Disk (cont.) • Track length varies across disk • Outside: More sectors per track, higher bandwidth • Disk is organized into regions of tracks with same # of sectors/track • Only outer half of radius is used • Most of disk area in outer regions of disk • Disks are so big that some companies (like Google) reportedly only use part of disk for active data • Rest is archival data www.lorextechnology.com

Recommend


More recommend