40
Operating Systems Operating Systems COMP 4850/CISG 5550 COMP 4850/CISG 5550 Disks, Part II Disks, Part II Dr. James Money Dr. James Money

Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

Embed Size (px)

Citation preview

Page 1: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

Operating SystemsOperating SystemsCOMP 4850/CISG 5550COMP 4850/CISG 5550

Disks, Part IIDisks, Part II

Dr. James MoneyDr. James Money

Page 2: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

Disk FormattingDisk Formatting

• What does the hard disk consist of?What does the hard disk consist of?– Stack of plattersStack of platters– Each platter is coated with a thin layer Each platter is coated with a thin layer

of magnetizable metal oxideof magnetizable metal oxide– Read/Write headsRead/Write heads– Associated motorsAssociated motors

Page 3: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

Disk FormattingDisk Formatting

• Before use, the disk must have a Before use, the disk must have a low-low-level formatlevel format, which is done by , which is done by softwaresoftware– There are a series of concentric tracksThere are a series of concentric tracks– Each track has sectorsEach track has sectors– There is a gap between consecutive There is a gap between consecutive

sectorssectors

Page 4: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

Disk FormattingDisk Formatting

• The format of a sector consists ofThe format of a sector consists of– Preamble – contains a particular bit Preamble – contains a particular bit

pattern so the hardware recognizes the pattern so the hardware recognizes the start of a sectorstart of a sector

– Data – The size is determined by the Data – The size is determined by the low-level format used. Most of the time low-level format used. Most of the time it is 512 bytesit is 512 bytes

Page 5: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

Disk FormattingDisk Formatting

– ECC – Error correction code, which is ECC – Error correction code, which is used to recover from read errors. This used to recover from read errors. This size varies on the controller and size varies on the controller and generally gives higher reliability for generally gives higher reliability for bigger ECCs. Many times it is 16 bytesbigger ECCs. Many times it is 16 bytes

– Spare sectors – used to replace bad Spare sectors – used to replace bad sectors due to a manufacturing defectsectors due to a manufacturing defect

Page 6: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

Disk FormattingDisk Formatting

Page 7: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

Cylinder SkewCylinder Skew

• Sector 0 on each track is offset from Sector 0 on each track is offset from the previous trackthe previous track

• This is called This is called cylinder skewcylinder skew

• Used to improve performanceUsed to improve performance

• This allows one continuous read from This allows one continuous read from track to tracktrack to track

Page 8: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

Cylinder SkewCylinder Skew

• Consider a disk with 16 sectors per Consider a disk with 16 sectors per tracktrack

• Assume that we read 18 sectors Assume that we read 18 sectors starting a sector 0starting a sector 0

• Once we reach sector 17, we need to Once we reach sector 17, we need to go to the next trackgo to the next track

• However, if they are aligned, we have However, if they are aligned, we have to rotate around once before readingto rotate around once before reading

• Cylinder skew eliminates thisCylinder skew eliminates this

Page 9: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

Cylinder SkewCylinder Skew

Page 10: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

Cylinder SkewCylinder Skew

• The amount of skew depends on the drive The amount of skew depends on the drive geometrygeometry

• For example, a 10k RPM drive rotates in 6 For example, a 10k RPM drive rotates in 6 msecsmsecs

• If the track has 300 sectors, each sector If the track has 300 sectors, each sector takes 20takes 20μμsecssecs

• If track-to-track seek takes 800 If track-to-track seek takes 800 μμsecs, then secs, then 40 sectors pass by40 sectors pass by

• The skew should be 40 sectorsThe skew should be 40 sectors• There also a There also a head skewhead skew, but this is much , but this is much

smaller for switching headssmaller for switching heads

Page 11: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

Disk CapacityDisk Capacity

• When low-level formatting finishes, When low-level formatting finishes, the disk capacity has been reducedthe disk capacity has been reduced

• Many times, this amount is 20% less Many times, this amount is 20% less than the original valuethan the original value

• Spare sectors are not counted in Spare sectors are not counted in original capacityoriginal capacity

Page 12: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

Disk CapacityDisk Capacity

• There is much confusion in this areaThere is much confusion in this area• Many times, manufacturers report Many times, manufacturers report

unformatted capacityunformatted capacity• For example, consider a driver with 20 x For example, consider a driver with 20 x

101099 bytes unformatted bytes unformatted• This may be sold as 20GB diskThis may be sold as 20GB disk• But after formatting, this is 2But after formatting, this is 23434≈≈ 17.2 x 10 17.2 x 1099

bytesbytes• In addition, the OS may say it is 16GB due In addition, the OS may say it is 16GB due

to base 2 versus base 10to base 2 versus base 10

Page 13: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

PerformancePerformance

• Formatting also affects performanceFormatting also affects performance

• If a 10K RPM diver has 300 sectors per If a 10K RPM diver has 300 sectors per track of 512 bytes, it takes 6 msec to track of 512 bytes, it takes 6 msec to read the 153600 bytes on the trackread the 153600 bytes on the track

