brintos

brintos / linux-shallow public Read only

0
0
Text · 6.4 KiB · ed5a5ca Raw
136 lines · plain
1.. SPDX-License-Identifier: GPL-2.02 3Layout4------5 6The layout of a standard block group is approximately as follows (each7of these fields is discussed in a separate section below):8 9.. list-table::10   :widths: 1 1 1 1 1 1 1 111   :header-rows: 112 13   * - Group 0 Padding14     - ext4 Super Block15     - Group Descriptors16     - Reserved GDT Blocks17     - Data Block Bitmap18     - inode Bitmap19     - inode Table20     - Data Blocks21   * - 1024 bytes22     - 1 block23     - many blocks24     - many blocks25     - 1 block26     - 1 block27     - many blocks28     - many more blocks29 30For the special case of block group 0, the first 1024 bytes are unused,31to allow for the installation of x86 boot sectors and other oddities.32The superblock will start at offset 1024 bytes, whichever block that33happens to be (usually 0). However, if for some reason the block size =341024, then block 0 is marked in use and the superblock goes in block 1.35For all other block groups, there is no padding.36 37The ext4 driver primarily works with the superblock and the group38descriptors that are found in block group 0. Redundant copies of the39superblock and group descriptors are written to some of the block groups40across the disk in case the beginning of the disk gets trashed, though41not all block groups necessarily host a redundant copy (see following42paragraph for more details). If the group does not have a redundant43copy, the block group begins with the data block bitmap. Note also that44when the filesystem is freshly formatted, mkfs will allocate “reserve45GDT block” space after the block group descriptors and before the start46of the block bitmaps to allow for future expansion of the filesystem. By47default, a filesystem is allowed to increase in size by a factor of481024x over the original filesystem size.49 50The location of the inode table is given by ``grp.bg_inode_table_*``. It51is continuous range of blocks large enough to contain52``sb.s_inodes_per_group * sb.s_inode_size`` bytes.53 54As for the ordering of items in a block group, it is generally55established that the super block and the group descriptor table, if56present, will be at the beginning of the block group. The bitmaps and57the inode table can be anywhere, and it is quite possible for the58bitmaps to come after the inode table, or for both to be in different59groups (flex_bg). Leftover space is used for file data blocks, indirect60block maps, extent tree blocks, and extended attributes.61 62Flexible Block Groups63---------------------64 65Starting in ext4, there is a new feature called flexible block groups66(flex_bg). In a flex_bg, several block groups are tied together as one67logical block group; the bitmap spaces and the inode table space in the68first block group of the flex_bg are expanded to include the bitmaps69and inode tables of all other block groups in the flex_bg. For example,70if the flex_bg size is 4, then group 0 will contain (in order) the71superblock, group descriptors, data block bitmaps for groups 0-3, inode72bitmaps for groups 0-3, inode tables for groups 0-3, and the remaining73space in group 0 is for file data. The effect of this is to group the74block group metadata close together for faster loading, and to enable75large files to be continuous on disk. Backup copies of the superblock76and group descriptors are always at the beginning of block groups, even77if flex_bg is enabled. The number of block groups that make up a78flex_bg is given by 2 ^ ``sb.s_log_groups_per_flex``.79 80Meta Block Groups81-----------------82 83Without the option META_BG, for safety concerns, all block group84descriptors copies are kept in the first block group. Given the default85128MiB(2^27 bytes) block group size and 64-byte group descriptors, ext486can have at most 2^27/64 = 2^21 block groups. This limits the entire87filesystem size to 2^21 * 2^27 = 2^48bytes or 256TiB.88 89The solution to this problem is to use the metablock group feature90(META_BG), which is already in ext3 for all 2.6 releases. With the91META_BG feature, ext4 filesystems are partitioned into many metablock92groups. Each metablock group is a cluster of block groups whose group93descriptor structures can be stored in a single disk block. For ext494filesystems with 4 KB block size, a single metablock group partition95includes 64 block groups, or 8 GiB of disk space. The metablock group96feature moves the location of the group descriptors from the congested97first block group of the whole filesystem into the first group of each98metablock group itself. The backups are in the second and last group of99each metablock group. This increases the 2^21 maximum block groups limit100to the hard limit 2^32, allowing support for a 512PiB filesystem.101 102The change in the filesystem format replaces the current scheme where103the superblock is followed by a variable-length set of block group104descriptors. Instead, the superblock and a single block group descriptor105block is placed at the beginning of the first, second, and last block106groups in a meta-block group. A meta-block group is a collection of107block groups which can be described by a single block group descriptor108block. Since the size of the block group descriptor structure is 64109bytes, a meta-block group contains 16 block groups for filesystems with110a 1KB block size, and 64 block groups for filesystems with a 4KB111blocksize. Filesystems can either be created using this new block group112descriptor layout, or existing filesystems can be resized on-line, and113the field s_first_meta_bg in the superblock will indicate the first114block group using this new layout.115 116Please see an important note about ``BLOCK_UNINIT`` in the section about117block and inode bitmaps.118 119Lazy Block Group Initialization120-------------------------------121 122A new feature for ext4 are three block group descriptor flags that123enable mkfs to skip initializing other parts of the block group124metadata. Specifically, the INODE_UNINIT and BLOCK_UNINIT flags mean125that the inode and block bitmaps for that group can be calculated and126therefore the on-disk bitmap blocks are not initialized. This is127generally the case for an empty block group or a block group containing128only fixed-location block group metadata. The INODE_ZEROED flag means129that the inode table has been initialized; mkfs will unset this flag and130rely on the kernel to initialize the inode tables in the background.131 132By not writing zeroes to the bitmaps and inode table, mkfs time is133reduced considerably. Note the feature flag is RO_COMPAT_GDT_CSUM,134but the dumpe2fs output prints this as “uninit_bg”. They are the same135thing.136