Ch11

32
Chapter 11: File System Chapter 11: File System Implementation Implementation

Transcript of Ch11

Page 1: Ch11

Chapter 11: File System Chapter 11: File System ImplementationImplementation

Page 2: Ch11

11.2 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 1, 2005

File-System StructureFile-System Structure

File structure

Logical storage unit

Collection of related information

File system resides on secondary storage (disks)

File system organized into layers

File control block – storage structure consisting of information about a file

Page 3: Ch11

11.3 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 1, 2005

Layered File SystemLayered File System

Page 4: Ch11

11.4 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 1, 2005

A Typical File Control BlockA Typical File Control Block

Page 5: Ch11

11.5 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 1, 2005

File System Implementation File System Implementation

On-disk structures

A boot controller block (per volume), contains information needed to boot an OS (in NTFS is called boot sector).

A volume controller block (per volume), contains partition details such as number of blocks, size of blocks, etc. (in NTFS is called master file table).

A directory structure per file system (in NTFS is called master file table).

A per-file FCB, in Unix called inode, in NTFS information is stored in master file table (i.e. DB).

Page 6: Ch11

11.6 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 1, 2005

File System Implementation File System Implementation

In memory structures

An In memory mount table for each mounted volume.

An In memory directory-structure cache (holds the directory info. Of recently accessed directories.

The system-wide open file table, contains a copy of FCB of each open file.

The per-process open file table, contains a pointer to an entry in system-wide table.

Page 7: Ch11

11.7 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 1, 2005

In-Memory File System StructuresIn-Memory File System Structures

Page 8: Ch11

11.8 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 1, 2005

Partitions and mountingPartitions and mounting

Cooked disk, contains file system. Raw disk, no file system (in UNIX it is used for swap space).

Root partition (which contains the OS kernel) is mounted at boot time.

Mount table keeps track of mounted file systems by using pointers to blocks: In windows, file systems are mounted in drive

letters. Each volume is a separate name space denoted by a letter and a colon.

In UNIX, file systems are mounted as directories.

Page 9: Ch11

11.9 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 1, 2005

Virtual File SystemsVirtual File Systems

There are many different file systems available on any operating systems Windows: NTFS, FAT, FAT32 Linux: ext2/ext3, ufs, vfat, ramfs, tmpfs, reiserfs, xfs ...

Virtual File Systems (VFS) provide an object-oriented way of implementing file systems.

VFS allows the same system call interface (the API) to be used for different types of file systems.

The API is to the VFS interface, rather than any specific type of file system.

Page 10: Ch11

11.10 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 1, 2005

Schematic View of Virtual File SystemSchematic View of Virtual File System

Page 11: Ch11

11.11 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 1, 2005

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

fixed size

Page 12: Ch11

11.12 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 1, 2005

Allocation MethodsAllocation Methods

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

Contiguous allocation

Linked allocation

Indexed allocation

Page 13: Ch11

11.13 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 1, 2005

Contiguous AllocationContiguous Allocation

Each file occupies a set of contiguous blocks on the disk

Simple – only starting location (block #) and length (number of blocks) are required

Random access

Wasteful of space (dynamic storage-allocation problem)

Files cannot grow

Page 14: Ch11

11.14 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 1, 2005

Contiguous Allocation of Disk SpaceContiguous Allocation of Disk Space

Page 15: Ch11

11.15 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 1, 2005

Extent-Based SystemsExtent-Based Systems

Many newer file systems (I.e. 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.

Page 16: Ch11

11.16 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 1, 2005

Linked AllocationLinked Allocation

Each file is a linked list of disk blocks: blocks may be scattered anywhere on the disk.

pointerblock =

•Simple – need only starting address•Free-space management system – no waste of space •No random access

Page 17: Ch11

11.17 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 1, 2005

Linked AllocationLinked Allocation

Page 18: Ch11

11.18 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 1, 2005

File-Allocation TableFile-Allocation Table

Page 19: Ch11

11.19 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 1, 2005

Indexed AllocationIndexed Allocation

Brings all pointers together into the index block.

Logical view.

index table

Page 20: Ch11

11.20 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 1, 2005

Example of Indexed AllocationExample of Indexed Allocation

Page 21: Ch11

11.21 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 1, 2005

Indexed Allocation (Cont.)Indexed Allocation (Cont.)

Need index table Random access Dynamic access without external fragmentation, but have

overhead of index block. Mapping from logical to physical in a file of maximum size

of 256K words and block size of 512 words. We need only 1 block for index table.

Page 22: Ch11

11.22 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 1, 2005

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

outer-index

index table file

Page 23: Ch11

11.23 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 1, 2005

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

Page 24: Ch11

11.24 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 1, 2005

Free-Space ManagementFree-Space Management

Bit vector (n blocks)

0 1 2 n-1

bit[i] = 0 block[i] free

1 block[i] occupied

Block number calculation =

(number of bits per word) *(number of 0-value words) +offset of first 1 bit

Page 25: Ch11

11.25 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 1, 2005

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

Linked list (free list)

Cannot get contiguous space easily

No waste of space

Grouping

Counting

Page 26: Ch11

11.26 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 1, 2005

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

Need to protect: 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

Page 27: Ch11

11.27 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 1, 2005

Linked Free Space List on DiskLinked Free Space List on Disk

Page 28: Ch11

11.28 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 1, 2005

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 and read-ahead – techniques to optimize sequential access

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

Page 29: Ch11

11.29 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 1, 2005

Page CachePage 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) cache

This leads to the following figure

Page 30: Ch11

11.30 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 1, 2005

I/O Without a Unified Buffer CacheI/O Without a Unified Buffer Cache

Page 31: Ch11

11.31 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 1, 2005

Unified Buffer CacheUnified Buffer Cache

A unified buffer cache uses the same page cache to cache both memory-mapped pages and ordinary file system I/O

Page 32: Ch11

11.32 Silberschatz, Galvin and Gagne ©2005Operating System Concepts – 7th Edition, Jan 1, 2005

I/O Using a Unified Buffer CacheI/O Using a Unified Buffer Cache