Unit 10 - Secondary Storage Structure & IO Systems PDF
Document Details
Uploaded by GoodlyMatrix
Silberschatz, Galvin and Gagne
Tags
Summary
This document provides an overview of mass storage structure in modern computers. It covers topics such as magnetic disks, transfer rates, positioning time, and head crashes. It also discusses different disk structures, attachments, and scheduling algorithms.
Full Transcript
Chapter 10: Mass-Storage Systems Selected Topics Operating System Concepts Silberschatz, Galvin and Gagne Overview of Mass Storage Structure Magnetic disks provide bulk of secondary storage of modern...
Chapter 10: Mass-Storage Systems Selected Topics Operating System Concepts Silberschatz, Galvin and Gagne Overview of Mass Storage Structure Magnetic disks provide bulk of secondary storage of modern computers Drives rotate at 60 to 250 times per second Transfer rate is rate at which data flow between drive and computer Positioning time (random-access time) is time to move disk arm to desired cylinder (seek time) and time for desired sector to rotate under the disk head (rotational latency) Head crash results from disk head making contact with the disk surface -- That’s bad Disks can be removable Drive attached to computer via I/O bus Busses vary, including EIDE, ATA, SATA, USB, Fibre Channel, SCSI, SAS, Firewire Operating System Concepts 10.2 Silberschatz, Galvin and Gagne Moving-head Disk Mechanism Operating System Concepts 10.3 Silberschatz, Galvin and Gagne Hard Disk Performance Access Latency = Average access time = average seek time + average latency Examples: For fast disk 3ms + 2ms = 5ms For slow disk 9ms + 5.56ms = 14.56ms Average I/O time = average access time + (amount to transfer / transfer rate) + controller overhead Operating System Concepts 10.4 Silberschatz, Galvin and Gagne Disk Structure Disk drives are addressed as large 1-dimensional arrays of logical blocks, where the logical block is the smallest unit of transfer Low-level formatting creates logical blocks on physical media 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 Operating System Concepts 10.5 Silberschatz, Galvin and Gagne Disk Attachment Host-attached storage accessed through I/O ports talking to I/O busses SCSI (Small Computer System Interface) itself is a bus, up to 16 devices on one cable, SCSI initiator requests operation and SCSI targets perform tasks Each target can have up to 8 logical units (disks attached to device controller) Fibre Channel (FC) is high-speed serial architecture Can be switched fabric with 24-bit address space – the basis of storage area networks (SANs) in which many hosts attach to many storage units I/O directed to bus ID, device ID, logical unit Operating System Concepts 10.6 Silberschatz, Galvin and Gagne Storage Array Can just attach disks, or arrays of disks Storage Array has controller(s), provides features to attached host(s) Ports to connect hosts to array Memory, controlling software (sometimes NVRAM, etc) A few to thousands of disks RAID, hot spares, hot swap (discussed later) Shared storage -> more efficiency Features found in some file systems Snaphots, clones, thin provisioning, replication, deduplication, etc Operating System Concepts 10.7 Silberschatz, Galvin and Gagne Storage Area Network Common in large storage environments Multiple hosts attached to multiple storage arrays - flexible Operating System Concepts 10.8 Silberschatz, Galvin and Gagne 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 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 Operating System Concepts 10.9 Silberschatz, Galvin and Gagne Disk Scheduling (Cont.) There are many sources of disk I/O request OS System processes Users processes I/O request includes input or output mode, disk address, memory address, number of sectors to transfer OS maintains queue of requests, per disk or device Idle disk can immediately work on I/O request, busy disk means work must queue Optimization algorithms only make sense when a queue exists Operating System Concepts 10.10 Silberschatz, Galvin and Gagne Disk Scheduling (Cont.) Note that drive controllers have small buffers and can manage a queue of I/O requests (of varying “depth”) Several algorithms exist to schedule the servicing of disk I/O requests The analysis is true for one or many platters We illustrate scheduling algorithms with a request queue (0-199) 98, 183, 37, 122, 14, 124, 65, 67 Head pointer 53 Operating System Concepts 10.11 Silberschatz, Galvin and Gagne FCFS Illustration shows total head movement of 640 cylinders Operating System Concepts 10.12 Silberschatz, Galvin and Gagne 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 Operating System Concepts 10.13 Silberschatz, Galvin and Gagne 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. SCAN algorithm Sometimes called the elevator algorithm Illustration shows total head movement of 236 cylinders But note that if requests are uniformly dense, largest density at other end of disk and those wait the longest Operating System Concepts 10.14 Silberschatz, Galvin and Gagne SCAN (Cont.) Operating System Concepts 10.15 Silberschatz, Galvin and Gagne 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 Total number of cylinders? Operating System Concepts 10.16 Silberschatz, Galvin and Gagne C-SCAN (Cont.) Operating System Concepts 10.17 Silberschatz, Galvin and Gagne C-LOOK LOOK a version of SCAN, C-LOOK a 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 Total number of cylinders? Operating System Concepts 10.18 Silberschatz, Galvin and Gagne C-LOOK (Cont.) Operating System Concepts 10.19 Silberschatz, Galvin and Gagne 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 Less starvation Performance depends on the number and types of requests Requests for disk service can be influenced by the file-allocation method And metadata layout 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 What about rotational latency? Difficult for OS to calculate How does disk-based queueing effect OS queue ordering efforts? Operating System Concepts 10.20 Silberschatz, Galvin and Gagne Disk Management Low-level formatting, or physical formatting — Dividing a disk into sectors that the disk controller can read and write Each sector can hold header information, plus data, plus error correction code (ECC) Usually 512 bytes of data but can be selectable 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, each treated as a logical disk Logical formatting or “making a file system” To increase efficiency most file systems group blocks into clusters Disk I/O done in blocks File I/O done in clusters Operating System Concepts 10.21 Silberschatz, Galvin and Gagne RAID Structure RAID – redundant array of inexpensive disks multiple disk drives provides reliability via redundancy Increases the mean time to failure Mean time to repair – exposure time when another failure could cause data loss Mean time to data loss based on above factors If mirrored disks fail independently, consider disk with 1300,000 mean time to failure and 10 hour mean time to repair Mean time to data loss is 100, 000 2 / (2 ∗ 10) = 500 ∗ 106 hours, or 57,000 years! Frequently combined with NVRAM to improve write performance Several improvements in disk-use techniques involve the use of multiple disks working cooperatively Operating System Concepts 10.22 Silberschatz, Galvin and Gagne Fault Tolerant Disk FtDisk is the fault-tolerant disk driver for Windows. When installed, it provides several ways to combine multiple disk drives into one logical volume so as to improve performance, capacity, or reliability. Operating System Concepts 10.23 Silberschatz, Galvin and Gagne Chapter 13: I/O Systems Selected Topics Operating System Concepts Silberschatz, Galvin and Gagne Overview I/O management is a major component of operating system design and operation Important aspect of computer operation I/O devices vary greatly Various methods to control them Performance management New types of devices frequent Ports, busses, device controllers connect to various devices Device drivers encapsulate device details Present uniform device-access interface to I/O subsystem Operating System Concepts 10.25 Silberschatz, Galvin and Gagne I/O Hardware Incredible variety of I/O devices Storage Transmission Human-interface Common concepts – signals from I/O devices interface with computer Port – connection point for device Bus - daisy chain or shared direct access PCI bus common in PCs and servers, PCI Express (PCIe) expansion bus connects relatively slow devices Controller (host adapter) – electronics that operate port, bus, device Sometimes integrated Sometimes separate circuit board (host adapter) Contains processor, microcode, private memory, bus controller, etc – Some talk to per-device controller with bus controller, microcode, memory, etc Operating System Concepts 10.26 Silberschatz, Galvin and Gagne A Typical PC Bus Structure Operating System Concepts 10.27 Silberschatz, Galvin and Gagne I/O Hardware (Cont.) I/O instructions control devices Devices usually have registers where device driver places commands, addresses, and data to write, or read data from registers after command execution Data-in register, data-out register, status register, control register Typically 1-4 bytes, or FIFO buffer Devices have addresses, used by Direct I/O instructions Memory-mapped I/O Device data and command registers mapped to processor address space Especially for large address spaces (graphics) Operating System Concepts 10.28 Silberschatz, Galvin and Gagne Device I/O Port Locations on PCs (partial) Operating System Concepts 10.29 Silberschatz, Galvin and Gagne Polling For each byte of I/O 1. Read busy bit from status register until 0 2. Host sets read or write bit and if write copies data into data-out register 3. Host sets command-ready bit 4. Controller sets busy bit, executes transfer 5. Controller clears busy bit, error bit, command-ready bit when transfer done Step 1 is busy-wait cycle to wait for I/O from device Reasonable if device is fast But inefficient if device slow CPU switches to other tasks? But if miss a cycle data overwritten / lost Operating System Concepts 10.30 Silberschatz, Galvin and Gagne Interrupts Polling can happen in 3 instruction cycles Read status, logical-and to extract status bit, branch if not zero How to be more efficient if non-zero infrequently? CPU Interrupt-request line triggered by I/O device Checked by processor after each instruction Interrupt handler receives interrupts Maskable to ignore or delay some interrupts Interrupt vector to dispatch interrupt to correct handler Context switch at start and end Based on priority Some nonmaskable Interrupt chaining if more than one device at same interrupt number Operating System Concepts 10.31 Silberschatz, Galvin and Gagne Interrupt-Driven I/O Cycle Operating System Concepts 10.32 Silberschatz, Galvin and Gagne Intel Pentium Processor Event-Vector Table Operating System Concepts 10.33 Silberschatz, Galvin and Gagne Interrupts (Cont.) Interrupt mechanism also used for exceptions Terminate process, crash system due to hardware error Page fault executes when memory access error System call executes via trap to trigger kernel to execute request Multi-CPU systems can process interrupts concurrently If operating system designed to handle it Used for time-sensitive processing, frequent, must be fast Operating System Concepts 10.34 Silberschatz, Galvin and Gagne Direct Memory Access Used to avoid programmed I/O (one byte at a time) for large data movement Requires DMA controller Bypasses CPU to transfer data directly between I/O device and memory OS writes DMA command block into memory Source and destination addresses Read or write mode Count of bytes Writes location of command block to DMA controller Bus mastering of DMA controller – grabs bus from CPU Cycle stealing from CPU but still much more efficient When done, interrupts to signal completion Version that is aware of virtual addresses can be even more efficient - DVMA Operating System Concepts 10.35 Silberschatz, Galvin and Gagne Six Step Process to Perform DMA Transfer Operating System Concepts 10.36 Silberschatz, Galvin and Gagne Application I/O Interface I/O system calls encapsulate device behaviors in generic classes Device-driver layer hides differences among I/O controllers from kernel New devices talking already-implemented protocols need no extra work Each OS has its own I/O subsystem structures and device driver frameworks Devices vary in many dimensions Character-stream or block Sequential or random-access Synchronous or asynchronous (or both) Sharable or dedicated Speed of operation read-write, read only, or write only Operating System Concepts 10.37 Silberschatz, Galvin and Gagne A Kernel I/O Structure Operating System Concepts 10.38 Silberschatz, Galvin and Gagne Characteristics of I/O Devices Operating System Concepts 10.39 Silberschatz, Galvin and Gagne Characteristics of I/O Devices (Cont.) Subtleties of devices handled by device drivers Broadly I/O devices can be grouped by the OS into Block I/O Character I/O (Stream) Memory-mapped file access Network sockets For direct manipulation of I/O device specific characteristics, usually an escape / back door Unix ioctl() call to send arbitrary bits to a device control register and data to device data register Operating System Concepts 10.40 Silberschatz, Galvin and Gagne Block and Character Devices Block devices include disk drives Commands include read, write, seek Raw I/O, direct I/O, or file-system access Memory-mapped file access possible File mapped to virtual memory and clusters brought via demand paging DMA Character devices include keyboards, mice, serial ports Commands include get(), put() Libraries layered on top allow line editing Operating System Concepts 10.41 Silberschatz, Galvin and Gagne Network Devices Varying enough from block and character to have own interface Linux, Unix, Windows and many others include socket interface Separates network protocol from network operation Includes select() functionality Approaches vary widely (pipes, FIFOs, streams, queues, mailboxes) Operating System Concepts 10.42 Silberschatz, Galvin and Gagne Clocks and Timers Provide current time, elapsed time, timer Normal resolution about 1/60 second Some systems provide higher-resolution timers Programmable interval timer used for timings, periodic interrupts ioctl() (on UNIX) covers odd aspects of I/O such as clocks and timers Operating System Concepts 10.43 Silberschatz, Galvin and Gagne Nonblocking and Asynchronous I/O Blocking - process suspended until I/O completed Easy to use and understand Insufficient for some needs Nonblocking - I/O call returns as much as available User interface, data copy (buffered I/O) Implemented via multi-threading Returns quickly with count of bytes read or written select() to find if data ready then read() or write() to transfer Asynchronous - process runs while I/O executes Difficult to use I/O subsystem signals process when I/O completed Operating System Concepts 10.44 Silberschatz, Galvin and Gagne Two I/O Methods Synchronous Asynchronous Operating System Concepts 10.45 Silberschatz, Galvin and Gagne Vectored I/O Vectored I/O allows one system call to perform multiple I/O operations For example, Unix readve() accepts a vector of multiple buffers to read into or write from This scatter-gather method better than multiple individual I/O calls Decreases context switching and system call overhead Some versions provide atomicity Avoid for example worry about multiple threads changing data as reads / writes occurring Operating System Concepts 10.46 Silberschatz, Galvin and Gagne Kernel I/O Subsystem Scheduling Some I/O request ordering via per-device queue Some OSs try fairness Some implement Quality Of Service (i.e. IPQOS) Buffering - store data in memory while transferring between devices To cope with device speed mismatch To cope with device transfer size mismatch To maintain “copy semantics” Double buffering – two copies of the data Kernel and user Varying sizes Full / being processed and not-full / being used Copy-on-write can be used for efficiency in some cases Operating System Concepts 10.47 Silberschatz, Galvin and Gagne Device-status Table Operating System Concepts 10.48 Silberschatz, Galvin and Gagne Kernel I/O Subsystem Caching - faster device holding copy of data Always just a copy Key to performance Sometimes combined with buffering Spooling - hold output for a device If device can serve only one request at a time i.e., Printing Device reservation - provides exclusive access to a device System calls for allocation and de-allocation Watch out for deadlock Operating System Concepts 10.49 Silberschatz, Galvin and Gagne I/O Protection User process may accidentally or purposefully attempt to disrupt normal operation via illegal I/O instructions All I/O instructions defined to be privileged I/O must be performed via system calls Memory-mapped and I/O port memory locations must be protected too Operating System Concepts 10.50 Silberschatz, Galvin and Gagne Use of a System Call to Perform I/O Operating System Concepts 10.51 Silberschatz, Galvin and Gagne Life Cycle of An I/O Request Operating System Concepts 10.52 Silberschatz, Galvin and Gagne Improving Performance Reduce number of context switches Reduce data copying Reduce interrupts by using large transfers, smart controllers, polling Use DMA Use smarter hardware devices Balance CPU, memory, bus, and I/O performance for highest throughput Move user-mode processes / daemons to kernel threads Operating System Concepts 10.53 Silberschatz, Galvin and Gagne