CSE 380 Computer Operating Systems

Similar documents
CSE380 - Operating Systems. Communicating with Devices

UC Santa Barbara. Operating Systems. Christopher Kruegel Department of Computer Science UC Santa Barbara

CSE380 - Operating Systems

I/O Hardwares. Some typical device, network, and data base rates

Lecture 9. I/O Management and Disk Scheduling Algorithms

Mass-Storage Structure

CSE 120. Overview. July 27, Day 8 Input/Output. Instructor: Neil Rhodes. Hardware. Hardware. Hardware

I/O, Disks, and RAID Yi Shi Fall Xi an Jiaotong University

Chapter-6. SUBJECT:- Operating System TOPICS:- I/O Management. Created by : - Sanjay Patel

I/O Management and Disk Scheduling. Chapter 11

Disk Scheduling. Based on the slides supporting the text

Mass-Storage. ICS332 - Fall 2017 Operating Systems. Henri Casanova

UNIT 4 Device Management

Input/Output. Today. Next. Principles of I/O hardware & software I/O software layers Disks. Protection & Security

Introduction Disks RAID Tertiary storage. Mass Storage. CMSC 420, York College. November 21, 2006

Silberschatz, et al. Topics based on Chapter 13

Chapter 11. I/O Management and Disk Scheduling

Che-Wei Chang Department of Computer Science and Information Engineering, Chang Gung University

CISC 7310X. C11: Mass Storage. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 4/19/2018 CUNY Brooklyn College

CSE325 Principles of Operating Systems. Mass-Storage Systems. David P. Duggan. April 19, 2011

Operating Systems 2010/2011

Chap. 3. Input/Output

I/O CANNOT BE IGNORED

Input/Output. Chapter 5: I/O Systems. How fast is I/O hardware? Device controllers. Memory-mapped I/O. How is memory-mapped I/O done?

Chapter 5 Input/Output

CS510 Operating System Foundations. Jonathan Walpole

Operating Systems, Fall

Module 13: Secondary-Storage Structure

CSCI-GA Operating Systems. I/O : Disk Scheduling and RAID. Hubertus Franke

V. Mass Storage Systems

I/O Device Controllers. I/O Systems. I/O Ports & Memory-Mapped I/O. Direct Memory Access (DMA) Operating Systems 10/20/2010. CSC 256/456 Fall

CSE 120. Operating Systems. March 27, 2014 Lecture 17. Mass Storage. Instructor: Neil Rhodes. Wednesday, March 26, 14

Chapter 13: Mass-Storage Systems. Disk Scheduling. Disk Scheduling (Cont.) Disk Structure FCFS. Moving-Head Disk Mechanism

Chapter 13: Mass-Storage Systems. Disk Structure

Mass-Storage. ICS332 Operating Systems

Chapter 11 I/O Management and Disk Scheduling

Chapter 10: Mass-Storage Systems

Today: Secondary Storage! Typical Disk Parameters!

I/O CANNOT BE IGNORED

I/O Systems and Storage Devices

I/O Devices. Chapter 5 Input/Output. Memory-Mapped I/O (2) Memory-Mapped I/O (1) Interrupts Revisited. Direct Memory Access (DMA) 11/26/2013

Introduction. Operating Systems. Outline. Hardware. I/O Device Types. Device Controllers. One OS function is to control devices

Chapter 14: Mass-Storage Systems. Disk Structure

Introduction. Operating Systems. Outline. Hardware. I/O Device Types. Device Controllers. (done)

u Covered: l Management of CPU & concurrency l Management of main memory & virtual memory u Currently --- Management of I/O devices

COS 318: Operating Systems. Storage Devices. Vivek Pai Computer Science Department Princeton University

Disk scheduling Disk reliability Tertiary storage Swap space management Linux swap space management

Part IV I/O System. Chapter 12: Mass Storage Structure

Disk Scheduling. Chapter 14 Based on the slides supporting the text and B.Ramamurthy s slides from Spring 2001

Input/Output. Today. Next. ! Principles of I/O hardware & software! I/O software layers! Secondary storage. ! File systems

