File System Implementation Operating System Concepts Essentials 2

  • Slides: 25
Download presentation
File System Implementation Operating System Concepts Essentials – 2 nd Edition Silberschatz, Galvin and

File System Implementation Operating System Concepts Essentials – 2 nd Edition Silberschatz, Galvin and Gagne © 2013

File System Implementation n File-System Structure n File-System Implementation n Directory Implementation n Allocation

File System Implementation n File-System Structure n File-System Implementation n Directory Implementation n Allocation Methods n Efficiency and Performance n Recovery Operating System Concepts Essentials – 2 nd Edition 10. 2 Silberschatz, Galvin and Gagne © 2013

File-System Structure n n n File structure l Logical storage unit l Collection of

File-System Structure n n n File structure l Logical storage unit l Collection of related information File system resides on secondary storage (disks) why? l Provided user interface to storage, mapping logical to physical l Provides efficient and convenient access to disk by allowing data to be stored, located retrieved easily Disk provides in-place rewrite and random access l I/O transfers performed in blocks of sectors (usually 512 bytes) n File control block – storage structure consisting of information about a file n Device driver controls the physical device n File system organized into layers Operating System Concepts Essentials – 2 nd Edition 10. 3 Silberschatz, Galvin and Gagne © 2013

Layered File System Operating System Concepts Essentials – 2 nd Edition 10. 4 Silberschatz,

Layered File System Operating System Concepts Essentials – 2 nd Edition 10. 4 Silberschatz, Galvin and Gagne © 2013

Allocation Methods - Contiguous n An allocation method refers to how disk blocks are

