113. Secondary Storage (S&G, Ch. 13) Operating SystemsCertificate Program in Software Development CSE-TC and CSIM, AIT September--November, 200313. Secondary Storage (S&G, Ch. 13)Objectivesintroduce issues such as disk scheduling, formatting, and swap space management
2Contents 1. A Hard Disk (Again) 2. Disk Scheduling 3. Disk Formatting 4. Boot Blocks5. Swap Space Management6. Disk Reliability
3: 1. A Hard Disk (Again) Fig. 2.5, p.33 spindle track t actuator sector sread-write head:cylinder carmplatterrotationcontinued
4Mapping to the hardware: The Logical View:one-dimensional array of logical blocksa block is the smallest transfer unit (typically bytes)Mapping to the hardware:for each cylinder (outer to inner)start at first sector of outermost trackgo round the trackmove to the next track on the cylinder
5Mapping Issues Avoiding defective sectors: use substitutes from elsewhere on the diskThe number of sectors varies per trackless sectors per track in the centreZonesa zone is a collection of tracks whose sectors/track are the same
62. Disk Scheduling Fast access times requires: High disk bandwidth fast seek timemove head to the right cylinder quicklylow rotational latencyrotate the disk under the head quickly so the required sector can be accessedHigh disk bandwidthtotal number of bytes transferred in the time between the initial request and its completion
7Controller SelectionDisk I/O requests are placed on a queue managed by the hard drive controller.When the controller comes to do the next request, its scheduler chooses a request which:improves access timeimproves disk bandwidth
8Types of Disk Scheduling First-Come First-Served (FCFS)Shortest Seek-Time First (SSTF)SCAN (and C-SCAN)LOOK (and C-LOOK)
92.1. FCFS Scheduling Fair Not the fastest service Large swings across the disk are possible.The following example(s) will assume a disk queue of I/O requests to blocks on cylinders.
10ExampleFig. 13.1, p.433Queue: 98, 183, 37, 122, 14, 124, 65, 67Head starts at cylinder 53.143753656798122124183Total head movement= 640 cylinders
112.2. SSTF SchedulingThe next request to be serviced is the one closest to the current head positionminimize seek timeReduces overall head movement.May lead to starvation for some requests.
12ExampleFig. 13.2, p.434Queue: 98, 183, 37, 122, 14, 124, 65, 67Head starts at cylinder 53.143753656798122124183Total head movement= 236 cylinders
13Not Optimal If the queue was serviced in a slightly different order: 53, 37, 14, 65, 67, 98, 122, 124, 183then the total head movement would be less: 208 cylinders
142.3. SCAN Scheduling Scan back and forth across the disk sometimes called the elevator algorithmProblem: if a request arrives just behind the head then it will have to wait until the head returns.
15ExampleFig. 13.3, p.435Queue: 98, 183, 37, 122, 14, 124, 65, 67Head starts at cylinder 53, and moves left.143753656798122124183Total head movement= 236 cylinders
16C-SCAN Scheduling ‘C’ for “circular list”. When a scan reaches one end of the disk, it jumps to the other endno point reversing since it is unlikely that there will be requests in recently serviced areas
17ExampleFig. 13.4, p.436Queue: 98, 183, 37, 122, 14, 124, 65, 67Head starts at cylinder 53, and moves right.143753656798122124183
182.4. LOOK SchedulingSCAN (C-SCAN) moves the head across the full width of the disk.LOOK (C-LOOK) moves the head only as far as the last request in each direction, and then reverses (wraps around).
19C-LOOK ExampleFig. 13.5, p.437Queue: 98, 183, 37, 122, 14, 124, 65, 67Head starts at cylinder 53, and moving right.143753656798122124183
202.5. Which Disk Scheduling Algorithm? SSTF - commonly usedSCAN/C-SCANgood for heavily loaded disks since they avoid starvationChoice depends on number/type of requestse.g. file I/O will generate sequences of requests to adjacent blockscontinued
21Caching?Comparisons can utilise seek distances (as here) and disk rotational latency.Logical addresses hide useful physical information (e.g. sector and track positions), that an OS-level scheduler could use.continued
22There may be conflict between the OS and disk controller scheduling policies: e.g. the OS may want disk writes to happen immediately and in a fixed order when a transaction is being carried out
233. Disk FormattingThe disk controller uses low-level formatting (physical formatting)a data structure per each sectorconsists ofheader, data area (512 bytes), trailerutilises an error-correcting code (ECC)continued
24The OS adds its own data structures: partitions the disk into groups of cylinderslogical formatting (make the file system)includes the directory/file structure, and lists of free and allocated pages
25data blocks (subdirectories) 4. Boot BlocksMost book blocks hold a simple bootstrap loader whose only job is to load and execute a fuller bootstrap program from diskthe program is located in a fixed place on disk (a boot partition)sector 0book blocksector 1FATroot directorydata blocks (subdirectories)MS-DOS
26Bad Blocks A bad block is a defective sector. The OS can mark bad blocks and then skip them, or maintain a list of bad blocks.Sector sparing (forwarding)substitute a (close) good block for the bad oneSector slippingmove related blocks to be contiguous if they contain a bad block
275. Swap space Management Swap space algorithms use virtual memory (VM) disk space treated as RAMslowmanagement aim is to speed-up VM throughput
28Swap Space Implementation As a file:standard interfaceeasy to implementinefficient use of physical memoryAs a special partition:no need to impose directory/file structuresfasterhard to reconfigure
295.1. UNIX Swap Space (4.3 BSD)Each process is assigned a swap space which holds:text segments (for pages of the program)data segments (for runtime data)The kernel uses two swap maps to track swap space usage in a process.
30Swap Maps Figs. 13.7 and 13.8, p.444 text segment swap map 512K 512K data segment swap map16K32K64K128K
316. Disk Reliability Common approach is to use multiple disks. Disk stripping (interleaving)store data spread across several disksreduces chance of complete failureI/O data transfers can use parallelismcontinued
32RAID (Redundant Array of Independent Disks) Mirroring (shadowing) duplicates data across diskscostlyparallelism can increase speedBlock interleaved parityif data on one machine is corrupted, it can be recalculated from the remaining data and parity information stored on the other machines