Presentation is loading. Please wait.

Presentation is loading. Please wait.

© Janice Regan, CMPT 300, May 2007 0 CMPT 300 Introduction to Operating Systems DISK I/0.

Similar presentations


Presentation on theme: "© Janice Regan, CMPT 300, May 2007 0 CMPT 300 Introduction to Operating Systems DISK I/0."— Presentation transcript:

1 © Janice Regan, CMPT 300, May 2007 0 CMPT 300 Introduction to Operating Systems DISK I/0

2 © Janice Regan, CMPT 300, May 2007 1 Disks  Hard disks: gigabytes – terabytes  CD’s  DVD’s  Disks are  flat and circular (called a platter)  Hard disks contain multiple platters  Surface of platter divided to hold data (formatted, formatting may cause a decrease in capacity)  Disk access is about 10 6 times slower than register access

3 © Janice Regan, CMPT 300, May 2007 2 Platter surface geometry track Sector

4 © Janice Regan, CMPT 300, May 2007 3 Hard disk

5 © Janice Regan, CMPT 300, May 2007 4 Zones zone  Real disks will have zones with more sectors towards the outer edge and fewer toward the inner edge  Most disks present a virtual geometry to the OS, which assumes a constant number of sectors per track. The controller maps the OS requested sector to the physical sector on the disk

6 Cylinders  In the disk there are multiple platters (often two sided). And there are heads to read each side of each platter  All the heads move in and out together.  If we consider one head it is above a particular track on a particular platter of the disk  If we consider the whole disk, A cylinder is the group of tracks (track n on each side of each platter) that can be read when the heads are in a particular position (above a certain track) © Janice Regan, CMPT 300, May 2007 5

7 6 Components of Disk access speed  Platters spin at some rate (7200rpm is a typical fast disk)  Read/write head must move to the correct track (seek time)  Read/write head must wait for the correct sector (rotational latency, rotational delay)  Actual read/write of data must occur (access time)  Data must be transferred to/from the disk controller (transfer time)

8 © Janice Regan, CMPT 300, May 2007 7 Sectors  Each sector contains  Preamble: synchronization marker  sector information, cylinder and sector number  Data  Error detection/correction information  Whole sector is read to buffer in controller  Error detection/correction is performed  Data is transferred to its destination from the disk controller’s buffer

9 © Janice Regan, CMPT 300, May 2007 8  To optimize access time consider  It is faster to read the ‘next’ sector than a random sector on the disk.  The ‘next’ sector may not be the next one physically, may read every nth sector  Remember the sector is read into the controllers buffer then transferred  This takes time, during this time the disk is spinning along the track under the read/write head  Reading every nth sector means when the ‘average’ transfer from the controller buffer is complete the head will be approaching the ‘next’ sector and can read almost immediately Optimization strategy

10 © Janice Regan, CMPT 300, May 2007 9 Disk interleaving 0 1 2 3 4 5 6 7  This illustrates double interleaving (skipping two sectors between reads) and is appropriate if the copying process is slow  Single interleaving (skipping one sector between reads) was more common  Many modern controllers buffer a whole track, no need for interleaving

11 © Janice Regan, CMPT 300, May 2007 10  To optimize access time consider.  It is faster to read the ‘adjacent’ track than a random track on the disk.  Moving to any track on the disk requires moving the read/write heads which takes time.  Consider that one track has just been read (final block on track)  The read/write head is now positioned at the start of sector 0 on the track it just read. Next read sector 0 on the adjacent track  The head must first move to the new track, while it does sector zero on the track to be read has been missed. Must then wait for the disk to rotate back to cylinder 0 before it can be read  Can offset which cylinder is cylinder 0 on adjacent tracks to improve performance, the number of cylinders the sector is offset is called the skew Cylinder skew

12 © Janice Regan, CMPT 300, May 2007 11 Cylinder skew 2 1 4 3 0 7 6 5 2 1 6 5 4 3 0 7 54 7 6 3 2 1 0

13 © Janice Regan, CMPT 300, May 2007 12 Components of Disk access speed  Platters spin at some rate (7200rpm is a typical fast disk)  Read/write head must move to the correct track (seek time) increases with number of tracks traversed. T s  Read/write head must wait for the correct sector (rotational latency, rotational delay) average delay is T d =1/(2r) where r is the rotation speed (rpm)  Actual read/write of data must occur (access time)  Data must be transferred to/from the disk controller (transfer time) T t =b/(rN) where b is the number of bytes and N is the number of bytes per track

