48
College of Software Engineering, Southeast University 14.1 Chapter 12: Mass Storage Structure Operating System Concepts 张竞慧 办公室:计算机楼366电邮:[email protected] 主页:http://cse.seu.edu.cn/PersonalPage/zjh/ 电话:025-52091017

Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.1

Chapter 12: Mass Storage Structure

Operating System Concepts

张竞慧 办公室:计算机楼366室

电邮:[email protected] 主页:http://cse.seu.edu.cn/PersonalPage/zjh/

电话:025-52091017

Page 2: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.2 Operating System Concepts

Chapter 12: Mass-Storage Systems

Disk Structure Disk Attachment Disk Scheduling Disk Management Swap-Space Management RAID Structure Stable-Storage Implementation Tertiary Storage Devices Operating System Issues Performance Issues

Page 3: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.3 Operating System Concepts

Page 4: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.4 Operating System Concepts

Disk Hardware (Cont.)

Disk parameters for the original IBM PC floppy disk and a Western Digital WD 18300 hard

disk

Page 5: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.5 Operating System Concepts

Disk Structure Disk drives are addressed as large 1-

dimensional arrays of logical blocks, where the logical block is the smallest unit of transfer.

The 1-dimensional array of logical blocks is mapped into the sectors of the disk sequentially. Sector 0 is the first sector of the first track on the

outermost cylinder. Mapping proceeds in order through that track, then

the rest of the tracks in that cylinder, and then through the rest of the cylinders from outermost to innermost.

Page 6: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.6 Operating System Concepts

Disk Attachment

Disks may be attached one of two ways:

1. Host attached via an I/O port

2. Network attached via a network connection

Page 7: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.7 Operating System Concepts

Network-Attached Storage

Page 8: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.8 Operating System Concepts

Storage-Area Network

Page 9: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.9 Operating System Concepts

Page 10: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.10 Operating System Concepts

Disk Scheduling The operating system is responsible for

using hardware efficiently — 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 are to move

the heads to the cylinder containing the desired sector. Rotational latency is the additional time waiting

for the disk to rotate the desired sector to the disk head.

Page 11: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.11 Operating System Concepts

Disk Scheduling (Cont.)

Minimize seek time Seek time ≈ seek distance Disk bandwidth is the total number of bytes

transferred, divided by the total time between the first request for service and the completion of the last transfer.

Page 12: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.12 Operating System Concepts

Disk Scheduling (Cont.)

Several algorithms exist to schedule the servicing of disk I/O requests.

We illustrate them with a request queue (0-199).

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

Head pointer 53

Page 13: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.13 Operating System Concepts

FCFS Illustration shows total head movement of 640 cylinders.

Page 14: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.14 Operating System Concepts

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 236 cylinders.

Page 15: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.15 Operating System Concepts

SSTF (Cont.)

Page 16: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.16 Operating System Concepts

SCAN

The disk arm starts at one end of the disk, and moves toward the other end, servicing requests until it gets to the other end of the disk, where the head movement is reversed and servicing continues.

Sometimes called the elevator algorithm. Illustration shows total head movement of

208 cylinders.

Page 17: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.17 Operating System Concepts

SCAN (Cont.)

Page 18: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.18 Operating System Concepts

C-SCAN Provides a more uniform wait time than

SCAN. The head moves from one end of the disk to

the other. 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 wraps around from the last cylinder to the first one.

Page 19: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.19 Operating System Concepts

C-SCAN (Cont.)

Page 20: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.20 Operating System Concepts

C-LOOK

Version of C-SCAN Arm only goes as far as the last request in

each direction, then reverses direction immediately, without first going all the way to the end of the disk.

Page 21: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.21 Operating System Concepts

C-LOOK (Cont.)

Page 22: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.22 Operating System Concepts

Selecting a Disk-Scheduling Algorithm

SSTF is common and has a natural appeal SCAN and C-SCAN perform better for systems

that place a heavy load on the disk. Performance depends on the number and types

of requests. Requests for disk service can be influenced by

the file-allocation method. Contiguous allocation and linked allocation

Page 23: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.23 Operating System Concepts

Selecting a Disk-Scheduling Algorithm (Cont.)

The disk-scheduling algorithm should be written as a separate module of the operating system, allowing it to be replaced with a different algorithm if necessary.

Either SSTF or LOOK is a reasonable choice for the default algorithm.

Page 24: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.24 Operating System Concepts

Disk Formatting

