Docsity

Understanding File System Implementation: Volumes, Directories, and Caching - Prof. E. Sir, Study notes of Operating Systems

Toggle sidebar
bg1
3/9/2009
1
K๎˜ƒBi
K
en
๎˜ƒBi
rman
File๎˜ƒSystem๎˜ƒImplementation
yChange๎˜ƒof๎˜ƒtopicโ€ฆ
yHow๎˜ƒexactly๎˜ƒare๎˜ƒfile๎˜ƒsystems๎˜ƒimplemented?
yComes๎˜ƒdown๎˜ƒto:๎˜ƒhow๎˜ƒdo๎˜ƒwe๎˜ƒrepresent
Vl
y
V
o
l
umes
yDirectories๎˜ƒ(link๎˜ƒfile๎˜ƒnames๎˜ƒto๎˜ƒfile๎˜ƒโ€œstructureโ€)
yThe๎˜ƒlist๎˜ƒof๎˜ƒblocks๎˜ƒcontaining๎˜ƒthe๎˜ƒdata
yOther๎˜ƒinformation๎˜ƒsuch๎˜ƒas๎˜ƒaccess๎˜ƒcontrol๎˜ƒlist๎˜ƒor๎˜ƒpermissions,๎˜ƒ
owner,๎˜ƒtime๎˜ƒof๎˜ƒaccess,๎˜ƒetc?
yAnd,๎˜ƒcan๎˜ƒwe๎˜ƒbe๎˜ƒsmart๎˜ƒabout๎˜ƒlayout?
2
Overall๎˜ƒstructure
User
Process
File System Cache (โ€œbufferโ€) Inode cache Copy of
superblock
User
Process
File System
Module
(k l)
User mode
3
Disk
Driver
I/O๎˜ƒ
requests
superblock
(k
erne
l)
Physical
Storage
Layer
Basic๎˜ƒsequence
yUser๎˜ƒapplication๎˜ƒdoes๎˜ƒa๎˜ƒfile๎˜ƒoperation
yPerhaps ,๎˜ƒopen,๎˜ƒthen๎˜ƒseek,๎˜ƒthen๎˜ƒread
yO/S๎˜ƒtries๎˜ƒto๎˜ƒsatisfy๎˜ƒrequests๎˜ƒusing๎˜ƒcached๎˜ƒrecords
y
If๎˜ƒneeded๎˜ƒdata๎˜ƒisn
โ€™
t๎˜ƒin๎˜ƒthe๎˜ƒcache ๎˜ƒposts๎˜ƒan๎˜ƒI/O๎˜ƒrequest๎˜ƒ
y
If๎˜ƒneeded๎˜ƒdata๎˜ƒisnt๎˜ƒin๎˜ƒthe๎˜ƒcache
,
๎˜ƒposts๎˜ƒan๎˜ƒI/O๎˜ƒrequest๎˜ƒ
and๎˜ƒmakes๎˜ƒthe๎˜ƒuser๎˜ƒprocess๎˜ƒ(actually:๎˜ƒthe๎˜ƒkernel๎˜ƒthread)๎˜ƒ
wait
yUpon๎˜ƒcompletion ,๎˜ƒperform๎˜ƒthe๎˜ƒrequest,๎˜ƒcopying ๎˜ƒdata๎˜ƒ
into๎˜ƒor๎˜ƒfrom๎˜ƒthe๎˜ƒuserโ€™s๎˜ƒspace๎˜ƒas๎˜ƒneeded
yThen๎˜ƒmake๎˜ƒuser๎˜ƒprocess๎˜ƒrunable again
yWith๎˜ƒa๎˜ƒcache๎˜ƒhit,๎˜ƒa๎˜ƒfile๎˜ƒsystem๎˜ƒoperation๎˜ƒmight๎˜ƒtake๎˜ƒ
100usโ€ฆ๎˜ƒif๎˜ƒit๎˜ƒmisses,๎˜ƒperhaps๎˜ƒ10โ€50ms๎˜ƒto๎˜ƒa๎˜ƒhard๎˜ƒdisk
4
Prefetch policy
yMost๎˜ƒkernel s๎˜ƒprefetch file๎˜ƒblocks
yFetch๎˜ƒfirst๎˜ƒtwo๎˜ƒblocks๎˜ƒof๎˜ƒdata๎˜ƒwhen๎˜ƒfile๎˜ƒis๎˜ƒopened
yIf๎˜ƒuser๎˜ƒreads๎˜ƒblocks๎˜ƒi,๎˜ƒi+1๎˜ƒthen๎˜ƒprefetch i+2
Gl?
y
G
oa
l?
yKeep๎˜ƒthe๎˜ƒdisk๎˜ƒa๎˜ƒlittle๎˜ƒahead๎˜ƒof๎˜ƒthe๎˜ƒapplication
yBut๎˜ƒdonโ€™t๎˜ƒwaste๎˜ƒtime๎˜ƒdoing๎˜ƒunnecessary๎˜ƒI/O
5
Writeโ€behind๎˜ƒpolicy
yWhen๎˜ƒuser๎˜ƒdoes๎˜ƒa๎˜ƒwrite,๎˜ƒupdate๎˜ƒthe๎˜ƒcache
yThus,๎˜ƒcached๎˜ƒversion๎˜ƒof๎˜ƒfile,๎˜ƒinode and๎˜ƒsuper๎˜ƒblock๎˜ƒcan๎˜ƒ
be๎˜ƒโ€œmore๎˜ƒcurrentโ€๎˜ƒthan๎˜ƒthe๎˜ƒversion ๎˜ƒactually๎˜ƒon๎˜ƒthe๎˜ƒdisk
yPeriod icall
y,
๎˜ƒlike๎˜ƒonce๎˜ƒever
y
๎˜ƒ60๎˜ƒseconds
,
๎˜ƒโ€œs
y
ncโ€๎˜ƒthe๎˜ƒcache
๎˜ƒ
y, y , y
with๎˜ƒthe๎˜ƒdisk๎˜ƒby๎˜ƒwriting๎˜ƒout๎˜ƒdirty๎˜ƒentries
yAlso๎˜ƒif๎˜ƒfile๎˜ƒis๎˜ƒclosed๎˜ƒor๎˜ƒuser๎˜ƒexplicitly๎˜ƒcalls๎˜ƒfsync()
yCrash?
yO/S๎˜ƒwants๎˜ƒfile๎˜ƒsystem๎˜ƒto๎˜ƒmake๎˜ƒsenseโ€ฆ๎˜ƒbut๎˜ƒdoesnโ€™t๎˜ƒcare๎˜ƒif๎˜ƒ
some๎˜ƒโ€œunsyncedโ€๎˜ƒdata๎˜ƒwas๎˜ƒlost!๎˜ƒ๎˜ƒ
yIf๎˜ƒan๎˜ƒapplication๎˜ƒdoes๎˜ƒsomething๎˜ƒsensitive,๎˜ƒit๎˜ƒcalls๎˜ƒ
fsync()๎˜ƒbefore๎˜ƒtelling๎˜ƒthe๎˜ƒhuman๎˜ƒuser๎˜ƒthe๎˜ƒrequest๎˜ƒis๎˜ƒdone
6
pf3
pf4
pf5

