Chapter 11 File System Implementation Operating System Concepts

  • Slides: 35
Download presentation
Chapter 11: File System Implementation Operating System Concepts – 8 th Edition, Silberschatz, Galvin

Chapter 11: File System Implementation Operating System Concepts – 8 th Edition, Silberschatz, Galvin and Gagne © 2009

Chapter 11: File System Implementation n File System Structure n File System Implementation n

Chapter 11: File System Implementation n File System Structure n File System Implementation n Directory Implementation n Allocation Methods n Free-Space Management n Efficiency and Performance n Recovery n Log-Structured File Systems Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne © 2009

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

File-System Structure n File structure l Logical storage unit l Collection of related information n File system resides on secondary storage (disks) n File system organized into layers n File control block – storage structure consisting of information about a file Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne © 2009

Layered File System Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne

Layered File System Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne © 2009

Layered File System Summary n I/O control – device drivers & interrupt handlers n

Layered File System Summary n I/O control – device drivers & interrupt handlers n Basic File System – issues command to device driver to read/write physical blocks (uses numeric disk address: drive 1, cyl 73, track 2, sector 10) n File-Organization Module – translates logical block address to physical block address, manages free-space n Logical File System – Manages the “metadata” – information relating to the file-system structure via FCBs Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne © 2009

Overview n On- Disk structures l Boot control block – information needed to boot

Overview n On- Disk structures l Boot control block – information needed to boot the system l Partition control block – contains partition details – number of blocks in partition, size of block, free- block data l Directory structure – contains data about organization of files l FCBs – actual file data n In-Memory structures l Partition table – information about mounted partitions l Directory structure – recently accessed directories l System-wide open-file table – FCB of open file l Per-process open-file table – pointer to system-wide openfile table’s entry … (index is returned from open( )) Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne © 2009

A Typical File Control Block Operating System Concepts – 8 th Edition Silberschatz, Galvin

A Typical File Control Block Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne © 2009

In-Memory File System Structures n The following figure illustrates the necessary file system structures

In-Memory File System Structures n The following figure illustrates the necessary file system structures provided by the operating systems. n Figure 12 -3(a) refers to opening a file. n Figure 12 -3(b) refers to reading a file. Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne © 2009

In-Memory File System Structures Operating System Concepts – 8 th Edition Silberschatz, Galvin and

In-Memory File System Structures Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne © 2009

Directory Entry Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne ©

Directory Entry Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne © 2009

Example of a File lookup Operating System Concepts – 8 th Edition Silberschatz, Galvin

Example of a File lookup Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne © 2009

Directory Implementation n Linear list of file names with pointer to the data blocks.

Directory Implementation n Linear list of file names with pointer to the data blocks. l simple to program l time-consuming to execute n Hash Table – linear list with hash data structure. l decreases directory search time l collisions – situations where two file names hash to the same location l fixed size – difficult to change size of directory- must change hash function and reorganize all entries Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne © 2009

Allocation Methods An allocation method refers to how disk blocks are allocated for files:

Allocation Methods An allocation method refers to how disk blocks are allocated for files: n Contiguous allocation n Linked allocation n Indexed allocation Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne © 2009

Contiguous Allocation n Each file occupies a set of contiguous blocks on the disk.

