CS34 2013-05-17 CS 134: Operating Systems File System Implementation CS 134: Operating Systems File System Implementation 1 / 34
Overview CS34 Overview 2013-05-17 Implementation Issues Caching Failures Disk Scheduling Overview API What Goes in an API? Two Strange APIs Consistency Other File Operations Implementation Issues Caching Failures Disk Scheduling API What Goes in an API? Two Strange APIs Consistency Other File Operations 2 / 34
Implementation Issues Caching Disk Caching—Class Exercise CS34 Disk Caching—Class Exercise 2013-05-17 Implementation Issues Caching If OS caches blocks of a file in memory, ◮ How should it track what it’s caching? ◮ How should it decide what to cache? Disk Caching—Class Exercise There’s a close relationship to paging algorithms. If OS caches blocks of a file in memory, ◮ How should it track what it’s caching? ◮ How should it decide what to cache? 3 / 34
Implementation Issues Caching Disk Buffering CS34 Disk Buffering 2013-05-17 Implementation Issues Allow writes to return immediately ◮ Copy data into a buffer Caching ◮ Write out to the disk Buffers vs. Caches Disk Buffering Which do we actually need ? We need some kind of buffer (the write may not be the same size as Allow writes to return immediately the block). We don’t need the cache; it just improves performance. ◮ Copy data into a buffer ◮ Write out to the disk Buffers vs. Caches Which do we actually need ? 4 / 34
Implementation Issues Caching Buffer Cache CS34 Buffer Cache 2013-05-17 Store disk blocks waiting to write in buffer cache Implementation Issues ◮ “Free” buffers used as cache for blocks recently read ◮ Dirty buffers will eventually be written to disk ◮ Allow buffer cache to use any free memory in the machine Caching ◮ Ensure that a certain number of buffers are always available Class Exercises & Reminders Buffer Cache Store disk blocks waiting to write in buffer cache When should we write the dirty buffers? Per-process or system-wide? Remind you of anything? ◮ “Free” buffers used as cache for blocks recently read ◮ Dirty buffers will eventually be written to disk ◮ Allow buffer cache to use any free memory in the machine ◮ Ensure that a certain number of buffers are always available Class Exercises & Reminders When should we write the dirty buffers? Per-process or system-wide? Remind you of anything? 5 / 34
Implementation Issues Caching Buffer Cache (cont.) CS34 Buffer Cache (cont.) 2013-05-17 Implementation Issues One buffer cache for all processes and all block devices Caching ◮ Local disks ◮ Remote disks ◮ Tapes, CD-ROMs, etc. Buffer Cache (cont.) One buffer cache for all processes and all block devices ◮ Local disks ◮ Remote disks ◮ Tapes, CD-ROMs, etc. 6 / 34
Implementation Issues Failures Dealing with System Failure—Class Exercise CS34 Dealing with System Failure—Class Exercise 2013-05-17 Implementation Issues Extending the file by one block. . . In what order should we update the structures on disk to cause Failures minimum damage if the system crashes? (Assume disk will never leave a block half-written. . . ) Dealing with System Failure—Class Exercise What about ◮ File creation? ◮ File deletion? Extending the file by one block. . . In what order should we update the structures on disk to cause minimum damage if the system crashes? (Assume disk will never leave a block half-written. . . ) What about ◮ File creation? ◮ File deletion? 7 / 34
Implementation Issues Failures Recovering from System Failure CS34 Recovering from System Failure 2013-05-17 Implementation Issues Before system failure. . . ◮ Backups! Failures After system failure. . . ◮ Run consistency checker—compares data in directory Recovering from System Failure structure with data blocks on disk, tries to fix inconsistencies. ◮ Recover lost files (or disk) by restoring data from backup Before system failure. . . ◮ Backups! After system failure. . . ◮ Run consistency checker—compares data in directory structure with data blocks on disk, tries to fix inconsistencies. ◮ Recover lost files (or disk) by restoring data from backup 8 / 34
Implementation Issues Disk Scheduling Disk Scheduling CS34 Disk Scheduling 2013-05-17 Implementation Issues OS needs to use all I/O devices efficiently: ◮ Minimize access time—composed of ◮ Seek time Disk Scheduling ◮ Rotational latency ◮ Maximize disk bandwidth ◮ Bandwidth = Total Bytes Transferred / Total Time Taken ◮ Usually, disk requests can be re-ordered Disk Scheduling ◮ Several algorithms exist to schedule disk I/O requests ◮ Consider, e.g., cylinders 98, 183, 37, 122, 14, 124, 65, 67 and an initial head position of 53 OS needs to use all I/O devices efficiently: ◮ Minimize access time—composed of ◮ Seek time ◮ Rotational latency ◮ Maximize disk bandwidth ◮ Bandwidth = Total Bytes Transferred / Total Time Taken ◮ Usually, disk requests can be re-ordered ◮ Several algorithms exist to schedule disk I/O requests ◮ Consider, e.g., cylinders 98, 183, 37, 122, 14, 124, 65, 67 and an initial head position of 53 9 / 34
Implementation Issues Disk Scheduling First-Come First-Served (FCFS) CS34 First-Come First-Served (FCFS) 2013-05-17 Handle request queue in order. . . Implementation Issues Disk Scheduling Handle request queue in order. . . First-Come First-Served (FCFS) Total head movement of 640 cylinders—Yuck! Total head movement of 640 cylinders—Yuck! 10 / 34
Implementation Issues Disk Scheduling Shortest Seek Time First (SSTF) CS34 Shortest Seek Time First (SSTF) 2013-05-17 Service request with minimum seek time from current head position Implementation Issues Disk Scheduling Service request with minimum seek time from current head Shortest Seek Time First (SSTF) position Total head movement of 236 cylinders SSTF may starve requests (why?). Total head movement of 236 cylinders 11 / 34
Implementation Issues Disk Scheduling Scan (aka The Elevator Algorithm) CS34 Scan (aka The Elevator Algorithm) 2013-05-17 Move head from one end of the disk to the other, servicing requests as we go Implementation Issues Disk Scheduling Move head from one end of the disk to the other, servicing Scan (aka The Elevator Algorithm) requests as we go Total head movement of 208 cylinders Total head movement of 208 cylinders 12 / 34
Implementation Issues Disk Scheduling Look CS34 Look 2013-05-17 Like Scan, but only go as far as least/greatest request. . . Implementation Issues Disk Scheduling Like Scan, but only go as far as least/greatest request. . . Look Total head movement of 180 cylinders Total head movement of 180 cylinders 13 / 34
Implementation Issues Disk Scheduling Circular-SCAN (C-Scan) CS34 Circular-SCAN (C-Scan) 2013-05-17 Like Scan, but only move in one direction. . . Implementation Issues Disk Scheduling Like Scan, but only move in one direction. . . Circular-SCAN (C-Scan) Total head movement of 382 cylinders Why do this? It wastes head movement. . . Total head movement of 382 cylinders 14 / 34
Implementation Issues Disk Scheduling C-Look CS34 C-Look 2013-05-17 The circular variant of Look (again, only move in one direction) Implementation Issues Disk Scheduling The circular variant of Look (again, only move in one direction) C-Look Total head movement of 322 cylinders Total head movement of 322 cylinders 15 / 34
Implementation Issues Disk Scheduling Fairness CS34 Fairness 2013-05-17 Implementation Issues What if we had two processes, each producing the following Disk Scheduling requests ◮ 0, 5, 10, . . . , 75 ◮ 125, 130, 135, . . . , 200 Fairness How fair would these techniques be? What if we had two processes, each producing the following requests ◮ 0, 5, 10, . . . , 75 ◮ 125, 130, 135, . . . , 200 How fair would these techniques be? 16 / 34
Implementation Issues Disk Scheduling Fairness—Look CS34 Fairness—Look 2013-05-17 Implementation Issues Disk Scheduling Fairness—Look 17 / 34
Implementation Issues Disk Scheduling Fairness—FCFS CS34 Fairness—FCFS 2013-05-17 Implementation Issues Disk Scheduling Fairness—FCFS 18 / 34
Implementation Issues Disk Scheduling Fairness—FScan / N-step-Scan CS34 Fairness—FScan / N-step-Scan 2013-05-17 Implementation Issues Disk Scheduling Fairness—FScan / N-step-Scan 19 / 34
Implementation Issues Disk Scheduling Selecting a Disk-Scheduling Algorithm CS34 Selecting a Disk-Scheduling Algorithm 2013-05-17 Implementation Issues Comparing algorithms, we find that: ◮ FCFS can be okay if disk controller manages the scheduling Disk Scheduling (many do these days) ◮ SSTF is common and has natural appeal ◮ LOOK works well (lowest amount of head moment in our test) Selecting a Disk-Scheduling Algorithm ◮ LOOK and C-LOOK perform better for systems under heavy load Comparing algorithms, we find that: ◮ FCFS can be okay if disk controller manages the scheduling (many do these days) ◮ SSTF is common and has natural appeal ◮ LOOK works well (lowest amount of head moment in our test) ◮ LOOK and C-LOOK perform better for systems under heavy load 20 / 34
Recommend
More recommend