File Systems: Fundamentals.

Slides:



Advertisements
Similar presentations
Chapter 6 File Systems 6.1 Files 6.2 Directories
Advertisements

1 Chapter 12 File Management Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design Principles,
Chapter 12: File System Implementation
File Management.
Databasteknik Databaser och bioinformatik Data structures and Indexing (II) Fang Wei-Kleiner.
Hash Tables.
More on File Management
Chapter 6 File Systems 6.1 Files 6.2 Directories
Chapter 4 : File Systems What is a file system?
File Management.
File Systems.
File Systems Examples.
COS 318: Operating Systems File Layout and Directories
Chapter 11: File System Implementation
1 Storing Data: Disks and Files Yanlei Diao UMass Amherst Feb 15, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
File System Implementation CSCI 444/544 Operating Systems Fall 2008.
Efficient Storage and Retrieval of Data
1 Outline File Systems Implementation How disks work How to organize data (files) on disks Data structures Placement of files on disk.
1 Friday, July 07, 2006 “Vision without action is a daydream, Action without a vision is a nightmare.” - Japanese Proverb.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
File System Design David E. Culler CS162 – Operating Systems and Systems Programming Lecture 24 October 24, 2014 Reading: A&D 13.3 HW 4 due 10/27 Proj.
File Systems. Main Points File layout Directory layout.
File Systems (1). Readings r Silbershatz et al: 10.1,10.2,
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D.
File Systems and Disk Management. File system Interface between applications and the mass storage/devices Provide abstraction for the mass storage and.
File Implementation. File System Abstraction How to Organize Files on Disk Goals: –Maximize sequential performance –Easy random access to file –Easy.
1Fall 2008, Chapter 11 Disk Hardware Arm can move in and out Read / write head can access a ring of data as the disk rotates Disk consists of one or more.
1 File Systems Chapter Files 6.2 Directories 6.3 File system implementation 6.4 Example file systems.
File System Implementation Chapter 12. File system Organization Application programs Application programs Logical file system Logical file system manages.
CSC 322 Operating Systems Concepts Lecture - 20: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
OSes: 11. FS Impl. 1 Operating Systems v Objectives –discuss file storage and access on secondary storage (a hard disk) Certificate Program in Software.
CSCI-375 Operating Systems Lecture Note: Many slides and/or pictures in the following are adapted from: slides ©2005 Silberschatz, Galvin, and Gagne Some.
File Storage Organization The majority of space on a device is reserved for the storage of files. When files are created and modified physical blocks are.
Module 4.0: File Systems File is a contiguous logical address space.
Disk & File System Management Disk Allocation Free Space Management Directory Structure Naming Disk Scheduling Protection CSE 331 Operating Systems Design.
CE Operating Systems Lecture 17 File systems – interface and implementation.
Lecture 10 Page 1 CS 111 Summer 2013 File Systems Control Structures A file is a named collection of information Primary roles of file system: – To store.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems File systems.
CS 3204 Operating Systems Godmar Back Lecture 21.
Chapter 6 File Systems. Essential requirements 1. Store very large amount of information 2. Must survive the termination of processes persistent 3. Concurrent.
File Systems.  Issues for OS  Organize files  Directories structure  File types based on different accesses  Sequential, indexed sequential, indexed.
Lecture Topics: 11/22 HW 7 File systems –block allocation Unix and NT –disk scheduling –file caches –RAID.
W4118 Operating Systems Instructor: Junfeng Yang.
File Systems and Disk Management
File System Implementation
Chapter 11: File System Implementation
FileSystems.
File System Structure How do I organize a disk into a file system?
Chapter 11: File System Implementation
26 - File Systems.
Filesystems.
EECE.4810/EECE.5730 Operating Systems
Chapter 11: File System Implementation
File Systems and Disk Management
File Systems Implementation
File Systems: Fundamentals.
Chapter 11: File System Implementation
Introduction to Operating Systems
File Systems and Disk Management
File Systems and Disk Management
File Systems and Disk Management
Chapter 16 File Management
File Systems and Disk Management
Chapter 14: File-System Implementation
File Systems and Disk Management
File Systems and Disk Management
Chapter 11: File System Implementation
File Systems: Fundamentals
SE350: Operating Systems Lecture 12: File Systems.
Chapter 5 File Systems -Compiled for MCA, PU
Presentation transcript:

File Systems: Fundamentals

Files What is a file? File attributes File operations A named collection of related information recorded on secondary storage (e.g., disks) File attributes Name, type, location, size, protection, creator, creation time, last-modified-time, … File operations Create, Open, Read, Write, Seek, Delete, … How does the OS allow users to use files? “Open” a file before use OS maintains an open file table per process, a file descriptor is an index into this file. Allow sharing by maintaining a system-wide open file table