14 © Janice Regan, CMPT 300, May 2007 13 Disk Scheduling  Want to schedule disk requests to optimize performance. Must consider  Seek time (move to correct cylinder)  Rotational delay  Transfer time  Different approaches to the order in which disk accesses are processed  Simply taking a random request from the I/O queue is the benchmark and will be referred to a random scheduling.

15 © Janice Regan, CMPT 300, May 2007 14 First Come First Served  Requests are removed from the queue in the order that they arrived.  For a small number of processes, each process will have clusters of nearby accesses so some improvement over random scheduling may occur  For a large number of processes, many areas on the disk may be in demand. May perform very similarly to random request order

16 Example: First Come First Served  Consider the following sequence of accesses (each number represents a track number, 0 Is the centre of the disk). Initially the heads are over track 48  23 96 65 104 12 4 77 Track 48 to 23 25 tracks scanned Track 23 to 96 73 tracks scanned Track 96 to 65 31 tracks scanned Track 65 to 104 39 tracks scanned Track 104 to 1292 tracks scanned Track 12 to 48 tracks scanned Track 4 to 77 73 tracks scanned Average seek length (25+73+31+39+92+8+73)/7 = 48.7 © Janice Regan, CMPT 300, May 2007 15

17 First Come First Served © Janice Regan, CMPT 300, May 2007 16

18 © Janice Regan, CMPT 300, May 2007 17 Shortest seek (service) time  Choose the request in the queue whose location on the disk is closest to the present location of the head (shortest seek time)  More efficient, transfer time cannot be changed so minimizing seek time will help optimize the system  Can cause starvation, If there are many requests in one area of the disk, processes using other parts of the disk may never have their requests filled.  On a busy system the arm will tend to stay near the centre sectors (or initial sectors) of the disk  Need a tie breaking algorithm (what if there are two requests the same distance away in different directions)

19 Example: Shortest Seek  Consider the following sequence of accesses (each number represents a track number, 0 Is the centre of the disk). Initially the heads are over track 48  23 96 65 104 12 4 77 Track 48 to 65 17 tracks scanned Track 65 to 77 12 tracks scanned Track 77 to 96 19 tracks scanned Track 96 to 104 8 tracks scanned Track 104 to 2381 tracks scanned Track 23 to 1211 tracks scanned Track 12 to 4 8 tracks scanned Average seek length (17+12+19+8+81+11+8)/7 = 22.3 © Janice Regan, CMPT 300, May 2007 18

20 © Janice Regan, CMPT 300, May 2007 19 Shortest Seek

21 © Janice Regan, CMPT 300, May 2007 20 Elevator algorithm: (SCAN)  Choose the closest request moving toward the centre (edge) of the disk  Take successive requests moving towards the centre (edge) of the disk  When you reach the innermost (outermost) request move to the centre (edge) of the disk  Change direction: then take successive requests moving toward the outer edge (centre).  Move from the outermost (innermost) request to the outer (inner) edge, then change direction again

22 Example: Elevator Algorithm (SCAN)  Consider the following sequence of accesses (each number represents a track number, 0 Is the centre of the disk). Initially the heads are over track 48 (head is moving towards the centre of disk)  23 96 65 104 12 4 77 Track 48 to 23 25 tracks scanned Track 23 to 12 11 tracks scanned Track 12 to 4 8 tracks scanned Track 4 to 04 tracks scanned Track 0 to 65 65 tracks scanned Track 65 to 7712 tracks scanned Track 77 to 9619 tracks scanned Track 96 to 104 8 tracks scanned Average seek length (25+11+8+4+65+12+19+8)/7 = 21.7 © Janice Regan, CMPT 300, May 2007 21

23 Elevator (Scan) © Janice Regan, CMPT 300, May 2007 22

24 © Janice Regan, CMPT 300, May 2007 23 LOOK  Choose the closest request moving toward the centre (edge) of the disk  Take successive requests moving towards the centre (edge) of the disk  When you reach the innermost (outermost) request Change direction  Then service successive requests moving toward the outer edge (centre).  When you reach the outermost (innermost) request change direction again  Advantage: no extra seeks to centre or edge