Input Output (IO) Management

Input/Output Management

Administrivia. CMSC 411 Computer Systems Architecture Lecture 19 Storage Systems, cont. Disks (cont.) Disks - review

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

Tape pictures. CSE 30341: Operating Systems Principles

Disks. Storage Technology. Vera Goebel Thomas Plagemann. Department of Informatics University of Oslo

Lecture 23: Storage Systems. Topics: disk access, bus design, evaluation metrics, RAID (Sections )

Mass-Storage Structure

CS3600 SYSTEMS AND NETWORKS

COS 318: Operating Systems. Storage Devices. Kai Li Computer Science Department Princeton University

Input/Output. Today. Next. Principles of I/O hardware & software I/O software layers Secondary storage. File systems

Chapter 11: File System Implementation. Objectives

Chapter 10: Mass-Storage Systems

Database Systems. November 2, 2011 Lecture #7. topobo (mit)

Operating System 1 (ECS-501)

Chapter 10: Mass-Storage Systems. Operating System Concepts 9 th Edition

Operating System: Chap13 I/O Systems. National Tsing-Hua University 2016, Fall Semester

CS370: System Architecture & Software [Fall 2014] Dept. Of Computer Science, Colorado State University

Chapter 12: Mass-Storage

Part IV I/O System Chapter 1 2: 12: Mass S torage Storage Structur Structur Fall 2010

Module 13: Secondary-Storage

Introduction. Operating Systems. Outline. Hardware. I/O Device Types. Device Controllers. One OS function is to control devices

Chapter 12: Secondary-Storage Structure. Operating System Concepts 8 th Edition,

Chapter 14: Mass-Storage Systems

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

Storage Systems. Storage Systems

Computer System Architecture

CS370: Operating Systems [Fall 2018] Dept. Of Computer Science, Colorado State University

Physical Representation of Files

Main Points of the Computer Organization and System Software Module

COS 318: Operating Systems. Storage Devices. Jaswinder Pal Singh Computer Science Department Princeton University

CS370: Operating Systems [Fall 2018] Dept. Of Computer Science, Colorado State University

Virtual Memory. Reading. Sections 5.4, 5.5, 5.6, 5.8, 5.10 (2) Lecture notes from MKP and S. Yalamanchili

High Performance Computing Course Notes High Performance Storage

2. Which of the following resources is not one which can result in deadlocking processes? a. a disk file b. a semaphore c. the central processor (CPU)

RAID SEMINAR REPORT /09/2004 Asha.P.M NO: 612 S7 ECE

Chapter 12: Mass-Storage

CS370: Operating Systems [Spring 2017] Dept. Of Computer Science, Colorado State University

Chapter 10: Mass-Storage Systems

Chapter 12: Mass-Storage

I/O Design, I/O Subsystem, I/O-Handler Device Driver, Buffering, Disks, RAID January WT 2008/09

Outline. Operating Systems: Devices and I/O p. 1/18

RAID (Redundant Array of Inexpensive Disks)

COT 4600 Operating Systems Fall 2009

Operating Systems. V. Input / Output

CSCI-GA Database Systems Lecture 8: Physical Schema: Storage

OPERATING SYSTEMS CS3502 Spring Input/Output System Chapter 9

Storage. Hwansoo Han

CS370 Operating Systems

OPERATING SYSTEMS CS3502 Spring Input/Output System Chapter 9

Transcription:

CSE 380 Computer Operating Systems Instructor: Insup Lee University of Pennsylvania Fall 2003 Lecture Note on Disk I/O 1

I/O Devices Storage devices Floppy, Magnetic disk, Magnetic tape, CD-ROM, DVD User interaction Keyboard, mouse, monitor, sound card, printer, modem. Significant part of OS code deals with I/O devices Communication with device drivers Error handling Interrupt management Convenient interfaces 2

Pentium Bus Architecture 3