• The data rate is 25,600,000 bytes/sec The data rate is 25,600,000 bytes/sec or 24.4 MB/sec.or 24.4 MB/sec.

• Not possible to get faster than this!Not possible to get faster than this!

Page 14: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

PerformancePerformance

• Reading continuous also affects the Reading continuous also affects the performanceperformance

• If the controller has a one sector buffer If the controller has a one sector buffer and is reading two consecutive sectorsand is reading two consecutive sectors

• This first is read, but cannot read the This first is read, but cannot read the second since it has to be copied to second since it has to be copied to main memorymain memory

• The track has to spin around an extra The track has to spin around an extra timetime

Page 15: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

PerformancePerformance

• We can eliminate this with sector We can eliminate this with sector interleavinginterleaving

• There are three typesThere are three types– No interleaveNo interleave– Single InterleaveSingle Interleave– Double Interleave – needed if copying is Double Interleave – needed if copying is

slowslow

• Many controllers read entire track into Many controllers read entire track into memorymemory

Page 16: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

InterleavingInterleaving

Page 17: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

PartitioningPartitioning

• After the low-level format, the disk is After the low-level format, the disk is partitionedpartitioned

• Each partition is like a separate diskEach partition is like a separate disk• Sector 0 usually contains the Sector 0 usually contains the master master

boot recordboot record• The MBR contains boot code with the The MBR contains boot code with the

partition table at the endpartition table at the end• Partition table has starting sector and Partition table has starting sector and

sizesize

Page 18: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

High-Level FormatHigh-Level Format

• The final step in disk preparation is The final step in disk preparation is the the high-level formathigh-level format

• This is performed on each partitionThis is performed on each partition

• It sets up the boot block, free storage It sets up the boot block, free storage administration and the file systemadministration and the file system

• It also stores the type of file system It also stores the type of file system in the partition tablein the partition table

Page 19: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

Disk Arm Scheduling Disk Arm Scheduling AlgorithmsAlgorithms• We now consider some of the issues We now consider some of the issues

associated with the disk driverassociated with the disk driver

• The time required to read/write a block is The time required to read/write a block is determined bydetermined by

– Seek time – time to move arm to proper Seek time – time to move arm to proper cylindercylinder

– Rotational Delay – time for proper sector Rotational Delay – time for proper sector to rotate under the headto rotate under the head

– Actual data transfer timeActual data transfer time

Page 20: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

Disk Arm Scheduling Disk Arm Scheduling AlgorithmsAlgorithms

• Seek time tends to dominate the Seek time tends to dominate the other two timesother two times

• We wish to reduce the mean seek We wish to reduce the mean seek time to improve our performancetime to improve our performance

Page 21: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

Disk Arm Scheduling Disk Arm Scheduling AlgorithmsAlgorithms• If the disk driver accepts requests one If the disk driver accepts requests one

at a time and carries them out in that at a time and carries them out in that order, then we have First-Come, First-order, then we have First-Come, First-ServedServed

• We can do little to optimize seek timeWe can do little to optimize seek time• However, many times multiple However, many times multiple

requests come in about the same timerequests come in about the same time• Usually there is a table with the list of Usually there is a table with the list of

requests by cylinder numberrequests by cylinder number

Page 22: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

Disk Arm Scheduling Disk Arm Scheduling AlgorithmsAlgorithms

• Consider a disk with 40 cylindersConsider a disk with 40 cylinders

• A request comes to read cylinder 11A request comes to read cylinder 11

• While the seek to cylinder 11 occurs, While the seek to cylinder 11 occurs, we get requests for cylinders 1, 36, we get requests for cylinders 1, 36, 16, 34, 9, and 12 in that order16, 34, 9, and 12 in that order

• When the request for 11 is finished, it When the request for 11 is finished, it has to decide which cylinder to has to decide which cylinder to request nextrequest next

Page 23: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

First-Come First ServedFirst-Come First Served

•We could use FCFS, but this is We could use FCFS, but this is inefficientinefficient

• It would require arm motions of 10, It would require arm motions of 10, 35, 20, 18, 25, and 11 for a total of 35, 20, 18, 25, and 11 for a total of 111 cylinders111 cylinders

Page 24: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

Shortest Seek FirstShortest Seek First

•A better approach is Shortest Seek A better approach is Shortest Seek First (SSF)First (SSF)

•The sequence would be 12, 9, 16, The sequence would be 12, 9, 16, 1, 34, 361, 34, 36

•The arm motions are 1,3,7,15,33,2 The arm motions are 1,3,7,15,33,2 with a total of 61 cylinderswith a total of 61 cylinders

Page 25: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

Shortest Seek FirstShortest Seek First

Page 26: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

Shortest Seek FirstShortest Seek First

• If there is repeat incoming requests If there is repeat incoming requests all nearby, further away requests do all nearby, further away requests do not get servicednot get serviced

• In a heavily loaded disk, this leads to In a heavily loaded disk, this leads to only requests in the middle of the only requests in the middle of the disk being performeddisk being performed

Page 27: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

Elevator AlgorithmElevator Algorithm