Allocation Methods - Contiguous n An allocation method refers to how disk blocks are allocated for files: n Contiguous allocation – each file occupies set of contiguous blocks l Best performance in most cases l Simple – only starting location (block #) and length (number of blocks) are required l Problems include finding space for file, knowing file size, external fragmentation. Operating System Concepts Essentials – 2 nd Edition 10. 5 Silberschatz, Galvin and Gagne © 2013

Allocation Methods - Contiguous n Example : n The file ‘mail’ in the following

Allocation Methods - Contiguous n Example : n The file ‘mail’ in the following figure starts from the block 19 with length = 6 blocks. Therefore, it occupies 19, 20, 21, 22, 23, 24 blocks Operating System Concepts Essentials – 2 nd Edition 10. 6 Silberschatz, Galvin and Gagne © 2013

Operating System Concepts Essentials – 2 nd Edition 10. 7 Silberschatz, Galvin and Gagne

Operating System Concepts Essentials – 2 nd Edition 10. 7 Silberschatz, Galvin and Gagne © 2013

Contiguous Allocation n Mapping from logical to physical n Logical address= byte location within

Contiguous Allocation n Mapping from logical to physical n Logical address= byte location within a file n Physical address= block address +offset within that block n Let LA be the Logical address and let block size=512 byte n Q=LA/512 (BLOCK NUMBER) n R=LA%512 (OFFSET) Q Block to be accessed = Q + starting address Displacement into block = R Operating System Concepts Essentials – 2 nd Edition 10. 8 LA/512 R Silberschatz, Galvin and Gagne © 2013

Contiguous Allocation n Mapping from logical to physical Q LA/512 R Block to be

Contiguous Allocation n Mapping from logical to physical Q LA/512 R Block to be accessed = Q + starting address Displacement into block = R Operating System Concepts Essentials – 2 nd Edition 10. 9 Silberschatz, Galvin and Gagne © 2013

Allocation Methods - Linked n Linked allocation – each file a linked list of

Allocation Methods - Linked n Linked allocation – each file a linked list of blocks l File ends at nil pointer l No external fragmentation l Each block contains pointer to next block l No compaction, external fragmentation l Free space management system called when new block needed l Improve efficiency by clustering blocks into groups but increases internal fragmentation l Locating a block can take many I/Os and disk seeks Operating System Concepts Essentials – 2 nd Edition 10. 10 Silberschatz, Galvin and Gagne © 2013

Chained Allocation n Each file is a linked list of disk blocks: blocks may

Chained Allocation n Each file is a linked list of disk blocks: blocks may be scattered anywhere on the disk. block = pointer n Simple: need only starting address. n Free-space management: no waste of space. n No random access. You have to follow the link from the first block to the end. Operating System Concepts Essentials – 2 nd Edition 10. 11 Silberschatz, Galvin and Gagne © 2013

Chained/Linked Allocation Example Operating System Concepts Essentials – 2 nd Edition 10. 12 Silberschatz,

Chained/Linked Allocation Example Operating System Concepts Essentials – 2 nd Edition 10. 12 Silberschatz, Galvin and Gagne © 2013

Linked List Allocation Using a Table in Memory Operating System Concepts Essentials – 2

Linked List Allocation Using a Table in Memory Operating System Concepts Essentials – 2 nd Edition 10. 13 Silberschatz, Galvin and Gagne © 2013

Linked Allocation Operating System Concepts Essentials – 2 nd Edition 10. 14 Silberschatz, Galvin

Linked Allocation Operating System Concepts Essentials – 2 nd Edition 10. 14 Silberschatz, Galvin and Gagne © 2013

Operating System Concepts Essentials – 2 nd Edition 10. 15 Silberschatz, Galvin and Gagne

Operating System Concepts Essentials – 2 nd Edition 10. 15 Silberschatz, Galvin and Gagne © 2013

Operating System Concepts Essentials – 2 nd Edition 10. 16 Silberschatz, Galvin and Gagne

Operating System Concepts Essentials – 2 nd Edition 10. 16 Silberschatz, Galvin and Gagne © 2013

Allocation Methods – Linked (Cont. ) n FAT (File Allocation Table) variation l Beginning

Allocation Methods – Linked (Cont. ) n FAT (File Allocation Table) variation l Beginning of volume has table, indexed by block number l Much like a linked list, but faster on disk and cacheable l New block allocation simple Operating System Concepts Essentials – 2 nd Edition 10. 17 Silberschatz, Galvin and Gagne © 2013

File-Allocation Table Operating System Concepts Essentials – 2 nd Edition 10. 18 Silberschatz, Galvin

File-Allocation Table Operating System Concepts Essentials – 2 nd Edition 10. 18 Silberschatz, Galvin and Gagne © 2013

Allocation Methods - Indexed n Indexed allocation l n Each file has its own

Allocation Methods - Indexed n Indexed allocation l n Each file has its own index block(s) of pointers to its data blocks Logical view Operating System Concepts Essentials – 2 nd Edition 10. 19 Silberschatz, Galvin and Gagne © 2013

Operating System Concepts Essentials – 2 nd Edition 10. 20 Silberschatz, Galvin and Gagne

Operating System Concepts Essentials – 2 nd Edition 10. 20 Silberschatz, Galvin and Gagne © 2013

Operating System Concepts Essentials – 2 nd Edition 10. 21 Silberschatz, Galvin and Gagne

Operating System Concepts Essentials – 2 nd Edition 10. 21 Silberschatz, Galvin and Gagne © 2013

Example of Indexed Allocation Operating System Concepts Essentials – 2 nd Edition 10. 22

Example of Indexed Allocation Operating System Concepts Essentials – 2 nd Edition 10. 22 Silberschatz, Galvin and Gagne © 2013

Performance n Best method depends on file access type l Contiguous great for sequential

Performance n Best method depends on file access type l Contiguous great for sequential and random n Linked good for sequential, not random n Declare access type at creation -> select either contiguous or linked n Indexed more complex l Single block access could require 2 index block reads then data block read l Clustering can help improve throughput, reduce CPU overhead Operating System Concepts Essentials – 2 nd Edition 10. 23 Silberschatz, Galvin and Gagne © 2013

Recovery n Consistency checking – compares data in directory structure with data blocks on

Recovery n Consistency checking – compares data in directory structure with data blocks on disk, and tries to fix inconsistencies l Can be slow and sometimes fails n Use system programs to back up data from disk to another storage device (magnetic tape, other magnetic disk, optical) n Recover lost file or disk by restoring data from backup Operating System Concepts Essentials – 2 nd Edition 10. 24 Silberschatz, Galvin and Gagne © 2013

Log Structured File Systems n Log structured (or journaling) file systems record each metadata

Log Structured File Systems n Log structured (or journaling) file systems record each metadata update to the file system as a transaction n All transactions are written to a log l n A transaction is considered committed once it is written to the log (sequentially) The transactions in the log are asynchronously written to the file system structures l When the file system structures are modified, the transaction is removed from the log n If the file system crashes, all remaining transactions in the log must still be performed n Faster recovery from crash, removes chance of inconsistency of metadata Operating System Concepts Essentials – 2 nd Edition 10. 25 Silberschatz, Galvin and Gagne © 2013