Contiguous Allocation n Each file occupies a set of contiguous blocks on the disk. Advantages n Simple – only starting location (block #) and length (number of blocks) are required. n Entire file can be read from disk in one operation n Random access. Disadvantages n Need to know maximum size at creation n Extreme fragmentation until reaches fullsize n Files cannot grow – size may be underestimated n Placement strategies – first fit/best fit Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne © 2009

Contiguous Allocation of Disk Space Operating System Concepts – 8 th Edition Silberschatz, Galvin

Contiguous Allocation of Disk Space Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne © 2009

Extent-Based Systems n Many newer file systems (I. e. Veritas File System) use a

Extent-Based Systems n Many newer file systems (I. e. Veritas File System) use a modified contiguous allocation scheme. n Extent-based file systems allocate disk blocks in extents. n An extent is a contiguous block of disks. Extents are allocated for file allocation. A file consists of one or more extents. Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne © 2009

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

Linked Allocation n Each file is a linked list of disk blocks: blocks may be scattered anywhere on the disk. block Operating System Concepts – 8 th Edition = pointer Silberschatz, Galvin and Gagne © 2009

Linked Allocation (Cont. ) Advantages n Simple – need only starting address n Free-space

Linked Allocation (Cont. ) Advantages n Simple – need only starting address n Free-space management system – no waste of space n Fragmentation only in last block Disadvantages n No random access n If one block goes bad – lose entire file n Pointer is substantial overhead Alternative: collect blocks into clusters and allocate clusters – pointers use much smaller percentage of disk space Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne © 2009

Linked Allocation Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne ©

Linked Allocation Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne © 2009

Linked using Index n Remove pointer from data block and store pointer in a

Linked using Index n Remove pointer from data block and store pointer in a table Advantages n Speed up random access n Lookup can be done in memory Disadvantages n Tables needs to be in memory n Small blocks create large tables Example: File Allocation Table – Index set aside at start of disk partition. Indexed by physical blocks (0 indicates free block). Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne © 2009

File-Allocation Table Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne ©

File-Allocation Table Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne © 2009

Indexed Allocation n Brings all pointers together into the index block. The ith index

Indexed Allocation n Brings all pointers together into the index block. The ith index indicates physical address of ith block n Logical view. index table Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne © 2009

Example of Indexed Allocation Operating System Concepts – 8 th Edition Silberschatz, Galvin and

Example of Indexed Allocation Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne © 2009

Indexed Allocation (Cont. ) Advantages n Random access is simple and fast n Files

Indexed Allocation (Cont. ) Advantages n Random access is simple and fast n Files can grow – add entry to index Disadvantages n Index table has fragmentation n Random access How large should the index block be? How should we index large files? n Linked scheme – link several indexes together n Multilevel index – use first level to point to next level n Combine – UNIX inode scheme Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne © 2009

Indexed Allocation – Multilevel outer-index table Operating System Concepts – 8 th Edition file

Indexed Allocation – Multilevel outer-index table Operating System Concepts – 8 th Edition file Silberschatz, Galvin and Gagne © 2009

Combined Scheme: UNIX Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne

Combined Scheme: UNIX Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne © 2009

Free-Space Management Bit vector (n blocks) 0 1 2 n-1 … bit[i] = 0

Free-Space Management Bit vector (n blocks) 0 1 2 n-1 … bit[i] = 0 block[i] free 1 block[i] occupied Block number calculation (number of bits per word) * (number of 0 -value words) + offset of first 1 bit Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne © 2009

Free-Space Management (Cont. ) n Bit map requires extra space. Example: block size =

Free-Space Management (Cont. ) n Bit map requires extra space. Example: block size = 212 bytes disk size = 230 bytes (1 gigabyte) n = 230/212 = 218 bits (or 32 K bytes) n Easy to get contiguous files Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne © 2009

Free-Space Management (Cont. ) Linked list (free list) - free list head pointer points

Free-Space Management (Cont. ) Linked list (free list) - free list head pointer points to first free block. l Cannot get contiguous space easily l No waste of space – only one pointer to keep in memory Allocation – remove block on front of list, change head pointer to next block Adding free block – add to front of list Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne © 2009

Linked Free Space List on Disk Operating System Concepts – 8 th Edition Silberschatz,

Linked Free Space List on Disk Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne © 2009

Free-Space Management (Cont. ) Grouping – Use first free block to store the next

Free-Space Management (Cont. ) Grouping – Use first free block to store the next n free block addresses. At end of this block point to n+1 block which contains the next n free blocks. Only one block needs to be stored in memory. l Allocation – delete first entry in first block l Adding to free list – add entry to first available spot in block (may need to go to next block) Counting – If blocks are allocated contiguously – store address of start block and number of free blocks in the same format as grouping Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne © 2009

Free-Space Management (Cont. ) n Need to protect: l Pointer to free list l

Free-Space Management (Cont. ) n Need to protect: l Pointer to free list l Bit map 4 Must be kept on disk 4 Copy in memory and disk may differ. 4 Cannot allow for block[i] to have a situation where bit[i] = 1 in memory and bit[i] = 0 on disk. l Solution: 4 Set bit[i] = 1 in disk. 4 Allocate 4 Set block[i] bit[i] = 1 in memory Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne © 2009

Efficiency and Performance n Efficiency dependent on: l disk allocation and directory algorithms l

Efficiency and Performance n Efficiency dependent on: l disk allocation and directory algorithms l types of data kept in file’s directory entry n Performance l disk cache – separate section of main memory for frequently used blocks l free-behind and read-ahead – techniques to optimize sequential access l improve PC performance by dedicating section of memory as virtual disk, or RAM disk. Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne © 2009

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. n Use system programs to back up data from disk to another storage device (floppy disk, magnetic tape). n Recover lost file or disk by restoring data from backup. Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne © 2009

End of Chapter 11 Operating System Concepts – 8 th Edition, Silberschatz, Galvin and

End of Chapter 11 Operating System Concepts – 8 th Edition, Silberschatz, Galvin and Gagne © 2009