40
File System Implementation Sunu Wibirama Thursday, December 16, 2010

File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

  • Upload
    letuong

  • View
    230

  • Download
    0

Embed Size (px)

Citation preview

Page 1: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

File System ImplementationSunu Wibirama

Thursday, December 16, 2010

Page 2: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

11.

Outline File-System Structure

File-System Implementation

Directory Implementation

Allocation Methods

Free-Space Management

Discussion

Thursday, December 16, 2010

Page 3: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

11.

File System Structure File system is provided by OS to allow the data to be

stored, located, and retrieved easily Two problems on file system design:

How the file system should look to the user Algorithms and data structures to map logical file

system onto the physical secondary-storage devices

File system organized into layers, uses features from lower levels to create new features for use by higher levels.

I/O Control controls the physical device using device driver

Basic file system needs only to issue generic commands to the device driver to read and write physical block on the disk (ex. drive 1, cylinder 73, track 2, sector 11)

Thursday, December 16, 2010

Page 4: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

11.

File System Implementation

File organization module knows physical and logical blocks, translating logical block address to physical block address. It also manages free-space on the disk

Logical file system manages metadata information (all file system structure except the actual data or contents of the file).

Logical file system maintains file structure via file-control blocks (FCB)

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

Thursday, December 16, 2010

Page 5: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

11.

A Typical File Control Block

Thursday, December 16, 2010

Page 6: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

11.

On-Disk File System Structures

Boot control block contains info needed by system to boot OS from that volume (UNIX: boot block, NTFS: partition boot sector)

Volume control block contains volume details (UNIX: superblock, NTFS: master file table)

Directory structure organizes the files (UNIX: inode numbers, NTFS: master file table)

Per-file File Control Block (FCB) contains many details about the file

Thursday, December 16, 2010

Page 7: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

11.

In-Memory File System Structures

It is used for file-system management and performance improvement (via caching).

The data are loaded at mount time and discarded at dismount.

The structures including: In-memory mount table: information of each mounted

volume In-memory directory structureSystem-wide open-file table: a copy of FCB of each open

filePer-process open-file table: a pointer to the appropriate

entry in the system-wide open-file table, as well as other information based on process that uses the file.

Thursday, December 16, 2010

Page 8: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

11.

New File Creation Process

Application program calls the logical file system

Logical file system knows the directory structures. It allocates a new FCB.

The system then reads the appropriate directory into memory, updates it with the new file name and FCB, and writes it back to the disk.

Now, the new created file can be used for I/O operation, which will be explained in the next slide

Thursday, December 16, 2010

Page 9: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

11.

In-Memory File System Structures

Thursday, December 16, 2010

Page 10: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

11.

Directory Implementation

Directory-allocation and directory-management algorithms significantly affects the efficiency, performance, and reliability of the file system.

Linear list of file names with pointer to the data blocks. simple to program time-consuming to execute, because it requires a

linear search to create or delete file.

Hash Table – linear list with hash data structure. decreases directory search time problem: fixed size of hash table

Thursday, December 16, 2010

Page 11: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

11.

Allocation Methods

Many files are stored in the disk

How to allocate space to these files so that disk space is utilized effectively and files can be accessed quickly

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

Contiguous allocation

Linked allocation

Indexed allocation

Thursday, December 16, 2010

Page 12: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

11.

Contiguous Allocation

