302ac412d01

Upload: chelg24

Post on 09-Apr-2018

229 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/7/2019 302AC412d01

    1/31

    CS231:OS CH14: 1

    Chapter 14: Mass-Storage Structure

    Disk Structure

    Disk SchedulingDisk Management

  • 8/7/2019 302AC412d01

    2/31

    CS231:OS CH14: 2

    Background

    Magnetic disks and tapes are examples of secondarystorage.Access time for tapes is much slower than for disks.Tapes are currently used for:

    BackupStorage of infrequently used informationTransferring info from one system to anotherStoring very large quantities of data

    Disks provide the bulk of secondary storage for moderncomputer systems.

  • 8/7/2019 302AC412d01

    3/31

    CS231:OS CH14: 3

    Disk StructureDisk drives are addressed as large 1-dimensionalarrays of logical blocks , where the logical block is thesmallest unit of transfer.

    The 1-dimensional array of logical blocks is mappedinto the sectors of the disk sequentially.

    Sector 0 is the first sector of the first track on theoutermost cylinder.Mapping proceeds in order through that track, thenthe rest of the tracks in that cylinder, and thenthrough the rest of the cylinders from outermost toinnermost.

  • 8/7/2019 302AC412d01

    4/31

    CS231:OS CH14: 4

    Disk Scheduling The operating system is responsible for using hardwareefficiently 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 arm to move theheads to the cylinder containing the desired sector.Rotational latency is the additional time waiting forthe disk to rotate the desired sector to the disk head.

  • 8/7/2019 302AC412d01

    5/31

    CS231:OS CH14: 5

    Disk Scheduling (cont.)

    Minimize seek time

    Seek time

    seek distanceDisk bandwidth is the total number of bytes transferred,divided by the total time between the first request forservice and the completion of the last transfer.We can improve access time and bandwidth byscheduling the servicing of disk I/O requests in a goodorder.

  • 8/7/2019 302AC412d01

    6/31

    CS231:OS CH14: 6

    Disk Scheduling (Cont.)

    Several algorithms exist to schedule the servicing of diskI/O requests.We illustrate them with a disk queue with requests for I/Oto blocks on cylinders (0-199).

    98, 183, 37, 122, 14, 124, 65, 67

    in that order. And disk head is initially at cylinder 53.

  • 8/7/2019 302AC412d01

    7/31

    CS231:OS CH14: 7

    1) FCFS

    First-come, first-served is the simplest algorithm.

    But it does not provide the fastest service.In the example, Illustration shows total head movementof 640 cylinders

  • 8/7/2019 302AC412d01

    8/31

    CS231:OS CH14: 8

    FCFS (cont.)Illustration shows total head movement of 640 cylinders.

  • 8/7/2019 302AC412d01

    9/31

    CS231:OS CH14: 9

    2) SSTF

    Shortest-seek-time-first.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 236cylinders.Improvement in performance.Not optimal.

    Better: 53, 37 , 14, 65, 67, 98, 122, 124, 183 = 208cylinders.

  • 8/7/2019 302AC412d01

    10/31

    CS231:OS CH14: 10

    SSTF (Cont.)

  • 8/7/2019 302AC412d01

    11/31

    CS231:OS CH14: 11

    3) SCAN

    The disk arm starts at one end of the disk, and movestoward the other end, servicing requests until it gets tothe other end of the disk, where the head movement isreversed and servicing continues.Need to know the direction of head movement, inaddition to the heads current position (53).Sometimes called the elevator algorithm .In example, the disk arm is moving toward 0.

  • 8/7/2019 302AC412d01

    12/31

    CS231:OS CH14: 12

    SCAN (Cont.)

  • 8/7/2019 302AC412d01

    13/31

    CS231:OS CH14: 13

    4) C-SCAN

    Circular SCAN

    Provides a more uniform wait time than SCAN.The head moves from one end of the disk to theother, 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 wrapsaround from the last cylinder to the first one.

  • 8/7/2019 302AC412d01

    14/31

    CS231:OS CH14: 14

    C-SCAN (Cont.)

  • 8/7/2019 302AC412d01

    15/31

    CS231:OS CH14: 15

    5) LOOK and C-LOOK

    Versions of SCAN and C-SCANArm only goes as far as the last request in eachdirection, then reverses direction immediately, withoutfirst going all the way to the end of the disk.They LOOK for a request before continuing to move in agiven direction.

  • 8/7/2019 302AC412d01

    16/31

    CS231:OS CH14: 16

    C-LOOK (Cont.)

  • 8/7/2019 302AC412d01

    17/31

    CS231:OS CH14: 17

    exampleWork Queue : 23, 89, 132, 42, 187

    there are 200 cylinders numbered from 0 - 199

    the disk head stars at number 100 (goingtowards 0)

    Starting from the current head position, what isthe total distance (in cylinders) that the disk armmoves to satisfy all the pending requests for

    each of the following disk-schedulingalgorithms:FCFS, SSTF, SCAN, LOOK, C-SCAN, C-LOOK

  • 8/7/2019 302AC412d01

    18/31

    CS231:OS CH14: 18

    Selecting a Disk-Scheduling Algorithm

    SSTF is common and has a natural appealSCAN and C-SCAN perform better for systems thatplace a heavy load on the disk, because they are lesslikely to have a starvation problem.Performance depends on the number and types ofrequests.Requests for disk service can be influenced by the file-allocation method (if they are contiguously allocated ornot).

  • 8/7/2019 302AC412d01

    19/31

    CS231:OS CH14: 19

    Selecting a Disk-Scheduling Algorithm

    (cont.)The location of directories is also important.Since every file must be opened to be used,

    and opening it requires searching the directorystructure, the directories will be accessedfrequently.

    The disk-scheduling algorithm should bewritten as a separate module of the operatingsystem, allowing it to be replaced with adifferent algorithm if necessary.Either SSTF or LOOK is a reasonable choicefor the default algorithm.

  • 8/7/2019 302AC412d01

    20/31

    CS231:OS CH14: 20

    ExerciseSuppose that a disk drive has 5000 cylindersnumbered 0 to 4999. the drive is currentlyserving a request at cylinder 143, and theprevious request was at cylinder 125. Thequeue of pending requests, in FIFO order is:

    86,1470, 913, 1774, 948,1509, 1022, 1750, 130Starting from the current head position, what isthe total distance (in cylinders) that the disk armmoves to satisfy all the pending requests foreach of the following disk-schedulingalgorithms:

    FCFS, SSTF, SCAN, LOOK, C-SCAN, C-LOOK

  • 8/7/2019 302AC412d01

    21/31

    CS231:OS CH14: 21

    Disk scheduling (cont.)

    Whenever a process needs I/O to or from disk, it issuesa system call to the OS. The request specifies thefollowing information:

    Whether this operation is input or output.What the disk address for the transfer is.What the memory address for the transfer is.What the number of bytes to be transferred is.

  • 8/7/2019 302AC412d01

    22/31

    CS231:OS CH14: 22

    Disk Management1- Disk Formatting:

    Low-level formatting , or physical formatting Dividing a disk into sectors that the disk controllercan read and write.Low-level formatting fills the disk with a special datastructure for each sector consists of:

    HeaderData area (usually 512 bytes in size)Trailer

    Header and trailer contain information used by thedisk controller such as sector number and error-correcting code (ECC).

  • 8/7/2019 302AC412d01

    23/31

    CS231:OS CH14: 23

    Disk Formatting (cont.)Most hard disks are low-level formatted at the factory asa part of the manufacturing process.

    Formatting a disk with a larger sector size means thatfewer sectors can fit on each track, So, fewer headersand trailers are written on each track increase thespace available for user data.

  • 8/7/2019 302AC412d01

    24/31

    CS231:OS CH14: 24

    Disk Formatting (cont.)

    To use a disk to hold files, the operating system stillneeds to record its own data structures on the disk. Itdoes that in 2 steps:1. Partition the disk into one or more groups of

    cylinders.2. Logical formatting or creation of a file system. In this

    step , the OS stores the initial file-system datastructures onto the disk (maps of free and allocatedspace FAT and an initial empty directory)

  • 8/7/2019 302AC412d01

    25/31

    CS231:OS CH14: 25

    Block Addressing

    8 blocks / track

    01

    2

    34

    5

    67 0

    12

    3 4

    56

    70

    3

    1

    6

    4

    7

    25

    No interleaving Single interleaving Double interleaving

    Interleaving: is used to give controller time to transfer data tomemory.

    Block numbering: When the disk is formatted, the blocks are

    numbered to take account of the interleave factor.

  • 8/7/2019 302AC412d01

    26/31

    CS231:OS CH14: 26

    Disk Management

    2- Boot Block For a computer to start running, it needs to have aninitial program to run.The bootstrap program is usually stored in ROMbecause ROM :

    Needs no initialization

    Is at fixed locationIs Read only, cant be infected by virus.

    Problem: changing bootstrap code requires changing the

    ROM hardware chips.Most systems store a tiny bootstrap loader program inthe boot ROM, whose only job is to bring in a fullbootstrap program from disk.

  • 8/7/2019 302AC412d01

    27/31

    CS231:OS CH14: 27

    Boot Block (cont.)

    Full bootstrap program is stored in a partition calledthe boot blocks at a fixed location on the disk.Boot block initializes system.Boot disk or system disk : A disk that has a bootpartition.Full bootstrap code may be small. (example: MS-DOS uses one 512-byte for its boot program).

  • 8/7/2019 302AC412d01

    28/31

    CS231:OS CH14: 28

    MS-DOS Disk Layout

  • 8/7/2019 302AC412d01

    29/31

    CS231:OS CH14: 29

    Disk Management

    3- Bad BlocksBecause disk have moving parts and smalltolerances (disk head flies just above the disk

    surface), they are prone to failure.Complete failure: replace diskIncomplete failure: one or more sectors

    become defective (bad blocks)Bad blocks are handled in a variety of ways:

    On simple disks:manually (format, chkdsk)

  • 8/7/2019 302AC412d01

    30/31

    CS231:OS CH14: 30

    Bad Blocks (cont.)More sophisticated disks:

    1. Methods such as sector sparing (forwarding) used to handle bad blocks: controller replace eachbad sector logically with one of the spare sectors.

    Example:OS tries to read logical block 87.Controller calculates the ECC and finds that the

    sector is bad.When system is rebooted, a special command isrun to tell the controller to replace the bad sectorwith a spare.After that, whenever the system requests logicalblock 87, the sector is translated into thereplacement sectors address by the controller.

  • 8/7/2019 302AC412d01

    31/31

    CS231:OS CH14: 31

    Bad Blocks (cont.)2. Replace a bad sector by sector slipping .

    Example:Suppose that logical block 17 becomes defective, and the

    first available spare follows sector 202.Sector slipping would remap all the sectors from 17 to202, moving them all down one spot.

    (sector 202 copied to spare, sector 201 to 202.. Sector 18to 19.)Slipping sectors in that way frees up the space of sector

    18, so sector 17 can be mapped to it.Data in bad block are usually lost, thus, whatever file wasusing that block must be repaired (restored from backup

    tape).