Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Commodore DOS wikipedia , lookup
Mobile operating system wikipedia , lookup
Copland (operating system) wikipedia , lookup
Security-focused operating system wikipedia , lookup
Unix security wikipedia , lookup
Distributed operating system wikipedia , lookup
Object storage wikipedia , lookup
Chapter 8: Mass-Storage Systems Overview of Mass Storage Chapter 8: Device Management I/O Hardware Structure Application I/O Interface Disk Structure Kernel I/O Subsystem Disk Attachment Transforming I/O Requests to Disk Scheduling Hardware Operations Disk Management STREAMS Swap-Space Management Performance RAID Structure Disk Attachment Stable-Storage g Implementation p Tertiary Storage Devices Operating System Support Performance Issues Operating System Concepts – 8th Silberschatz, Galvin and Gagne ©2009 Edition, Operating System Concepts – 8th Edition Objectives and the resulting effects on the uses of the devices Explain the performance characteristics of mass-storage devices Magnetic disks provide bulk of secondary storage of modern computers z Drives rotate at 60 to 200 times per second z Transfer rate is rate at which data flow between drive and computer z Positioning time (random-access time) is time to move disk arm to desired cylinder li d ((seek k titime)) and d titime ffor d desired i d sector t tto rotate t t under d the th disk di k h head d (rotational latency) z Head crash results from disk head making contact with the disk surface Discuss operating-system services provided for mass storage, including RAID and HSM Explore the structure of an operating system’s I/O subsystem Discuss the principles of I/O hardware and its complexity Provide details off the performance f aspects off I/O /O hardware and software f 8.3 Silberschatz, Galvin and Gagne ©2009 Overview of Mass Storage Structure Describe the physical structure of secondary and tertiary storage devices Operating System Concepts – 8th Edition 8.2 Silberschatz, Galvin and Gagne ©2009 That’s bad Disks can be removable Drive attached to computer p via I/O bus z Busses vary, including EIDE, ATA, SATA, USB, Fibre Channel, SCSI z Host controller in computer uses bus to talk to disk controller built into drive or storage array Operating System Concepts – 8th Edition 8.4 Silberschatz, Galvin and Gagne ©2009 Moving-head Disk Mechanism Overview of Mass Storage Structure (Cont) Magnetic tape Operating System Concepts – 8th Edition 8.5 Silberschatz, Galvin and Gagne ©2009 z W early Was l secondary-storage d t medium di z Relatively permanent and holds large quantities of data z Access time slow z Random access ~1000 times slower than disk z Mainly used for backup, storage of infrequently-used data, transfer medium between systems z Kept in spool and wound or rewound past read-write head z Once data under head head, transfer rates comparable to disk z 20-200GB typical storage z Common technologies g are 4mm, 8mm, 19mm, LTO-2 and SDLT Operating System Concepts – 8th Edition Disk Structure 8.6 Silberschatz, Galvin and Gagne ©2009 Disk Attachment Disk drives are addressed as large 1-dimensional arrays of logical blocks, where the logical block is the smallest unit of transfer Host-attached storage accessed through I/O ports talking to I/O busses SCSI itself it lf is i a bus, b up tto 16 devices d i on one cable, bl SCSI iinitiator iti t requests t operation and SCSI targets perform tasks The 1-dimensional array of logical blocks is mapped into the sectors of the di k sequentially disk ti ll z Sector 0 is the first sector of the first track on the outermost cylinder z Mapping proceeds in order through that track, then the rest of the tracks in that cylinder, and then through the rest of the cylinders from outermost to innermost Operating System Concepts – 8th Edition 8.7 Silberschatz, Galvin and Gagne ©2009 z Each target can have up to 8 logical units (disks attached to device controller FC is high-speed serial architecture z Can be switched fabric with 24-bit 24 bit address space – the basis of storage area networks (SANs) in which many hosts attach to many storage units z Can be arbitrated loop (FC-AL) of 126 devices Operating System Concepts – 8th Edition 8.8 Silberschatz, Galvin and Gagne ©2009 Network-Attached Storage Network-attached storage (NAS) is storage made available over a network rather than over a local connection (such as a bus) Storage Area Network Common in large storage environments (and becoming more common) Multiple M lti l hosts h t attached tt h d to t multiple lti l storage t arrays - flexible fl ibl NFS and CIFS are common protocols Implemented via remote procedure calls (RPCs) between host and storage New iSCSI protocol uses IP network to carry the SCSI protocol 8.9 Operating System Concepts – 8th Edition Silberschatz, Galvin and Gagne ©2009 Disk Scheduling Operating System Concepts – 8th Edition 8.10 Silberschatz, Galvin and Gagne ©2009 Disk Scheduling (Cont) The operating system is responsible for using hardware efficiently — for the disk drives drives, this means having a fast access time and disk bandwidth Several algorithms exist to schedule the servicing of disk I/O requests We W illustrate ill t t th them with ith a requestt queue (0 (0-199) 199) Access time has two major components z Seek time is the time for the disk are to move the heads to the cylinder containing the desired sector z Rotational latency is the additional time waiting for the disk to rotate the desired sector to the disk head 98, 183, 37, 122, 14, 124, 65, 67 Head pointer 53 Minimize seek time Seek time ≈ seek distance Disk bandwidth is the total number of bytes transferred, divided by the total time between the first request for service and the completion of the last transfer Operating System Concepts – 8th Edition 8.11 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8th Edition 8.12 Silberschatz, Galvin and Gagne ©2009 FCFS SSTF Illustration shows total head movement of 640 cylinders Selects the request with the minimum seek time from the current head position SSTF scheduling is a form of SJF scheduling; may cause starvation of some requests Illustration shows total head movement of 236 cylinders Operating System Concepts – 8th Edition 8.13 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8th Edition SSTF (Cont) 8.14 Silberschatz, Galvin and Gagne ©2009 SCAN The disk arm starts at one end of the disk, and moves toward the other end, servicing requests until it gets to the other end of the disk disk, where the head movement is reversed and servicing continues. SCAN algorithm Sometimes called the elevator algorithm Illustration shows total head movement of 208 cylinders Operating System Concepts – 8th Edition 8.15 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8th Edition 8.16 Silberschatz, Galvin and Gagne ©2009 SCAN (Cont.) C-SCAN Provides a more uniform wait time than SCAN The Th h head d moves ffrom one end d off th the di disk k tto th the other, th servicing i i requests t as it goes z When it reaches the other end, however, it immediately returns to the beginning of the disk, without servicing any requests on the return trip Treats the cylinders as a circular list that wraps around from the last cylinder to the first one Operating System Concepts – 8th Edition 8.17 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8th Edition C-SCAN (Cont) 8.18 Silberschatz, Galvin and Gagne ©2009 C-LOOK Version of C-SCAN Arm A only l goes as ffar as the th last l t requestt in i each h di direction, ti th then reverses direction immediately, without first going all the way to the end of the disk Operating System Concepts – 8th Edition 8.19 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8th Edition 8.20 Silberschatz, Galvin and Gagne ©2009 C-LOOK (Cont) Selecting a Disk-Scheduling Algorithm SSTF is common and has a natural appeal SCAN and dC C-SCAN SCAN perform f b better tt ffor systems t th thatt place l ah heavy lload d on the disk Performance depends on the number and types of requests Requests for disk service can be influenced by the file-allocation method The disk-scheduling algorithm should be written as a separate module of the operating system system, allowing it to be replaced with a different algorithm if necessary Either SSTF or LOOK is a reasonable choice for the default algorithm 8.21 Operating System Concepts – 8th Edition Silberschatz, Galvin and Gagne ©2009 Disk Management Operating System Concepts – 8th Edition 8.22 Silberschatz, Galvin and Gagne ©2009 Booting from a Disk in Windows 2000 Low-level formatting, or physical formatting — Dividing a disk into sectors that the disk controller can read and write To use a disk to hold files, the operating system still needs to record its own data structures on the disk z Partition the disk into one or more groups of cylinders z Logical formatting or “making a file system” z To increase efficiency most file systems group blocks into clusters Disk I/O done in blocks File I/O done in clusters Boot block initializes system z The bootstrap is stored in ROM z Bootstrap loader program Methods such as sector sparing used to handle bad blocks Operating System Concepts – 8th Edition 8.23 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8th Edition 8.24 Silberschatz, Galvin and Gagne ©2009 Swap-Space Management Swap-space — Virtual memory uses disk space as an extension of main RAID Structure RAID – multiple disk drives provides reliability via redundancy memory Swap-space can be carved out of the normal file system, or, more Increases the mean time to failure commonly, it can be in a separate disk partition Swap-space management Frequently combined with NVRAM to improve write performance z 4.3BSD allocates swap space when process starts; holds text segment (the program) and data segment z Kernel uses swap maps to track swap-space use z Solaris 2 allocates swap space only when a page is forced out of physical memory, not when the virtual memory page is first f created 8.25 Operating System Concepts – 8th Edition Silberschatz, Galvin and Gagne ©2009 RAID is arranged into six different levels Operating System Concepts – 8th Edition 8.26 Silberschatz, Galvin and Gagne ©2009 RAID 0 – Non redundant RAID (Cont) คือการเอา harddisk มากกวา 1 ตัวมาตอรวมกันในลักษณะ non-redundant ซึง่ Several improvements in disk-use techniques involve the use of multiple disks working cooperatively Disk striping uses a group of disks as one storage unit RAID schemes improve performance and improve the reliability of the storage system by storing redundant data z Mirroring or shadowing (RAID 1) keeps duplicate of each disk z Striped mirrors (RAID 1+0) or mirrored stripes (RAID 0+1) provides high performance and high reliability z Block interleaved parity (RAID 4, 5, 6) uses much less redundancy RAID 0 นี้มีจุดประสงค เพื่อทีจ่ ะเพิ่มความเร็วในการอาน/เขียนขอมูล harddisk โดยตรง ไมมี การเก็บขอมูลสํารอง ดังนัน้ ถาฮารดดิสกตัวใดตัวหนึ่งเกิดเสียหาย ก็จะสงผลใหขอมูลทั้งหมดไม สามารถใชงานไดทันที จุดเดนของ RAID 0 คือความเร็วในการเขาถึงขอมูล แตขอเสียก็คือหาก harddisk ตัวใดตัว หนึ่งเสียหาย จะสงผลกับขอมูลทั้งระบบทันที RAID within a storage g array y can still fail if the array y fails, so automatic replication of the data between arrays is common Frequently, a small number of hot-spare disks are left unallocated, automatically replacing a failed disk and having data rebuilt onto them Operating System Concepts – 8th Edition 8.27 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8th Edition 8.28 Silberschatz, Galvin and Gagne ©2009 RAID 1: Mirrored Disks RAID 1 (disk mirroring) ประกอบไปดวย harddisk 2 ตัวที่เก็บขอมูลเหมือนกันทุก ประการ เสมือนการสํารองขอมูล หาก harddisk ตัวใดตัวหนึง่ เกิดเสียหาย ระบบก็ยังสามารถดึงขอมูล จาก harddisk อีกตัวหนึ่งมาใชงานไดตามปกติ สําหรับ RAID controller ที่ถูกออกแบบมาเปนอยางดีแลว การเขียนขอมูลลง harddisk 2 ตัว ในเวลาเดียวกัน จะใชเวลาพอๆ กับการเขียนขอมูลลง harddisk ตัวเดียว ในขณะที่เวลาในการอานก็จะ นอยลง เพราะ RAID controller จะเลือกอานขอมูลจาก harddisk ตัวไหนก็ได โดยหากมี คําสัง่ ใหอานขอมลล 2 ชุชดในเวลาเดี คาสงใหอานขอมู ดในเวลาเดยวกน ยวกัน ตว ตัว RAID controller กสามารถประมวลผลคาสงเพอ ก็สามารถประมวลผลคําสั่งเพื่อ อานขอมูลจาก harddisk ตัวหนึง่ และคําสั่งอีกชุดนึงจาก harddisk อีกตัวนึงก็ได RAID 2: Error-Correcting Codes RAID 2 นี้ ขอมูลทั้งหมดจะถูกตัดแบงเพื่อจัดเก็บลง harddisk แตละตัวใน disk array โดยมี harddisk ตัวหนึ่งเก็บขอมูลที่ใชตรวจสอบและแกไขขอผิดพลาด (ECC - Error Checking and Correcting) ถาเกิดการปรากฏวา harddisk ตัวใดตัวหนึ่งเสียหาย ระบบก็จะสามารถสรางขอมูลทั้งหมดใน harddisk ตัวนั้นขึ้นมาไดใหม โดยอาศัยขอมูลจาก harddisk ตัวอื่นๆ และจากคา ECC ที่เก็บเอาไว ซึง่ การทํา ECC นี้สง ผลให harddisk ทั้งระบบตองทํางานคอนขางมากทีเดียว และ RAID 2 นั้นจะเห็นไดวาตองใช harddisk จํานวนมากในการเก็บคา ECC ซึง่ ทําใหคอนขางสิ้นเปลือง Hamming code is an algorithm that adds extra, redundant bits to the data and d iis th therefore f able bl tto correctt single-bit i l bit errors and dd detect t td double-bit bl bit errors จุจดเด ดเดนของ นของ RAID 1 คอความปลอดภยของขอมู คือความปลอดภัยของขอมลล ไมเนนเรองประสทธภาพและความเรวเหมอนอยาง ไมเนนเรื่องประสิทธิภาพและความเร็วเหมือนอยาง RAID 0 แมวาประสิทธิภาพในการอานขอมูลของ RAID 1 จะสูงขึ้นก็ตาม Operating System Concepts – 8th Edition 8.29 Silberschatz, Galvin and Gagne ©2009 RAID 3: Bit-interleaved parity คลายกับ RAID 2 แตแทนทีจ่ ะตัดแบงขอมูลในระดับ bit เหมือน RAID 2 ก็จะตัดเก็บขอมูลใน ระดับ byte y แทนและการตรวจสอบและแกไขขอผิดพลาดของขอมููล จะใช p parity y แทนทีจ่ ะเปน ECC ทําให RAID 3 มีความสามารถในการอานและเขียนขอมูลไดอยางรวดเร็ว เพราะมีการตอ harddisk แตละตัวแบบ stripe และใช harddisk ที่เก็บ parity เพียงแคตัวเดียว แตถานํา RAID 3 ไปใชในงานที่มีการสงผานขอมูลในจํานวนทีน ่ อ ยๆ ซึ่ง RAID 3 ตองกระจาย Operating System Concepts – 8th Edition 8.30 Silberschatz, Galvin and Gagne ©2009 RAID 4: Block-Interleaved Parity RAID 4 มีลักษณะโดยรวมเหมือนกับ RAID 3 ทุกประการ ยกเวนเรื่องการตัดแบงขอมูลทีท่ ํา ในระดับ block แทนที่จะเปน bit หรือ byte ซึง่ ทําใหการอานขอมูลแบบ random ทําได รวดเร็วกวา อยางไรก็ตาม ปญหาคอขวดที่กลาวใน RAID 3 ก็ยังมีโอกาสเกิดขึ้นเหมือนเดิม ขอดีคือ ถามีดิสตใดเสีย สามารถกูขอมูลคืนโดยอาศัยตัว parity disk ได ขอมูลไปทั่วทัง้ harddisk จะทําใหเกิดปญหาที่เรียกวา คอขวด ที่ harddisk ทีเ่ ก็บ parity เพราะไม ไ วาขอ มูลจะมีขี นาดใหญ ใ ข นาดไหน ไ RAID 3 ตอ งเสียี เวลาไปสร ไป า งสว น parity it ทังั้ สินิ้ ยิงิ่ ขอมูลมีขนาดเล็กๆ แต parity ตองสรางขึ้นตลอด ทําใหขอมูลถูกจัดเก็บเสร็จกอนการสราง parity ทัง้ ระบบตองมารอใหสราง parity เสรจกอน ทงระบบตองมารอใหสราง เสร็จกอน จึจงจะทางานตอได งจะทํางานตอได RAID 3 เหมาะสําหรับใชในงานที่มีการสงขอมูลจํานวนมากๆ เชนงานตัดตอ Video Operating System Concepts – 8th Edition 8.31 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8th Edition 8.32 Silberschatz, Galvin and Gagne ©2009 RAID 5: Block-interleaved Distributed Parity มีการตัดแบงขอมูลในระดับ block เชนเดียวกับ RAID 4 แตจะไมทําการแยก harddisk ตัว ใดตัวหนึ่งเพื่อเก็บ parity p y ในการเก็บ parity ของ RAID 5 นัน ้ จะกระจาย parity ไปยัง harddisk ทุกตัว โดยปะปน ไปกับขอมููลปกติ จึงชวยลดปญหาคอขวด ซึง่ เปนปญหาที่สําคัญใน RAID 3 และ RAID 4 คุณสมบัติอีกอันหนึง่ ทีน ่ าสนใจของ RAID 5 คือ เทคโนโลยี Hot Swap คือเราสามารถทําการ RAID 6: P+Q Redundancy RAID 6 อาศัยพื้นฐานการทํางานของ RAID 5 เกือบทุกประการ แตมีการเพิ่ม parity block เขาไปอก เขาไปอีก 1 ชุชดด เพอยอมใหเราทาการ เพื่อยอมใหเราทําการ Hot Swap ไดพรอมกน ไดพรอมกัน 2 ตว ตัว (RAID 5 ทา ทํา การ Hot Swap ไดทีละ 1 ตัวเทานัน้ หาก harddisk มีปญหาพรอมกัน 2 ตัว จะทําใหเสีย ทัง้ ระบบ)) เรียกวาเปนการเพิ่ม Fault Tolerance ใหกับระบบ RAID 6 เหมาะกับงานที่ตองการความปลอดภัยและเสถียรภาพของขอมูลที่สงู มากๆ เปลี่ยน harddisk ในกรณีที่เกิดปญหาไดในขณะที่ระบบยังทํางานอยูู เหมาะสําหรับงาน Server ตางๆ ที่ตองทํางานตอเนื่อง Operating System Concepts – 8th Edition 8.33 Silberschatz, Galvin and Gagne ©2009 RAID Levels Operating System Concepts – 8th Edition 8.35 Operating System Concepts – 8th Edition 8.34 Silberschatz, Galvin and Gagne ©2009 RAID (0 + 1) and (1 + 0) Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8th Edition 8.36 Silberschatz, Galvin and Gagne ©2009 Stable-Storage Implementation Tertiary Storage Devices Write-ahead log scheme requires stable storage Low cost is the defining characteristic of tertiary storage To implement stable storage: Generally, tertiary storage is built using removable media z Replicate information on more than one nonvolatile storage media with independent failure modes z Update information in a controlled manner to ensure that we can recover the stable data after any failure during data transfer or recovery 8.37 Operating System Concepts – 8th Edition Silberschatz, Galvin and Gagne ©2009 Common examples of removable media are floppy disks and CD-ROMs; other types are available Operating System Concepts – 8th Edition Removable Disks 8.38 Silberschatz, Galvin and Gagne ©2009 Removable Disks (Cont.) Floppy disk — thin flexible disk coated with magnetic material, enclosed i a protective in t ti plastic l ti case z Most floppies hold about 1 MB; similar technology is used for removable disks that hold more than 1 GB z Removable magnetic disks can be nearly as fast as hard disks, but theyy are at a g greater risk of damage g from exposure p A magneto-optic disk records data on a rigid platter coated with magnetic material z Laser heat is used to amplify a large, weak magnetic field to record a bit z Laser light is also used to read data (Kerr effect) z The magneto-optic head flies much farther from the disk surface than a magnetic disk head, and the magnetic material is covered with a protective layer of plastic or glass; resistant to head crashes Optical disks do not use magnetism; they employ special materials that are altered by laser light Operating System Concepts – 8th Edition 8.39 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8th Edition 8.40 Silberschatz, Galvin and Gagne ©2009 WORM Disks Tapes The data on read-write disks can be modified over and over WORM (“Write (“W it O Once, R Read dM Many Ti Times”) ”) disks di k can b be written itt only l once Thin aluminum film sandwiched between two glass or plastic platters To write a bit, bit the drive uses a laser light to burn a small hole through the aluminum; information can be destroyed by not altered Very durable and reliable Read-only disks, such ad CD-ROM and DVD, com from the factory with the data pre-recorded Compared to a disk, a tape is less expensive and holds more data, but random access is much slower Tape is an economical medium for purposes that do not require fast random access, e.g., backup copies of disk data, holding huge volumes of data Large tape installations typically use robotic tape changers that move tapes between tape drives and storage slots in a tape library z stacker – library that holds a few tapes z silo – library that holds thousands of tapes A disk-resident file can be archived to tape for low cost storage; the computer can stage it back into disk storage for f active use Operating System Concepts – 8th Edition 8.41 Silberschatz, Galvin and Gagne ©2009 Operating System Support Major OS jobs are to manage physical devices and to present a virtual machine abstraction to applications Operating System Concepts – 8th Edition 8.42 Silberschatz, Galvin and Gagne ©2009 Application Interface Most OSs handle removable disks almost exactly like fixed disks — a new cartridge is formatted and an empty file system is generated on the disk Tapes are presented as a raw storage medium, i.e., and application does For hard disks, the OS provides two abstraction: not not open a file on the tape, it opens the whole tape drive as a raw d i device z Raw device – an array of data blocks z File system – the OS queues and schedules the interleaved requests from several applications Usually the tape drive is reserved for the exclusive use of that application Since the OS does not provide file system services, the application must decide how to use the array of blocks Since every application makes up its own rules for how to organize a tape, a tape full of data can generally only be used by the program that created it Operating System Concepts – 8th Edition 8.43 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8th Edition 8.44 Silberschatz, Galvin and Gagne ©2009 File Naming Hierarchical Storage g Management g (HSM) ( ) The issue of naming files on removable media is especially difficult when we want to write data on a removable cartridge on one computer computer, and then use the cartridge in another computer Contemporary OSs generally leave the name space problem unsolved for removable bl media, di and dd depend d on applications li ti and d users tto fifigure outt h how to access and interpret the data Some kinds of removable media (e.g., CDs) are so well standardized that all computers use them the same way Operating System Concepts – 8th Edition 8.45 A hierarchical storage system extends the storage hierarchy beyond primary memory and secondary storage to incorporate tertiary storage — usually implemented as a jukebox of tapes or removable disks Usually incorporate tertiary storage by extending the file system z Small and frequently used files remain on disk z Large, old, inactive files are archived to the jukebox HSM is usually found in supercomputing centers and other large installations that have enormous volumes of data Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8th Edition Speed 8.46 Silberschatz, Galvin and Gagne ©2009 Speed (Cont) Two aspects of speed in tertiary storage are bandwidth and latency Bandwidth is measured in bytes per second z Sustained bandwidth – average data rate during a large transfer; # of bytes/transfer time Data rate when the data stream is actually flowing z Effective bandwidth – average over the entire I/O time, including seek() or locate(), and cartridge switching Drive’s overall data rate Access latency – amount of time needed to locate data z Access time for a disk – move the arm to the selected cylinder and wait for the rotational latency; < 35 milliseconds z Access on tape requires winding the tape reels until the selected block reaches the tape head; tens or hundreds of seconds z Generally say that random access within a tape cartridge is about a thousand times slower than random access on disk The low cost of tertiary storage is a result of having many cheap cartridges share a few expensive drives A removable library is best devoted to the storage of infrequently used data, because the library can only satisfy a relatively small number of I/O requests per hour Operating System Concepts – 8th Edition 8.47 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8th Edition 8.48 Silberschatz, Galvin and Gagne ©2009 Reliability Cost A fixed disk drive is likely to be more reliable than a removable disk or tape Main memory is much more expensive than disk storage drive The cost per megabyte of hard disk storage is competitive with magnetic An optical cartridge is likely to be more reliable than a magnetic disk or tape A head crash in a fixed hard disk generally destroys the data, whereas the failure of a tape drive or optical disk drive often leaves the data cartridge unharmed tape if only one tape is used per drive The cheapest tape drives and the cheapest disk drives have had about the same storage capacity over the years Tertiary storage gives a cost savings only when the number of cartridges is considerably y larger g than the number of drives 8.49 Operating System Concepts – 8th Edition Silberschatz, Galvin and Gagne ©2009 I/O Hardware Operating System Concepts – 8th Edition 8.50 Silberschatz, Galvin and Gagne ©2009 A Typical PC Bus Structure Incredible variety of I/O devices Common C concepts t z Port z Bus (daisy chain or shared direct access) z Controller (host adapter) I/O instructions control devices Devices have addresses, used by z Direct I/O instructions z Memory-mapped I/O Operating System Concepts – 8th Edition 8.51 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8th Edition 8.52 Silberschatz, Galvin and Gagne ©2009 Polling Device I/O Port Locations on PCs (partial) Determines state of device z command-ready d d z busy z Error Busy-wait cycle to wait for I/O from device 8.53 Operating System Concepts – 8th Edition Silberschatz, Galvin and Gagne ©2009 Interrupts Operating System Concepts – 8th Edition 8.54 Silberschatz, Galvin and Gagne ©2009 Interrupt-Driven I/O Cycle 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 z Based on priority z Some nonmaskable Interrupt mechanism also used for exceptions Operating System Concepts – 8th Edition 8.55 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8th Edition 8.56 Silberschatz, Galvin and Gagne ©2009 Direct Memory Access Intel Pentium Processor Event-Vector Table 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 Operating System Concepts – 8th Edition 8.57 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8th Edition Six Step Process to Perform DMA Transfer 8.58 Silberschatz, Galvin and Gagne ©2009 Application I/O Interface I/O system calls encapsulate device behaviors in generic classes Device-driver D i di llayer hid hides diff differences among I/O controllers t ll ffrom kkernell Devices vary in many dimensions Operating System Concepts – 8th Edition 8.59 Silberschatz, Galvin and Gagne ©2009 z Character-stream Character stream or block z Sequential or random-access z Sharable or dedicated z Speed of operation z read-write, read only, or write only Operating System Concepts – 8th Edition 8.60 Silberschatz, Galvin and Gagne ©2009 Characteristics of I/O Devices A Kernel I/O Structure Operating System Concepts – 8th Edition 8.61 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8th Edition Block and Character Devices Block devices include disk drives z C Commands d iinclude l d read, d write, it seek k z Raw I/O or file-system access z Memory-mapped Memory mapped file access possible 8.62 Silberschatz, Galvin and Gagne ©2009 Network Devices Varying enough from block and character to have own interface Unix and Windows NT/9x/2000 include socket interface z Separates network protocol from network operation z Includes select() functionality Character devices include keyboards, mice, serial ports z Commands include get(), put() z Libraries layered on top allow line editing Operating System Concepts – 8th Edition 8.63 Approaches vary widely (pipes (pipes, FIFOs FIFOs, streams streams, queues queues, mailboxes) Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8th Edition 8.64 Silberschatz, Galvin and Gagne ©2009 Clocks and Timers Blocking and Nonblocking I/O Provide current time, elapsed time, timer Blocking - process suspended until I/O completed Programmable interval timer used for timings, periodic interrupts ioctl() (on UNIX) covers odd aspects of I/O such as clocks and timers z E Easy tto use and d understand d t d z Insufficient for some needs Nonblocking - I/O call returns as much as available z User interface, data copy (buffered I/O) z Implemented via multi-threading z Returns quickly with count of bytes read or written Asynchronous - process runs while I/O executes Silberschatz, Galvin and Gagne ©2009 8.65 Operating System Concepts – 8th Edition z Difficult to use z I/O subsystem signals process when I/O completed Operating System Concepts – 8th Edition Two I/O Methods 8.66 Silberschatz, Galvin and Gagne ©2009 Kernel I/O Subsystem Scheduling z S Some I/O requestt ordering d i via i per-device d i queue z Some OSs try fairness Buffering - store data in memory while transferring between devices Synchronous Operating System Concepts – 8th Edition z To cope with device speed mismatch z To cope with device transfer size mismatch z To maintain “copy semantics” A Asynchronous h 8.67 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8th Edition 8.68 Silberschatz, Galvin and Gagne ©2009 Device-status Table Kernel I/O Subsystem Caching - fast memory holding copy of data z Al Always jjustt a copy z Key to performance Spooling - hold output for a device z If device can serve only one request at a time z i.e., Printing Device reservation - p provides exclusive access to a device Operating System Concepts – 8th Edition 8.69 Silberschatz, Galvin and Gagne ©2009 z System calls for allocation and deallocation z Watch out for deadlock Operating System Concepts – 8th Edition Error Handling 8.70 Silberschatz, Galvin and Gagne ©2009 I/O Protection OS can recover from disk read, device unavailable, transient write failures User process may accidentally or purposefully attempt to disrupt normal operation via illegal I/O instructions Most return an error number or code when I/O request fails System error logs hold problem reports Operating System Concepts – 8th Edition 8.71 z All I/O instructions defined to be privileged z I/O must be performed via system calls Silberschatz, Galvin and Gagne ©2009 Memory-mapped and I/O port memory locations must be protected too Operating System Concepts – 8th Edition 8.72 Silberschatz, Galvin and Gagne ©2009 Use of a System Call to Perform I/O Kernel Data Structures Kernel keeps state info for I/O components, including open file tables, network connections connections, character device state Many, many complex data structures to track buffers, memory allocation, “di t ” bl “dirty” blocks k Some use object-oriented methods and message passing to implement I/O Operating System Concepts – 8th Edition 8.73 Silberschatz, Galvin and Gagne ©2009 UNIX I/O Kernel Structure Operating System Concepts – 8th Edition 8.74 Silberschatz, Galvin and Gagne ©2009 I/O Requests to Hardware Operations Consider reading a file from disk for a process: Operating System Concepts – 8th Edition 8.75 Silberschatz, Galvin and Gagne ©2009 z Determine device holding file z Translate name to device representation z Physically read data from disk into buffer z Make data available to requesting process z Return control to process Operating System Concepts – 8th Edition 8.76 Silberschatz, Galvin and Gagne ©2009 Life Cycle of An I/O Request STREAMS STREAM – a full-duplex communication channel between a user-level process and a device in Unix System V and beyond A STREAM consists of: - STREAM head interfaces with the user process - driver end interfaces with the device - zero or more STREAM modules between them. Each module contains a read queue and a write queue Message passing is used to communicate between queues Operating System Concepts – 8th Edition 8.77 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8th Edition The STREAMS Structure 8.78 Silberschatz, Galvin and Gagne ©2009 Performance I/O a major factor in system performance: Operating System Concepts – 8th Edition 8.79 Silberschatz, Galvin and Gagne ©2009 z Demands CPU to execute device driver, kernel I/O code z Context switches due to interrupts z Data copying z Network traffic especially stressful Operating System Concepts – 8th Edition 8.80 Silberschatz, Galvin and Gagne ©2009 Intercomputer Communications Improving Performance Reduce number of context switches Reduce R d d data t copying i Reduce interrupts by using large transfers, smart controllers, polling Use DMA Balance CPU, memory, bus, and I/O performance for highest throughput Operating System Concepts – 8th Edition 8.81 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8th Edition 8.82 Silberschatz, Galvin and Gagne ©2009