Low-level formatting, or physical formatting — Dividing a disk into sectors that the disk controller can read and write.

To use a disk to hold files, the operating system still needs to record its own data structures on the disk. Partition the disk into one or more groups of

cylinders. Logical formatting or “making a file system”.

Page 25: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.25

Offset sector from one track to next one in order to get consecutive sectors

Cylinder Skew(柱面斜进)

Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice Hall Inc All rights

10000 rpm 300 sectors per track seek time 800 us cylinder skew= ?

Page 26: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.26 Operating System Concepts

Error Handling

A disk track with a bad sector Substituting a spare for the bad sector(sector

sparing) Shifting all the sectors to bypass the bad one

(sector forwarding)

Page 27: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.27

RAID Motivation Disks are improving, but not as fast as CPUs

1970s seek time: 50-100 ms. 2000s seek time: <5 ms. Factor of 20 improvement in 3 decades

We can use multiple disks for improving performance By Striping files across multiple disks (placing

parts of each file on a different disk), parallel I/O can improve access time

Striping reduces reliability 100 disks have 1/100th mean time between failures of one

disk

So, we need Striping for performance, but we need something to help with reliability / availability

To improve reliability, we can add redundant data to the disks, in addition to Striping

Page 28: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.28

RAID

A RAID is a Redundant Array of Inexpensive Disks In industry, “I” is for “Independent” The alternative is SLED, single large expensive disk

Disks are small and cheap, so it’s easy to put lots of disks (10s to 100s) in one box for increased storage, performance, and availability

The RAID box with a RAID controller looks just like a SLED to the computer

Data plus some redundant information is Striped across the disks in some way

How that Striping is done is key to performance and reliability.

Page 29: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.29

Raid Level 0 Level 0 is non-redundant disk array Files are Striped across disks, no redundant info High read throughput Best write throughput (no redundant info to write) Any disk failure results in data loss

Reliability worse than SLED

Stripe 0

Stripe 4

Stripe 3 Stripe 1 Stripe 2

Stripe 8 Stripe 10 Stripe 11

Stripe 7 Stripe 6 Stripe 5

Stripe 9

data disks

Page 30: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.30

Raid Level 0

Raid level 0 uses strips of k sectors per strip. Consecutive strips are on different disks Write/read on consecutive strips in parallel Good for big enough requests

Operating System Concepts

Page 31: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.31

Raid Level 1 Mirrored Disks Data is written to two places

On failure, just use surviving disk

On read, choose fastest to read Write performance is same as single drive, read

performance is 2x better

Expensive

data disks mirror copies

Stripe 0

Stripe 4

Stripe 3 Stripe 1 Stripe 2

Stripe 8 Stripe 10 Stripe 11

Stripe 7 Stripe 6 Stripe 5

Stripe 9

Stripe 0

Stripe 4

Stripe 3 Stripe 1 Stripe 2

Stripe 8 Stripe 10 Stripe 11

Stripe 7 Stripe 6 Stripe 5

Stripe 9

Page 32: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.32

RAID 0+1 and 1+0

Which is better in safety?

Page 33: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.33

Parity and Hamming Codes What do you need to do in order to detect and correct

a one-bit error ? Suppose you have a binary number, represented as a

collection of bits: <b3, b2, b1, b0>, e.g. 0110

Detection is easy Parity:

Count the number of bits that are on, see if it’s odd or even EVEN parity is 0 if the number of 1 bits is even

Parity(<b3, b2, b1, b0 >) = P0 = b0 ⊗ b1 ⊗ b2 ⊗ b3 Parity(<b3, b2, b1, b0, p0>) = 0 if all bits are intact Parity(0110) = 0, Parity(01100) = 0 Parity(11100) = 1 => ERROR! Parity can detect a single error, but can’t tell you which of the

bits got flipped

Page 34: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.34

Parity and Hamming Code Detection and correction require more work Hamming codes can detect double bit errors and detect & correct

single bit errors 7/4 Hamming Code

h0 = b0 ⊗ b1 ⊗ b3 h1 = b0 ⊗ b2 ⊗ b3 h2 = b1 ⊗ b2 ⊗ b3 H0(<1101>) = 0 H1(<1101>) = 1 H2(<1101>) = 0 Hamming(<1101>) = <b3, b2, b1, h2, b0, h1, h0> = <1100110> If a bit is flipped, e.g. <1110110> Hamming(<1111>) = <h2, h1, h0> = <111> compared to <010>,

