cse 513 introduction to operating systems class 8...

95
CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems Jonathan Walpole Dept. of Comp. Sci. and Eng. Oregon Health and Science University

Upload: trinhkien

Post on 06-Sep-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

CSE 513Introduction to Operating Systems

Class 8 - Input/OutputFile Systems

Jonathan WalpoleDept. of Comp. Sci. and Eng.

Oregon Health and Science University

Page 2: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

I/O devices

q Device (mechanical hardware)q Device controller (electrical hardware)q Device driver (software)

Page 3: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Devices and their controllers

q Components of a simple personal computer

Monitor

Bus

Page 4: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

How to communicate with a device?

q Hardware supports I/O ports or memorymapped I/O for accessing device controllerregisters and buffers

Page 5: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Wide performance range for I/O

Page 6: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Performance challenges: I/O hardware

q How to prevent slow devices from slowing downmemory

q How to identify I/O addresses withoutinterfering with memory performance

Page 7: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Single vs. Dual Memory Bus Architecture

(a) A single-bus architecture(b) A dual-bus memory architecture

Page 8: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Hardware view of Pentium

Structure of a large Pentium system

Page 9: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Performance challenges: I/O software

q How to prevent CPU throughput from beinglimited by I/O device speed (for slow devices)

q How to prevent I/O throughput from beinglimited by CPU speed (for fast devices)

q How to achieve good utilization of CPU and I/Odevices

q How to meet the real-time requirements ofdevices

Page 10: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Programmed I/O

Steps in printing a string

Page 11: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Programmed I/O

q Polling/busy-waiting approach

copy_from_user(buffer,p,count);for(i=0;i<count;i++){ while (*p_stat_reg != READY); *p_data_reg = p[i]; }

return();

Page 12: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Interrupt-driven I/O

q Asynchronous approachv give device data, do something else!v resume when device interrupts

copy_from_user(buffer,p,count);enable_interrupts();while (*p_stat_reg != READY);*p_data_reg=p[0];scheduler();

if (count==0){ unblock_user();} else { *p_data_reg = p[i]; count--; i++;}ack_interrupt();return_from_interrupt();

Page 13: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Interrupt driven I/O

(b)

Page 14: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Hardware Support for Interrupts

How interrupts happens. Connections between devices and interruptcontroller actually use interrupt lines on the bus rather thandedicated wires

Page 15: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

DMA

q Offload all work to a DMA controllerv avoids using the CPU to do the transferv reduces number of interruptsv DMA controller is like a co-processor doing

programmed I/O

copy_from_user(buffer,p,count);set_up_DMA_controller();scheduler();

ack_interrupt();unblock_user();return_from_interrupt();

Page 16: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

DMA

Page 17: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Software engineering-related challenges

q How to remove the complexities of I/O handlingfrom application programsv standard I/O APIs (libraries and system calls)v generic categories across different device types

q How to support a wide range of device types ona wide range of operating systemsv standard interfaces for device driversv standard/published interfaces for access to kernel

facilities

Page 18: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

I/O Software Layers

Layers of the I/O Software System

Page 19: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Interrupt Handlers

q Interrupt handlers are best hiddenv have driver starting an I/O operation block until

interrupt notifies of completion

q Interrupt procedure does its taskv then unblocks driver that started it

q Steps must be performed in software afterinterrupt completed

− Save regs not already saved by interrupt hardware− Set up context for interrupt service procedure

Page 20: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Interrupt Handlers

l Set up stack for interrupt service procedurel Ack interrupt controller, reenable interruptsl Copy registers from where savedl Run service procedurel Set up MMU context for process to run nextl Load new process' registersl Start running the new process

Page 21: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Device Drivers

q Communications between drivers and device controllers goes overthe bus

Page 22: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

I/O Software: Device Drivers

q Device drivers “connect” devices with theoperating systemv Typically a nasty assembly-level job

• Must deal with hardware changes• Must deal with O.S. changes

v Hide as many device-specific details as possible

q Device drivers are typically given kernelprivileges for efficiencyv Can bring down O.S.!v How to provide efficiency and safety???

Page 23: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Device-Independent I/O Software Functions

Functions of the device-independent I/O software

Providing a deice-independent block size

Allocating and releasing dedicate devices

Error reporting

Buffering

Uniform interfacing for device drivers

Page 24: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Device-Independent I/O Software Interface

(a) Without a standard driver interface(b) With a standard driver interface

Page 25: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Device-Independent I/O Software Buffering

(a) Unbuffered input(b) Buffering in user space(c) Buffering in the kernel followed by copying to user space(d) Double buffering in the kernel

Page 26: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Copying Overhead in Network I/O

Networking may involve many copies

Page 27: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

User-Space I/O Software

Layers of the I/O system and the main functionsof each layer

Page 28: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Devices as files

q Before mounting,v files on floppy are inaccessible

q After mounting floppy on b,v files on floppy are part of file hierarchy

Page 29: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Disk Geometry

q Disk head, platters, surfaces

cylinder

Track

Sector

Page 30: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Physical vs. logical disk geometry

