Disk Scheduling COMPSCI 386
Topics Disk Structure (9.1 9.2) Disk Scheduling (9.4) Allocation Methods (11.4) Free Space Management (11.5)
Hard Disk Platter diameter ranges from 1.8 to 3.5 inches. Both sides coated with magnetic material. A motor spins the platters at 5000 15000 RPMs. A read/write head floats above each platter on thin cushion of air (measured in microns). Heads connected to a disk arm that moves the heads as a unit.
Hard Disk Surface of a platter is logically divided into concentric tracks. Tracks subdivided into sectors. The set of tracks at one arm position forms a cylinder. 1000s of cylinders. 100s of sectors per track. Storage measured in GBs.
Hard Disk The transfer rate is the rate at which data flows between the drive and the computer. Random access time: seek time (disk arm moves to target cylinder). rotational latency (target sector rotates into position under the head).
Hard Disk OS places a command into host controller via memory-mapped I/O ports. Host controller communicates with disk controller built into the disk drive. Data transferred between disk controller cache and the surface of the disk.
Solid-State Disks Non-volatile memory used as a hard drive. No moving parts. consume less power more reliable and faster resistant to shock and vibration resistant to environmental conditions More expensive: 23 vs 3 per GB Sometimes used as cache for HDD. Disk scheduling algorithms do not apply.
Disk Structure HDDs addressed as linear arrays of logical blocks. Logical block size is usually 512 bytes. Array is mapped sequentially onto sectors. Sector 0 is 1st sector on 1st track on outermost cylinder. The mapping proceeds in order through the track, then through the remaining tracks in that cylinder, and then through the other cylinders (moving inward). In principle, it is easy to map logical disk block to physical (cylinder, track, sector) address, but...
Disk Structure Some disks have damaged sectors. Hidden by the mapping through the use of spare sectors elsewhere. The number of sectors per track may not be constant. With constant linear velocity media, the density of bits per track is uniform. The farther a track is from the center, the greater its length, so more sectors per track. The disk spins faster as the heads move toward the inner tracks in order to maintain constant data transfer rate. With constant angular velocity, rotation speed is fixed and the density of bits decreases from inner to outer tracks so that the data transfer rate remains constant.
Disk Scheduling Bandwidth: total number of bytes transferred divided by the total time between the first request for service and the completion of the last request. When a process needs to read/write from/to disk, it makes a system call specifying: input or output? disk address for the transfer memory address for the transfer total number of sectors to be transferred If the drive is busy, the request will be queued. How is the queue to be serviced?
Disk Scheduling Suppose the queue has requests for I/O to blocks on cylinders 98, 183, 37, 122, 14, 124, 65, 67. FCFS SSTF (shortest seek time first); starvation? SCAN (elevator algorithm) C-SCAN When the head reaches one end of the disk and reverses direction, the greatest density of requests will be at the other end (since it has just traversed the near end). LOOK AND C-LOOK
Disk Scheduling FCFS SCAN SSTF C-SCAN
Caveat It seems that empirical studies of the performance of disk scheduling algorithms done in the 1970s often relied on an invalid assumption: The seek time to service a request is proportional to the distance travelled by the disk arm. Can you guess why this assumption is invalid?
Caveat It seems that empirical studies of the performance of disk scheduling algorithms done in the 1970s often relied on an invalid assumption: The seek time to service a request is proportional to the distance travelled by the disk arm. Can you guess why this assumption is invalid? The arm does not move at constant velocity. It must accelerate to full speed and decelerate to stop. Elementary physics: d = ½a t 2
Caveat Suppose disk arm accelerates at constant rate for the first half of a seek, then decelerates at the same rate for the second half. Assume the disk can perform a seek to an adjacent cylinder in 1 ms and a seek over all 5000 cylinders in 18 ms. Can we write an equation for the seek time as a function of the seek distance?
Caveat Equation should have the form t = x + y sqrt(l), where L is the seek distance in cylinders. Solve simultaneous equations from (t = 1, L = 1) and (t = 18, L = 4999). t = 0.7561 + 0.2439 sqrt(l) Performance of disk scheduling algorithms should really be analysed in terms of seek times, not seek distances.
Explain Solid state disks often use FCFS disk scheduling. FCFS is fair, unlike SSTF, SCAN, and C-SCAN. The OS must sometimes be unfair. Paging and swapping take priority over user process I/O. Kernel-initiated I/O (e.g., writing file system metadata) may need to take priority over user process I/O requests. Kernel may support real-time process priorities.
Explain There are 5000 cylinders numbered 0-4999. Drive is currently serving request at cylinder 2150. Previous request was at cylinder 1805. The queue of pending requests in FIFO order is 2069, 1212, 2296, 2800, 544, 1618, 356, 1523, 4965, 3681. Calculate the total distance (in cylinders) traversed by the disk arm to satisfy all pending requests using FCFS, SSTF, SCAN, LOOK, C-SCAN, C-LOOK
Project Compare performance of SCAN and C-SCAN scheduling with uniform distribution of requests. Evaluate in terms of the average response time, variance of response times, and effective bandwidth. Why would there be a difference in variance? SCAN favors request near the middle cylinders.
Question (Part 1) Requests are not usually uniformly distributed. For example, a cylinder with file-system metadata will probably be accessed much more frequently than cylinders containing only files. Suppose 50% of requests are for a small, fixed set of cylinders. Would any of the scheduling algorithms we considered be good for this case?
Question (Part 1) Requests are not usually uniformly distributed. For example, a cylinder with file-system metadata will probably be accessed much more frequently than cylinders containing only files. Suppose 50% of requests are for a small, fixed set of cylinders. Would any of the scheduling algorithms we considered be good for this case? SSTF would take greatest advantage of this situation. FCFS would suffer if requests for high-demand cylinders were interspersed with request for those far away.
Question (Part 2) Propose a disk scheduling algorithm that gives even better performance by taking advantage of the hot spot on the disk.
Question (Part 2) Propose a disk scheduling algorithm that gives even better performance by taking advantage of the hot spot on the disk. Place hot data near the middle of the disk. Modify SSTF to prevent starvation. If disk is idle for more than 50 ms, do an anticipatory seek to the hot spot.
Allocation Methods How should space be allocated for files so that access is fast and disk space is utilized efficiently? Contiguous Linked Indexed
Contiguous Allocation Simple and fast (for sequential and random access). Up against the dynamic storage-allocation problem. First fit and best fit are better than worst fit in terms of time and storage utilization. Neither first fit nor best fit is particularly good in terms of storage utilization, but first fit is faster.
Contiguous Allocation Big problem: external fragmentation, just as with contiguous memory allocation. Compaction can be done on-line, but performance penalty is significant, especially for large disks. Another problem: how much space needed for file? Even if total amount of needed space were known, preallocation can be wasteful (file grows slowly).
Linked Allocation Each file is a linked list of disk blocks. A directory contains a pointer to first and last blocks of a file. No external fragmentation and size of file need not be declared when file is created.
Linked Allocation Effective only for sequential access of files. If a pointer requires 4 bytes from a 512-byte block, 0.78% of the disk is being used just for pointers. The usual solution is to allocate clusters, which improves disk throughput (fewer head seeks) and decreases pointer storage overhead. Drawback: internal fragmentation.
Linked Allocation Reliability is also a problem. If a pointer is corrupted by an OS bug or a hardware failure, then an I/O operation on the file might lead into the free space or into another file.
Linked Allocation A File Allocation Table (FAT) is a variant of linked allocation that was used by MS DOS. A section of disk set aside to contain a table whose indices correspond to disk blocks. Basically, it s a linked list embedded in an array. An unused block indicated by zero entry in table. Efficient for random access. But there are many seeks since table must be consulted for each request; table must be cached in memory.
Indexed Allocation All pointers stored in one location. Each file has its own index block, an array of disk block addresses. Random access without external fragmentation. Pointer overhead greater than for linked allocation. UNIX systems keep the first few pointers of an index block in the file s inode; some point to direct blocks, some to indirect blocks.
Indexed Allocation All pointers stored in one location. Each file has its own index block, an array of disk block addresses. Random access without external fragmentation. Pointer overhead greater than for linked allocation. UNIX systems keep the first few pointers of an index block in the file s inode; some point to direct blocks, some to indirect blocks.
Indexed Allocation Pointer overhead greater than for linked allocation.
Free Space Management The OS must keep track of disk blocks not yet allocated to a file or directory. To create a file, the free-space list must be searched for a block of adequate size. How to implement free-space list? bit map linked list grouping counting space maps
Bitmap Suppose blocks 2, 3, 5, 8, 13, and 21 are free. 0011010010000100000001 Using machine instructions for bit manipulation, is it simple and efficient to find the first free block or the first sequence of n free blocks. Interpret bitmap as a sequence of words and check each on in sequence for inequality with zero. Block number: (bits per word) * (number of zero-valued words) + (offset of first 1 in first non-zero-valued word)
Bitmap Inefficient unless kept in main memory. Feasible in main memory only for small disks. 1 TB disk with 4KB blocks = 32 MB bitmap. 240 / 212 = 228 bits = 225 bytes = 32 * 220 bytes = 32 MB And disk size is constantly increasing.
Linked List A pointer to the first free block is stored in a special location on disk and cached in memory. Traversing linked list to find sufficient storage for a file is not efficient, but this does not happen often; usually the OS just needs one more block to allocate to a file.
Grouping Modification of linked-list approach. First free block stores the addresses of n free blocks, the last of which stores addresses of n free blocks,... Addresses of large number of free blocks can be obtained quickly.
Counting Motivating idea: several contiguous blocks may be allocated or freed at one time. Store address of the first free block and the number of contiguous free blocks following it. Each entry in the free-space list contains a disk address and a count. Each entry requires more space, but there will be fewer (probably) entries. Entries can be stored as a balanced tree for fast insertion, deletion, and lookup.
Self-Balancing Trees Search Trees AVL trees Red-Black trees Splay trees Multiway Search Trees (2, 4) Trees External Search Trees (optimized for reading and writing large blocks) B trees B+ trees
2-4 Trees Size property: each internal node has 2, 3, or 4 children Depth property: each leaf has the same depth. O(log n) time to search, insert, or delete. 12 5, 10 3, 4 6, 7, 8 15 11 13, 14 17 Convenient to assume keys stored at internal nodes and leaves are merely placeholders.
Space Maps Oracle s ZFS file system designed to handle massive numbers of files, directories, and file systems. File systems can be arranged hierarchically. Freeing 1 GB of data on a 1 TB disk could cause changes to thousands of blocks of bitmap. ZFS uses a combination of simple and sophisticated techniques (including structures called space maps). Details omitted...