Fundamental Ontology of File Systems Metadata The index node (inode) is the fundamental data structure The superblock also has important file system metadata, like block size Data The contents that users actually care about Files Contain data and have metadata like creation time, length, etc. Directories Map file names to inode numbers

Basic data structures Disk File Directory An array of blocks, where a block is a fixed size data array File Sequence of blocks (fixed length data array) Directory Creates the namespace of files Heirarchical – traditional file names and GUI folders Flat – like the all songs list on an ipod Design issues: Representing files, finding file data, finding free blocks

Some systems allow transferring of many sectors between interrupts. Block vs. Sector The operating system may choose to use a larger block size than the sector size of the physical disk. Each block consists of consecutive sectors. Why? A larger block size increases the transfer efficiency (why?) It can be convenient to have block size match (a multiple of) the machine's page size (why?) Some systems allow transferring of many sectors between interrupts. Some systems interrupt after each sector operation (rare these days) “consecutive” sectors may mean “every other physical sector” to allow time for CPU to start the next transfer before the head moves over the desired sector

File System Functionality and Implementation Pick the blocks that constitute a file. Must balance locality with expandability. Must manage free space. Provide file naming organization, such as a hierarchical name space. File system implementation: File header (descriptor, inode): owner id, size, last modified time, and location of all data blocks. OS should be able to find metadata block number N without a disk access (e.g., by using math or cached data structure). Data blocks. Directory data blocks (human readable names) File data blocks (data). Superblocks, group descriptors, other metadata…

File System Properties Most files are small. Need strong support for small files. Block size can’t be too big. Some files are very large. Must allow large files (64-bit file offsets). Large file access should be reasonably efficient. Most systems fit the following profile: Most files are small Most disk space is taken up by large files. I/O operations target both small and large files. --> The per-file cost must be low, but large files must also have good performance.

If my file system only has lots of big video files what block size do I want? Large Small

How do we find and organize files on the disk? The information that we need: file header points to data blocks fileID 0, Block 0 --> Disk block 19 fileID 0, Block 1 --> Disk block 4,528 … Key performance issues: We need to support sequential and random access. What is the right data structure in which to maintain file location information? How do we lay out the files on the physical disk?

File Allocation Methods Contiguous allocation File header specifies starting block & length Placement/Allocation policies First-fit, best-fit, ... Now we look look at methods for allocating space to files. — The compliment of the free-list representation problem. Contiguous allocation also gives the best performance for the initial write of a file (i.e., once space has been allocated). — Subsequent writes may cause the file to grow in which case it may have to be copied and moved. Pluses Best file read performance Efficient sequential & random access Minuses Fragmentation! Problems with file growth Pre-allocation? On-demand allocation?

File Allocation Methods Linked allocation Files stored as a linked list of blocks File header contains a pointer to the first and last file blocks Why have a pointer to the last block? — Makes it easy to grow the file. You don’t have to scan the chain to find the end of the list. Pluses Easy to create, grow & shrink files No external fragmentation Minuses Impossible to do true random access Reliability Break one link in the chain and...

Maintain linked list in a separate table File Allocation Methods Linked allocation – File Allocation Table (FAT) (Win9x, OS2) Maintain linked list in a separate table A table entry for each block on disk Each table entry in a file has a pointer to the next entry in that file (with a special “eof” marker) A “0” in the table entry  free block Comparison with linked allocation If FAT is cached  better sequential and random access performance How much memory is needed to cache entire FAT? 400GB disk, 4KB/block  100M entries in FAT  400MB Solution approaches Allocate larger clusters of storage space Allocate different parts of the file near each other  better locality for FAT

Vista reading the master file table MFT contains a record for each file, inlines small files

File Allocation Methods Direct allocation File header points to each data block If a disk pointer is 32 bits (we can address up to 4 billion sectors), then: — An index block can contain 512/32 = 16 pointers, so — Under indexed allocation, a file can be 16512 = 8K bytes (using the Seagate disk example). Pluses Easy to create, grow & shrink files Little fragmentation Supports direct access Minuses Inode is big or variable size How to handle large files?

File Allocation Methods Indexed allocation IB Create a non-data block for each file called the index block A list of pointers to file blocks File header contains the index block If a disk pointer is 32 bits (we can address up to 4 billion sectors), then: — An index block can contain 512/32 = 16 pointers, so — Under indexed allocation, a file can be 16512 = 8K bytes (using the Seagate disk example). Pluses Easy to create, grow & shrink files Little fragmentation Supports direct access Minuses Overhead of storing index when files are small How to handle large files?

Indexed Allocation Handling large files Linked index blocks (IB+IB+…) Multilevel index blocks (IB*IB*…) I IB IB IB (Draw these out again in the margin using a more tree-like structure...) I IB IB IB IB