• Tall building have the same problem Tall building have the same problem with elevatorswith elevators

• The idea they use is to keep going in The idea they use is to keep going in the same direction until there are no the same direction until there are no more requestsmore requests

• Then the direction switchesThen the direction switches• This method is called the This method is called the elevator elevator

algorithmalgorithm

Page 28: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

Elevator AlgorithmElevator Algorithm

• Assume, up directionAssume, up direction• The service order is then 12, 16, 34, The service order is then 12, 16, 34,

36, 9, and 136, 9, and 1• The arm motion is 1, 4, 18, 2, 27, The arm motion is 1, 4, 18, 2, 27,

and 8 for a total of 60 cylindersand 8 for a total of 60 cylinders• Tends to be a little worse than SSFTends to be a little worse than SSF• The upper bound on the total motion The upper bound on the total motion

is twice the number of cylindersis twice the number of cylinders

Page 29: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

Elevator AlgorithmElevator Algorithm

Page 30: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

Error HandlingError Handling

• Manufacturers push the limits of Manufacturers push the limits of hardwarehardware

• Many times you see 5000 bits/mmMany times you see 5000 bits/mm

• This requires a fine coating on the diskThis requires a fine coating on the disk

• We cannot manufacture a disk without We cannot manufacture a disk without defectsdefects

• Otherwise, we increase density and Otherwise, we increase density and repeat the processrepeat the process

Page 31: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

Error HandlingError Handling

• This results in bad sectorsThis results in bad sectors

• How to deal with them?How to deal with them?

• If it is just a few bytes, the ECC can If it is just a few bytes, the ECC can correct itcorrect it

• Otherwise, we have to use one of the Otherwise, we have to use one of the spare sectors and substitute it for the spare sectors and substitute it for the bad onebad one

Page 32: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

Error HandlingError Handling

• There are two ways to do this There are two ways to do this substitutionsubstitution– Remap the sectorRemap the sector– Move all the sector numbers up by oneMove all the sector numbers up by one

• This is kept track using internal tables This is kept track using internal tables on the disk or by rewriting the on the disk or by rewriting the preambles with new sector numberspreambles with new sector numbers

• Tradeoff with performance and re-Tradeoff with performance and re-writing preambleswriting preambles

Page 33: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

Error HandlingError Handling

Swap with spare Re-write preambles

Page 34: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

Error HandlingError Handling

• What happens after the disk is being What happens after the disk is being used?used?– We can handle the error in the OS or We can handle the error in the OS or

controllercontroller– If the controller handles it, the first If the controller handles it, the first

approach must be used to swap sectors approach must be used to swap sectors since there is data on the disk nowsince there is data on the disk now

Page 35: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

Error HandlingError Handling

• If the OS handles the remappingIf the OS handles the remapping– It must determine the sector does not It must determine the sector does not

affect any filesaffect any files– Remove references in the free block listRemove references in the free block list– One way to keep track of these bad One way to keep track of these bad

sectors is to have a sector file for the file sectors is to have a sector file for the file systemsystem

Page 36: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

Error HandlingError Handling

• Another class of errors is seek errorsAnother class of errors is seek errors• If the arm goes to the wrong position, If the arm goes to the wrong position,

you have a seek erroryou have a seek error• In effect, you are reading the wrong In effect, you are reading the wrong

sectorsector• Most controllers fix this automaticallyMost controllers fix this automatically• Floppy drives do not and just set an Floppy drives do not and just set an

error biterror bit

Page 37: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

Stable StorageStable Storage

• We have seen that we can prevent We have seen that we can prevent some errors and correct from some some errors and correct from some others (RAID, etc)others (RAID, etc)

• However, we do not protect against However, we do not protect against writing bad data to the disks yetwriting bad data to the disks yet

• We want to correct write the data or We want to correct write the data or nothing at allnothing at all

• This is called This is called stable storagestable storage

Page 38: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

Stable StorageStable Storage

• We use a pair of identical disksWe use a pair of identical disks

• The corresponding blocks work The corresponding blocks work together to form one error free blocktogether to form one error free block

• The data should be same on both The data should be same on both blocks if the write was a successblocks if the write was a success

Page 39: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

Stable StorageStable Storage

• We need three operations:We need three operations:– Stable writes – write block on first drive, Stable writes – write block on first drive,

retrying if needed. Then write to second driveretrying if needed. Then write to second drive– Stable read – read block from drive 1, retrying Stable read – read block from drive 1, retrying

if needed. Unlikely blocks on both drives failif needed. Unlikely blocks on both drives fail– Crash Recovery – If both blocks are the same, Crash Recovery – If both blocks are the same,

nothing is done. If one drive has ECC error, nothing is done. If one drive has ECC error, the good block replaces the bad one. If both the good block replaces the bad one. If both blocks are good, but one is different, drive 1 blocks are good, but one is different, drive 1 replaces drive 2 datareplaces drive 2 data

Page 40: Operating Systems COMP 4850/CISG 5550 Disks, Part II Dr. James Money

Stable StorageStable Storage