File system : Disk Space Management

Slides:



Advertisements
Similar presentations
Chapter 12: File System Implementation
Advertisements

File Management.
Chapter 4 : File Systems What is a file system?
File Systems.
SEMINAR ON FILE SLACK AND DISK SLACK
File System Implementation
File System Implementation: beyond the user’s view A possible file system layout on a disk.
File System Implementation CSCI 444/544 Operating Systems Fall 2008.
File Systems Implementation
1 Operating Systems Chapter 7-File-System File Concept Access Methods Directory Structure Protection File-System Structure Allocation Methods Free-Space.
Ceng Operating Systems
1 Outline File Systems Implementation How disks work How to organize data (files) on disks Data structures Placement of files on disk.
File System Structure §File structure l Logical storage unit l Collection of related information §File system resides on secondary storage (disks). §File.
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.
Contiguous Allocation of Disk Space. Linked Allocation.
1 File Systems Chapter Files 6.2 Directories 6.3 File system implementation 6.4 Example file systems.
File Systems (1). Readings r Silbershatz et al: 10.1,10.2,
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D.
File System Implementation Chapter 12. File system Organization Application programs Application programs Logical file system Logical file system manages.
The disk surface is divided into tracks. into tracks. 1.
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.
Dr. T. Doom 11.1 CEG 433/633 - Operating Systems I Chapter 11: File-System Implementation File structure –Logical storage unit –Collection of related information.
Free Space Management.
Silberschatz and Galvin  Operating System Concepts File-System Implementation File-System Structure Allocation Methods Free-Space Management.
File System Implementation
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 11: File System Implementation.
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.
Why Do We Need Files? Must store large amounts of data. Information stored must survive the termination of the process using it - that is, be persistent.
File Systems. 2 What is a file? A repository for data Is long lasting (until explicitly deleted).
I MPLEMENTING FILES. Contiguous Allocation:  The simplest allocation scheme is to store each file as a contiguous run of disk blocks (a 50-KB file would.
FAT File Allocation Table
CS 3204 Operating Systems Godmar Back Lecture 21.
File Systems.  Issues for OS  Organize files  Directories structure  File types based on different accesses  Sequential, indexed sequential, indexed.
Operating Systems Files, Directory and File Systems Operating Systems Files, Directory and File Systems.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 12: File System Implementation.
File Systems and Disk Management
File-System Management
File System Implementation
File-System Implementation
Chapter 11: File System Implementation
FileSystems.
Day 27 File System.
File System Structure How do I organize a disk into a file system?
Chapter 11: File System Implementation
26 - File Systems.
Filesystems.
Management and Optimization Example File Systems
File Management.
Module IV Memory Organization.
Chapter 11: File System Implementation
CS510 Operating System Foundations
File Systems Implementation
UNIVERSITY of WISCONSIN-MADISON Computer Sciences Department
Disk storage Index structures for files
Chapter 11: File System Implementation
File System B. Ramamurthy B.Ramamurthy 11/27/2018.
Virtual Memory Hardware
Secondary Storage Management Brian Bershad
Files Management – The interfacing
Chapter 14: File-System Implementation
Secondary Storage Management Hank Levy
File Organization.
Chapter 11: File System Implementation
Chapter 12: File-System Implementation CSS503 Systems Programming
Chapter 5 File Systems -Compiled for MCA, PU
Presentation transcript:

File system : Disk Space Management Files are normally stored on a hard disk, therefore management of the disk space is a major concern to the file system. Suppose it is desired to store an n byte file on a disk. Two strategies are possible: Allocate n consecutive bytes of the disk Disadvantage: if the file grows, remaining part must be moved else where on the disk and in case of shrinkage, the released space would be wasted. Split the file into blocks and store different blocks of the file on different blocks of the disk This is reasonable and all the file systems chop up files into fixed size blocks that need not be contiguous on the disk.

File system : Disk Space Management Problem: what should be the block size? The obvious candidates are: Sector, Track, Cylinder, Page (in a paging system). The block of a file is called allocation unit in general and cluster in MS DOS/windows. Typical block sizes are 512, 1024, 2048, .. Bytes ( simple multiples of sector size) Keeping in view the organization of the disk

Disk Space Management: Small Vs Large blocks Small blocks Advantages: Less wastage of space in the last block Disadvantages: File occupies more disk blocks, more accesses (seeks + searches) to read a file; reading a file is slow. Large blocks Advantages: File occupies fewer disk blocks, fewer accesses (seeks + searches) to read a file; reading a file is faster. disadvantages: more wastage of space in the last block Conclusion: use blocks of medium size.

Disk Space Management A disk can be visualized as a one dimensional array of blocks. (Fig.1) When a file is created it consists of a single cluster. As the file grows, it fills the cluster and may occupy more clusters as the need arises. If the disk is brand new these blocks could be contiguous (Fig.2). If the disk has been in use, it contains many files whose blocks may not be adjacent; rather blocks of different file are intermingled on the disk. (Fig. 3). Fig.1 A A A Fig.2 A B C B Fig.3

Disk Space Management (contd.) Cluster are released by the deleted / contracted files; this results in mixing of free blocks with the blocks allocated to different files. Clearly, the system requires a mechanism to find out which block belongs to which file. Two techniques used to solve this problem are worth considering: Linked List Allocation Form a linked list of blocks; each block contains the number of the next block in the chain. This scheme has the following disadvantages: 2 bytes of a block are used to store address of next block; the block size is no more a power of 2 which is desired in computers. To access a block of a file, a chain of pointers is to be followed; the access is sequential and hence slow.

Disk Space Management (contd.) Linked List Allocation using a Table in the RAM A table called File allocation Table (FAT) is associated with each disk / partition. FAT has one entry for each disk block. The name and block number of the first block of the file are placed in the directory entry for that file. A slot of the FAT having the same number as that of the first block of the file contains the number of the next block and so on. The last block contains EOF (end of file). Note: The size of the FAT depends upon: Numbers of slots in the FAT Size of each slot

Disk Space Management (contd.) Linked List Allocation using a Table in the RAM A table called File allocation Table (FAT) is associated with each disk / partition. (Fig.4) FAT has one entry for each disk block. The name and block number of the first block of the file are placed in the directory entry for that file. A slot of the FAT having the same number as that of the first block of the file contains the number of the next block and so on. The last block contains EOF (end of file). Note: FAT was originally designed for IBM’s 320 K floppy disk using blocks of size one k each. The size of the FAT depends upon: Numbers of slots in the FAT Size of each slot

Storing Files Using the FAT Directory Entries X 1 EOF 2 3 4 12 5 8 6 7 9 10 11 13 14 A,6 File A has been stored on disk blocks 6, 8, 4, and 2. B,11 File B has been stored on disk blocks 11, 9, 5 and 12.

Computing the Size of FAT Compute FAT size for 320 K Floppy disk having block of size 1K. ( The first disk launched by IBM) Disk size = 320 K Block size = 1k No. of blocks = 320 Address size = ? 8 bit (1 byte) is not sufficient (0-255) 12 bit (1.5 byte) is sufficient (0-4095) FAT size = 320*1.5 = 480 bytes  1 sector (512 byte) is ok for FAT O.S. used to allocate 1 sector Later IBM introduced 360 K floppy. Using block of size 1k, FAT size for this disk is 540 byte. This cannot be accommodated on one sector. O.S. used to allocate 2 sector ( formatting changed!)

Computing the Size of FAT Compute FAT size for 64 MB disk having blocks of size (a) 1K (b) 2k Disk size = 64 MB = 64 K*K Block size = 1k No. of blocks = 64k = 65536 Address size = ? 12 bit (1.5 byte) is not sufficient (0-4095) 16 bit (2 byte) is just sufficient (0-65536) FAT size = 64K*2 = 128 K (b) Disk size = 64 MB = 64 K*K Block size = 2k No. of blocks = 32k = 32768 16 bit (2 byte) is sufficient (0-65536) FAT size = 32K*2 = 64 K  When the block size is doubled the FAT size becomes half.

FAT (continued) Compute FAT size for 70 MB disk having blocks of size (a) 1K (b) 2k Disk size = 70 MB = 70 K*K Block size = 1k No. of blocks = 70k = 71680 16 bit (2 byte) is not sufficient (0-65536) 20 bit (2.5 byte) is sufficient (0-1048576) FAT size = 70K*2.5 = 175 K (b) Disk size = 70 MB = 70 K*K Block size = 2k No. of blocks = 30k = 35840 Now 16 bit (2 byte) is sufficient (0-65536) FAT size = 35K*2 = 70 K  When the block size is doubled the FAT size becomes less than half. Conclusion: When the block size is doubled the FAT size becomes either half or less than half. EX. Compute FAT size for 1GB hard disk using block sizes of 1, 16, 32K.

FAT (continued) Major disadvantage of FAT A FAT is associated with the whole disk. It contains block numbers of all the files on the hard disk. Entire FAT must be loaded in the main memory even if one file is opened. This is wastage of space because the FAT takes a lot of space. What is solution then? Associate a separate table with each file. This technique is used by Unix / Linux and the table is called I-node.

The I-node What is i-node? An I-node is a table attached with each file in Unix environment. It contain information about size, owner, links, date of creation, etc. of the file. In addition, it contains 10 slots for direct block addresses One slot for single indirect One slot for double indirect One slot for triple indirect Each slot is of size 4 bytes

Storing a File using an I-node Assume that bock size is 1K (1024 bytes). Acquire a vacant block of a disk, store its address in first out of 10 slots for direct disk block numbers and then store contents of file on the disk block. When this block fills acquire another disk block, store its address in the second out of 10 slots for direct disk block numbers and then store contents of file on the disk block and so on. If the file is up to 10 disk blocks storing it is straightforward. The maximum size of the file that can be stored using 10 slots for direct disk block numbers = 10 blocks = 10K First time problem arises when file size exceeds 10 disk blocks because there is no slot to store the address of the 11th and next blocks of the file.

Storing a File using an I-node What should be done when the size of file exceeds 10 blocks? Acquire a vacant disk block, store its address in the single indirect slot and convert it into index consisting of slots of 4 byte each; in this way index contains 1024/4 = 256 slots. Acquire a vacant block of a disk, store its address in first out of 256 newly created slots & then store contents of file on the disk block and so on. The single indirect can handle 256 additional disk bocks. The maximum size of the file that can be stored using single indirect = 10 + 256 = 266 blocks = 266 K. Next time trouble arises when the file size exceeds 266 blocks! Why?

Storing a File using an I-node What should be done when the size of file exceeds 266 Construct a Two-level index. How? Acquire a vacant disk block, store its address in the double indirect slot and convert it into index consisting 256 slots. Acquire another vacant block of a disk, store its address in first out of 256 newly created slots & then convert it into second level index also consisting of 256 slots. Now acquire another vacant block of a disk, store its address in first out of 256 slots of the second level index & then store contents of file on the disk block and so on. The double indirect can handle 256*256 additional disk bocks. The maximum size of the file that can be stored using double indirect = 10 + 256 +256*256 = 65802 = 65802K= 64.259MB. Next time trouble arises when the file size exceeds 266 blocks! Why?

I-node 10 slots for direct disk block numbers Owner UID Single Indirect Double Indirect Triple Indirect 255 .. 255 255 255 255 255 255 255 255 10 slots for direct disk block numbers

Storing a File using an I-node Assume that block size is 1K (1024 bytes). Acquire a vacant block of a disk, store its address in first out of 10 slots for direct disk block numbers and then store contents of file on the disk block. When this block fills acquire another disk block, store its address in the second out of 10 slots for direct disk block numbers and then store contents of file on the disk block and so on. addresses. If the file is up to 10 disk blocks storing it is straightforward. First time problem arises when file exceeds 10 blocks because there is no slot to store the address of the 11th block of the file.

Storing a File using an I-node What should be done when the file size exceeds 10 blocks? Acquire a vacant disk block, store its address in the single indirect slot and convert it into index consisting of slots of 4 byte each; in this way index contains 1024/4 = 256 slots. Acquire another vacant block of a disk, store its address in first out of 256 newly created slots & then store contents of file on the disk block and so on. Single indirect can handle 256 additional disk blocks. The total number of blocks that can be handled by single indirect are 266. Next time trouble arises when file exceeds 266 blocks because there is no slot to store the address of the 267th block of the file.

Storing a File using an I-node What should be done when the file size exceeds 266 blocks? Acquire a vacant disk block, store its address in the single indirect slot and convert it into index consisting of slots of 4 byte each; in this way index contains 1024/4 = 256 slots. Acquire another vacant block of a disk, store its address in first out of 256 newly created slots & then store contents of file on the disk block and so on. Single indirect can handle 256 additional disk blocks. The total number of blocks that can be handled by single indirect are 266. Next time trouble arises when file exceeds 266 blocks because there is no slot to store the address of the 267th block of the file.