Block size and partition maximum capacity single file maximum capacity relationship

Source: Internet
Author: User

The relationship between block size and maximum capacity of individual files (article from bird's Linux private dish http://vbird.dic.ksu.edu.tw/linux_basic/0230filesystem_1.php#ps2)

Let's take a rough look at the relationship between Inode/block and file size. Inode to record a lot of data, but only 128bytes, and Inode record a block number to spend 4byte, if I have a file with 400MB and each block is 4K, then at least 100,000 block number records It! What's the inode with so much information to record? For this reason, our system is smart. Defines the area of the Inode record block number as 12 direct, one indirect, one double indirect with a three indirect record area. What is this? Let's draw the structure of the inode.


Figure 1.3.2, Inode structure (Note 5)

On the left is the Inode itself (bytes), there are 12 directly to the block number of the control, these 12 records can be directly obtained block number! As for the so-called indirect is to take a block to record the block number record area, if the file is too large, you will use the indirect block to record the number. For example, the 1.3.2 indirectly just takes a block to record the extra number. Similarly, if the file continues to grow, then the so-called double-indirect, the first block will only point out where the next record number of blocks, the actual record in the second block. And so on, three indirectly is to use the third block to record the number!

How many blocks can be specified by this sub-inode? We illustrate this with a smaller 1K block, which can be specified as follows:

    • 12 Direct points: 12*1k=12k
      Since it is direct pointing, a total of 12 records can be recorded, so the total size is as shown above;

    • Indirect: 256*1k=256k
      Each block number of records will take 4bytes, so the size of 1K can record 256 records, so an indirect can record the size of the file as above;

    • Double indirect: 256*256*1k=2562k
      The first block will specify 256 second level, each second layer can specify 256 numbers, so the total size is as above;

    • Three indirect: 256*256*256*1k=2563k
      The first block will specify 256 second level, each second layer can specify 256 third layer, each third layer can specify 256 numbers, so the total size is as above;

    • Total: Direct, indirect, double indirect, three indirect plus total, get + + + 256*256 + 256*256*256 (K) = 16GB

At this point we know that when the file system to the block format 1K size, can accommodate the largest file is 16GB, compare the file system limit table results can be found to be consistent! However, this method can not be used in 2K and 4K block size calculation, because the block larger than 2K will be limited by the Ext2 file system itself, so the results of the calculation will be less consistent.

Block size and partition maximum capacity relationship (from Wikipedia)

File System Limits[edit]
theoretical ext2 limits under Linux [4]
block size: 1 KiB 2 KiB 4 KiB 8 KiB
max. File si Ze: 16 Gib 256 GiB 2 TiB 4 TiB 8 tib 16 tib 32 Tib

The reason for some limits of ext2 is the file format of the data and the operating system ' s kernel. Mostly These factors would be a determined once when the file system is built. They depend on the block size and the ratio of the number of blocks and inodes. In Linux the block size was limited by the architecture page size. (The block size limit comes from the page size, the common block size is 1 2 3 8)

There is also some userspace programs that can ' t handle files larger than 2 GiB.

If B is the block size, the maximum file size was limited to min(((b/4) (b/4)b< /C4>/4+12) *b, (232-1) *512) due to the I_block structure (an array of Direct/indirect ext2_n_blocks) and I_blocks (32-bit integer value) representing the number of 512-byte "blocks" in the file. (The relationship between calculating the block size and the maximum capacity of a single file)

The max number of sublevel-directories is 31998, due to the link count limit. (The maximum number of subdirectories is 31998 because the number of directory Connections is limited) Directory indexing is isn't available in ext2, so there be performance issues for directories with a large number of files (10,000+). The theoretical limit on the number of files in a directory is 1.3x1020 because the file index is not used in the Ext2 file system, it appears when there are more than 10000 files in a folder The current problem, theoretically the number of files is limited to 1.3*10^20, although this is not the relevant for practical situations.

Note:in Linux 2.4 and earlier, block devices were limited to 2 TiB, limiting the maximum size of a partition, regardless of block size. (This shows that the partitions are not related to blocks, I do not know if I understand, this should be the system kernel limit)

Block size and partition maximum capacity single file maximum capacity relationship

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.