Partial preview of the text

Download Understanding File System Implementation: Volumes, Directories, and Caching - Prof. E. Sir and more Study notes Operating Systems in PDF only on Docsity!

KK en BiBirman

File System Implementation

y Change of topicโ€ฆ

y How exactly are file systems implemented?

y Comes down to: how do we represent

y V lVolumes y Directories (link file names to file โ€œstructureโ€) y The list of blocks containing the data y Other information such as access control list or permissions, owner, time of access, etc?

y And, can we be smart about layout?

2

Overall structure

User Process

File System Cache (โ€œbufferโ€) Inode cache Copy of superblock

User Process

File System Module (k l)

User mode

3

Disk requestsI/O Driver

(kernel)^ superblock

Physical Storage Layer

Basic sequence

y User application does a file operation

y Perhaps, open, then seek, then read

y O/S tries to satisfy requests using cached records

yy IfIf neededneeded datadata isnโ€™tisn t inin thethe cachecache, postsposts anan I/OI/O requestrequest

and makes the user process (actually: the kernel thread)

wait

y Upon completion, perform the request, copying data

into or from the userโ€™s space as needed

y Then make user process runable again

y With a cache hit, a file system operation might take

100usโ€ฆ if it misses, perhaps 10 โ€50ms to a hard disk

4

Prefetch policy

y Most kernels prefetch file blocks

y Fetch first two blocks of data when file is opened

y If user reads blocks i, i+1 then prefetch i+

y GG oal?l?

y Keep the disk a little ahead of the application

y But donโ€™t waste time doing unnecessary I/O

5

Writeโ€behind policy

y When user does a write, update the cache

y Thus, cached version of file, inode and super block can

be โ€œmore currentโ€ than the version actually on the disk

y Periodically,y, like once everyy 60 seconds,, โ€œsyncโ€y the cache

with the disk by writing out dirty entries

