1
Free Space Management
Bit Vector
2
Simple and efficient to find the first free block, or consecutive free blocks◦ By bit-manipulation
Requires extra space◦ block size = 212 bytes◦ disk size = 230 bytes◦ n = 230/212 = 218 bits (or
32K bytes) Efficient only when the
entire vector is kept in main memory◦ Write back to the disk
occasionally for recovery needs
001111001111100011000011100…
…0 1 2 n-1
bit[i] = 0 block[i] free
1 block[i] occupied
Question: What’s the block # of the fist free block?
Linked List
3
Link together all free blocksKeep a pointer to the first free block in a
special location on the disk and caching it in memory
Cannot get contiguous space easilyNo waste of spaceNot efficient: have to traverse the disk for
free spaces◦ Usually, OS needs one free block at a time
FAT incorporate the linked list mechanism
Grouping And Counting
4
Grouping: store the address of n free blocks in the first free block. The first n-1 are actually free. The final block contains the addresses of another n free blocks…
Counting: Each entry has a disk address and a countSeveral contiguous blocks may be allocated
or freed simultaneously
Example Of Free-Space Management
5
Bit Vector 11000011000000111001111110001111
Counting 2 4 8 6 17 2 25 3
Grouping Block 2 3, 4, 5 Block 5 8, 9, 10 Block 10 11, 12, 13 Block 13 17, 28, 25 Block 25 26, 27
6
Efficiency and Performance
Efficiency and Performance
7
Efficiency dependent on◦ Disk allocation and directory algorithms◦ Types of data kept in file’s directory entry
Performance◦ On-board cache – local memory in disk controller to
store entire tracks at a time◦ Disk cache – separate section of main memory for
frequently used blocks (LRU is a reasonable algorithm for block replacement)
◦ Free-behind and read-ahead – techniques to optimize sequential access (optimize the disk cache’s block replacement algorithm)
◦ Improve PC performance by dedicating section of memory as virtual disk, or RAM disk.
Various Disk-Caching Locations
8
Page Cache
9
Non-unified buffer cache◦ A page cache caches pages rather than disk
blocks using virtual memory techniques◦ Memory-mapped I/O uses a page cache◦ Routine I/O through the file system uses the
buffer (disk) cacheUnified Buffer Cache
◦ A unified buffer cache uses the same buffer cache to cache both memory-mapped pages and ordinary file system I/O
I/O Without/With A Unified Buffer Cache
10
Recovery
11
Consistency checker – compares data in directory structure with data blocks on disk, and tries to fix inconsistencies
Use system programs to back up data from disk to another storage device (floppy disk, magnetic tape)
Recover lost file or disk by restoring data from backup
Log Structured File Systems
12
Log structured (or journaling) file systems record each update to the file system as a transaction
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 updatedThe transactions in the log are asynchronously
written to the file system. When the file system is modified, the transaction is removed from the log
If the file system crashes, all remaining transactions in the log must still be performed