Docsity

File Systems and I/O Abstractions in Operating Systems: An Overview by Peter M. Chen - Pro, Study notes of Electrical and Electronics Engineering

Toggle sidebar
bg1
EECS 482 1 Peter M. Chen
I/O and file systems
What abstractions does the OS provide above I/O devices(viz.
disks)?
Device independence
Problem: lots of different brands of disks, disk interfaces, and
disk controllers, each with their own custom control inter-
face. Same is true of any I/O device (network card, video
card, keyboard, mouse, etc.)
Add a “device driver” layer to hide this diversity/complexity
An abstraction makes things “better” for things that use the
abstraction
• threads: user doesn’t have to worry about sharing CPU
• addresses spaces: user doesn’t have to worry about shar-
ing physical memory (or physical memory size)
• TCP: user doesn’t have to worry about the unreliable net-
work
• device drivers: frees the user (the rest of the OS) from
worrying about differences in devices (e.g. the device
registers used to control the device)
millions of hardware devices
device drivers
rest of operating system
virtual interface
physical interface
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download File Systems and I/O Abstractions in Operating Systems: An Overview by Peter M. Chen - Pro and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

EECS 482

1

I/O and file systems

What abstractions does the OS provide above I/O devices (viz.

disks)?

De

vice independence

Problem: lots of different brands of disks, disk interfaces, and

disk controllers, each with their own custom control inter-face. Same is true of any I/O device (network card, videocard, keyboard, mouse, etc.) Add a “device driver” layer to hide this diversity/complexityAn abstraction makes things “better” for things that use the

abstraction• threads: user doesn’t have to worry about sharing CPU• addresses spaces: user doesn’t have to worry about shar-

ing physical memory (or physical memory size)

  • TCP: user doesn’t have to worry about the unreliable net-

work

  • device drivers: frees the user (the rest of the OS) from

worrying about differences in devices (e.g. the deviceregisters used to control the device)

millions of hardware devices

device drivers rest of operating system

virtual interface physical interface

EECS 482

2

Peter M. Chen

Byte-oriented access -> block-oriented access Disks are accessed in terms of blocks (sectors), e.g. 512 bytesBut programs deal in bytesHow to read less than a blockHow to write less than a block

Disk geometry and access

Disk geometry

  • disk is made of a stack of spinning

platters

  • the top and bottom surface of each platter has concentric

circles of data (called

tracks

). The set of tracks at the

same radial distance is called a

cylinder

  • each track is made of a number of

sectors

Accessing a disk

  • queueing time (wait for disk to be free): 0-infinity• position disk arm and head (seek and rotate): 0-12 ms• access disk data: size/transfer rate (e.g. disk transfer rate

of 49 MB/s on Seagate Barracuda 1181677LW)

Inner Track

Outer Track

Sector

Actuator

Head

Platter

Arm

EECS 482

4

Disk scheduling

Re-order a set of disk accesses to decrease the total positioning

time• can be implemented in the OS, or in the disk hardware FCFS (first come, first served)

  • e.g. (start at track 53): 98, 183, 37, 122, 14, 124, 65, 67• total head movement: 640 tracks (average 80 per seek) SSTF (shortest seek time first) - e.g. 53->65->67->37->14->98->122->124->183• total head movement: 236 tracks (average 30 per seek)• any problems with SSTF?

SCAN: sweep the disk from one end to the other, then back

again (sometimes called “Elevator algorithms”). We usethe variant of SCAN called “LOOK” (when sweepingtoward the end, stop if there are no requests beyond thecurrent point)• e.g. 53->37->14->65->67->98->122->124->183• total head movement: 208 tracks (average 26 per seek) C-SCAN: always sweep the disk from beginning to end, then

seek all the way back to the beginning and repeat. Disk scheduling only improves positioning time with multiple

outstanding requests (otherwise service the sole request)

EECS 482

5

File systems

A file system is an OS abstraction to make the disk easier to

use How to map file space onto disk space?

  • file system structure on disk; disk allocation• this will be similar to issues in memory management How to use symbolic (english) names instead of disk sectors? - naming; directories• no equivalent issue in memory management, because the

virtual and physical address spaces used the same typeof “names” (i.e. addresses)

File system structur

e

Overall question: how to organize files on disk

  • what data structure is the right one to use when storing a

file on disk?

Need an initial structure that describes the object

  • this is a “file header”; called an inode (index node) in

Unix

  • file header also contains miscellaneous information about

the file, e.g. file size, modification date, permissions

Many ways to organize data on diskUsage patterns guide our design choices

  • 80% of file accesses are reads• most programs that access a file sequentially access the

whole file (the alternative is random access)

  • most files are small; most bytes on disk are from large

files

disk file system

user

virtual interface physical interface

EECS 482

7

Peter M. Chen

Multi-le

vel indexed files

Indexed files are like a shallow treeCould change this to a multi-level tree This allows really big files without wasting header space for