Device Controllers I/O devices have components: mechanical component electronic component The electronic component is the device controller may be able to handle multiple devices Should have a standardized interface Controller's tasks convert serial bit stream to block of bytes perform error correction as necessary Controller interface Device registers Data buffers for reading/writing data (separate from main memory, or not?) 4

Accessing the device Basically, two choices: I/O instructions that read/write I/O ports, or memory mapped I/O I/O instructions can be of the form IN R, P R is a register, P is a port number In memory mapped I/O, no special instructions, but some addresses in virtual memory correspond to ports MOV R, L L can be an address which is reserved for a specific device Pentium provides both schemes I/O ports numbered 0 to 64K used for control information Memory addresses from 64K to 1M used for device buffers 5

Memory Mapped I/O In an instruction such as MOV R, L, L can be A location in main memory, or A control register, or address in data buffer, of a specific I/O device I/O space viewed as an extension of main memory, and addressed in the same way Of course, no overlap between the two address spaces Advantages Device drivers are written in C Protection managed by pages accessible in each user space Savings in number of instructions Issues Caching must be disabled for I/O pages (why?) How to separate real memory references from I/O ones 6

I/O Programming Uniform naming of devices In Unix, special directories such as /dev/lp, /dev/tty Device Independence Buffering of data user-space or kernel-space or double buffering Driver routines Busy waiting vs. Interrupt driven vs. DMA 7

I/O Code with Busy Waiting Goal: user wants to send N bytes from Buffer to an I/O device (e.g. printer or floppy) Device controller has registers for status and for putting data Basic approach (too wasteful for CPU): Copy data into kernel buffer B; for (i=0; i< N; i++) { /* wait for device to be free */ while (*DeviceStatusReg!= READY); *DeviceDataReg = B[i]; } 8

I/O Code with Interrupts Goal: To let CPU schedule other processes while device is busy processing data Code for driver: Copy data into kernel buffer B while (*DeviceStatusReg!= ready); *DeviceDataReg = B[0]; /* Do only the first step */ InvokeScheduler(); Code for interrupt handler: if (N == 0) Wakeup(); /* unblock the process */ else { DeviceDataReg = B[i]; N--; i++; }; ResetInterrupt(); /*Notify device as an ack */ 9

I/O with Direct Memory Access Goal: Device should interrupt CPU only after the entire transfer Solution: Provide direct access between memory and device so that data can be copied into memory DMA Controller: separate unit that manages this Driver routine Copy data into kernel space Set up DMA controller registers Schedule another process Interrupt handler Ack the interrupt Wakeup User 10

Mechanism of DMA Transfer A program running on CPU sets up the registers in DMA controller (e.g. write N bytes into memory starting at location XYZ) Is the address XYZ virtual or physical? DMA controller sets up the registers in device controller to request the transfer Original request may be divided into chunks Disk controller transfers the data directly into memory Bus architecture should resolve contention for memory Disk controller notifies DMA controller When the original request is entirely processed, DMA controller interrupts the CPU 11

Secondary Storage Management Why secondary storage? 1 main memory too small 2 main memory volatile Devices: Disks, Tapes, Drums Disks are critical components For virtual memory management Storing files Disk technology hasn t changed much compared to processor technology (esp., speed) 12

Disk Drives Tracks and Cylinders 13

Typical Disk Parameters Compare Seek time, rotation time, transfer time 14

Disk Formatting Typical sector is 512 bytes Preamble identifying start code and sector address Data Error correction code (16 bits). At least detecting errors possible with probability almost 1 Cylinder skew: After reading an entire track, as head is moved across a cylinder, seeking next sector shouldn t cause waiting for full rotation Interleaving sectors: As a sector is copied into controller buffer, it needs to be copied into main memory. So next sector should not be adjacent if we wish to avoid waiting for one full rotation 15

Disk Formatting (1) A disk sector 16

Disk Formatting (2) An illustration of cylinder skew 17

Disk Formatting (3) No interleaving Single interleaving Double interleaving 18

