Download I/O Systems: Devices, Performance, Disk Organization, Optimizations, Trends and more Slides Computer Numerical Control in PDF only on Docsity! 1 I/O Systems Arvind Krishnamurthy Spring 2004 I/O Devices n Typically, IO devices generate an interrupt when something happens n Three alternatives: n Raise an interrupt for every byte transferred from/to the I/O device n Do block transfers to memory (direct memory access or DMA) and raise interrupt when transfer is done n Bitmap display – CPU writes to video memory what should be displayed, display reads video memory, illuminating pixels n Done at user-level without kernel intervention 2 Performance issues n Terminals, modems are connected to computers via serial lines n Raise an interrupt for every character n CPU could get swamped due to “overhead” of handling each byte n Example: 10 terminals connect at 9600 baud (about 1KB/s) n 10 thousand interrupts per second n If each interrupt takes 1 us to handle, load = 0.01 secs = 1% n If each interrupt takes 100 us to handle, CPU is loaded n Block device performance depends n Overhead to initiate a request n Latency of performing a 1 byte transfer (dominates cost of small I/Os) n Bandwidth of I/O transfer once started (dominates cost of large transfers) Disk organization n Disk surface n Circular disk coated with magnetic material n Tracks n Concentric rings around disk surface, bits laid out serially along each track n Sectors n Each track is split into arc of track (min unit of transfer) sector 5 Disk Performance Optimizations n Minimize seek and rotational latency by putting related data together n Always read/write large amounts of data n If there are multiple requests, adaptively schedule the requests n Use multiple arms? Use multiple disks? n Can we improve both bandwidth and latency? Scheduling Disk Requests n Method FIFO n First come first serve n Pros n Fairness among requests n In the order applications expect n Cons n Arrival may be on random spots on the disk (long seeks) n Consider files accessed at a server – merging accesses from different users n Wild swings can happen 0 199 98, 183, 37, 122, 14, 124, 65, 67 53 6 SSTF (Shortest Seek Time First) n Method n Pick the one closest on disk n Pros n Try to minimize seek time n Cons n Starvation n Extension: n SATF – shortest access time first n Include rotational cost n Can we implement this?? 0 199 98, 183, 37, 122, 14, 124, 65, 67 (65, 67, 37, 14, 98, 122, 124, 183) 53 Elevator (SCAN) n Method n Take the closest request in the direction of travel n Real implementations do not go to the end n Pros n Bounded time for each request n Cons n Request at the other end will take a while 0 199 98, 183, 37, 122, 14, 124, 65, 67 (37, 14, 65, 67, 98, 122, 124, 183) 53 7 C-SCAN (Circular SCAN) n Method n Like SCAN n But, wrap around n Real implementation doesn’t go to the end n Pros n Uniform service time n Cons n Do nothing on the return 0 199 98, 183, 37, 122, 14, 124, 65, 67 (65, 67, 98, 122, 124, 183, 14, 37) 53 Disk caching n Method n Disk controller has a piece of RAM to cache recently accessed blocks n IBM Ultra160 SCSI has 16MB n Some of the RAM space stores “firmware” (an OS) n Blocks are replaced usually in LRU order n Pros n Good for reads if you have locality n Cons n Expensive n Need to deal with reliable writes 10 File usage patterns n How do users access files? n Sequential: bytes read in order n Random: read/write element out of middle of arrays n Content-based access: find me next byte starting with “CS422” n How are files used? n Most files are small n Large files account for most of the bytes transferred n Large files use up most of the disk space n Bad news n Need everything to be efficient Data structures for Disks n A file header for each file (part of the file meta-data) n Disk sectors associated with each file n A data structure to represent free space on disk n Bit map n 1 bit per block (or sector) n blocks numbered in cylinder-major order, why? n How much space does a bitmap need for a 4G disk? n Linked list n Caching: keep most recently accessed blocks in memory 11 Approach 1: Contiguous allocation n Request in advance for the size of the file n Search bit map or linked list to locate a space n File header n first sector in file n number of sectors n Pros n Fast sequential access n Easy random access n Cons n External fragmentation n Hard to grow files Approach 2: Linked files n File header points to 1st block on disk n A block points to the next n Pros n Can grow files dynamically n Free list is similar to a file n No waste of space n Cons n Sequential access: slow n random access: horrible n unreliable: losing a block means losing the rest File header null . . . 12 Approach 3: File Allocation Table n FAT Approach (used by MSDOS) n A section of disk for each partition is reserved n One entry for each block n A file is a linked list of blocks n A directory entry points to the 1st block of the file n Pros n Simple n Improved random access n Cons n Always go to FAT 619 399 foo 217 EOF FAT 0 217 399 619 Approach 4: Indexed files n Used in Nachos n User declares max size n A file header holds an array of pointers to point to disk blocks n Pros n Can grow up to a limit n Random access is faster n No external fragmentation n Cons n Clumsy to grow beyond the limit n File headers typically need to be of fixed size File header Disk blocks 15 File attributes n Name n Type – needed for systems that support different types. n Location – pointer to file blocks on device. n Size – current file size. n Protection – controls who can do reading, writing, executing. n Time, date, and user identification – data for protection, security, and usage monitoring. n Information about files are stored at: n Directory (typically contains just the name) n File-headers (typically contains all other file attributes) Unix file header (I-node) 16 n Superblock defines a file system n size of the file system n size of the file descriptor area n free list pointer, or pointer to bitmap n location of the file descriptor of the root directory n other meta-data such as permission and various times Super block File descriptors (i-node in Unix) File data blocks Boot block Disk Layout