1 / 47

Outline

Outline. Principles of I/O hardware Principles of I/O software I/O software layers Disks Clocks. Types of Disks. Magnetic disks Hard disks and floppy disks Reads/writes are equally fast Ideal secondary memory Highly reliable storage Optical disks CD-ROM, CD-R: 600MB DVD: 4.7-17GB.

Télécharger la présentation

Outline

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Outline • Principles of I/O hardware • Principles of I/O software • I/O software layers • Disks • Clocks

  2. Types of Disks • Magnetic disks • Hard disks and floppy disks • Reads/writes are equally fast • Ideal secondary memory • Highly reliable storage • Optical disks • CD-ROM, CD-R: 600MB • DVD: 4.7-17GB

  3. Read/write head (1 per surface) Surface 1 Direction of arm motion Surface 0 Structure of Magnetic Disks Cylinder Sector 1. Cylinders  tracks  sectors 2. Seek time and rotational delay Track

  4. Cost of Read / Write A Disk Block • Seek time • The time to move the arm to the proper cylinder • Dominate the other two times for most disks • E.g., 0.8 msec for adjacent cylinders • Rotational delay • The time for the proper sector to rotate under the head • E.g, 0.03 msec for adjacent sectors • Actual data transfer time • E.g., 17 sec for one sector

  5. Specifications of Disks • Geometry • Physical geometry: more sectors in outer cylinders • To OS: same number of sectors for all cylinders: x cylinders, y heads, and z sectors. • Logical block addressing • Disk sectors are numbered consecutively from 0 to some maximum value

  6. Disk Formatting Gap A disk sector • Preamble: recognize the start of the sector. It also contains the cylinder and sector numbers. • Data: most disks use 512-byte sectors • ECC: can be used to recover from read errors • Gap between sectors

  7. Cylinder Skew • The position of sector 0 on each track is offset from the previous track. This offset is called cylinder skew. • Allow the disk to read multiple tracks in one continuous operation without losing data Direction of disk rotation Direction of disk rotation 3 0 0 0 2 3 3 3 1 0 1 1 2 2 1 2 No skew 1-sector skew

  8. 5 0 7 0 7 0 2 3 6 3 4 1 7 6 5 6 1 2 4 1 2 5 4 3 Sector Interleaving • Consider a controller with one sector buffer. A request of reading two consecutive sectors. When the controller is busy with transferring one sector of data to memory, the next sector will fly by the head. • Solution: sector interleaving No interleaving Single interleaving Double interleaving

  9. Disk Arm Scheduling Algorithm • Time required to read/write a disk block • Seek time • Rotational delay • Actual data transfer time • For most disks, the seek time dominates the other two times. • How to reduce the mean seek time? • Assume we know the cylinder numbers of all the pending requests.

  10. Optimize Seek Time • Fist-come, first-served: • Accept requests one at a time and carry them out in that order • Little can be done • Shortest seek first • Handle the closest request next • The arm will tend to oscillate between two cylinders • Starvation: with a heavily loaded disk, requests for cylinders at either extreme get poor service

  11. Elevator Algorithm • Keep moving the arm in the same direction until there are no more outstanding requests in that direction, then switch the direction. • Upper bound: twice of the number of cylinders

  12. Initial position An Example Request order 1 19 9 16 Cylinder Number 6 8 13 18 FCFS: cylinder 811316196189, total 59 motions SSF: cylinder 896113161819, total 27 motions EA: cylinder 891316181961, total 29 motions Assume the direction is initially UP.

  13. Stable Storage Model • No disk works all the time with no errors • Achievable: either correctly writes the data or does nothing, leaving the existing data intact. • Possible errors (model assumptions): • Incorrect write: detected by ECC • Correctly written can go bad. However, ignore the chance that two independent drives have the same sector going bad

  14. Model • Hardware: a pair of identical disks • Corresponding blocks works together to form one error-free block • At any time, for any pair of blocks, at least one is in good condition. • Target: • If no error, the corresponding blocks on both drives are the same • If error occurs, at least one block can provide the correct data (either new or old)

  15. Model: Stable Writes/Reads • Stable writes • Write the block in drive 1read and verify • Keep writing until it successes • Write the block in drive 2read and verify • Stable reads • Read the block from drive 1. If incorrect (detected by examining ECC), the corresponding block in drive 2 must contain the correct data. Why? • Stable writes leave two good copies • Both copies go bad: impossible (assumption 2)

  16. Model: Crash Recovery • Compare corresponding blocks • Both good: nothing is done • One is bad: overwrite the bad copy • Both good but different: block 1 overwrites block2. Why? Disk Disk Disk Disk Disk 2 2 2 1 2 1 1 2 1 1 New Bad New Old Old Old Bad Old New New Crash Crash Crash Crash Crash

  17. Outline • Principles of I/O hardware • Principles of I/O software • I/O software layers • Disks • Clocks

  18. Clocks • Essential for multi-programming system • Maintain the time of day • Prevent processes from monopolizing the CPU • Hardware components: • Crystal oscillator: generate high frequency periodic signal, typically several hundred MHz • Counter: value is decreased by 1 when a signal is generated. It causes a CPU interrupt when it gets to zero. • Holding register: programmable. Used to control the frequency of interrupt.

  19. Operation Modes • One-shot mode • Copy the value of the holding register into the counter • Decrease the counter at each pulse (signal) • Cause an interrupt if it gets zero • Stop • Square-wave mode • After causing the interrupt, the holding register is automatically copied into the counter, and the whole process is repeated again.

  20. Summary • Hardware Principle • Device controller: between devices and OS • Memory mapped I/O Vs. I/O port number • DMA Vs. Interrupt • Software Principle • Programmed I/O: waste CPU time • Interrupts: overheads • DMA: DMA controller may not drive the device at full speed

  21. Summary (Cont.) • Four layers of I/O software • Interrupt handlers: context switch, wake up driver when I/O completed • Device drivers: set up device registers, issue commands, check status and errors • Device-independent software: naming, protection, buffering, allocating • User-space software: make I/O call, format I/O, spooling

  22. Summary (Cont.) • Disks • Structure: cylindertracksector • Optimize seek time: elevator algorithm • Stable storage • Clocks • One-shot and square-wave modes

  23. CMPT 300 Operating System I Chapter 6 File Systems

  24. Outline • Files • Directories • File system implementation

  25. Store Information in Memory? • How to store a very large amount of information? • All account info in a bank >> main memory size • How to survive the termination of processes? • Store your program when the PC is turned off • How to share information among processes • Share airline reservation info among multiple processes • Share information around the world?

  26. Files: Long-term Storages • Files: info on disk/other external media • Persistent, huge capacity, shared by multiple processes • File system: the part of OS dealing with files • Structure, name, access, protection, … • User interface of file systems • How do files appear to users? • Naming rules and protection • File operations

  27. File Naming • Strings as file names • Letters, digits • Special characters are also permitted in some system • File name length, usually less than 255 • Case sensitive? • Processes access files using file names • File name extensions: file_stem.extension • Indicates the type of a file • E.g., code.c, code.o, code.c.Z • Register extensions with programs • Specify a program to open files with a specific extension • Convention & Enforcement

  28. File Structure • An unstructured sequence of bytes • Most widely used, e.g., UNIX and Windows • User programs impose meaning of files • A sequence of fixed-length records • Records have internal structure • Read/write in records • Not used in any current general-purpose system • A tree of records • Search records by keys • Used on some large mainframe computers

  29. Examples of File Structures 1 byte 1 record Tree Byte sequence Record sequence

  30. File Types • Regular files – store user’s information • ASCII files (text file): lines of text • Can be displayed and printed as is. • E.g., source code file • Binary files: binary streams • Internal structure know to programs • Object file, executable code. Word file? • Directories – maintained by system • Maintaining the structure of the file system • UNIX special files: modeling I/O devices • Character special files: serial I/O devices • Block special files: disks/block devices

  31. File Access • Sequential access • Read all the bytes in order from the beginning • Rewind if read again • Random access files • Read the bytes/records by specifying positions • Applications: database, etc. • All the files are random access nowadays • How to specify the starting point for reading • Use seek operation to set the current position • Roll forward/backward for n bytes

  32. File Attributes File protection and access Flags control/enable some specific property Used in file with records having a key Time stamps Size

  33. File Operations • Store and retrieve information • System calls relating to files • Open: a process must open a file first before using it • Open mode: read, write, append, modify, etc • Close it after you use it • Read: read data starting from the current position • Write data • Seek: specify where to take the data • Other calls • Delete, append, get attributes, set attributes, rename • How to copy a file using these system calls?

  34. Outline • Files • Directories • File system implementation

  35. Organization: Single-level / Two-level • Single-level: one directory for all the files • Not good for huge amount of files • Not good for multi-user system • Two-level: userdirectory • How to access a file? • A large number of files from one user, inconvenient root root User A User B User A: File mymails User B: File mymails File mymails File mymails

  36. Hierarchical Directory Systems • A general hierarchy: a tree of directories User directory root directory directory directory file file file directory directory directory file file file file

  37. Path Names • Mechanism to locate files • Absolute path name • Path starting from the root directory • E.g., /usr/fran/mailbox. ‘/’ is path separator • Relative path name • Relative to the current working directory • E.g., if working directory is /usr/fran, then /usr/fran/mailbox = mailbox • Each process has its own working directory • Current directory “.” and parent directory “..” • E.g., ../cindy/mailbox, ./mailbox

  38. Directory Operations (UNIX) • Create: a directory is created • Empty except ‘.’ and “..” entries • Delete, rename a directory • Link (hard link) • Allow a file to appear in more than one directory • One copy of a file, multiple directory entries • Unlink • A directory entry is removed • Link count > 0 • Yes: remove the file (free the i-node and data blocks) • No: keep the file

  39. Outline • Files • Directories • File system implementation

  40. File System Layout • Disk is divided up into several partitions • Each partition has one file system • MBR – master boot record • boot the computer & contain the partition table • Partition table • Starting & ending addresses of each partition • One partition is marked as active • Within each partition • Boot block – first block, a program loads the OS • Superblock – key parameters about the file sys.

  41. Implementing Files • Key issue: how to keep track of which disk sectors go with which file? • E.g., block size= 512B, file size=2014B, so where are these 2014/514=4 blocks on disk? • Many methods • Contiguous allocation • Linked list allocation • I-nodes • Each one has its own pros and cons

  42. Contiguous Allocation • Store each file as a contiguous run of disk sectors • Advantages • Simple to implement • Each file has two numbers, starting address & length • Read performance is excellent • Drawback • Holes. • Relocate if file grows. Free blocks

  43. Linked List Allocation • Keep all the blocks as a linked list • Only the address of the first block is stored • Every sector can be used, no holes • Random access is extremely slow • The amount of data storage in a sector is no longer a power of two • Read a block of data requires accessing two sectors Physical sector 4 7 2 10

  44. File Allocation Table (FAT) • Move the pointer from each block to a table in memory • FAT– shared by all the files • Indexed by physical sector number • Each entry contains the number of next block • E.g., 47210 • Random access is much easier • FAT is in main memory • FAT must be held in main memory • 20 GB disk, 1 KB/block, 4 bytes/entry • 80MB FAT • Size of FAT is linear to size of disk First block

  45. Index Nodes (I-nodes) • An i-node lists the attributes and disk addresses of the file’s blocks • Only when a file is open, its i-nodes should be loaded into memory • Much smaller than FAT • Irrelevant to size of disk Disk block containing additional disk addresses

  46. Implementing Directories • Directory system: map the ASCII file name onto the info needed to locate the data • Directory entry • Where are the attributes stored? • In the directory entry (MS-DOS/Windows) • In the i-nodes (UNIX) i-node DOS/Windows UNIX

  47. Locate A File: /usr/ast/mbox Block 406 is /usr/ast dir. I-node 6 is for /usr I-node 26 is for /usr/ast root Block 132 is /usr dir. /usr/ast is in block 406 /usr is in block 132 /usr/ast/mbox is i-node 60 Looking up usr yields i-node 6 /usr/ast is i-node 26

More Related