Overview File system implementation cont 4 Indexed allocation

  • Slides: 19
Download presentation
Overview: File system implementation (cont) 4 Indexed allocation 4 Free space management < Bit

Overview: File system implementation (cont) 4 Indexed allocation 4 Free space management < Bit maps < Linked list 4 Memory mapped files 10/17/2021 CSE 30341: Operating Systems Principles page 1

Indexed Allocation 4 Brings all pointers together into the index block. 4 Logical view.

Indexed Allocation 4 Brings all pointers together into the index block. 4 Logical view. index table 10/17/2021 CSE 30341: Operating Systems Principles page 2

Example of Indexed Allocation 10/17/2021 CSE 30341: Operating Systems Principles page 3

Example of Indexed Allocation 10/17/2021 CSE 30341: Operating Systems Principles page 3

Indexed Allocation (Cont. ) 4 Need index table 4 Random access 4 Dynamic access

Indexed Allocation (Cont. ) 4 Need index table 4 Random access 4 Dynamic access without external fragmentation, but have overhead of index block. 4 Mapping from logical to physical in a file of maximum size of 256 K words and block size of 512 words. We need only 1 block for index table. 10/17/2021 CSE 30341: Operating Systems Principles page 4

Indexed Allocation – Mapping (Cont. ) � outer-index table 10/17/2021 CSE 30341: Operating Systems

Indexed Allocation – Mapping (Cont. ) � outer-index table 10/17/2021 CSE 30341: Operating Systems Principles file page 5

Combined Scheme: UNIX (4 K bytes per block) 10/17/2021 CSE 30341: Operating Systems Principles

Combined Scheme: UNIX (4 K bytes per block) 10/17/2021 CSE 30341: Operating Systems Principles page 6

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

Free-Space Management 4 Bit vector (n blocks) 0 1 2 n-1 ��� … bit[i] = 0 block[i] free 1 block[i] occupied 4 Block number calculation = (number of bits per word) * (number of 0 -value words) + offset of first 1 bit 10/17/2021 CSE 30341: Operating Systems Principles page 7

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

Free-Space Management (Cont. ) 4 Bit map requires extra space < Example: block size = 212 bytes disk size = 238 bytes (256 Gigabyte) n = 238/212 = 226 bits (or 8 Mbytes) 4 Easy to get contiguous files 4 Linked list (free list) < Cannot get contiguous space easily < No waste of space 4 Grouping 4 Counting 10/17/2021 CSE 30341: Operating Systems Principles page 8

Free-Space Management (Cont. ) 4 Need to protect against inconcistency: < Pointer to free

Free-Space Management (Cont. ) 4 Need to protect against inconcistency: < Pointer to free list < Bit map = Must be kept on disk = Copy in memory and disk may differ = Cannot allow for block[i] to have a situation where bit[i] = 1 in memory and bit[i] = 0 on disk < Solution: = Set bit[i] = 1 in disk = Allocate block[i] = Set bit[i] = 1 in memory 10/17/2021 CSE 30341: Operating Systems Principles page 9

Linked Free Space List on Disk 10/17/2021 CSE 30341: Operating Systems Principles page 10

Linked Free Space List on Disk 10/17/2021 CSE 30341: Operating Systems Principles page 10

Efficiency and Performance 4 Efficiency dependent on: < disk allocation and directory algorithms <

Efficiency and Performance 4 Efficiency dependent on: < disk allocation and directory algorithms < types of data kept in file’s directory entry 4 Performance < disk cache – separate section of main memory for frequently used blocks < free-behind and read-ahead – techniques to optimize sequential access < improve PC performance by dedicating section of memory as virtual disk, or RAM disk 10/17/2021 CSE 30341: Operating Systems Principles page 11

Memory-Mapped Files 4 Memory-mapped file I/O allows file I/O to be treated as routine

Memory-Mapped Files 4 Memory-mapped file I/O allows file I/O to be treated as routine memory access by mapping a disk block to a page in memory 4 A file is initially read using demand paging. A pagesized portion of the file is read from the file system into a physical page. Subsequent reads/writes to/from the file are treated as ordinary memory accesses. 4 Simplifies file access by treating file I/O through memory rather than read() write() system calls 4 Also allows several processes to map the same file allowing the pages in memory to be shared 10/17/2021 CSE 30341: Operating Systems Principles page 12

Memory Mapped Files 10/17/2021 CSE 30341: Operating Systems Principles page 13

Memory Mapped Files 10/17/2021 CSE 30341: Operating Systems Principles page 13

Page Cache 4 A page caches pages rather than disk blocks using virtual memory

Page Cache 4 A page caches pages rather than disk blocks using virtual memory techniques 4 Memory-mapped I/O uses a page cache 4 Routine I/O through the file system uses the buffer (disk) cache 4 This leads to the following figure 10/17/2021 CSE 30341: Operating Systems Principles page 14

I/O Without a Unified Buffer Cache 10/17/2021 CSE 30341: Operating Systems Principles page 15

I/O Without a Unified Buffer Cache 10/17/2021 CSE 30341: Operating Systems Principles page 15

Unified Buffer Cache 4 A unified buffer cache uses the same page cache to

Unified Buffer Cache 4 A unified buffer cache uses the same page cache to cache both memory-mapped pages and ordinary file system I/O 10/17/2021 CSE 30341: Operating Systems Principles page 16

I/O Using a Unified Buffer Cache 10/17/2021 CSE 30341: Operating Systems Principles page 17

I/O Using a Unified Buffer Cache 10/17/2021 CSE 30341: Operating Systems Principles page 17

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

Recovery 4 Consistency checking – compares data in directory structure with data blocks on disk, and tries to fix inconsistencies 4 Use system programs to back up data from disk to another storage device (floppy disk, magnetic tape, other magnetic disk, optical) 4 Recover lost file or disk by restoring data from backup 10/17/2021 CSE 30341: Operating Systems Principles page 18

Log Structured File Systems 4 Log structured (or journaling) file systems record each update

Log Structured File Systems 4 Log structured (or journaling) file systems record each update to the file system as a transaction 4 All transactions are written to a log < A transaction is considered committed once it is written to the log < However, the file system may not yet be updated 4 The transactions in the log are asynchronously written to the file system < When the file system is modified, the transaction is removed from the log 4 If the file system crashes, all remaining transactions in the log must still be performed 10/17/2021 CSE 30341: Operating Systems Principles page 19