File_system

Document Sample
File_system Powered By Docstoc
					          File System
        Implementations
              Presented by:
              Gaurav Gupta
          Department of CSEE
University Of Maryland Baltimore County
                Introduction
   Local File systems & Remote File Systems
   Two general File systems in modern Unix
     • System V File system, original
     • Berkeley fast file system, 4.2 BSD,
       better
   Vnode/Vfs interface supports multiple file
    systems.
   This chapter summarizes and compares
    the two file systems
    System V File System (s5fs)
   Single logical disk or partition, one FS per
    partition
   Each FS has own root, sub directories,
    Files, data and metadata
   Disk Block = 512 * n, granularity of disk
    allocation for a file
   Translated by disk drivers in to track
    sectors and cylinders

     B      S    Inode list   Data blocks

Boot area       superblock
   Layout:
     • Boot area: Bootstrap code
     • Superblock: Attributes and metadata of
       file system
     • Inode list: one inode/file 64 bytes, fix
       the size of file system
     • Data area: files, directories and indirect
       blocks which hold pointers to other file
       data blocks
   Directories:
     • File containing list of files and
       subdirectories
     • Fixed record of 16 bytes
• 2 bytes ( 216= 65535 files) inode
  number, 14 bytes file name
• 0 inode number means file no longer
  exist
• Root directory and parent have inode
  number equal to 2

  73     .
  38     ..
  9      File1
  0      Deleted file
  110    Subdirectory1
  65     File2
   Inodes ( Index nodes):
    • Each file has one unique inode
    • Inode contains metadata of the file
    • on-disk inode and in-core inode
        Field   Size          Description

    di_mode      2     File type, permissions
    di_uid       2     Owner UID
    di_gid       2     Owner GID
    di_size      4     Size in bytes
    di_addr     39     Array of block addresses
    :            :                     :
    di_addr:
     • File is not stored in contiguous blocks,
       prevents fragmentation
     • An array of block address is required,
       Stored in inode, prevent extra read
     • Size of array depends on the size of file
 0
 1
 2
 3
 4
 5
 6
 7
 8
 9
10   indirect
11   Double indirect
12   triple indirect
   Superblock
    • Metadata about File system
    • One Superblock per File system
    • Kernel reads Superblock when mounting
      the File system
    • Superblock contains following
      information
       Size in blocks of the file system
       Size in blocks of the inode list

       Number of free blocks and inodes

       Free block list (Partial)

       Free inode list (Full)
            Kernel Organization
   In-Core Inodes
     • Represented by struct inode
     • All fields of on-disk inode and following extra
       fields
          vnode: contains the vnode of the file

          Device ID of the partition containing the file

          Inode number of the file

          Flags for synchronization and cache
           management
          Pointers to keep the inode on a free list

          Pointers to keep the inode on a hash queue

          Block number of last block read
   Inode Lookup
     • Lookuppn(), a file system independent
       function performs pathname parsing
     • When searching s5fs directory it translates
       to a call to s5lookup()
     • s5lookup first checks directory name
       lookup cache
     • On miss it reads the directory one block at
       a time
     • If directory contains a valid filename entry,
       s5lookup() obtains inode number of file
     • iget() is called to locate inode
     • iget() searches the appropriate hash table
       to get the inode
   File I/O
    • Read and write system call accept
          File descriptor, user buffer address, count of number
           of byte transferred
    • Offset if obtained from the open file object
    • Offset is advanced to the number of byte
      transferred
    • For random I/O “lseek” is used to set the
      offset to desired location
    • Kernel verifies the file mode and puts an
      exclusive lock on the inode for serialized
      access
    • I n read s5read() translate the starting offset
      to logical block number in the file
   Allocating and Reclaiming Inodes
    • Inode remains active as long as vnode has a
      non-zero reference count
    • New implementations puts the inactive inode
      on free list
    • Inode caching uses LRU replacement algorithm
      ( suboptimal)
    • When file is actively used, inode is pinned (
      ineligible for freeing)
        When file becomes inactive some pages may
         still be in the memory
    • Inode is free only when no pages are present
      in the memory
    • New inodes are allocated from the top of the
      free list
   Analysis
    • Simple design
    • Single superblock can be corrupted
    • Grouping of inode in the beginning
      requires long seek time between inode
      read and file access
    • Fixed lock size wastes space
    • Filename is limited to 14 characters
    • Number of inodes are limited to 65535
 The Berkeley Fast File System
 Improves performance, reliability
  and functionality
 Provides all functionality of s5fs,

  system call handling algorithms and
  kernel data structures
 Difference in disk layout, on disk
  structures and free block allocation
  methods
   Data layout on hard disk
      Sector 0                   track2
      Sector 1                            track0
                                     track1

        head 0




                    Cylinder 0

                                              platters
        head 1




                   Cylinder 1

        head 2
 Sector size is 512 bytes
 Unix view of disk is linear array of
  blocks
 Number of sectors/block = 2n, n is
  small number
 Device driver translates block
  number to logical sector number and
  the physical track, head and sector
  number
 Each cylinder contains a sequential
  set of block numbers
 Head seek time, rotation latency
   On disk organization
    • Disk partition comprises of set of
      consecutive cylinders on disk
    • FFS further divides the partition into one
      or more cylinder groups (consecutive
      cylinders)
    • Traditional superblock is divided into two
      structures
    • FFS superblock contains information like
      number, size and location of cylinder
      group, block size, inodes etc.
    • Superblock does not change unless file
      system is rebuilt
    • Every cylinder group has information
      about the group including free inodes,
      free block lists etc
    • Each group has a copy of superblock
   Blocks and fragments
    • Advantage & disadvantage of block size
    • FFS divides blocks in to fragments
    • Block size is 2n , min = 4096, much
      larger then s5fs ( 512/1024 bytes)
    • Small size files fragments are useful
    • Lower bound of fragments = 512 bytes
    • File has complete disk blocks except last
    • First block should be a single block not
      set of fragments
    • Occasional recopying of data incase the
      file grows in size
    • FFS controls this by allowing only direct
      block to contain fragments
   Allocation Policies
    • In s5fs free inode and block list is
      random except at the file system
      creation time
    • FFS aim to collocate related information
      on the disk to optimize sequential
      access
    • FFS places inodes of all the files of a
      single directory into same cylinder
      group (improves commands like ls –l )
    • Create new directory in a different
      cylinder group from the parent ( for
      uniform distribution)
    • Place data blocks of file in the same cylinder
      group as inodes
    • Change cylinder group when the file reaches
      48KB size and again at every MB
    • Allocate sequential blocks of a file at
      rotationally optimal positions

   FFS Functional enhancements
    • Long file names- 255 characters and variable
      directory entry length
    • Symbolic links- Symbolic link is a file that
      points to another file.
        type field of the inode identifies the file as
         symbolic link
   |Analysis
    • Read throughput increases from 29KB/s
      in s5fs to 221 KB/s in FFS
    • CPU utilization increases from 11% to
      43%
    • Write throughput increases from 48KB/s
      to 142 KB/s
    • Average wastage in data block is half
      block per file in s5fs and half fragment
      per file in FFS
       Same when fragment size equals block size
       Overhead to maintain fragments

				
DOCUMENT INFO
Shared By:
Categories:
Stats:
views:86
posted:3/5/2010
language:English
pages:22