"File Management Function of Os - PDF"
File Management W7-W8 Implementing File System Allocation and Performance Performance and Recovery File Management W7-W8 KMBS Rev. 1.2 OS-W8 – 1 / 22 File Management W7-W8 Implementing File System y Basic Concepts y File-System Structure y Layered ﬁle system y File-System Implementation y Directory Implementing File System Implementation Allocation and Performance Performance and Recovery KMBS Rev. 1.2 OS-W8 – 2 / 22 Basic Concepts Implementation: q File storage and access q Ways to structure ﬁle 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 blocks 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 ﬁle system application programs I/O control consists of device ⇓ drivers and interrupt logical ﬁle system handlers. Input consist ⇓ of high level commands and ﬁle-organization module ouput consists of low-level ⇓ hardware instruction basic ﬁle system Basic ﬁle 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 ﬁle 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 ﬁrst block of a volume. Volume control block contains volume (or partition) details suc as number of blocks per partition, free ﬁle-control block count, and ﬁle-control block pointer Directory structure per ﬁle system used to organize ﬁles 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 ﬁle names with pointers the ﬁle name and returns a to data blocks pointer to the ﬁle name q Limitation: time-consuming to q i.e. assume a hash table execute because ﬁnding ﬁle that holds 64 entries. Hash require a linear search function converts ﬁle names q To create a new ﬁle, we must into integers from 0 to 63 ﬁrst search the directory to q Limitation: Fixed sized and be sure that no existing ﬁle dependence on hash function has the same name, then add new entry at the end of the directory q To delete or reuse a ﬁle, ... KMBS Rev. 1.2 OS-W8 – 7 / 22 File Management W7-W8 Implementing File System Allocation and Performance y Allocation Methods y Contiguous Allocation y Linked Allocation y Indexed Allocation Allocation and Performance y Allocation Performance y Free-Space Management Performance and Recovery KMBS Rev. 1.2 OS-W8 – 8 / 22 Allocation Methods How to allocate space to ﬁles 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 ﬁle occupy a set of contiguous blocks on the disk q Deﬁne 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 ﬁles is minimal q Limitation: difﬁculty of ﬁnding space for a new ﬁle, requires defragmentation/compaction KMBS Rev. 1.2 OS-W8 – 10 / 22 Linked Allocation q Solves contiguous allocation limitation q Each ﬁle is a linked list of disk blocks and disk blocks may be scattered anywhere on the disk q Directory contains a pointer to the ﬁrst and last blocks of the ﬁle 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: ﬁle-allocation table (FAT) that allocate a section of disk at the beginning of each volume. Results in a signiﬁcant 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 ﬁle 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 efﬁciency and data-block access times q Before selecting allocation method determine how the system will be used q i.e. Boot disk, ﬁle 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: inefﬁcient 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 ﬁrst free block Grouping store addresses of n free blocks in the ﬁrst free block. Address of a large number of free blocks can be found quickly Counting keep the ﬁrst free block and the number of n free contiguous blocks that follow the ﬁrst 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 W7-W8 Implementing File System Allocation and Performance Performance and Recovery y Efﬁciency y Performance y Recovery: Performance and Recovery Consistency Checking y Recovery: Backup and Restore y Log-Structured File Systems y y Recommended Reading KMBS Rev. 1.2 OS-W8 – 15 / 22 Efﬁciency q Depends heavily on disk allocation and directory algorithms q Unix inodes (ﬁle pointers) are preallocated, even empty disk has a percentage lost to inodes. By spreading them across the volume, the ﬁle system efﬁciency is improved q BSD varies cluster size (multiples of blocks) as a ﬁle grows. i.e. small cluster for small ﬁle q Pointer size 3 Limit the length of ﬁle. i.e.16-bit pointers allow length of 216 (64KB). Implementing 64-bit pointers take more space to store 3 limit the volume/partition size. i.e. DOS could support only 32MB partition KMBS Rev. 1.2 OS-W8 – 16 / 22 Performance 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 ﬁle system in inconsistent state q Consistency checker compares directory structure and data blocks on disk and tries to ﬁx any inconsistencies it ﬁnds (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 ﬁle 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 ﬁle 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