File Management Function of Os - PDF

Document Sample
File Management Function of Os - PDF Powered By Docstoc
					File Management
Implementing File

Allocation and
Performance and

                    File Management W7-W8

  KMBS Rev. 1.2                             OS-W8 – 1 / 22
File Management
Implementing File
y Basic Concepts
y File-System
y Layered file system
y File-System
y Directory            Implementing File System

Allocation and
Performance and

  KMBS Rev. 1.2                                   OS-W8 – 2 / 22
                 Basic Concepts

  q      File storage and access
  q      Ways to structure file use
  q      Allocate space
  q      Recover freed space
  q      Track locations of data
  q      Interface to secondary storage

KMBS Rev. 1.2                             OS-W8 – 3 / 22
                    File-System Structure

  q      File system is usually maintained in disks
         3      Rewritten
         3      Sequential or random access
  q      I/O transfer between memory and disk are performed in units of
         3      Each blocks has one or more sectors
         3      Sectors vary from 32 bytes to 4096 bytes, usually 512 bytes

KMBS Rev. 1.2                                                            OS-W8 – 4 / 22
                Layered file system

      application programs     I/O control consists of device
                ⇓                   drivers      and     interrupt
       logical file system           handlers.       Input consist
                ⇓                   of high level commands and
    file-organization module         ouput consists of low-level
                ⇓                   hardware instruction
        basic file system       Basic file system issue
                ⇓                   generic      commands       to
           I/O control              the device driver for blocks
                ⇓                   read/write
             devices           File organization module
                                    translate logical block to
                                    physical block address
                               Logical file system manage
                                    metadata information. i.e.
                                    directory structure
KMBS Rev. 1.2                                              OS-W8 – 5 / 22
                File-System Implementation

  Boot control block contain information needed by the system to boot
       an OS from that volume. Typically the first block of a volume.
  Volume control block contains volume (or partition) details suc as
       number of blocks per partition, free file-control block count, and
       file-control block pointer
  Directory structure per file system used to organize files
  File-Control Block ...

KMBS Rev. 1.2                                                     OS-W8 – 6 / 22
                Directory Implementation

  Linear List                         Hash Table
  q Simplest method using linear      q   Takes a value computed from
    list of file names with pointers       the file name and returns a
    to data blocks                        pointer to the file name
  q Limitation: time-consuming to     q   i.e.    assume a hash table
    execute because finding file            that holds 64 entries. Hash
    require a linear search               function converts file names
  q To create a new file, we must          into integers from 0 to 63
    first search the directory to      q   Limitation: Fixed sized and
    be sure that no existing file          dependence on hash function
    has the same name, then add
    new entry at the end of the
  q To delete or reuse a file, ...

KMBS Rev. 1.2                                                  OS-W8 – 7 / 22
File Management
Implementing File

Allocation and
y Allocation Methods
y Contiguous
y Linked Allocation
y Indexed Allocation
                       Allocation and Performance
y Allocation
y Free-Space

Performance and

  KMBS Rev. 1.2                                     OS-W8 – 8 / 22
                Allocation Methods

  How to allocate space to files so that disk space is utilized effectively
  q      Contiguous allocation
  q      Linked allocation
  q      Indexed allocation

KMBS Rev. 1.2                                                         OS-W8 – 9 / 22
                Contiguous Allocation

  q Requires each file occupy a set of contiguous blocks on the disk
  q Define a linear ordering on the disk
  q Accessing block b+1 after block b requires no head movement
  q ∴ number of disk seeks required for accessing contiguously
    allocated files is minimal
  q Limitation: difficulty of finding space for a new file, requires

KMBS Rev. 1.2                                                   OS-W8 – 10 / 22
                 Linked Allocation

  q      Solves contiguous allocation limitation
  q      Each file is a linked list of disk blocks and disk blocks may be
         scattered anywhere on the disk
  q      Directory contains a pointer to the first and last blocks of the file
  q      File can continue to grow as long as free blocks are available
  q      Limitation: requires sequential-access, pointers require space,
         reliability if pointer is lost
  q      Solution: file-allocation table (FAT) that allocate a section of disk at
         the beginning of each volume. Results in a significant number of
         disk head seek. Why?