small files

How many accesses to get 1 block of data?

  • how to solve? Non-uniform depth multi-level indexed files

diskblock 18

diskblock 50

diskblock 8

diskblock 15

diskblock 18

diskblock 50

diskblock 8

diskblock 15

level 1node level 2node

level 2node ...

diskblock 8

diskblock 15

diskblock 75

diskblock 40

level 2

level 1node

node

diskblock 18

diskblock 50

EECS 482

8

Peter M. Chen

Pros and cons

  • files can easily expand+ small files don’t pay full overhead of deep trees- lots of indirect blocks for big files- lots of seeks for sequential access How to reduce seeks for sequential access, and still avoid

needing to pre-allocate a contiguous segment?

Naming

How to specify which file you want to access?

  • eventually, OS must find out which file header you want

(viz. the disk location of the file header)

Typically, the user provides a symbolic name (e.g. english

name, icon); OS translates name to a numeric file header(or disk location of the file header)• alternative is to describe the contents of the file, have the

OS find the name by looking through the files for thatcontent. This is usually done by databases on top of filesystems.

Lots of ways to translate from symbolic name to file header’s

disk block #• e.g. hash table, expandable array, etc.• the data structure that does the mapping is called a

direc-

tory

EECS 482

10

Peter M. Chen

Current working directory: a shortcut for the user and the sys-

tem• cache the file header # for the “current” directory• allows a user to specify a file name relative to the current

directory

  • allows the system to access a file without traversing the

entire directory from /

Reducing positioning overhead by taking advantage of usage

patterns

Combining (mounting) multiple disks into a

single file system

Each disk has a file system

  • each disk’s file system starts at its own root (/) Can tie several disks together into a single file system - have an entry in one directory point to the root directory

of

another disk’s

file system (this entry is called a

“mount point”)

E.g. CAEN workstation % ls /afs/

kernel/

sbin/

bin@

lib@

template-server@

core

lost+found/

template-server-ro@

dev/

nfs/

tmp/

devices/

opt/

usr/

etc/

platform/

var/

export/

proc/

vol/

home/

root/

/bin is a normal

directory

in

/

/usr points to

the

root

file

system

of

disk

1

/var points to

the

root

file

system

of

disk

2

/afs points to

the

root

file

system

of

a

distributed

file

system

Windows: disks are made visible under my_computer/

{C,D,E}

Unix: can mount disks at any place in the directory hierarchy

EECS 482

11

File caching

File systems have lots of data structures on disk

  • data blocks• metadata: bitmap of free blocks, directories, file headers,

indirect blocks, etc.

File caches speed access to all these types of dataChanging random disk I/O to sequential I/O can help some-

what• throughput increases dramatically• response time for small requests doesn’t improve Changing disk I/O to memory access helps a lot more

  • throughput is better even than sequential disk I/O• response time can improve by 100,000x Should file cache be stored in virtual or physical memory?

Comparing file caching and virtual memory Both use physical memory as a cache for disk

  • VM: started with memory and added disk to get larger

memory

  • file systems: started with disk and added memory to get

faster performance

Why have two mechanisms that both cache disk data in mem-

ory? Memory-mapped files

  • use the VM paging system to cache both virtual address

spaces

and

files

  • map a file into a virtual address space, then mark the

backing store for the file as being allocated to the diskblocks for that file

  • VM knows how to cache address spaces; file cache

knows how to cache files. Memory-mapping makes fileslook like an address space, so VM cache can deal withit.

  • e.g. how to load a program from disk into memory?

EECS 482

13

Car

eful ordering

How to fix the problem in the prior example?Can careful ordering solve the problem of transferring money

from Peter’s account to Janet’s account? What 482 concept does this remind you of?

T

ransactions

Used a lot in databases. For us, the main component is atomic-

ity (all or nothing) begin

disk writedisk writedisk write

...

end (this is

“commits”

the

transaction)

Basic atomic unit provided by the hardware is writing a single

sector to disk How to make an arbitrary sequence of updates atomic using a

single sector update? Shadowing

  • keep two versions of the database (old and new), and

keep a pointer to which is the current version

  • update the new version, then switch the pointer to the

new version when you want to commit the changes

EECS 482

14

Logging

  • write new data to a append-only log• write “commit” sector to the end of the log after all the

changes

  • copy the new data to the original copy• what if the system crashes after writing the log record

(including commit) but before writing the in-placecopy?

Almost all file systems since 1985 use transactions (using log-

ging) to make atomic a group of updates to the file systemmetadata• why don’t file systems provide atomic transactions for

data updates?

Distrib

uted file systems

Distributed file system: file system that distributes where data

is actually stored, but unifies the view of this distributedstorage.• allows access to files stored on remote computers (with

same interface as to local files).

Benefits

  • share data and resources between people• enables uniform view from different machines Basic implementation - ask appropriate server for file (classic client/server

model)

  • but poor performance. How to improve?