<101> are in error. Error occurred in bit 5.

What if 1000110?

Page 35: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.35

Raid Level 2

Bit-level Striping with Hamming (ECC) codes for error correction(内存方式的差错纠正代码结构)

All 7 disk arms are synchronized and move in unison Complicated controller Single access at a time Tolerates only one error, but with no performance degradation

data disks

Bit 0 Bit 3 Bit 1 Bit 2 Bit 4 Bit 5 Bit 6

ECC disks

Page 36: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.36

Raid Level 3

Use a parity disk(位交织奇偶结构) Each bit on the parity disk is a parity function of the corresponding bits on

all the other disks A read accesses all the data disks A write accesses all data disks plus the parity disk On disk failure, read remaining disks plus parity disk to compute the

missing data

data disks Parity disk

Bit 0 Bit 3 Bit 1 Bit 2 Parity Single parity disk can be used

to detect and correct errors

Page 37: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.37

Raid Level 4

Combines Level 0 and 3 – block-level parity with Stripes(块交织奇偶结构)

A read accesses all the data disks A write accesses all data disks plus the parity disk Heavy load on the parity disk

data disks Parity disk

Stripe 0 Stripe 3 Stripe 1 Stripe 2 P0-3

Stripe 4

Stripe 8 Stripe 10 Stripe 11

Stripe 7 Stripe 6 Stripe 5

Stripe 9

P4-7

P8-11

Page 38: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.38

Raid Level 5

Block Interleaved Distributed Parity(块交织分布奇偶结构)

Like parity scheme, but distribute the parity info over all disks (as well as data over all disks)

Better read performance, large write performance Reads can outperform SLEDs and RAID-0

data and parity disks

Stripe 0 Stripe 3 Stripe 1 Stripe 2 P0-3

Stripe 4

Stripe 8 P8-11 Stripe 10

P4-7 Stripe 6 Stripe 5

Stripe 9

Stripe 7

Stripe 11

Page 39: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.39

RAID5 example

Operating System Concepts

http://www.elecfans.com/baike/zhujipeijian/yingpang/20100329212286.html

Page 40: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.40 Operating System Concepts

RAID Structure

RAID – multiple disk drives provides reliability via redundancy.

RAID is arranged into six different levels.

Page 41: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.41

Redundant Array of Inexpensive Disks (RAID)

o Parallel I/O to improve performance and reliability

o vs SLED, Single Large Expensive Disk o Bunch of disks which appear like a single disk to

the OS o SCSI disks often cheap, 7 disks per controller

Page 42: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.42 Operating System Concepts

Page 43: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.43 Operating System Concepts

RAID Levels

Page 44: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.44

Raid Levels o Raid level 0 uses strips of k sectors per strip.

o Consecutive strips are on different disks o Write/read on consecutive strips in parallel o Good for big enough requests

o Raid level 1 duplicates the disks o Writes are done twice, reads can use either

disk o Improves reliability

o Level 2 works with individual words, spreading word + ecc over disks. o Need to synchronize arms to get parallelism

Page 45: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.45

Backup and parity drives are shown shaded.

RAID Levels 0,1,2

Page 46: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.46

Raid Levels 4 and 5

o Raid level 3 works like level 2, except all parity bits go on a single drive

o Raid 4,5 work with strips. Parity bits for strips go on separate drive (level 4) or several drives (level 5)

Page 47: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.47

Backup and parity drives are shown shaded.

Page 48: Chapter 12: Mass Storage Structure€¦ · Operating System Concepts 14.2 College of Software Engineering, Southeast University Chapter 12: Mass-Storage Systems Disk Structure Disk

College of Software Engineering, Southeast University 14.48

RAID 01 vs RAID10

Operating System Concepts

http://www.storageonline.com.cn/storage/storage-fundamental/raid-10-vs-the-raid-01-raid-1-0-vs-raid-0-1/

下面以4块盘为例来介绍安全性方面的差别: 1、RAID10的情况 这种情况中,我们假设当DISK0损坏时,在剩

下的3块盘中,只有当DISK1一个盘发生故障时,才会导致整个RAID失效,我们可简单计算故障率为1/3。

2、RAID01的情况 这种情况下,我们仍然假设DISK0损坏,这时左边的条带将无法读取。在剩下的3块盘中,只要DISK2,DISK3两个盘中任何一个损坏,都会导致整个RAID失效,我们可简单计算故障率为2/3。 因此RAID10比RAID01在安全性方面要强。