q Constant Angular Velocity vs. Constant LinearVelocity

Page 31: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Disks

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

Page 32: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

CD-ROMs

Page 33: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

CD-ROM data layout

Logical data layout on a CD-ROM

Page 34: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

CD-R Structure

q Cross section of a CD-R disk and laserv not to scale

q Silver CD-ROM has similar structurev without dye layerv with pitted aluminum layer instead of gold

Page 35: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Double sided dual layer DVD

Page 36: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Plastic technology

q CDsv Approximately 650 Mbytes of datav Approximately 74 minutes of audio

q DVDsv Many types of formats

• DVD-R, DVD-ROM, DVD-Videov Single layer vs. multi-layerv Single sided vs. double sidedv Authoring vs. non-authoring

Page 37: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Disk Formatting

A disk sector

Page 38: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Disk formatting with cylinder skew

Page 39: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Disk formatting with interleaving

q No interleavingq Single interleavingq Double interleaving

Page 40: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Disk scheduling algorithms

q Time required to read or write a disk blockdetermined by 3 factorsv Seek timev Rotational delayv Actual transfer time

q Seek time dominates

q Error checking is done by controllers

Page 41: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Disk scheduling algorithms

q First-come first serve

q Shortest seek time first

q Scan à back and forth to ends of disk

q C-Scan à only one direction

q Look à back and forth to last request

q C-Look à only one direction

Page 42: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Disk scheduling algorithms

Page 43: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Error handling complicates scheduling

q A disk track with a bad sectorq Substituting a spare for the bad sectorq Shifting all the sectors to bypass the bad one

Page 44: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

RAID levels 0 to 2

Page 45: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

RAID levels 3 to 5

Page 46: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Part B

File Systems

Page 47: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Long-term Information Storage

q Must store large amounts of data

q Information stored must survive the terminationof the process using it

q Multiple processes must be able to access theinformation concurrently

Page 48: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

File naming and file extensions

Typical file extensions.

Page 49: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

File Structure

q Three kinds of file structurev byte sequencev record sequencev tree

Page 50: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

File Types

(a) An executable file (b) An archive

Page 51: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

File access

q Sequential accessv read all bytes/records from the beginningv cannot jump around, could rewind or back upv convenient when medium was mag tape

q Random accessv bytes/records read in any orderv essential for data base systemsv read can be …

• move file marker (seek), then read or …• read and then move file marker

Page 52: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

File attributes

Page 53: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

File operations

CreateDeleteOpenCloseReadWrite

AppendSeekGet attributesSet AttributesRename

Page 54: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Exmple Program Using File System Calls (1/2)

Page 55: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Example Program Using File System Calls (2/2)

Page 56: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Memory-mapped files

(a) Segmented process before mapping filesinto its address space

(b) Process after mapping existing file abc into one segment creating new segment for xyz

Page 57: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Directories - single level

q A single level directory systemv contains 4 filesv owned by 3 different people, A, B, and C

Page 58: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Directories - two-level

Letters indicate owners of the directories and files

Page 59: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Hierarchical directory systems

Page 60: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Path names in Unix

Page 61: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Directory operations

CreateDeleteOpendirClosedir

ReaddirRenameLinkUnlink

Page 62: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

File system implementation on disk

A possible file system disk layout

Page 63: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Implementing files - contiguous allocation

(a) Contiguous allocation of disk space for 7 files(b) State of the disk after files D and E have been removed

Page 64: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Implementing files - linked allocation

Storing a file as a linked list of disk blocks

Page 65: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Implementing Files - FAT

Linked list allocation using a file allocation table (FAT) in RAM

Page 66: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Implementing files - index nodes

An example i-node

Page 67: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Implementing directories

(a) A simple directoryfixed size entriesdisk addresses and attributes in directory entry

(b) Directory in which each entry just refers to an i-node

Page 68: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Implementing directories

q Two ways of handling long file names in directoryv (a) In-line, (b) In a heap

Page 69: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Shared files - hard links

File system containing a shared file

Page 70: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Problems with shared files

(a) Situation prior to linking(b) After the link is created(c)After the original owner removes the file

Page 71: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Disk space management and performance

q Dark line (left hand scale) gives data rate of a diskq Dotted line (right hand scale) gives disk space efficiencyq All files 2KB

Block size

Page 72: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Disk space management

(a) Storing the free list on a linked list(b) A bit map

Page 73: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Disk Space Management (3)

(a) Almost-full block of pointers to free disk blocks in RAM- three blocks of pointers on disk

(b) Result of freeing a 3-block file(c) Alternative strategy for handling 3 free blocks

- shaded entries are pointers to free disk blocks

Page 74: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Disk space management - quotas

Quotas for keeping track of each user’s disk use

Page 75: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Maintaining File System Consistency

q Crashes can cause file system to havecorrupted data

q First: bitmap vs. linked storage maps

q fsck / scandiskv Block-level à ensure that all blocks on disk are

accounted for• traverse inodes counting allocated blocks• compare result to free list

v File-level à ensure that all files are accounted for• traverse directory system counting files

