1 free space management. bit vector 2 simple and efficient to find the first free block, or...

12
1 Free Space Management

Upload: jody-lang

Post on 05-Jan-2016

214 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: 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

1

Free Space Management

Page 2: 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

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?

Page 3: 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

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

Page 4: 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

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

Page 5: 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

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

Page 6: 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

6

Efficiency and Performance

Page 7: 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

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.

Page 8: 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

Various Disk-Caching Locations

8

Page 9: 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

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

Page 10: 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

I/O Without/With A Unified Buffer Cache

10

Page 11: 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

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

Page 12: 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

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