25 Example: LOOK  Consider the following sequence of accesses (each number represents a track number, 0 Is the centre of the disk). Initially the heads are over track 48 (head is moving towards the centre of disk)  23 96 65 104 12 4 77 Track 48 to 23 25 tracks scanned Track 23 to 12 11 tracks scanned Track 12 to 4 8 tracks scanned Track 4 to 65 61 tracks scanned Track 65 to 7712 tracks scanned Track 77 to 9619 tracks scanned Track 96 to 104 8 tracks scanned Average seek length (25+11+8+61+12+19+8)/7 = 20.6 © Janice Regan, CMPT 300, May 2007 24

26 LOOK © Janice Regan, CMPT 300, May 2007 25

27 © Janice Regan, CMPT 300, May 2007 26 Circular Scan  Choose one direction, towards the centre (edge)  Choose the closest request in that direction, move to that request  Take successive requests moving in the same direction  After servicing the innermost (outermost) request continue to the centre (edge) of the disk.  Go to the edge (centre) of the disk, begin again  all requests will be serviced  Reduces maximum delay experienced by new requests

28 Example: Circular Scan  Consider the following sequence of accesses (each number represents a track number, 0 Is the centre of the disk). Initially the heads are over track 48 (head is moving towards the centre of disk)  23 96 65 104 12 4 77 Track 48 to 23 25 tracks scanned Track 23 to 12 11 tracks scanned Track 12 to 4 8 tracks scanned Track 4 to 0 4 tracks scanned go to track 127 Track 127 to 10423 tracks scanned Track 104 to 968 tracks scanned Track 96 to 77 19 tracks scanned Track 77 to 65 12 tracks scanned Average seek length (25+11+8+4+23+8+19+12)/7 = 15.7 © Janice Regan, CMPT 300, May 2007 27

29 © Janice Regan, CMPT 300, May 2007 28 Circular SCAN

30 © Janice Regan, CMPT 300, May 2007 29 Circular Look  Restrict shortest seek in one direction  Choose the closest request in that particular direction. Start at the centre (edge)  Take successive requests moving toward the edge (centre)  When you reach the outermost (innermost) request go back to the innermost (outermost) request and begin again  all requests will be serviced, fewer tracks seeked  Reduces maximum delay experienced by new requests

31 Example: Circular Look  Consider the following sequence of accesses (each number represents a track number, 0 Is the centre of the disk). Initially the heads are over track 48 (head is moving towards the centre of disk)  23 96 65 104 12 4 77 Track 48 to 23 25 tracks scanned Track 23 to 12 11 tracks scanned Track 12 to 4 8 tracks scanned Track 4 to 104100 tracks scanned (see below) Track 104 to 968 tracks scanned Track 96 to 77 19 tracks scanned Track 77 to 65 12 tracks scanned Average seek length (25+11+8+8+19+12)/7 = 11.9  Seek from 4-104 will take time but be much faster than other seeks © Janice Regan, CMPT 300, May 2007 30

32 Example: Circular Look © Janice Regan, CMPT 300, May 2007 31

33 © Janice Regan, CMPT 300, May 2007 32 N step scan  Segment the request queue into segments of length N processes  All requests in one subsequence are processed before requests in the next subsequence are considered  N=1 FIFO, large N approaches scan  Prevents ‘sticking’ in one cylinder if there are a large volume of requests for that cylinder

34 © Janice Regan, CMPT 300, May 2007 33 Error recovery  Can have a physical problem reading a particular sector on the disk (from manufacture or wear)  Can have mechanical problems with other disk components (heads, arms …) reading particular sectors  How do we deal with ‘bad’ sectors (sectors with unrecoverable errors)  Most disks set aside some spare sectors when they are formatted.  When a bad sector is found the bad sector will be ‘replaced’ by one of the spare sectors.  This can make sector by sector backups difficult

35 Error recovery: disk controller  For manufacturing defects (before shipping) Usually done within the disk controller  For additional bad sectors that develop due to ware  First try reread: error may be transient (dust on head for example) done by controller  Replace sector that cannot be recovered, usually done by disk controller © Janice Regan, CMPT 300, May 2007 34

36 Error recovery and the OS  When the controller cannot or does not transparently manage recovery, then what?  The OS must keep track of bad blocks and make sure they are not used for files or placed in the list of available blocks © Janice Regan, CMPT 300, May 2007 35

37 Errors and backups  If backup are done file by file things should work  If backups are done sector by sector, then bad block within the sector will be copied regardless of whether they are part of a file or an available list.  Copying a sector with bad blocks will fail © Janice Regan, CMPT 300, May 2007 36