Why bother with index blocks? A. Allows greater file size. B. Faster to create files. C. Simpler to grow files. D. Simpler to prepend and append to files. E. Scott Summers is the X-men’s Cyclops

Multi-level Indirection in Unix File header contains 13 pointers 10 pointes to data blocks; 11th pointer  indirect block; 12th pointer  doubly-indirect block; and 13th pointer  triply-indirect block Implications Upper limit on file size (~2 TB) Blocks are allocated dynamically (allocate indirect blocks only for large files) Features Pros Simple Files can easily expand Small files are cheap Cons Large files require a lot of seek to access indirect blocks

Indexed Allocation in UNIX Multilevel, indirection, index blocks 10 Data Blocks 1st Level Indirection Block Inode n Data Blocks n2 Data Blocks IB IB 2nd Level Indirection Block In this figure n is the number of pointer you can store in a disk block. Assuming a first level block can contain 16 pointers then — a “small” file is 8K bytes — a “medium” file is 64 MB — a “large” file is 512 GB! IB IB n3 Data Blocks IB IB IB IB 3rd Level Indirection Block IB IB IB IB

How big is an inode? A. 1 byte B. 16 bytes C. 128 bytes D. 1 KB E. 16 KB

Allocate from a free list Need a data block Consult list of free data blocks Need an inode Consult a list of free inodes Why do inodes have their own free list? A. Because they are fixed size B. Because they exist at fixed locations C. Because there are a fixed number of them

Free list representation Represent the list of free blocks as a bit vector: 111111111111111001110101011101111... If bit i = 0 then block i is free, if i = 1 then it is allocated Simple to use and vector is compact: 1TB disk with 4KB blocks is 2^28 bits or 32 MB If free sectors are uniformly distributed across the disk then the expected number of bits that must be scanned before finding a “0” is n/r where n = total number of blocks on the disk, r = number of free blocks One of the key things a directory must do is make it easy to allocate new space on the disk. — The directory must keep track of which blocks are free and which are allocated. Often CPUs have instructions to perform this search in a small number of machine cycles. But are free blocks uniformly spread out over the disk? — Not likely. If they were then file I/O performance would likely be poor. If a disk is 90% full, then the average number of bits to be scanned is 10, independent of the size of the disk

Writing the free list on Vista

Deleting a file is a lot of work Data blocks back to free list Coalescing free space Indirect blocks back to free list Expensive for large files, an ext3 problem Inodes cleared (makes data blocks “dead”) Inode free list written Directory updated The order of updates matters! Can put block on free list only after no inode points to it

Naming and Directories Files are organized in directories Directories are themselves files Contain <name, pointer to file header> table Only OS can modify a directory Ensure integrity of the mapping Application programs can read directory (e.g., ls) Directory operations: List contents of a directory Search (find a file) Linear search Binary search Hash table Create a file Delete a file Changing gears… How do you find what you’re looking for on a disk? All this information could be stored in memory but what happens if the power is cycled? —This information could be stored on disk (and this is what we’re going to describe!).

Every directory has an inode A. True B. False Given only the inode number (inumber) the OS can find the inode on disk

Directory Hierarchy and Traversal Directories are often organized in a hierarchy Directory traversal: How do you find blocks of a file? Let’s start at the bottom Find file header (inode) – it contains pointers to file blocks To find file header (inode), we need its I-number To find I-number, read the directory that contains the file But wait, the directory itself is a file Recursion !! Example: Read file /A/B/C C is a file B/ is a directory that contains the I-number for file C A/ is a directory that contains the I-number for file B How do you find I-number for A? “/” is a directory that contains the I-number for file A What is the I-number for “/”? In Unix, it is 2

Directory Traversal (Cont’d.) How many disk accesses are needed to access file /A/B/C? Read I-node for “/” (root) from a fixed location Read the first data block for root Read the I-node for A Read the first data block of A Read the I-node for B Read the first data block of B Read I-node for C Read the first data block of C Optimization: Maintain the notion of a current working directory (CWD) Users can now specify relative file names OS can cache the data blocks of CWD

Naming and Directories Once you have the file header, you can access all blocks within a file How to find the file header? Inode number + layout. Where are file headers stored on disk? In early Unix: Special reserved array of sectors Files are referred to with an index into the array (I-node number) Limitations: (1) Header is not near data; (2) fixed size of array  fixed number of files on disk (determined at the time of formatting the disk) Berkeley fast file system (FFS): Distribute file header array across cylinders. Ext2 (linux): Put inodes in block group header. How do we find the I-node number for a file? Solution: directories and name lookup

A corrupt directory can make a file system useless A. True B. False

Other Free List Representations In-situ linked lists Grouped lists D Why would we consider one scheme as being any better or worse than another? — Fault tolerance. — Efficiency of allocation. — Overhead? D G Next group block Allocated block Empty block