Page 76: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

File system consistency

q File system states(a) consistent(b) missing block(c) duplicate block in free list(d) duplicate data block

Page 77: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Maintaining File System Consistency

q File level consistencyv Have directories with i-node #’s of filesv Have link status in the i-nodes themselvesv Compare!

Page 78: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Performance issues

q Buffer cachev A buffer in between the application and the FS

• Hold buffer of accessed data• Allows data to be reused by other apps• Can implement prefetch strategies to minimize

latency• Serves a buffer for writing out application data

– Delayed writes allow the writes to happen whenconvenient

– Trade-off between consistency andperformance

v Hash table indexed to minimize the searching

Page 79: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

File system performance - buffer cache

The buffer cache data structures

Page 80: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

File system performance - data placement

q I-nodes placed at the start of the diskq Disk divided into cylinder groups

v each with its own blocks and i-nodes

Page 81: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Log-Structured File Systems

q With CPUs faster, memory largerv disk caches can also be largerv increasing number of read requests can come from cachev thus, most disk accesses will be writes

q LFS Strategy structures entire disk as a logv have all writes initially buffered in memoryv periodically write these to the end of the disk log

• long contiguous writes to disk• requires large contiguous free space!• data not updated in place

v when file opened, locate i-node, then find blocks

Page 82: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Example: The Unix file system

q File systems structure

q The file system in UNIX is an integral part of theoperating system. Files are used for:v Terminal handling /dev/tty***v Pipes “ls | more”v Directoriesv Sockets (for networking)

q The design of the UNIX file system allows the user towrite code that has a uniform interface.

Boot block superblock i-nodes data block data block …

Page 83: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Unix file system structures

q Superblock - tells the UNIX O.S. what theformat of the disk is, the # of blocks, thenumber of i-nodes, etc...

q I-nodes - are the metadata data structuresfor files and directoriesv Files - holds information such as owner, permissions,

date of modification, where the data isv Directories are just a special case of files that have

the pairs <file-name, i-node #> stored in the file

Page 84: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

The Unix name space

q Filesv Represented with an I-node and disk blocks that

hold the datav File names are not stored with the i-node (they’re in

the directories that refer to them)• This is why there is a link count in the inode

q Directoriesv Directories are also filesv Entries are disblocks with <filename, i-node #> pairsv Special directory marking in i-node

Page 85: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Unix directory entries

A UNIX V7 directory entry

Page 86: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

The Unix name space

/ inode #22

. 22

.. 22usr 24var 35home 26txt 23

/ inode #24

. 24

.. 22src 38conf 53

/ inode #53

## config..## Frame rate 33Frame size ..

Page 87: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Pathname translation in Unix

The steps in looking up /usr/ast/mbox

Page 88: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Unix I-node structure

q UNIX files consist of i-node and data blocks

q UNIX uses an indexed allocation scheme withv 10 direct pointers to blocksv 1 indirect pointer to blocksv 1 double indirect

pointer to blocksv 1 triple indirect

pointer to blocks

i-node

...

...

...

...

...

triple indirect pointer

Page 89: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Unix I-node structrure

A UNIX i-node

Page 90: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Maximum file size in Unix

q Several parameters determine how many (and of whatsize) files can be representedv No. of bits in a disk addressv No. of bits in a virtual memory referencev Disk block size

q Example:v 10 direct, 1 indirect, 1 double indirect, 1 triple indirectv No. bits in disk address --> 16-bitsv No. of bits in virtual memory reference --> 32-bitsv Disk block size --> 1024 kbytes

v What is the maximum file size in this system?

Page 91: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

The “mount” command in Unix

q Commandsv “mount” allows file systems to be added to the

names spacev “umount” takes a file systems out of the name space

q Mount pointsv Mount points can be any directory in the name spacev Once a file system is mounted, the entire subtree

at the mount point is no longer accessible (until thefile system is unmounted)

Page 92: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Some UNIX file system features

q mounting - allows other file systems (disks),whether local or remote to be “mounted” into auniform file system name space

/

mntusr var

home X11

bin

Page 93: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

Associating files with processes

q To provide uniform access to data, UNIX has a level ofindirection that is used for opening files

process 1

process n

...

Open File Table ......

.........

......

.........

...

Files

Each open file entry holds, permissions (R/W), file offset

Page 94: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

File system vs. virtual memory

Process

Paging

FSDisk

Swap

OpenFile

Table

Page 95: CSE 513 Introduction to Operating Systems Class 8 …web.cecs.pdx.edu/~walpole/class/cse513/slides/8.pdf · CSE 513 Introduction to Operating Systems Class 8 - Input/Output File Systems

A file-centric view of IPC

q All input and output in UNIX are handledthrough the open file table structurev This is how UNIX can provide a single uniform

interface for local or remote data access

q Pipes in UNIX are nothing more thanv A writing process that has its “stdout” linked to a

“pipe” file (instead of a /dev/tty*** file)v A reading process that has its “stdin” linked to a

“pipe” file (instead of a /dev/tty*** file)