Disk Access Physical address on a disk (cylinder number, head number, sector number) Sectors can be given logical numbers that get decoded by Disk Controller Design considerations Seek time (moving head to correct cylinder) and rotational latency time (waiting for correct sector) are greater than data transfer time (time to read) Lots of errors possible (bad sectors, bad bits) Caching blocks that happen to pass under disk head commonly used 19

Disk-Head Scheduling Time required to read or write a disk block determined by 3 factors 1. Seek time 2. Rotational delay 3. Actual transfer time Seek time dominates Error checking is done by controllers 20

Disk-Arm Scheduling: FCFS Basic strategy for moving disk arm across cylinders: Firstcome-first-served queue disk queue: 98, 183, 37, 122, 14, 124, 65, 67 initial r/w head position: cylinder 53 --- ----- -------- ----------------- ---- 37 53 98 183 ------ ---------------- ------------------------------- total head movement = 45 + 75 + 146 + 85 + 108 + 110 + 59 + 2 = 640 tracks OK for small load, low variance of waiting time 21

Disk-Arm Scheduling:SSF Shortest Seek-Time First (SSF): Pick the closest one next Consider example from last slide: ordering will be 65, 67, 37, 14, 98, 122, 124, 183 total head movement (starting at 53) = 12 + 2 + 30 + 23 + 84 + 24 + 2 + 59 = 236 tracks High variance (starvation possible) 22

Disk-Arm Scheduling: Scan Maintain a direction bit Pick the request with shortest seek time in current direction first, and change direction only at edges. Previous example: Assume head was moving toward 0. Ordering: 37, 14, 0, 65, 67, 98, 122, 124, 183 total head movement = 16+23+14+65+2+31+24+2+59 = 236 tracks Almost as good as SSF in mean wait time, lower variance. 23

Disk-Arm Scheduling Algorithms Look (elevator): Variation of Scan algorithm Change direction if no more requests farther down in current direction Preferable to Scan (total head movement 208 in our case) Circular Look Always scan in the same direction servicing cylinders in a circular manner (i.e. go to lowest numbered pending request if no requests are higher than current position) 24

Fault Tolerance for Disks Disks can have lots of errors Corrupted bits Corrupted sectors Manufacturing defects Disk crashes Many levels of protection implemented Error correction within sectors Extra sectors within a disk Mirroring RAID (redundancy and parallelism) 25

Error Correction Code in Sectors 16 bytes within 512 byte sector used for ECC Basic idea for k-bit ECC for n-bit data Define a function f from n-bit integers to k-bit integers n-bit data I is tagged with the ECC f(n) If two n-bit data items I and J differ only in small number of bits then f(i) and f(j) are guaranteed to be different To store a value I, write <I,f(I)> While reading, read n+k bits, and check that last k-bits correspond to the ECC of first n-bits Simplest scheme: Parity k=1, f(i)=1 if number of 1 s in binary encoding of I is even Error detection possible if just one bit changes, but can t correct 26

Hamming Codes (1950 s) Let s see how 1 error can be corrected in n-bits of data by adding (log n) extra bits Suppose 11-bits of data D1.. D11, we are going compute correction bits C1.. C4 Let s number the total 15 bits together so that correction bits occupy positions of powers of 2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 C1 C2 D1 C3 D2 D3 D4 C4 D5 D6 D7 D8 D9 D10 D11 Consider a sequence of 11 bits, say, 10101000100, map it to above format, and find out which bit positions are 1 s 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 C1 C2 1 C3 0 1 0 C4 1 0 0 0 1 0 0 Chosen positions are: 3, 6, 9, 13. Take their binary representations, and XOR all the words (0011) XOR (0110) XOR (1001) XOR (1101) = (0001) So the error correction bits are: C1 = 1, C2=0, C3=0, C4=0 27

