380 likes | 468 Views
Chapter 14. Mass-Storage Structure. Disk Structure. 磁碟結構. Disk drives are addressed as large 1-dimensional arrays of logical blocks, where the logical block is the smallest unit of transfer. The 1-dimensional array of logical blocks is mapped into the sectors of the disk sequentially.
E N D
Chapter 14 Mass-Storage Structure
Disk Structure 磁碟結構 • Disk drives are addressed as large 1-dimensional arrays of logical blocks, where the logical block is the smallest unit of transfer. • The 1-dimensional array of logical blocks is mapped into the sectors of the disk sequentially. • Sector 0 is the first sector of the first track on the outermost cylinder. • 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.
Disk Scheduling 磁碟排程 • The operating system is responsible for using hardware efficiently — for the disk drives, this means having a fast access time and disk bandwidth. • Access time has two major components • Seek time is the time for the disk are to move the heads to the cylinder containing the desired sector. • Rotational latency is the additional time waiting for the disk to rotate the desired sector to the disk head. • 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. 尋找時間 旋轉延遲 磁碟頻寬
Multiple Choices Question: ( )Two major determining factors of disk access time is the _________ and the rotational latency. (A) around time (B) feedback time (C) seek time (D) execution time (E) wait time Ans: C
Disk Scheduling (Cont.) • Several algorithms exist to schedule the servicing of disk I/O requests. • We illustrate them with a request queue (0-199). 98, 183, 37, 122, 14, 124, 65, 67 Head pointer 53
FCFS Illustration shows total head movement of 640 cylinders.
SSTF • 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.
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, where the head movement is reversed and servicing continues. • Sometimes called the elevator algorithm. • Illustration shows total head movement of 208 cylinders.
Multiple Choices Question: ( ) Which algorithm listed below is also called “elevator algorithm”? (A) SCAN (B) SSTF (C) LOOK (D) C-LOOK (E) FCFS Ans: A
C-SCAN • Provides a more uniform wait time than SCAN. • The 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. • Treats the cylinders as a circular list that wraps around from the last cylinder to the first one.
C-LOOK • Version of C-SCAN • Arm 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.
Selecting a Disk-Scheduling Algorithm • SSTF is common and has a natural appeal • SCAN and C-SCAN perform better for systems that place a heavy load 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, allowing it to be replaced with a different algorithm if necessary. • Either SSTF or LOOK is a reasonable choice for the default algorithm.
True-False Question: ( )Either FCFS or LOOK is a reasonable choice for the default disk scheduling algorithm. Ans: X
Disk Management §14.3 • Disk Formatting • Boot Block • Bad Block
Disk Formatting §14.3.1 • Low-level formatting: Before a disk can store data, it must be divided into sectors that the disk controller can read and write. It fills the disk with a special data structure for each sector. • header • data area (usually 512 bytes) • trailer Consists of
Error-correcting code (ECC) • The header and the trailer contain information used by the disk controller, such as sector number and ECC. • ECC: value calculated from all the bytes in the data area. Can be used to calculate the correct value if few bits of data have been corrupted. • The controller automaticaly does the ECC processing whenever a sector is read and written.
Disk Structure • To hold files, the OS needs to record its own data structure on the disk. • First step: partition the disk into one or more groups of cylinders. Each partition can be treated as a separate disk. • Second step: logical formatting (or create a file system). OS stores the initial file-system data structures onto the disk. • maps of free and allocated space(FAT or inodes) • initial empty directory includes
Boot Block §14.3.2 • Initial (tiny) bootstrap loader program stored in read-only memory (ROM) to bring in a full bootstrap program from disk. • The full bootstrap program is stored in a partition called the boot block, at a fixed location on the disk. • A disk that has a boot partition is called a boot disk or system disk.
Bad Blocks §14.3.3 • Frequently, one or more sectors become defected... Bad blocks. They are handled differently: • IDE controller: handled manually.When formatting, also scans the disk to find bad blocks. If bad blocks are found, it is remembered in the FAT. Later bad blocks must be found by manually run chkdsk command to search.
Sector Sparing • SCSI controller: The controller maintains a list of bad blocks on the disk, which is initialized during formatting and updated over the life of the disk.Formatting also set aside spare sectors for replacing bad sectors logically...sector sparing or forwarding.
Sector Sparing • A typical bad-sector transaction: • OS read a logical block • Controller calculates the ECC and finds it bad. Reported to the OS. • During next reboot, the SCSI controller replace the bad sector with a spare. • After that, requests this logical block is translated into the replacement sector’s address by the controller.
Sector Sparing • Redirection by the controller could invalidate any optimization by the OS’s disk-scheduling algorithm! • Provide a few spare sectors in each cylinder, and a spare cylinder as well. • When a bad block is remapped, the controller uses a spare sector from the same cylinder, if possible.
Sector Slipping • Suppose logical block 17 becomes defective, and the first available spare follows sector 202. • Sector slipping would remap all the sectors from 17 to 202, moving them all down one spot. • This would frees up sector 18, so 17 can be mapped to it.
Swap-Space Management §14.4 • Virtual memory uses disk space as an extension of main memory. • Decreases system performance but provide better throughput for virtual-memory system.
Swap-Space Use §14.4.1 • Swapping uses swap space to hold the entire process image. • Paging stores pages that have been pushed out of main memory. • UNIX allow multiple swap spaces put on separate disks so the loading placed on the I/O system by paging and swapping can be spread over the system’s I/O devices. • It is safer to overestimate than to underestimate swap space.
Swap-Space Location §14.4.2 • Swap space can be from normal file system or can be in a separate disk partition. • From normal file system: inefficient.Navigating the directory structure takes time and extra disk accesses. • External fragmentation can greatly increase swapping times by forcing multiple seeks during reading or writing of a process image.
Swap-Space Location • From separate disk partition: a separate swap-space storage manager is used to allocate and deallocate the blocks. • Manager optimized for speed, not for storage efficiency. • Although internal fragmentation may increase, it is acceptable because data in the swap space generally live for much shorter amounts of time than do files in the file system.
Swap-Space Management Example -- UNIX §14.4.3 • UNIX 4.3 BSD preallocate swap space to a process when it is started. • Enough space is set aside to hold the program, known as the text pages or text segment, and the data segemnt of the process. • File system is consulted only once for each text page.
Swap-Space Management Example -- UNIX §14.4.3 • Two swap maps per process are used by the kernel to track swap-space use. • The text segment is a fixed size of 512 KB chunks allocated, except the final chunk for last page.
Swap-Space Management Example -- UNIX §14.4.3 • The data segment can grow over time, the map contains swap addresses for blocks of varying size. • Given index i, a block pointed to by swap-map entry i is of size 2i x 16KB, to a maximum of 2 MB.
Swap-Space Management Example -- UNIX §14.4.3 • When a process tries to grow its data segment beyond the final allocated block in its swap area, the OS allocates another double-sized block. • This scheme results in small processes using only small blocks. It also minimizes fragmentation.
Swap-Space Management Example – Solaris 1 §14.4.3 • Thrown away pages if selected for pageout. • More efficient to reread a page from the file system than to write it to swap space and then to reread it from there. • Solaris 2 allocates swap space only when a page is forced out of physical memory, rather than when the virtual-memory page is first created.
RAID Structure §14.5 • Before, disk-organization techniques called redundant arrays of inexpensive disks (RAID) composed of small cheap disks as a cost-effective alternative to large, expensive disks. • Today, RAIDs are used for their higher reliability and higher data-transfer rate, rather than for economic reasons.