Chapter 11: File System Implementation. 11.2/27 Chapter 11: File System Implementation Chapter 11:...

27
Chapter 11: File System Chapter 11: File System Implementation Implementation

Transcript of Chapter 11: File System Implementation. 11.2/27 Chapter 11: File System Implementation Chapter 11:...

Page 1: Chapter 11: File System Implementation. 11.2/27 Chapter 11: File System Implementation Chapter 11: File System Implementation File-System Structure File-System.

Chapter 11: File System Chapter 11: File System ImplementationImplementation

Page 2: Chapter 11: File System Implementation. 11.2/27 Chapter 11: File System Implementation Chapter 11: File System Implementation File-System Structure File-System.

11.2/27

Chapter 11: File System ImplementationChapter 11: File System Implementation

File-System Structure

File-System Implementation

Directory Implementation

Allocation Methods

Free-Space Management

Efficiency and Performance

Page 3: Chapter 11: File System Implementation. 11.2/27 Chapter 11: File System Implementation Chapter 11: File System Implementation File-System Structure File-System.

11.3/27

ObjectivesObjectives

To describe the details of implementing local file systems and directory structures

To describe the implementation of remote file systems

To discuss block allocation and free-block algorithms and trade-offs

Page 4: Chapter 11: File System Implementation. 11.2/27 Chapter 11: File System Implementation Chapter 11: File System Implementation File-System Structure File-System.

11.4/27

About diskAbout disk

a convenient medium for storing multiple files:

A disk can be rewritten in place; it is possible to read a block from the disk, modify the block, and write it back into the same place.

A disk can access directly any given block of information it contains. Thus, it is simple to access any file either sequentially or randomly, and switching from one file to another requires only moving the read-write heads and waiting for the disk to rotate.

to improve efficiency I/O transfers between memory and disk are performed in units of blocks. Each block has one or more sectors.

P411

Page 5: Chapter 11: File System Implementation. 11.2/27 Chapter 11: File System Implementation Chapter 11: File System Implementation File-System Structure File-System.

11.5/27

Two different design problems of File systemTwo different design problems of File system

defining how the file system should look to the user.

This task involving defining a file and its attributes, the operations allowed on a file, and the directory structure for organizing files.

Creating algorithms and data structures to map the logical file system onto the physical secondary-storage devices.

P412

Page 6: Chapter 11: File System Implementation. 11.2/27 Chapter 11: File System Implementation Chapter 11: File System Implementation File-System Structure File-System.

11.6/27

Layered File SystemLayered File System

Page 7: Chapter 11: File System Implementation. 11.2/27 Chapter 11: File System Implementation Chapter 11: File System Implementation File-System Structure File-System.

11.7/27

logical file systemlogical file system

manages the directory structure to provide the file organization module with the information the latter needs, given a symbolic file name. It maintains file structure via file-control blocks.

A file-control block (FCB) contains information about the file, including ownership, permissions, and location of the file contents.

The logical file system is also responsible for protection and security.

P413

Page 8: Chapter 11: File System Implementation. 11.2/27 Chapter 11: File System Implementation Chapter 11: File System Implementation File-System Structure File-System.

11.8/27

A Typical File Control BlockA Typical File Control Block

Page 9: Chapter 11: File System Implementation. 11.2/27 Chapter 11: File System Implementation Chapter 11: File System Implementation File-System Structure File-System.

11.9/27

Directory ImplementationDirectory Implementation

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

simple to program

time-consuming to execute

Hash Table – linear list with hash data structure.

decreases directory search time

collisions – situations where two file names hash to the same location

P420

Page 10: Chapter 11: File System Implementation. 11.2/27 Chapter 11: File System Implementation Chapter 11: File System Implementation File-System Structure File-System.

11.10/27

Allocation MethodsAllocation Methods

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

Contiguous allocation

Linked allocation

Indexed allocation

P421

Page 11: Chapter 11: File System Implementation. 11.2/27 Chapter 11: File System Implementation Chapter 11: File System Implementation File-System Structure File-System.

11.11/27

Contiguous AllocationContiguous Allocation

Each file occupies a set of contiguous blocks on the disk

文件目录中存放起始盘块号和块数。 优点:访问容易,速度快 缺点:

分配算法复杂(最先适应、 最优适应) 外碎片问题 必须事先知道文件的长度 , Files cannot grow

P421

Page 12: Chapter 11: File System Implementation. 11.2/27 Chapter 11: File System Implementation Chapter 11: File System Implementation File-System Structure File-System.

11.12/27

Contiguous Allocation of Disk SpaceContiguous Allocation of Disk Space

Page 13: Chapter 11: File System Implementation. 11.2/27 Chapter 11: File System Implementation Chapter 11: File System Implementation File-System Structure File-System.

11.13/27

Linked AllocationLinked Allocation

基本思想:每个文件由磁盘块链表组成,每一个盘块含有指向下一盘块的指针。 Each file is a linked list of disk blocks: blocks may be scattered anywhere on the disk.

文件目录中存放指向第一个盘块和最后一个盘块的指针。 优点:实现了离散分配;无外碎片;文件大小可变。 缺点:只能顺序访问;指针占空间;链断致命。 改进措施 1 :按簇分配 改进措施 2 :链接信息专门存放,形成 FAT ;双 FAT 更安