y Also if file is closed or user explicitly calls fsync()

y Crash?

y O/S wants file system to make senseโ€ฆ but doesnโ€™t care if

some โ€œunsyncedโ€ data was lost!

y If an application does something sensitive, it calls

fsync() before telling the human user the request is done

6

File Control Block

y FCB has all the information about the file

y Linux systems call these iโ€node structures

7

Files Open and Read

8

File System Layout

y File System is stored on disks

y Disk is divided into 1 or more partitions y Sector 0 of disk called Master Boot Record y End of MBR has ppartition table (start & end address of ppartitions)

y First block of each partition has boot block

y Loaded by MBR and executed on boot

9

Implementing Files

y Contiguous Allocation: allocate files contiguously on disk

10

Contiguous Allocation

y Pros:

y Simple: state required per file is start block and size y Performance: entire file can be read with one seek

y Cons:Cons:

y Fragmentation: external is bigger problem y Usability: user needs to know size of file

y Used in CDROMs, DVDs

11

Linked List Allocation

y Each file is stored as linked list of blocks

y First word of each block points to next block y Rest of disk block is file data

12

Implementing Directories

y When a file is opened, OS uses path name to find dir

y Directory has information about the fileโ€™s disk blocks y Whole file (contiguous), first block (linkedโ€list) or Iโ€node y Directory also has attributes of each file

y Directory:y mapp ASCII file name to file attributes & location

y 2 options: entries have all attributes, or point to file Iโ€node

19

Implementing Directories

y What if files have large, variableโ€length names?

y Solution:

y Limit file name length, say 255 chars, and use previous scheme y Pros: Simplep^ Cons: wastes spacep y Directory entry comprises fixed and variable portion y Fixed part starts with entry size, followed by attributes y Variable part has the file name y Pros: saves space y Cons: holes on removal, page fault on file read, word boundaries y Directory entries are fixed in length, pointer to file name in heap y Pros: easy removal, no space wasted for word boundaries y Cons: manage heap, page faults on file names

20

Managing file names: Example

21

Directory Search

y Simple Linear search can be slow

y Alternatives:

y Use a perโ€directory hash table y Could use hash of file name to store entryy for file y Pros: faster lookup y Cons: More complex management y Caching: cache the most recent searches y Look in cache before searching FS

22

Shared Files

y If B wants to share a file owned by C

y One Solution: copy disk addresses in Bโ€™s directory entry y Problem: modification by one not reflected in other userโ€™s view

23

Sharing Files: Solutions

y 2 approaches:

y Use iโ€nodes to store file information in directories y Cons: What happens if owner deletes file?

y Symbolic links: B links to Cโ€™s file by creating a file in its directory y The new Link file contains path name of file being linked y Cons: read overhead

24

Disk Space Management

y Files stored as fixedโ€size blocks

y What is a good block size? (sector, track, cylinder?)

y If 131,072 bytes/track, rotation time 8.33 ms, seek time 10 ms y ToTo readread kk bytesbytes block:block: 10+10+ 4.1654.165 ++ (k/131072)(k/131072) 8.33*8.33 msms y Median file size: 2 KB

Block size^25

Managing Free Disk Space

y 2 approaches to keep track of free disk blocks

y Linked list and bitmap approach

26

Tracking free space

y Storing free blocks in a Linked List

y Only one block need to be kept in memory y Bad scenario: Solution (c)

y Storing bitmaps

y Lesser storage in most cases y Allocated disk blocks are closer to each other

27

Measured file lifetimes, sizes

y Source: โ€œA Comparison of File System Workloadsโ€, Drew

Roselli, Jacob R. Lorch, and Thomas E. Anderson, 2000

USENIX Technical Conference

y File Size Lifetime (byte) Lifetime (block)

y (C): Block deletedโ€block created; (D): File deletedโ€File created

28

Observations?

y Many files are quite small

y So Linux idea was a good oneโ€ฆ

y Many files have fairly short lifetimes

y So writeโ€throughh h cacheh policyl can bb e a bbig win

y With luck, file may be deleted before we ever write it to

the disk at all!

29

Fancier issues

y Optimizing disk head movement

y It turns out that the cost of moving the disk arm (seek)

is very high

yy OptimalOptimal wayway toto readread aa listlist ofof blocks?blocks?

y Put them in order y Seek to the outside rim of the disk y Then pick up blocks in โ€œinwardโ€ orderโ€ฆ.

y Many disk drivers reorder requests for this reason.

Algorithm is called โ€œCโ€Scanโ€ because disk arm moves in

a circular motion

30