Computer Operating System - Chapter 14: File-System Implementation

File-System Structure
■ File-System Operations
■ Directory Implementation
■ Allocation Methods
■ Free-Space Management
■ Efficiency and Performance
■ Recovery
■ Example: WAFL File System 
pdf 43 trang xuanthi 30/12/2022 2340
Bạn đang xem 20 trang mẫu của tài liệu "Computer Operating System - Chapter 14: File-System Implementation", để tải tài liệu gốc về máy hãy click vào nút Download ở trên.

File đính kèm:

  • pdfcomputer_operating_system_chapter_14_file_system_implementat.pdf

Nội dung text: Computer Operating System - Chapter 14: File-System Implementation

  1. Chapter 14: File-System Implementation ■ File-System Structure ■ File-System Operations ■ Directory Implementation ■ Allocation Methods ■ Free-Space Management ■ Efficiency and Performance ■ Recovery ■ Example: WAFL File System Operating System Concepts 14.2 Silberschatz, Galvin and Gagne ©2018
  2. File-System Structure ■ File structure ● Logical storage unit ● Collection of related information ■ File system resides on secondary storage (e.g., disks) ● Provided user interface to storage, mapping logical to physical ● Provides efficient and convenient access to disk by allowing data to be stored, located, and retrieved easily ■ Disk provides in-place rewrite and random access ● I/O transfers performed in blocks of sectors (usually 512 bytes) ■ File control block (FCB) – storage structure consisting of information about a file ■ Device driver controls the physical device ■ File system is organized into layers Operating System Concepts 14.4 Silberschatz, Galvin and Gagne ©2018
  3. File System Layers ■ Device drivers manage I/O devices at the I/O control layer ● E.g., Given commands like read drive1, cylinder 72, track 2, sector 10, into memory location 1060 outputs low-level hardware specific commands to hardware controller ■ Basic file system given command like retrieve block 123 translates to device driver ● Also manages memory buffers and caches (allocation, freeing, replacement) 4 Buffers hold data in transit 4 Caches hold frequently used data ■ File organization module understands files, logical address, and physical blocks ● Translates logical block # to physical block # ● Manages free space, disk allocation Operating System Concepts 14.6 Silberschatz, Galvin and Gagne ©2018
  4. File-System Implementation ■ We have system calls at the API level, but how do we implement their functions? ● On-disk and in-memory structures ■ Boot control block contains info needed by system to boot OS from that volume ● Needed if volume contains OS, usually first block of volume ■ Volume control block (e.g., superblock, master file table) contains volume details ● Total # of blocks, # of free blocks, block size, free block pointers or array ■ Directory structure organizes the files ● Names and inode numbers, master file table Operating System Concepts 14.8 Silberschatz, Galvin and Gagne ©2018
  5. File-System Implementation (Cont.) ■ Per-file File Control Block (FCB) contains many details about the file ● typically inode number, permissions, size, dates ● NTFS stores into in master file table using relational DB structures Operating System Concepts 14.10 Silberschatz, Galvin and Gagne ©2018
  6. In-Memory File System Structures Operating System Concepts 14.12 Silberschatz, Galvin and Gagne ©2018
  7. Allocation Methods – Contiguous ■ An allocation method refers to how disk blocks are allocated for files ■ Contiguous allocation – each file occupies set of contiguous blocks ● Best performance in most cases ● Simple – only starting location (block #) and length (number of blocks) are required ● Problems include finding space for file, knowing file size, external fragmentation, need for compaction off-line (downtime) or on-line Operating System Concepts 14.14 Silberschatz, Galvin and Gagne ©2018
  8. Extent-Based Systems ■ Many newer file systems (e.g., Veritas File System) use a modified contiguous allocation scheme ■ Extent-based file systems allocate disk blocks in extents ■ 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 14.16 Silberschatz, Galvin and Gagne ©2018
  9. Linked Allocation ■ Each file is a linked list of disk blocks: blocks may be scattered anywhere on the disk block = pointer Q ■ Mapping LA/511 R ● Block to be accessed is the Qth block in the linked chain of blocks representing the file ● Displacement into block = R + 1 Operating System Concepts 14.18 Silberschatz, Galvin and Gagne ©2018
  10. File-Allocation Table (FAT) Operating System Concepts 14.20 Silberschatz, Galvin and Gagne ©2018
  11. Example of Indexed Allocation Operating System Concepts 14.22 Silberschatz, Galvin and Gagne ©2018
  12. Performance ■ Best method depends on file access type ● Contiguous great for sequential and random ■ Linked good for sequential, not random ■ Declare access type at creation –> select either contiguous or linked ■ Indexed more complex ● Single block access could require 2 index block reads, then data block read ● Clustering can help improve throughput, reduce CPU overhead ■ For NVM, no disk head so different algorithms and optimizations needed ● An old algorithm uses many CPU cycles for trying to avoid non-existent head movement ● With NVM goal is to reduce CPU cycles and overall path needed for I/O Operating System Concepts 14.28 Silberschatz, Galvin and Gagne ©2018
  13. Free-Space Management (Cont.) ■ Bit map requires extra space ● Example: block size = 4KB = 212 bytes disk size = 240 bytes (1 terabyte) n = 240/212 = 228 bits (or 32MB) if clusters of 4 blocks -> 8MB of memory ■ Easy to get contiguous files Operating System Concepts 14.31 Silberschatz, Galvin and Gagne ©2018
  14. Free-Space Management (Cont.) ■ Grouping ● Modify linked list to store address of next (n-1) free blocks in first free block, plus a pointer to next block that contains free-block-pointers (like this one) ■ Counting ● Because space is frequently contiguously used and freed, with contiguous-allocation allocation, extents, or clustering 4 Keep address of first free block and count of following free blocks 4 Free space list then has entries containing addresses and counts Operating System Concepts 14.33 Silberschatz, Galvin and Gagne ©2018
  15. TRIMing Unused Blocks ■ HDDs overwrite in place so need only free list ● Blocks not treated specially when freed ● Keeps its data but without any file pointers to it, until overwritten ■ Storage devices not allowing overwrite (e.g., NVM) suffer badly with same algorithm ● Must be erased before written, erases made in large chunks (blocks, composed of pages) and are slow ● TRIM is a newer mechanism for the file system to inform the NVM storage device that a page is free 4 Can be garbage collected or if block is free, now block can be erased Operating System Concepts 14.35 Silberschatz, Galvin and Gagne ©2018
  16. Page Cache ■ A page cache caches pages rather than disk blocks using virtual memory techniques and addresses ■ Memory-mapped I/O uses a page cache ■ Routine I/O through the file system uses the buffer (disk) cache ■ This leads to the following figure Operating System Concepts 14.37 Silberschatz, Galvin and Gagne ©2018
  17. I/O Using a Unified Buffer Cache ■ A unified buffer cache uses the same page cache to cache both memory- mapped pages and ordinary file system I/O to avoid double caching ■ But which caches get priority, and what replacement algorithms to use? Operating System Concepts 14.39 Silberschatz, Galvin and Gagne ©2018
  18. Log Structured File Systems ■ Log structured (or journaling) file systems record each metadata update to the file system as a transaction ● All transactions are written to a log 4 A transaction is considered committed once it is written to the log (sequentially) 4 Sometimes to a separate device or section of disk 4 However, the file system may not yet be updated ● The transactions in the log are asynchronously written to the file system structures ● When the file system structures are modified, the transaction is removed from the log ■ If the file system crashes, all remaining transactions in the log must still be performed ■ Faster recovery from crash, removes chance of inconsistency of metadata Operating System Concepts 14.41 Silberschatz, Galvin and Gagne ©2018
  19. Snapshots in WAFL Operating System Concepts 14.43 Silberschatz, Galvin and Gagne ©2018
  20. Summary ■ Most file systems reside on secondary storage, which is designed to hold a large amount of data permanently. The most common secondary-storage medium is the disk, but the use of NVM devices is increasing. ■ Storage devices are segmented into partitions to control media use and to allow multiple, possibly varying, file systems on a single device. These file systems are mounted onto a logical file system architecture to make them available for use. ■ File systems are often implemented in a layered or modular structure. The lower levels deal with the physical properties of storage devices and communicating with them. Upper levels deal with symbolic file names and logical properties of files. ■ The various files within a file system can be allocated space on the storage device in three ways: through contiguous, linked, or indexed allocation. Contiguous allocation can suffer from external fragmentation. Direct access is very inefficient with linked allocation. Indexed allocation may require substantial overhead for its index block. Operating System Concepts 14.45 Silberschatz, Galvin and Gagne ©2018
  21. Summary (Cont.) ■ A consistency checker can be used to repair damaged file-system structures. Operating-system backup tools allow data to be copied to magnetic tape or other storage devices, enabling the user to recover from data loss or even entire device loss due to hardware failure, operating system bug, or user error. ■ Due to the fundamental role that file systems play in system operation, their performance and reliability are crucial. Techniques such as log structures and caching help improve performance, while log structures and RAID improve reliability. The WAFL file system is an example of optimization of performance to match a specific I/O load. Operating System Concepts 14.47 Silberschatz, Galvin and Gagne ©2018