全。

P423

Page 14: Chapter 11: File System Implementation. 11.2/27 Chapter 11: File System Implementation Chapter 11: File System Implementation File-System Structure File-System.

11.14/27

Linked AllocationLinked Allocation

16

1

10

25

Page 15: Chapter 11: File System Implementation. 11.2/27 Chapter 11: File System Implementation Chapter 11: File System Implementation File-System Structure File-System.

11.15/27

File-Allocation TableFile-Allocation Table

end of file

Page 16: Chapter 11: File System Implementation. 11.2/27 Chapter 11: File System Implementation Chapter 11: File System Implementation File-System Structure File-System.

11.16/27

Indexed AllocationIndexed Allocation

基本思想:为每个文件分配一个索引块,把分配给该文件的所有盘块号,都记录在该索引块中。

优点:支持直接访问;无外碎片。 缺点:浪费空间;索引块的大小问题 管理大文件的改进措施

链接( linked scheme ) 多级索引( Multilevel index ) 组合策略( Combined scheme ) UNIX 采用

P425-426

Page 17: Chapter 11: File System Implementation. 11.2/27 Chapter 11: File System Implementation Chapter 11: File System Implementation File-System Structure File-System.

11.17/27

Example of Indexed AllocationExample of Indexed Allocation

Page 18: Chapter 11: File System Implementation. 11.2/27 Chapter 11: File System Implementation Chapter 11: File System Implementation File-System Structure File-System.

11.18/27

Indexed Allocation – Mapping (Cont.)Indexed Allocation – Mapping (Cont.)

outer-index

index table file

Page 19: Chapter 11: File System Implementation. 11.2/27 Chapter 11: File System Implementation Chapter 11: File System Implementation File-System Structure File-System.

11.19/27

Combined Scheme: UNIX (4K bytes per block)Combined Scheme: UNIX (4K bytes per block)

Page 20: Chapter 11: File System Implementation. 11.2/27 Chapter 11: File System Implementation Chapter 11: File System Implementation File-System Structure File-System.

11.20/27

Free-Space ManagementFree-Space Management

Bit vector (n blocks)

0 1 2 n-1

bit[i] = 0 block[i] free

1 block[i] occupied

For example, consider a disk where blocks 2, 3, 3, 5, 8, 9, 10, 11, 12, 13/ 17,15,25,26, and 27 arc free and the rest of the blocks are allocated. The free-space bit map would be

P429

Page 21: Chapter 11: File System Implementation. 11.2/27 Chapter 11: File System Implementation Chapter 11: File System Implementation File-System Structure File-System.

11.21/27

Free-Space Management (Cont.)Free-Space Management (Cont.)

Bit map requires extra space

Example:

block size = 212 bytes

disk size = 230 bytes (1 gigabyte)

n = 230/212 = 218 bits (or 32K bytes)

Easy to get contiguous files

Page 22: Chapter 11: File System Implementation. 11.2/27 Chapter 11: File System Implementation Chapter 11: File System Implementation File-System Structure File-System.

11.22/27

Free-Space Management (Cont.)Free-Space Management (Cont.)

Linked list (free list)

Cannot get contiguous space easily

No waste of space

P430

Page 23: Chapter 11: File System Implementation. 11.2/27 Chapter 11: File System Implementation Chapter 11: File System Implementation File-System Structure File-System.

11.23/27

Linked Free Space List on DiskLinked Free Space List on Disk

Page 24: Chapter 11: File System Implementation. 11.2/27 Chapter 11: File System Implementation Chapter 11: File System Implementation File-System Structure File-System.

11.24/27

Free-Space Management (Cont.)Free-Space Management (Cont.)

Grouping: store the addresses of n free blocks in the first free block. The first n-1 of these blocks are actually free. The last block contains the addresses of another n free blocks, and so on. The addresses of a large number of free blocks can now be found quickly

Counting: keep the address of the first free block and the number n of free contiguous blocks that follow the first block. Each entry in the free-space list then consists of a disk address and a count.

P431

Page 25: Chapter 11: File System Implementation. 11.2/27 Chapter 11: File System Implementation Chapter 11: File System Implementation File-System Structure File-System.

11.25/27

Efficiency and PerformanceEfficiency and Performance Efficiency dependent on:

disk allocation and directory algorithms

types of data kept in file’s directory entry

Performance

disk cache – separate section of main memory for frequently used blocks

free-behind – removes a page from the buffer as sum as the next page is requested, the previous pages are not likely to be used again and waste buffer space.

read-ahead – a requested page and several subsequent pages are read and cached. These pages are likely to be requested after the current page is processed.

improve PC performance by dedicating section of memory as virtual disk, or RAM disk

P431

Page 26: Chapter 11: File System Implementation. 11.2/27 Chapter 11: File System Implementation Chapter 11: File System Implementation File-System Structure File-System.

11.26/27

RecoveryRecovery

Consistency checking – 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, other magnetic disk, optical)

Recover lost file or disk by restoring data from backup

P435

Page 27: Chapter 11: File System Implementation. 11.2/27 Chapter 11: File System Implementation Chapter 11: File System Implementation File-System Structure File-System.

Homework:1Homework:1 、、 22、、 33、、 44、、 66

End of Chapter 11End of Chapter 11