KMBS Rev. 1.2                                                             OS-W8 – 11 / 22
                 Indexed Allocation

  q Bring all pointers into one location: index block
  q Each file has its own index block, which is an array of disk-block
    addresses. Scheme almost similar to paging scheme
  q Support direct access, without suffering external fragmentation and
    wasted space
  q Limitation: Index block requires space

  q      Main difference between linked allocation and indexed allocation?

KMBS Rev. 1.2                                                        OS-W8 – 12 / 22
                Allocation Performance

  q Each allocation method vary in storage efficiency and data-block
    access times
  q Before selecting allocation method determine how the system will
    be used
  q i.e. Boot disk, file disk, etc

KMBS Rev. 1.2                                                  OS-W8 – 13 / 22
                 Free-Space Management

  q      To keep track of free disk space, system maintains free-space list
  q      Implementation:
  Bit Vector list implemented as bit map/vector. If block is free, the bit is
       1 and if block is allocated, bit is 0. Limitation: inefficient i.e a 1.3GB
       disk with 512-byte blocks require a bit map of over 332KB
  Linked List link all free desk block and keeping a pinter to the first
       free block
  Grouping store addresses of n free blocks in the first free block.
       Address of a large number of free blocks can be found quickly
  Counting keep the first free block and the number of n free
       contiguous blocks that follow the first block. This approach take
       advantage that, generally, several contiguous blocks may be
       allocated or freed simultaneously

KMBS Rev. 1.2                                                           OS-W8 – 14 / 22
File Management
Implementing File

Allocation and
Performance and
y Efficiency
y Performance
y Recovery:
                        Performance and Recovery
Consistency Checking
y Recovery: Backup
and Restore
y Log-Structured File
y Recommended

  KMBS Rev. 1.2                                    OS-W8 – 15 / 22

  q Depends heavily on disk allocation and directory algorithms
  q Unix inodes (file pointers) are preallocated, even empty disk has a
    percentage lost to inodes. By spreading them across the volume,
    the file system efficiency is improved
  q BSD varies cluster size (multiples of blocks) as a file grows. i.e.
    small cluster for small file
  q Pointer size

         3      Limit the length of file. i.e.16-bit pointers allow length of
                216 (64KB). Implementing 64-bit pointers take more space to
         3      limit the volume/partition size. i.e. DOS could support only
                32MB partition

KMBS Rev. 1.2                                                           OS-W8 – 16 / 22

  On-board cache is local memory provided for disk controllers that is
      large enough to store entire tracks at a time
  Buffer cache is a separate section of main memory maintained by
      the operating systems
  Asynchronous writes allows systems to buffers write operation.
      Data stored in cache and control returns to the caller
  Read ahead a requested page and several subsequent pages are
      read and cached

KMBS Rev. 1.2                                                   OS-W8 – 17 / 22
                Recovery: Consistency Checking

  q Data are kept in main memory (or cache) to speed up access
  q Cache information are not necessarily written to disk as soon as the
    update takes place
  q Crash result cache/buffer content lost and leave the file system in
    inconsistent state
  q Consistency checker compares directory structure and data blocks
    on disk and tries to fix any inconsistencies it finds (i.e. chkdsk, fsck)

KMBS Rev. 1.2                                                       OS-W8 – 18 / 22
                 Recovery: Backup and Restore

  q      Magnetic/Optical disks sometimes fail
  q      System programs can be used to back up data from disk to another
         storage device
  q      Recovery from the loss may then be a matter of restoring data from
         backup. Example?
  q      To minimize copying needed data, backup program must know
         when the last backup of a file was done
  q      Length of cycle is a compromise between the amount of backup
         medium needed and number of days back
  q      From time to time a full backup is required
  q      Permanent backup are stored far away from regular backups to
         protect against hazard

KMBS Rev. 1.2                                                       OS-W8 – 19 / 22
                Log-Structured File Systems

  q Algorithm for consistency checking also known as journaling
  q All changes are written sequentially to a log. Once changes are
    written to this log, they are considered to be committed
  q Log may be in a separate section of the file system or even on a
    separate disk spindle (platter)
  q If system crashes, log may contain incomplete transaction that must
    be completed

KMBS Rev. 1.2                                                   OS-W8 – 20 / 22
KMBS Rev. 1.2   OS-W8 – 21 / 22
                Recommended Reading

  1. Operating System Principles, pg. 395-398, 403-422

KMBS Rev. 1.2                                            OS-W8 – 22 / 22

Description: File Management Function of Os document sample