part iiipart iii storage managementshene/forum/taiwan-forum/... · infooo.rmation. a disk may...

27
Part III Part III Storage Management Chapter 11: File System Implementation Storage Management Chapter 11: File System Implementation 1 Fall 2010

Upload: others

Post on 31-Jan-2021

1 views

Category:

Documents


0 download

TRANSCRIPT

  • Part IIIPart IIIStorage Management

    Chapter 11: File System ImplementationStorage Management

    Chapter 11: File System Implementation

    1Fall 2010

  • LayeredLayered File System

    2

  • Overview: 1/4A file system has on-disk and in-memoryinformation.o o .A disk may contain the following for implementing a file system on it:

    A boot control block per volumeA volume control block per volumeA di t t t fil tA directory structure per file systemA file control block (FCB) per file

    In-memory information includeIn-memory information includeAn in-memory mounted table has info for each mounted volumeAn in-memory directory structureThe system-wide open-file tableThe per process open file table

    3

    The per-process open-file tableBuffers hold file-system blocks

  • Overview: 2/4Overview: 2/4

    A FCB fil t lA FCB, file control block, contains the d t il f filfile permission

    a typical file control block FCB

    details of a file.In Unix, a FCB is

    file permission

    file date

    called an i-node.file owner, group, ACL

    file size

    file data blocks

    4

  • Overview: 3/4Overview: 3/4kernel memory disk memory

    3: read the directory4: update FCB and directory

    user programe e e o y d s e o y

    open(filename) directory structuredirectory structure

    FCB1: create a new file

    5 fil d i /fil h dl5

    2: allocate a new FCB

    5: a file descriptor/file handleis returned

  • Overview: 4/4Overview: 4/4kernel memory disk memory

    index

    user programe e e o y d s e o y

    per-processopen-file table

    Data blocks

    read(index)

    Data blocks

    system-wideopen-file tablep

    FCB

    6

  • Directory ImplementationDirectory Implementation

    A Fil di t i ll i l t dA File directory is usually implemented as a linked-list, a tree (e.g., B-tree), a hash table

    ith h i i th bi ti f b thwith chaining, or the combination of both.The problem with the linked-list approach is its poor performance in searching for a file. Directory search is performed very frequently. The hash table approach speeds up search; however, we must deal with the problem of pcollisions. Thus, chaining is necessary.

    7

  • Directory Entries: 1/2Directory Entries: 1/2A directory is just a file!A directory is just a file!A directory entry may be very simple like the one used by MS DOS Or it may be quiteone used by MS-DOS. Or, it may be quite complex like the Unix i-node.

    O 98

    extended MS-DOS directory entry used in Windows 98

  • Directory Entries: 2/2

    find /usr/ast/mboxUnix directory entry

    find /usr/ast/mbox

    9

  • File Allocation Methods

    There are three typical file space allocation h dmethods:

    Contiguous AllocationLinked AllocationIndexed AllocationIndexed Allocation

    10

  • C ti All ti 1/3Contiguous Allocation: 1/3

    With th ti ll ti th dWith the contiguous allocation method, a user must indicate the file size before creating a file.Then, the operating system searches the disk to find contiguous disk blocks for the file.The directory entry is easy. It contains the initial disk address of this file and the number of disk blocks.Therefore, if the initial address is b and theTherefore, if the initial address is b and the number of blocks is n, the file will occupy blocks b, b+1, b+2, …, b+n-1.

    11

    b 1, b 2, …, b n 1.

  • Contiguous Allocation: 2/3

    directorydirectory

    Since blocks are allocatedcontiguously, externalg y,fragmentation may occur.Thus, compaction may be

    12needed.

  • Contiguous Allocation: 3/3Contiguous Allocation: 3/3Contiguous allocation is easy to implementContiguous allocation is easy to implement.Its disadvantages are

    It can be considered as a form of dynamic memory allocation, and external fragmentation may occur and compaction may be needed.It is difficult to estimate the file size. The size of a file may grow at run time and may be larger than the specified number of allocated blocks. pIn this case, the OS must move the blocks in order to provide more space. In some systems,

    13

    p p ythis is simply an error.

  • Li k d All ti 1/3Linked Allocation: 1/3With th li k d ll ti h di kWith the linked allocation approach, disk blocks of a file are chained together with a li k d li tlinked-list.The directory entry of a file contains a pointer to the first block and a pointer to the last block.To create a file, we create a new directory entry y yand the pointers are initialized to nil.When a write occurs, a new disk block isWhen a write occurs, a new disk block is allocated and appended to the end of the list.

    14

  • Linked Allocation: 2/3Linked Allocation: 2/3

    28 Last Block

    directoryFile Name Start End

    ………… …….. ……..Last Block………… …….. ……..B 1 28

    File blocks are chained into a linked-list.linked list.The directory entry has pointers to the first and last file blocksto the first and last file blocks.Append is difficult to do without th E d i t

    15the End pointer.

  • Linked Allocation: 3/3Linked Allocation: 3/3Advantages:Advantages:

    File size does not have to be specified.No external fragmentationNo external fragmentation.

    Disadvantages:It s pports seq ential access efficientl and isIt supports sequential access efficiently, and is not for direct accessEach block contains a pointer asting spaceEach block contains a pointer, wasting spaceBlocks scatter everywhere and a large number of disk seeks may be necessaryof disk seeks may be necessaryReliability: what if a pointer is lost or damaged?

    16

  • File Allocation Table (FAT)File Allocation Table (FAT)This is a variation of the0

    FATThis is a variation of the linked allocation by pulling all pointers into a t bl th fil ll ti

    0

    table, the file allocation table (FAT).The left diagram shows

    217 618

    testdirectory

    The left diagram shows file test has its first block at 217, followed by 618 339 ( d f fil )

    339 end-of-file

    618, 339 (end of file).Large no. of disk seeks.Can do direct access

    339618217

    Can do direct access.FAT needs space.What if FAT is damaged?f bl k 1

    17

    What if FAT is damaged? We all know it well!

    no. of blocks-1

  • Indexed Allocation: 1/4Indexed Allocation: 1/4Each file has an index block that is an array ofEach file has an index block that is an array of disk block addresses.Th i th t i th i d bl k i t t th i thThe i-th entry in the index block points to the i-th block of the file.A file’s directory entry contains a pointer to its index. Hence, the index block of an indexed allocation plays the same role as a page table does.Index allocation supports both sequential and pp qdirect access without external fragmentation.

    18

  • Indexed Allocation: 2/4Indexed Allocation: 2/4

    directory

    index block

    19

  • Indexed Allocation: 3/4Indexed Allocation: 3/4

    Th i d d ll ti ff f t dThe indexed allocation suffers from wasted space. The index block may not be fully used (i.e., internal f t ti )fragmentation).The number of entries of an index table determines the size of a file. To overcome this problem, we may

    Have multiple index blocks and chain them into pa linked-listHave multiple index blocks, but make them aHave multiple index blocks, but make them a tree just like the indexed access methodA combination of both

    20

    A combination of both

  • Indexed Allocation: 4/4

    256 entries per index table.What is the maximum size of a file?

    21

  • Free Space ManagementFree Space Management

    How do we keep track free blocks on a disk?How do we keep track free blocks on a disk?A free-list is maintained. When a new block is

    t d h thi li t t fi drequested, we search this list to find one.The following are commonly used techniques:

    Bit VectorLinked ListLinked ListLinked List + GroupingLi k d Li t+Add +C tLinked List+Address+Count

    22

  • Bit VectorBit VectorEach block is represented by a bit in a table. If p ythere are n disk blocks, the table has n bits.If a block is free, its corresponding bit is 1.gWhen a block is needed, the table is searched. If a 1 bit is found in position k, block k is free.If the disk capacity is small, the whole bit vector can be stored in memory. For a large disk, this bit vector will consume too much memory.We could group a few blocks into a cluster and allocate clusters. This saves space and may cause internal fragmentation.

    23

  • Linked ListLinked ListLike the linked allocation method free blocks canLike the linked allocation method, free blocks can be chained into a linked list.Wh f bl k i d d th fi t i th h i iWhen a free block is needed, the first in the chain is allocated.However, this method has the same disadvantages of the linked allocation method.We may use a FAT for the disk and chain the free block pointers together. Note that the FAT may be p g yvery large and consume space if it is stored in memory.

    24

    y

  • GroupinggThe first free block contains the addresses of nother free blocksother free blocks.For each group, the first n-1 blocks are actually free and the last (i e n-th) block contains thefree and the last (i.e., n-th) block contains the addresses of the next group.In this way we can quickly locate free blocksIn this way, we can quickly locate free blocks.

    3 8 50 3 63 8 50 3

    8

    6

    12

    (3 & 8 are free)

    50

    12

    20

    256 12 20(6 & 12 are free)

  • Address + CountinggThe list can be made short with the following trick:

    Blocks are often allocated and freed in groupsWe may store the address of the first free block and the number of the following n free blocks.

    free block list

    55

    326

    3disk

  • Th E dThe End

    27