[精选]操作系统有责任高效地使用硬件对于磁盘设备5305.pptx
Chapter 14:Mass-Storage SystemslDisk StructurelDisk SchedulinglDisk ManagementlSwap-Space ManagementlRAID StructurelDisk AttachmentlStable-Storage ImplementationlTertiary Storage DeviceslOperating System IssueslPerformance Issues 1 3/17/2023Disk StructurelDisk drives are addressed as large 1-dimensional arrays of logical blocks,where the logical block is the smallest unit of transfer.lThe 1-dimensional array of logical blocks is mapped into the sectors of the disk sequentially.nSector 0 is the first sector of the first track on the outermost cylinder.nMapping 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.2 3/17/2023Disk SchedulinglThe operating system is responsible for using hardware efficiently for the disk drives,this means having a fast access time and disk bandwidth.操作系统有责任高效地使用硬件操作系统有责任高效地使用硬件对于磁盘设备,这意味对于磁盘设备,这意味着很短的访问时间和磁盘带宽。着很短的访问时间和磁盘带宽。lAccess time has two major components 访问时间包括两个主访问时间包括两个主要部分要部分nSeek time is the time for the disk are to move the heads to the cylinder containing the desired sector.寻道时间是指寻道时间是指把磁头移到所需柱面的时间。把磁头移到所需柱面的时间。nRotational latency is the additional time waiting for the disk to rotate the desired sector to the disk head.旋转延迟是旋转延迟是指等待磁盘上所需要的扇区旋转到磁头下面的时间。指等待磁盘上所需要的扇区旋转到磁头下面的时间。3 3/17/2023Disk SchedulinglMinimize seek time 最小寻道时间最小寻道时间lSeek time seek distance 寻道时间寻道时间 寻道距离寻道距离lDisk 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.磁盘带宽,是用传输的总位数,除以第一个服务请求与最磁盘带宽,是用传输的总位数,除以第一个服务请求与最后传输完成之间的总时间。后传输完成之间的总时间。4 3/17/2023Disk Scheduling(Cont.)lSeveral algorithms exist to schedule the servicing of disk I/O requests.lWe illustrate them with a request queue(0-199).98,183,37,122,14,124,65,67Head pointer 53 5 3/17/2023FCFSIllustration shows total head movement of 640 cylinders.6 3/17/2023SSTFlSelects the request with the minimum seek time from the current head position.lSSTF scheduling is a form of SJF scheduling;may cause starvation of some requests.lIllustration shows total head movement of 236 cylinders.7 3/17/2023SSTF(Cont.)8 3/17/2023SCANlThe 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,where the head movement is reversed and servicing continues.lSometimes called the elevator algorithm(电梯算法).lIllustration shows total head movement of 208 cylinders.9 3/17/2023SCAN(Cont.)10 3/17/2023C-SCANlProvides a more uniform wait time than SCAN.lThe head moves from one end of the disk to the other.servicing requests as it goes.When it reaches the other end,however,it immediately returns to the beginning of the disk,without servicing any requests on the return trip.lTreats the cylinders as a circular list that wraps around from the last cylinder to the first one.11 3/17/2023C-SCAN(Cont.)12 3/17/2023C-LOOKlVersion of C-SCANlArm only goes as far as the last request in each direction,then reverses direction immediately,without first going all the way to the end of the disk.13 3/17/2023C-LOOK(Cont.)14 3/17/2023Selecting a Disk-Scheduling AlgorithmlSSTF is common and has a natural appeallSCAN and C-SCAN perform better for systems that place a heavy load on the disk.lPerformance depends on the number and types of requests.lRequests for disk service can be influenced by the file-allocation method.lThe disk-scheduling algorithm should be written as a separate module of the operating system,allowing it to be replaced with a different algorithm if necessary.lEither SSTF or LOOK is a reasonable choice for the default algorithm.15 3/17/2023Disk ManagementlLow-level formatting,or physical formatting Dividing a disk into sectors that the disk controller can read and write.lTo use a disk to hold files,the operating system still needs to record its own data structures on the disk.nPartition the disk into one or more groups of cylinders.nLogical formatting or“making a file system”.lBoot block initializes system.nThe bootstrap is stored in ROM.nBootstrap loader program.lMethods such as sector sparing used to handle bad blocks.16 3/17/2023MS-DOS Disk Layout 17 3/17/2023Swap-Space ManagementlSwap-space Virtual memory uses disk space as an extension of main memory.lSwap-space can be carved out of the normal file system,or,more commonly,it can be in a separate disk partition.lSwap-space managementn4.3BSD allocates swap space when process starts;holds text segment(the program)and data segment.nKernel uses swap maps to track swap-space use.nSolaris 2 allocates swap space only when a page is forced out of physical memory,not when the virtual memory page is first created.18 3/17/20234.3 BSD Text-Segment Swap Map 19 3/17/20234.3 BSD Data-Segment Swap Map 20 3/17/2023RAID StructurelRAID multiple disk drives provides reliability via redundancy.lRAID is arranged into six different levels.21 3/17/2023RAID(cont)lSeveral improvements in disk-use techniques involve the use of multiple disks working cooperatively.lDisk striping uses a group of disks as one storage unit.lRAID schemes improve performance and improve the reliability of the storage system by storing redundant data.nMirroring or shadowing keeps duplicate of each disk.nBlock interleaved parity uses much less redundancy.22 3/17/2023RAID Levels 23 3/17/2023RAID(0+1)and(1+0)24 3/17/2023Disk AttachmentlDisks may be attached one of two ways:1.Host attached via an I/O port2.Network attached via a network connection 25 3/17/2023Network-Attached Storage 26 3/17/2023Storage-Area Network 27 3/17/2023Stable-Storage ImplementationlWrite-ahead log scheme requires stable storage.lTo implement stable storage:nReplicate information on more than one nonvolatile storage media with independent failure modes.nUpdate information in a controlled manner to ensure that we can recover the stable data after any failure during data transfer or recovery.28 3/17/2023Tertiary Storage DeviceslLow cost is the defining characteristic of tertiary storage.lGenerally,tertiary storage is built using removable medialCommon examples of removable media are floppy disks and CD-ROMs;other types are available.29 3/17/2023Removable DiskslFloppy disk thin flexible disk coated with magnetic material,enclosed in a protective plastic case.nMost floppies hold about 1 MB;similar technology is used for removable disks that hold more than 1 GB.nRemovable magnetic disks can be nearly as fast as hard disks,but they are at a greater risk of damage from exposure.30 3/17/2023Removable Disks(Cont.)lA magneto-optic disk records data on a rigid platter coated with magnetic material.nLaser heat is used to amplify a large,weak magnetic field to record a bit.nLaser light is also used to read data(Kerr effect).nThe 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.lOptical disks do not use magnetism;they employ special materials that are altered by laser light.31 3/17/2023WORM DiskslThe data on read-write disks can be modified over and over.lWORM(“Write Once,Read Many Times”)disks can be written only once.lThin aluminum film sandwiched between two glass or plastic platters.lTo write a bit,the drive uses a laser light to burn a small hole through the aluminum;information can be destroyed by not altered.lVery durable and reliable.lRead Only disks,such ad CD-ROM and DVD,com from the factory with the data pre-recorded.32 3/17/2023TapeslCompared to a disk,a tape is less expensive and holds more data,but random access is much slower.lTape 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.lLarge tape installations typically use robotic tape changers that move tapes between tape drives and storage slots in a tape library.nstacker library that holds a few tapesnsilo library that holds thousands of tapes lA disk-resident file can be archived to tape for low cost storage;the computer can stage it back into disk storage for active use.33 3/17/2023Operating System IssueslMajor OS jobs are to manage physical devices and to present a virtual machine abstraction to applicationslFor hard disks,the OS provides two abstraction:nRaw device an array of data blocks.nFile system the OS queues and schedules the interleaved requests from several applications.34 3/17/2023Application InterfacelMost OSs handle removable disks almost exactly like fixed disks a new cartridge is formatted and an empty file system is generated on the disk.lTapes are presented as a raw storage medium,i.e.,and application does not not open a file on the tape,it opens the whole tape drive as a raw device.lUsually the tape drive is reserved for the exclusive use of that application.lSince the OS does not provide file system services,the application must decide how to use the array of blocks.lSince 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.35 3/17/2023Tape DriveslThe basic operations for a tape drive differ from those of a disk drive.llocate positions the tape to a specific logical block,not an entire track(corresponds to seek).lThe read position operation returns the logical block number where the tape head is.lThe space operation enables relative motion.lTape drives are“append-only”devices;updating a block in the middle of the tape also effectively erases everything beyond that block.lAn EOT mark is placed after a block that is written.36 3/17/2023File NaminglThe issue of naming files on removable media is especially difficult when we want to write data on a removable cartridge on one computer,and then use the cartridge in another computer.lContemporary OSs generally leave the name space problem unsolved for removable media,and depend on applications and users to figure out how to access and interpret the data.lSome kinds of removable media(e.g.,CDs)are so well standardized that all computers use them the same way.37 3/17/2023Hierarchical Storage Management(HSM)lA 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.lUsually incorporate tertiary storage by extending the file system.nSmall and frequently used files remain on disk.nLarge,old,inactive files are archived to the jukebox.lHSM is usually found in supercomputing centers and other large installations that have enormous volumes of data.38 3/17/2023Speed lTwo aspects of speed in tertiary storage are bandwidth and latency.lBandwidth is measured in bytes per second.nSustained bandwidth average data rate during a large transfer;#of bytes/transfer time.Data rate when the data stream is actually flowing.nEffective bandwidth average over the entire I/O time,including seek or locate,and cartridge switching.Drives overall data rate.39 3/17/2023Speed(Cont.)lAccess latency amount of time needed to locate data.nAccess time for a disk move the arm to the selected cylinder and wait for the rotational latency;35 milliseconds.nAccess on tape requires winding the tape reels until the selected block reaches the tape head;tens or hundreds of seconds.nGenerally say that random access within a tape cartridge is about a thousand times slower than random access on disk.lThe low cost of tertiary storage is a result of having many cheap cartridges share a few expensive drives.lA 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.40 3/17/2023ReliabilitylA fixed disk drive is likely to be more reliable than a removable disk or tape drive.lAn optical cartridge is likely to be more reliable than a magnetic disk or tape.lA 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.41 3/17/2023CostlMain memory is much more expensive than disk storagelThe cost per megabyte of hard disk storage is competitive with magnetic tape if only one tape is used per drive.lThe cheapest tape drives and the cheapest disk drives have had about the same storage capacity over the years.lTertiary storage gives a cost savings only when the number of cartridges is considerably larger than the number of drives.42 3/17/2023Price per Megabyte of DRAM,From 1981 to 2000 43 3/17/2023Price per Megabyte of Magnetic Hard Disk,From 1981 to 2000 44 3/17/2023Price per Megabyte of a Tape Drive,From 1984-2000 45 3/17/2023