Presentation is loading. Please wait.

Presentation is loading. Please wait.

File system : Disk Space Management

Similar presentations


Presentation on theme: "File system : Disk Space Management"— Presentation transcript:

1 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.

2 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

3 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.

4 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

5 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.

6 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

7 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

8 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.

9 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!)

10 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 ( ) 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 ( ) FAT size = 32K*2 = 64 K  When the block size is doubled the FAT size becomes half.

11 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 ( ) 20 bit (2.5 byte) is sufficient ( ) 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 ( ) 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.

12 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.

13 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

14 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.

15 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 = = 266 blocks = 266 K. Next time trouble arises when the file size exceeds 266 blocks! Why?

16 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 = *256 = = 65802K= MB. Next time trouble arises when the file size exceeds 266 blocks! Why?

17 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

18 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.

19 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.

20 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.


Download ppt "File system : Disk Space Management"

Similar presentations


Ads by Google