oses: 13. secondary storage 1 operating systems v objectives –introduce issues such as disk...
TRANSCRIPT
OSes: 13. Secondary Storage 1
Operating SystemsOperating Systems
ObjectivesObjectives– introduce issues such as disk scheduling, introduce issues such as disk scheduling,
formatting, and swap space managementformatting, and swap space management
Certificate Program in Software DevelopmentCSE-TC and CSIM, AITSeptember--November, 2003
13. Secondary Storage(S&G, Ch. 13)
OSes: 13. Secondary Storage 2
ContentsContents
1.1. A Hard Disk (Again)A Hard Disk (Again)
2.2. Disk SchedulingDisk Scheduling
3.3. Disk FormattingDisk Formatting
4.4. Boot BlocksBoot Blocks
5.5. Swap Space ManagementSwap Space Management
6.6. Disk ReliabilityDisk Reliability
OSes: 13. Secondary Storage 3
1. A Hard Disk (Again)1. A Hard Disk (Again) Fig. 2.5, p.33
:
rotation
armplatter
cylinder c
track t
read-writehead
spindleactuator
sector s
continued
OSes: 13. Secondary Storage 4
The Logical View:The Logical View:– one-dimensional array of logical one-dimensional array of logical blocksblocks– a block is the smallest transfer unita block is the smallest transfer unit
(typically 512-1024 bytes)(typically 512-1024 bytes)
Mapping to the hardware:Mapping to the hardware:– for each cylinder (outer to inner)for each cylinder (outer to inner)
start at first sector of outermost trackstart at first sector of outermost track go round the trackgo round the track move to the next track on the cylindermove to the next track on the cylinder
OSes: 13. Secondary Storage 5
Mapping IssuesMapping Issues
Avoiding defective sectors:Avoiding defective sectors:– use substitutes from elsewhere on the diskuse substitutes from elsewhere on the disk
The number of sectors varies per trackThe number of sectors varies per track– less sectors per track in the centreless sectors per track in the centre
ZonesZones– a zone is a collection of tracks whose a zone is a collection of tracks whose
sectors/track are the samesectors/track are the same
OSes: 13. Secondary Storage 6
2. Disk Scheduling2. Disk Scheduling Fast access times requires:Fast access times requires:
– fast seek timefast seek time move head to the right cylinder quicklymove head to the right cylinder quickly
– low rotational latencylow rotational latency rotate the disk under the head quickly so the rotate the disk under the head quickly so the
required sector can be accessedrequired sector can be accessed
High disk bandwidthHigh disk bandwidth– total number of bytes transferred in the time total number of bytes transferred in the time
between the initial request and its completionbetween the initial request and its completion
OSes: 13. Secondary Storage 7
Disk I/O requests are placed on a queue Disk I/O requests are placed on a queue managed by the hard drive controller.managed by the hard drive controller.
When the controller comes to do the next When the controller comes to do the next request, its scheduler chooses a request request, its scheduler chooses a request which:which:– improves access timeimproves access time– improves disk bandwidthimproves disk bandwidth
Controller SelectionController Selection
OSes: 13. Secondary Storage 8
Types of Disk SchedulingTypes of Disk Scheduling
First-Come First-Served (FCFS)First-Come First-Served (FCFS)
Shortest Seek-Time First (SSTF)Shortest Seek-Time First (SSTF)
SCAN (and C-SCAN)SCAN (and C-SCAN)
LOOK (and C-LOOK)LOOK (and C-LOOK)
OSes: 13. Secondary Storage 9
2.1. FCFS Scheduling2.1. FCFS Scheduling
FairFair Not the fastest serviceNot the fastest service Large swings across the disk are possible.Large swings across the disk are possible.
The following example(s) will assume a The following example(s) will assume a disk queue of I/O requests to blocks on disk queue of I/O requests to blocks on cylinders.cylinders.
OSes: 13. Secondary Storage 10
ExampleExample
Queue: 98, 183, 37, 122, 14, 124, 65, 67Queue: 98, 183, 37, 122, 14, 124, 65, 67 Head starts at cylinder 53.Head starts at cylinder 53.
Fig. 13.1, p.433
14 37 53 65 67 98 122 124 183
Total head movement = 640 cylinders
OSes: 13. Secondary Storage 11
2.2. SSTF Scheduling2.2. SSTF Scheduling
The next request to be serviced is the one The next request to be serviced is the one closest to the current head positionclosest to the current head position– minimize seek timeminimize seek time
Reduces overall head movement.Reduces overall head movement.
May lead to May lead to starvationstarvation for some requests. for some requests.
OSes: 13. Secondary Storage 12
ExampleExample
Queue: 98, 183, 37, 122, 14, 124, 65, 67Queue: 98, 183, 37, 122, 14, 124, 65, 67 Head starts at cylinder 53.Head starts at cylinder 53.
Fig. 13.2, p.434
Total head movement = 236 cylinders
14 37 53 65 67 98 122 124 183
OSes: 13. Secondary Storage 13
Not OptimalNot Optimal
If the queue was serviced in a slightly If the queue was serviced in a slightly different order:different order:– 53,53, 37, 14 37, 14, 65, 67, 98, 122, 124, 183, 65, 67, 98, 122, 124, 183
– then the total head movement would be less: then the total head movement would be less: 208208 cylinders cylinders
OSes: 13. Secondary Storage 14
2.3. SCAN Scheduling2.3. SCAN Scheduling
Scan back and forth across the diskScan back and forth across the disk– sometimes called the sometimes called the elevatorelevator algorithm algorithm
ProblemProblem: if a request arrives just behind the : if a request arrives just behind the head then it will have to wait until the head head then it will have to wait until the head returns.returns.
OSes: 13. Secondary Storage 15
ExampleExample
Queue: 98, 183, 37, 122, 14, 124, 65, 67Queue: 98, 183, 37, 122, 14, 124, 65, 67 Head starts at cylinder 53, Head starts at cylinder 53, andand moves left. moves left.
Fig. 13.3, p.435
Total head movement = 236 cylinders
14 37 53 65 67 98 122 124 183
OSes: 13. Secondary Storage 16
C-SCAN SchedulingC-SCAN Scheduling
‘‘C’ for “circular list”.C’ for “circular list”. When a scan reaches one end of the disk, it When a scan reaches one end of the disk, it
jumps to the other endjumps to the other end– no point reversing since it is unlikely that there no point reversing since it is unlikely that there
will be requests in recently serviced areaswill be requests in recently serviced areas
OSes: 13. Secondary Storage 17
ExampleExample
Queue: 98, 183, 37, 122, 14, 124, 65, 67Queue: 98, 183, 37, 122, 14, 124, 65, 67 Head starts at cylinder 53, Head starts at cylinder 53, andand moves right. moves right.
Fig. 13.4, p.436
14 37 53 65 67 98 122 124 183
OSes: 13. Secondary Storage 18
2.4. LOOK Scheduling2.4. LOOK Scheduling
SCAN (C-SCAN) moves the head across SCAN (C-SCAN) moves the head across the full width of the disk.the full width of the disk.
LOOK (C-LOOK) moves the head only as LOOK (C-LOOK) moves the head only as far as the last request in each direction, and far as the last request in each direction, and then reverses (wraps around).then reverses (wraps around).
OSes: 13. Secondary Storage 19
C-LOOK ExampleC-LOOK Example
Queue: 98, 183, 37, 122, 14, 124, 65, 67Queue: 98, 183, 37, 122, 14, 124, 65, 67 Head starts at cylinder 53, Head starts at cylinder 53, andand moving right. moving right.
Fig. 13.5, p.437
14 37 53 65 67 98 122 124 183
OSes: 13. Secondary Storage 20
2.5. Which Disk Scheduling Algorithm?2.5. Which Disk Scheduling Algorithm?
SSTF - commonly usedSSTF - commonly used SCAN/C-SCANSCAN/C-SCAN
– good for heavily loaded disks since they avoid good for heavily loaded disks since they avoid starvationstarvation
Choice depends on number/type of Choice depends on number/type of requestsrequests– e.g. file I/O will generate sequences of e.g. file I/O will generate sequences of
requests to adjacent blocksrequests to adjacent blocks
continued
OSes: 13. Secondary Storage 21
Caching?Caching?
Comparisons can utilise seek distances (as Comparisons can utilise seek distances (as here) here) andand disk rotational latency. disk rotational latency.
Logical addresses hide useful physical Logical addresses hide useful physical information (e.g. sector and track positions), information (e.g. sector and track positions), that an OS-level scheduler could use.that an OS-level scheduler could use.
continued
OSes: 13. Secondary Storage 22
There may be conflict between the OS and There may be conflict between the OS and disk controller scheduling policies:disk controller scheduling policies:– e.g. the OS may want disk writes to happen e.g. the OS may want disk writes to happen
immediately and in a fixed order when a immediately and in a fixed order when a transaction is being carried outtransaction is being carried out
OSes: 13. Secondary Storage 23
3. Disk Formatting3. Disk Formatting
The disk controller uses The disk controller uses low-level low-level formattingformatting (physical formatting) (physical formatting)– a data structure per each sectora data structure per each sector– consists ofconsists of
header, data area (512 bytes), trailerheader, data area (512 bytes), trailer
– utilises an error-correcting code (ECC)utilises an error-correcting code (ECC)
continued
OSes: 13. Secondary Storage 24
The OS adds its own data structures:The OS adds its own data structures:– partitions the disk into groups of cylinderspartitions the disk into groups of cylinders
– logical formattinglogical formatting (make the file system) (make the file system) includes the directory/file structure,includes the directory/file structure,
and lists of free and allocated pagesand lists of free and allocated pages
OSes: 13. Secondary Storage 25
4. Boot Blocks4. Boot Blocks
Most book blocks hold a simple bootstrap Most book blocks hold a simple bootstrap loader whose only job is to load and execute loader whose only job is to load and execute a fuller bootstrap program from diska fuller bootstrap program from disk– the program is located in a fixed the program is located in a fixed
place on disk (place on disk (a boot partitiona boot partition)) book block
FAT
root directory
data blocks(subdirectories)
sector 0sector 1
MS-DOS
OSes: 13. Secondary Storage 26
Bad BlocksBad Blocks A bad block is a defective sector.A bad block is a defective sector. The OS can mark bad blocks and then skip The OS can mark bad blocks and then skip
them, or maintain a list of bad blocks.them, or maintain a list of bad blocks.
Sector sparingSector sparing (forwarding) (forwarding)– substitute a (close) good block for the bad onesubstitute a (close) good block for the bad one
Sector slippingSector slipping– move related blocks to be contiguous if they move related blocks to be contiguous if they
contain a bad blockcontain a bad block
OSes: 13. Secondary Storage 27
5. Swap space Management5. Swap space Management
Swap space algorithms use virtual Swap space algorithms use virtual memory (VM) memory (VM) – disk space treated as RAMdisk space treated as RAM– slowslow– management aim is to speed-up VM management aim is to speed-up VM
throughput throughput
OSes: 13. Secondary Storage 28
Swap Space ImplementationSwap Space Implementation
As a file:As a file:– standard interfacestandard interface– easy to implementeasy to implement– inefficient use of physical memoryinefficient use of physical memory
As a special partition:As a special partition:– no need to impose directory/file structuresno need to impose directory/file structures– fasterfaster– hard to reconfigurehard to reconfigure
OSes: 13. Secondary Storage 29
5.1. UNIX Swap Space5.1. UNIX Swap Space (4.3 BSD) (4.3 BSD)
Each process is assigned a swap space Each process is assigned a swap space which holds:which holds:– text segmentstext segments (for pages of the program) (for pages of the program)– data segmentsdata segments (for runtime data) (for runtime data)
The kernel uses two The kernel uses two swap mapsswap maps to track to track swap space usage in a process.swap space usage in a process.
OSes: 13. Secondary Storage 30
Swap MapsSwap Maps Figs. 13.7 and 13.8, p.444
512K 512K 512K 32K
text segment swap map
data segment swap map
16K 32K 64K 128K
OSes: 13. Secondary Storage 31
6. Disk Reliability6. Disk Reliability
Common approach is to use multiple disks.Common approach is to use multiple disks.
Disk strippingDisk stripping (interleaving) (interleaving)– store data store data spreadspread across several disks across several disks– reduces chance of complete failurereduces chance of complete failure– I/O data transfers can use parallelismI/O data transfers can use parallelism
continued
OSes: 13. Secondary Storage 32
Mirroring (shadowing) Mirroring (shadowing) duplicatesduplicates data data across disksacross disks– costlycostly– parallelism can increase speedparallelism can increase speed
Block interleaved parityBlock interleaved parity– if data on one machine is corrupted, it can be if data on one machine is corrupted, it can be
recalculated from the remaining data and parity recalculated from the remaining data and parity information stored on the other machinesinformation stored on the other machines
RAIDRAID (Redundant Array of Independent Disks) (Redundant Array of Independent Disks)