39
I/O Management and Disk Structure Introduction to Operating Systems: Module 14

I/O Management and Disk Structure Introduction to Operating Systems: Module 14

Embed Size (px)

Citation preview

Page 1: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

I/O Management and Disk Structure

Introduction to Operating Systems: Module 14

Page 2: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

Operating System Design Objectives I/O is extremely slow compared to main memory, CPU Use of multiprogramming allows for some processes to be

waiting on I/O while another process executes Efficiency and generality are important Try to handle all I/O devices in a uniform manner Hide most of the details of device I/O in lower-level

routines so that processes and upper levels see devices in general terms such as Read, Write, Open, and Close

Page 3: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

A Model of I/O Organization

Scheduling& Control

DeviceI/O

Scheduling& Control

Scheduling& Control

Local peripheral device Communications port File System

DeviceI/O

DeviceI/O

HardwareHardware HardwareHardware HardwareHardware

UserProcesses

UserProcesses

UserProcesses

UserProcesses

UserProcesses

UserProcesses

LogicalI/O

Comm.Architecture

DirectoryManagement

FileSystem

PhysicalOrganization

Page 4: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

I/O Buffering Reasons for buffering

Process responsiveness a writing processes must wait for I/O to complete before

proceeding A reading process cannot do other things while waiting for

data Pages must remain in main memory during I/O

Page 5: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

I/O Buffering Block-oriented

information is stored in fixed sized blocks transfers are made a block at a time used for disks and tapes

Stream-oriented transfer information as a stream of bytes used for terminals, printers, communication ports,

mouse, and most other devices that are not secondary storage

Page 6: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

No Buffering

Operating System User Process

No buffering

I/O DeviceIn

Page 7: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

Single Buffer Operating system assigns a buffer in main memory

for an I/O request Block-oriented

input transfers made to buffer block moved to user space when needed another block is moved into the buffer

read ahead Operating System User Process

Single buffering

I/O DeviceIn Move

Page 8: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

Single Buffer Block-oriented

user process can process one block of data while next block is read in

swapping can occur since input is taking place in system memory, not user memory

operating system keeps track of assignment of system buffers to user processes

output is accomplished by the user process writing a block to the buffer and later actually written out

Page 9: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

Single Buffer Stream-oriented

used a line (or word, or char) at a time user input from a terminal is one line at a time with carriage

return signaling the end of the line output to the terminal is one line at a time

Page 10: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

Double Buffer Use two system buffers instead of one A process can transfer data to or from one buffer

while the operating system empties or fills the other buffer

I/O Device In Move

Operating System User Process

Double buffering

Page 11: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

Circular Buffer More than two buffers are used Each individual buffer is one unit in a circular

buffer Used when I/O operation must keep up with

process

I/O DeviceIn Move

Operating System User Process

Circular buffering

.

.

Page 12: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

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 3-dimensional disk, where the 3 dimensions are cylinder, sector, surface Sector 0 is the first sector of the first track on the

outermost cylinder (top surface) 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 13: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

Disk Structure

All of the sectors that can be accessed without moving the read/write heads belong to the same cylinder

This disk has 12 surfaces A sector is, like a pie slice, a

small angular displacement

Page 14: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

Disk Data Layout

Inter-sector gap

Sectors Tracks

Inter-track gap

Page 15: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

Disk Layout: Constant Angular Velocity

Track 2, Sector 7 Track 0, Sector 0

Page 16: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

Disk Management

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”

Boot block initializes system. The bootstrap is stored in ROM Bootstrap loader program

Methods such as sector sparing used to handle bad blocks

Page 17: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

Disk Reliability

Several improvements in disk-use techniques involve the use of multiple disks working cooperatively

Disk striping uses a group of disks as one storage unit

RAID schemes improve performance and improve the reliability of the storage system by storing redundant data Mirroring or shadowing keeps duplicate of each disk Block interleaved parity uses much less redundancy

Page 18: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

RAID 0 (non-redundant)

strip 0

strip 4

strip 8

strip 12

strip 1

strip 5

strip 9

strip 13

strip 2

strip 6

strip 10

strip 14

strip 3

strip 7

strip 11

strip 15

Page 19: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

RAID 1 (mirrored)

strip 0

strip 4

strip 8

strip 12

strip 1

strip 5

strip 9

strip 13

strip 2

strip 6

strip 10

strip 14

strip 3

strip 7

strip 11

strip 15

strip 0

strip 4

strip 8

strip 12

strip 1

strip 5

strip 9

strip 13

strip 2

strip 6

strip 10

strip 14

strip 3

strip 7

strip 11

strip 15

Page 20: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

RAID 2 (redundancy through Hamming code)

f0(b)b2b1b0 b2f1(b) f2(b)

Page 21: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

RAID 3 (bit-interleaved parity)

P(b)b2b1b0 b2

Page 22: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

RAID 4 (block-level parity)

block 0

block 4

block 8

block 12

block 1

block 5

block 9

block 13

block 2

block 6

block 10

block 14

block 3

block 7

block 11

block 15

P(0-3)

P(4-7)

P(8-11)

P(12-15)

Page 23: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

RAID 5 (block-level distributed parity)

block 0

block 4

block 8

block 12

P(16-19)

block 1

block 5

block 9

P(12-15)

block 16

block 2

block 6

P(8-11)

block 13

block 17

block 3

P(4-7)

block 10

block 14

block 18

P(0-3)

block 7

block 11

block 15

block 19

Page 24: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

Data Mapping for RAID Level 0 Array

strip 0

strip 4

strip 8

strip 12

strip 1

strip 5

strip 9

strip 13

strip 2

strip 6

strip 10

strip 14

strip 3

strip 7

strip 11

strip 15

PhysicalDisk 0

PhysicalDisk 1

PhysicalDisk 2

PhysicalDisk 3

strip 0

strip 1

strip 2

strip 3

strip 4

strip 15

strip 14

strip 13

strip 12

strip11

strip 10

strip 9

strip 8

strip 7

strip 6

strip 5

ArrayManagement

Software

Page 25: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

Disk Cache Buffer in main memory for disk sectors Contains a copy of some of the sectors on the disk

Page 26: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

Least Recently Used The block that has been in the cache the longest

with no reference to it is replaced The cache consists of a stack of blocks Most recently referenced block is on the top of the

stack When a block is referenced or brought into the

cache, it is placed on the top of the stack

Page 27: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

Least Recently Used The block on the bottom of the stack is removed

when a new block is brought in Blocks don’t actually move around in main

memory A stack of pointers is used

Page 28: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

Least Frequently Used The block that has experienced the fewest

references is replaced A counter is associated with each block Counter is incremented each time block accessed Some blocks may be referenced many times in a

short period of time and then not needed any more

Page 29: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

Disk Scheduling The operating system is responsible for using hardware efficiently

— for the disk drives, this means having a fast access time and high 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.

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 30: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

Disk Scheduling

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 31: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

FCFSIllustration shows total head movement of 640 cylinders

Page 32: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

SSTF

Selects the request with the minimum seek time from the current head position

SSTF scheduling may cause starvation of some requests

Illustration shows total head movement of 236 cylinders

Page 33: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

SSTF

Page 34: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

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 an elevator algorithm Illustration shows total head movement of 236

cylinders

Page 35: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

SCAN

Page 36: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

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 37: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

C-SCAN

Page 38: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

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 39: I/O Management and Disk Structure Introduction to Operating Systems: Module 14

C-LOOK