Error Correction in Hamming Codes What happens if a bit, say D11, gets flipped in storage/transmission D11 is in position 15, so decoder will compute the correction code as (0001) XOR (1111) = (1110) Correction code in stored data = 0001; computed correction code = 1110. Compute XOR of these two values; this gives 1111, which is the position number of the corrupted bit This correction scheme works for all bits (data as well as correction) Why does this work? C4 gives number of 1 s among bits D5 D11 C3 gives number of 1 s among bits D2 D4 and D8 D11 C2 gives number of 1 s among bits D1, D3, D4, D6, D7, D10, D11 C1 gives number of 1 s among bits D1, D2, D4, D5, D7, D9, D11 If C4 is decoded incorrectly, decoder knows that error must be in either C4 or D5 D11. Now if C3 is correct, then D8 D11 must be correct, and error must be in C4 or D5 D7. What happens if C2 is incorrect? Wrong bit must be D7. 28

Error Correction Continued In general, in Hamming code, k-bits of error correction are used to augment 2 k 1 k bits of data giving a encoded string of 2 k - 1 bits If there is a single error in storing or transmitting the encoded string, the decoder can detect the error, as well as correct it Reed-Solomon codes (1960 s: Polynomial codes over certain finite fields) Original codes can correct upto 2 errors in 251 bit/byte long messages by adding 5 extra bits/bytes Works well for bursty errors Error correction technology is central all data transmission, data storage for disks, CDs etc 29

Bad Sectors Sectors can get defective for a variety of reasons Detected by the format command (in MS-DOS) Every track has extra (spare) sectors that are not part of logical address space Disk controller keeps track of bad sectors and does remapping of sector numbers Two choices for renumbering Substitute a spare sector for defective Renumber all by shifting Obvious tradeoff Efficiency of reading consecutive sectors Initial effort of rewriting preambles in each sector 30

Read Errors After reading a sector, what if ECC indicates an error? 1 ECC may allow error correction 2 Read again, and error may go away 3 If read error seems to happen repeatedly, then the sector can be marked as bad, and replaced by a spare sector Instead of the driver, OS may need to keep track of bad sectors Backups have to worry about bad sectors 31

Reliability by Redundancy Mirroring (or Shadowing): duplicate disks Write every block to both the disks Read can be performed from any of the two disks This can be exploited to allow parallelism and speeding up of reads Also for error correction: if first read fails, try the other Crash: If one disk crashes, then the other one can be used to restore data If failures are independent, this dramatically increases meantime to failure This can be managed by device driver (if it can handle multiple disks) or by OS Duplicating a disk is expensive. 32

RAID Redundant Array of Independent Disks Disk access times are still slow compared to CPU/memory Natural solution: Read concurrently from multiple disks RAID Controller talks to OS just like a device driver and manages a suite of disks to improve reliability and performance Striping: Organize logically consecutive chunks of data across different disks to improve performance Striping can be at bit-level, byte-level, or sector-level Incoming request is split into all relevant disks by RAID controller, and their outputs are put together Redundancy through duplication Multiple requests can be load-balanced Error recovery on faults 33

RAID Level 0 Array of disks with block-level striping Strip = k sectors (for suitably chosen k) First k sectors are on first strip of first disk, next k sectors are on first strip of second disk, and so on Advantages: A large request spanning multiple strips can be parallelized easily Not much overhead Used in high-performance applications Disadvantages No redundancy Mean-time to failure is, in fact, less than standard disks (why?) No parallelism for small requests 34

RAID Level 0 0 4 1 5 2 6 3 7 35

RAID Level 1 Like mirroring, but with striping of level 0 Use same number of backup disks with same striping Same benefits/issues as in mirroring 0 4 1 5 2 6 3 7 0 4 1 5 2 6 3 7 36

RAID Level 2 Called memory-style error correcting code organization Uses bit-level striping Some of the bits used for parity or other error correction Sample: 4-bits of data encoded by additional 3-bits of ECC, and resulting 7 bits stored on 7 different disks CM-2 machine: 32-bits of data with 7-bits of ECC spanning over array of 39 disks Advantages Great parallelism for read as well as write Even if one disk crashes, all data can be recovered (due to ECC) Disadvantages Drives have to synchronized Overhead in putting together reads from different disks Crash recovery much slower (compared to RAID-1) 37

RAID Levels 3-5 Raid levels 3 through 5 Backup and parity drives are shaded 38