38 © Janice Regan, CMPT 300, May 2007 37 Error recovery: simplest 2 1 4 3 0 5 B 1 4 3 0 5 2 PROBLEM: takes two rotations to read the recovered track

39 © Janice Regan, CMPT 300, May 2007 38 Error recovery 2 1 4 3 0 5 B 1 2 2 0 4 5 More efficient: can read entire track in one read Less efficient: must rewrite preambles for each sector

40 © Janice Regan, CMPT 300, May 2007 39 RAID  Redundant Array of Inexpensive Disks  A set of physical disk drives seen as a single logical drive by the system (OS)  Data (individual files) are distributed across multiple physical drives Access can be faster, access multiple disks to get the data Controller controls mapping and setup of RAID structure on the group of disks OS sees the equivalent of a single disk  Different levels of optimization, different approaches

41 © Janice Regan, CMPT 300, May 2007 40 RAID level 0  Individual disk controllers are replaced by a single RAID 0 controller than simultaneously manages all disks. It is capable of simultaneously transferring from all the disks  Each disk is divided into strips. A strip may be a block, a sector, or some other unit.  When a large write to disk is requested the RAID 0 controller will break the requested data into strips. The first strip will be placed on the first disk, the second on the second disk and so on in a round robin fashion. Strip 12 Strip 8 Strip 4 Strip 0 Strip 13 Strip 9 Strip 5 Strip 1 Strip 14 Strip 10 Strip 6 Strip 2 Strip 15 Strip 11 Strip 7 Strip 3 Stripes indicated by colours

42 RAID level 0  Dividing the data between N disks allows the RAID) controller to read/write the data N times faster  If two requests are pending there is a good chance they are on different disks and can be serviced simultaneously. This reduces the average time in the I/O queue  Works best for large read/write requests  Systems with OSs that read one sector at a time will not see significant improvements using RAID 0  Decreases mean time to failure over single large disk  Also called striping, no redundancy (so not true RAID) © Janice Regan, CMPT 300, May 2007 41

43 © Janice Regan, CMPT 300, May 2007 42 RAID level 1  All data is duplicated, each logical strip is mapped to two different disks (same data stored in the two strips).  Each disk has a mirror disk that contains the same data. (in fact RAID 1 can be applied to unstriped disks)  To recover from failure on one disk read the data from the mirror disk Strip 12 Strip 8 Strip 4 Strip 0 Strip 13 Strip 9 Strip 5 Strip 1 Strip 14 Strip 10 Strip 6 Strip 2 Strip 15 Strip 11 Strip 7 Strip 3 Strip 12 Strip 8 Strip 4 Strip 0 Strip 13 Strip 9 Strip 5 Strip 1 Strip 14 Strip 10 Strip 6 Strip 2 Strip 15 Strip 11 Strip 7 Strip 3

44 © Janice Regan, CMPT 300, May 2007 43 RAID level 1  Each disk has a mirror disk that contains the same data.  A read request can be serviced by either disk containing the data (choose faster of the two available reads)  A write request requires both disks containing the data to be updated. (limited by slower or two writes)  Expensive, requires double the storage capacity  Useful, providing real time backup  If the bulk of I/O requests are reads can approach double the access speed of RAID0  If many of the I/O requests are writes may not see a significant access speed improvement

45 © Janice Regan, CMPT 300, May 2007 44 RAID level 2 and 3 Strip 12 Strip 8 Strip 4 Bit 0 Strip 13 Strip 9 Strip 5 Bit 1 Strip 14 Strip 10 Strip 6 Bit 2 Strip 15 Strip 11 Strip 7 Bit 3 Strip 15 Strip 11 Strip 7 parity  Strips may be as small as a single byte  N disks access simultaneously (are rotationally synchronized). All disks participate in each data request  Parity bits (RAID3) or error code (RAID2) is calculated over each stripe and stored on an additional disk (RAID3 or logN disks RAID2)  Would be useful in an environment with many errors, since the error code/parity is powerful enough to correct most errors.  Can reconstruct failed disk contents based on error code/parity  Provides very high data rates, but only one I/O request can be serviced at a time

46 © Janice Regan, CMPT 300, May 2007 45 RAID level 4 to 6  Each member disk operates independently. Multiple I/O requests can be satisfied in parallel  Relatively large strips are used  More complicated error detection/correction approaches are used


Download ppt "© Janice Regan, CMPT 300, May 2007 0 CMPT 300 Introduction to Operating Systems DISK I/0."

Similar presentations


Ads by Google