Each file occupies a set of contiguous blocks on the disk Simple – only starting location (block #) and length (number of blocks)

are required Both sequential and direct access are supported Disadvantages:

Wasteful of space (dynamic storage-allocation problem) File cannot grow External fragmentation: free space is broken into chunks

One of several solutions: 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

Thursday, December 16, 2010

Page 13: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

11.

Contiguous Allocation of Disk Space

Thursday, December 16, 2010

Page 14: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

11.

Linked Allocation

Linked allocation solves all problems of contiguous allocation

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

Ex: File “Jeep” Start at block 9 Then: block 16, 1, 10 Finally end at block 25

pointer (4 bytes)

1 block (512 bytes) 508 bytes

visible part to user

Thursday, December 16, 2010

Page 15: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

11.

Linked Allocation

Advantages: Free-space management system – no waste of space File can grow, depends on available free blocks

Disadvantages: No random access (only sequential access) Space required for pointers (0.78 percent of the disk is being used for pointers, rather

than for information) ~> solution, uses clusters (unit of blocks) Reliability, pointer damage will cause unlinked blocks in a file.

FAT (File Allocation Table): variation on linked allocation Located at the beginning of each volume

Thursday, December 16, 2010

Page 16: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

11.

File-Allocation Table

To do random access: 1. The disk head move to the start of volumeto read the FAT2. Find the location of the desired block3. Move to the location of the block itself

Thursday, December 16, 2010

Page 17: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

11.

Indexed Allocation Brings all pointers together into the

index block Each file has its own index block, which

is an array of disk-block addresses Directory contains the address of index

block Support direct access without external

fragmentation Each file has its allocation for all

pointers, so that it has wasted space greater than linked allocation (which contains one pointer per block).

We want the index block as small as possible, then we have several mechanisms: 1. Linked scheme2. Multilevel index3. Combined scheme

Thursday, December 16, 2010

Page 18: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

11.

Indexed Allocation

Linked Scheme An index block is normally one disk block Large files -> we can link together several index blocks Ex.: an index block contains:

- a small header of file name- a set of 100 disk-block addresses- nil (for small file) or a pointer to another index block (for a large file)

Multilevel index First-level index block points to second-level index blocks which in turn point to the

file blocks (see next slide) Combined scheme

In unix, for example: 15 pointers in fileʼs inode 12 first pointer: direct blocks, for small file (no more than 12 blocks). If the block

size is 4KB, then up to 48KB (12 x 4KB) can be accessed directly The next pointers point to indirect blocks, which implement multilevel index based

on their sequence (see next two slide)

Thursday, December 16, 2010

Page 19: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

11.

Multilevel Index

1st-level index block

2nd-level index block file

Back to Indexed Allocation

Thursday, December 16, 2010

Page 20: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

11.

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

Back to Indexed Allocation

Thursday, December 16, 2010

Page 21: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

11.

Free-Space Management Free-space list concept 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

Bit vector requires extra space. Example:" " block size = 212 bytes" " disk size = 230 bytes (1 gigabyte)" " n (amount of bits) = 230/212 = 218 bits (or 32K bytes)

Thursday, December 16, 2010

Page 22: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

11.

Free-Space Management Linked list

Link together all the free disk blocks Keeping a pointer to the first free block in a

special location on the disk and caching it in memory.

The first block contains a pointer to the next free disk block...

Must read each block to traverse list, increase I/O operation time.

Grouping Storing the address of n blocks in the first free

block. n-1 blocks are actually free blocks but the last

block contains the addresses of another n free blocks.

Counting Keep the address of the first free block and n of

free contiguous blocks that follow the first block. Each entry in free-space list consists of disk

address and a count

Thursday, December 16, 2010

Page 23: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

::DiscussionThursday, December 16, 2010

Page 24: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

FAT 32

•FAT - 32 (File Allocation Table - 32 bits)

•Maximum size of file: 232 - 1 byte

•The last byte cannot be allocated to the file so that no file has file size bigger than 0 x FFFFFFFF (4, 294, 967, 296)

•You can convert to NTFS, or split your file. Each method has its advantages and disadvantages.

Thursday, December 16, 2010

Page 25: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

Fragmentation

http://en.wikipedia.org/wiki/Defragmentation

Thursday, December 16, 2010

Page 26: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

Why Linux rarely needs defragmentation tools?

• Does fragmentation occur in Linux? Yes, but in very small quantity

• Block Groups: group file-data together in ‘clumps’ to manage small and large file (remember combined scheme in indexed allocation)

• Only write files to unused portion of the disk that are not predictably being fragmented in shorter time.

Thursday, December 16, 2010

Page 27: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

Combined Scheme

Possible to allocate bigger blocks for a file

Thursday, December 16, 2010

Page 28: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

Unix System• Keep fragmentation level below 20%

• More than 20%? You certainly need to fix your hard disk using shake-fs

• Run : e2fsck -nv /dev/sda1 as root, resulting:

Fragmented Part

Thursday, December 16, 2010

Page 30: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

Start with FAT file system....

Thursday, December 16, 2010

Page 31: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

Start with FAT file system....

I have hello.txt

Thursday, December 16, 2010

Page 32: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

Start with FAT file system....

I have hello.txt

OK, now add bye.txt

Thursday, December 16, 2010

Page 33: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

Start with FAT file system....

I have hello.txt

OK, now add bye.txt

I want to change hello.txt, dude...?

Thursday, December 16, 2010

Page 34: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

Thursday, December 16, 2010

Page 35: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

Just copy, delete the original content, and wrap it up in the

larger space.....

1st approach

Thursday, December 16, 2010

Page 36: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

Just copy, delete the original content, and wrap it up in the

larger space.....

Or, Put your extended file content to

the next space.....

If the first approach requires huge read and write operation, then the most possible approach is the second one. That’s why FAT

suffers from large fragmentation

1st approach

2nd approach

Thursday, December 16, 2010

Page 37: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

Initial condition

What About Linux?

Thursday, December 16, 2010

Page 38: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

What About Linux?

Add bye.txt

Thursday, December 16, 2010

Page 39: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

Change hello.txt

What About Linux?

Thursday, December 16, 2010

Page 40: File System Implementation - Gadjah Mada Universityte.ugm.ac.id/~wibirama/tif206/01/ch12/ch12-presentation.pdf · File-System Implementation ... NTFS: master file table) Per-file

Thank You

Thursday, December 16, 2010