Top Banner
Lecture 14 I/O Devices & Hard Disk Drives
39

Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

Dec 18, 2015

Download

Documents

Domenic Day
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

Lecture 14I/O Devices & Hard Disk

Drives

Page 2: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

• vgetmem only from private heap

Page 3: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

Midterm statistics

• Number of people taking the exam: 76• average: 72• medium: 69/70• below 60: 14• 60-70: 24• 70-80:13• 80-90:14• 90-100: 8• above 100: 3

Page 4: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

We need I/O devices

Page 5: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

The Canonical Device

Micro-controller (CPU)Memory (DRAM or SRAM or both)Other Hardware-specific Chips

Status Command DataDevice Registers

Hidden Internals

The interface for OS to interact

Page 6: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

The Canonical Protocol

While (STATUS == BUSY) // 1

; // wait until device is not busy

Write data to DATA register // 2

Write command to COMMAND register // 3

(To start the device & executes the command)

While (STATUS == BUSY) // 4

; // wait until device is done with your request

Page 7: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

A trace

CPU:

Disk:

A B

C A

3 1 2 4

Page 8: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

Using interrupts to avoid spinning

CPU:

Disk:

A A A B

C A

1 3,4 2

B B

Page 9: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

Interrupts vs. Polling

• Discussion: could interrupt be worse under some cases?

• Techniques:• Hybrid approach• Interrupt coalescing

Page 10: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

What else can we optimize?

CPU:

Disk:

A A A B

C A

1 3,4 2

B B

Page 11: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

Programmed I/O vs.Direct Memory Access• PIO (Programmed I/O):• CPU directly tells device what data is

• DMA (Direct Memory Access):• CPU leaves data in memory• Device reads it directly

Page 12: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

Using DMA

CPU:

Disk:

A A B

C A

1 3,4

B B

Page 13: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

How does OS access registers?• Special instructions• each device has a port• in/out instructions (x86) communicate with device

• Memory-Mapped I/O• H/W maps registers into address space• loads/stores sent to device

• Doesn’t matter much (both are used).

Page 14: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

Protocol Variants

• Status checks: polling vs. interrupts

• Data: PIO vs. DMA

• Control: special instructions vs. memory-mapped I/O

Page 15: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

Variety is a Challenge

• Problem:• many, many devices• each has its own protocol

• How can we avoid writing a slightly different OS for each H/W combination?• Encapsulation!• Write driver for each device.• Drivers are 70% of Linux source code.

Page 16: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

The File System Stack

Page 17: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

Hard Disk Basic Interface

• Disk has a sector-addressable address space(so a disk is like an array of sectors).• Sectors are typically 512 bytes or 4096 bytes.

• By the end of 2007, Samsung and Toshiba began shipments of 1.8-inch hard disk drives with 4096 byte sectors. In 2010, the International Disk Drive Equipment and Materials Association (IDEMA) completed the Advanced Format standard for 4096 sector drives, setting the date for the transition from 512 to 4096 byte sectors as January 2011 for all manufacturers, and Advanced Format drives soon became prevalent. [wiki]

• Main operations: reads + writes to sectors.

Page 18: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

Disk Internals

• Platter: covered with a magnetic film.• Surface: each platter has two surfaces• Spindle: many platters may be bound to the

spindle.• Track: each surface is divided into rings, each track

is further divided into numbers sectors• Cylinder: a stack of tracks across platters• Heads on a moving arm can read from each

surface.

Page 19: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

Three Tracks Plus A Head

Page 20: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

• http://youtu.be/9eMWG3fwiEU?t=30s

Page 21: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

Seek, Rotate, Transfer

• Must accelerate, coast, decelerate, settle

• Seeks often take several milliseconds!

• Settling alone can take 0.5 - 2 ms.

• Entire seek often takes 4 - 10 ms.

Page 22: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

Seek, Rotate, Transfer

• Depends on rotations per minute (RPM).• 7200 RPM is common, 15000 RPM is high end.

• 1 / 7200 RPM =1 minute / 7200 rotations =1 second / 120 rotations =8.3 ms / rotation

• so it may take 4.2 ms on avg to rotate to target (0.5 * 8.3 ms)

Page 23: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

Seek, Rotate, Transfer

• Pretty fast — depends on RPM and sector density.

• 100+ MB/s is typical.

• 1s / 100 MB = 10 ms / MB = 4.9 us / sector (assuming 512-byte sector)

Page 24: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

Workload

• So…• seeks are slow• rotations are slow• transfers are fast

• What kind of workload is fastest for disks?• Sequential: access sectors in order (transfer dominated)• Random: access sectors arbitrarily (seek+rotation

dominated)

Page 25: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

Disk Spec

• Sequential workload: what is throughput for each?• Close to max transfer rate if workload large enough

• Random workload: what is throughput for each?• Assume 16-KB reads, 2.5 MB/s and 1.2MB/s

Page 26: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

Track Skew

Page 27: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

Zones

Page 28: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

Other Improvements

• Track Skew

• Zones

• Cache• Drives may cache both reads and writes.

Page 29: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

Schedulers

• Given a stream of requests, in what order should they be served?• Try to follow SJF (shortest job first)• SSTF: Shortest Seek Time First• Difficult for OS, starvation

• Elevator (a.k.a. SCAN or C-SCAN)• Still ignore rotation time

Page 30: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

SPTF:Shortest Positioning Time First

Page 31: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

Other Issues

• Both OS and disk do some scheduling

• I/O merging

• Work Conservation

Page 32: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

Only One Disk?

• Sometimes we want many disks — why?• capacity• performance• reliability

• Challenge: most file systems work on only one disk.

Page 33: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

Solution 1: JBOD

• JBOD: Just a Bunch Of Disks

• Application is smart, stores different files on different file systems.

FS FS FS FS

Application

Page 34: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

Solution 2: RAID

• RAID: Redundant Array of Inexpensive Disks• Transparent and deployable

• Capacity and performance• Reliability?

FS

Fake Disk

Application

Page 35: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

Why Inexpensive Disks?

• Economies of scale! Cheap disks are popular.• You can often get many commodity H/W components

for the same price as a few expensive components.

• Strategy: write S/W to build high-quality logical devices from many cheap devices.

• Alternative to RAID: buy an expensive, high-end disk.

Page 36: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

General Strategy

• Build fast, large disk from smaller ones.• Add even more disks for reliability.

Disk

RAID

0 100 200

DiskDisk Disk0 100 0 1000 100 0 100

Page 37: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

Mapping

• How should we map logical to physical addresses?• How is this problem similar to virtual memory?

• Dynamic mapping: use data structure (hash table, tree)• paging

• Static mapping: use math• RAID

Page 38: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.

Redundancy

• Redundancy: how many copies?

• System engineers are always trying to increase or decrease redundancy.• Increase: replication (e.g., RAID)• Decrease: deduplication (e.g., code sharing)

• One strategy: reduce redundancy as much is possible. Then add back just the right amount.

Page 39: Lecture 14 I/O Devices & Hard Disk Drives. vgetmem only from private heap.