Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) .. SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) Layout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) ------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) The layout of a standard block group is approximately as follows (each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) of these fields is discussed in a separate section below):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) .. list-table::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)    :widths: 1 1 1 1 1 1 1 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)    :header-rows: 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)    * - Group 0 Padding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)      - ext4 Super Block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)      - Group Descriptors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)      - Reserved GDT Blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)      - Data Block Bitmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)      - inode Bitmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)      - inode Table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)      - Data Blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)    * - 1024 bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)      - 1 block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)      - many blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)      - many blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)      - 1 block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)      - 1 block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)      - many blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)      - many more blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) For the special case of block group 0, the first 1024 bytes are unused,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) to allow for the installation of x86 boot sectors and other oddities.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) The superblock will start at offset 1024 bytes, whichever block that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) happens to be (usually 0). However, if for some reason the block size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 1024, then block 0 is marked in use and the superblock goes in block 1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) For all other block groups, there is no padding.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) The ext4 driver primarily works with the superblock and the group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) descriptors that are found in block group 0. Redundant copies of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) superblock and group descriptors are written to some of the block groups
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) across the disk in case the beginning of the disk gets trashed, though
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) not all block groups necessarily host a redundant copy (see following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) paragraph for more details). If the group does not have a redundant
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) copy, the block group begins with the data block bitmap. Note also that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) when the filesystem is freshly formatted, mkfs will allocate “reserve
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) GDT block” space after the block group descriptors and before the start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) of the block bitmaps to allow for future expansion of the filesystem. By
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) default, a filesystem is allowed to increase in size by a factor of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 1024x over the original filesystem size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) The location of the inode table is given by ``grp.bg_inode_table_*``. It
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) is continuous range of blocks large enough to contain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) ``sb.s_inodes_per_group * sb.s_inode_size`` bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) As for the ordering of items in a block group, it is generally
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) established that the super block and the group descriptor table, if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) present, will be at the beginning of the block group. The bitmaps and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) the inode table can be anywhere, and it is quite possible for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) bitmaps to come after the inode table, or for both to be in different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) groups (flex\_bg). Leftover space is used for file data blocks, indirect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) block maps, extent tree blocks, and extended attributes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) Flexible Block Groups
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) ---------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) Starting in ext4, there is a new feature called flexible block groups
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) (flex\_bg). In a flex\_bg, several block groups are tied together as one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) logical block group; the bitmap spaces and the inode table space in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) first block group of the flex\_bg are expanded to include the bitmaps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) and inode tables of all other block groups in the flex\_bg. For example,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) if the flex\_bg size is 4, then group 0 will contain (in order) the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) superblock, group descriptors, data block bitmaps for groups 0-3, inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) bitmaps for groups 0-3, inode tables for groups 0-3, and the remaining
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) space in group 0 is for file data. The effect of this is to group the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) block group metadata close together for faster loading, and to enable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) large files to be continuous on disk. Backup copies of the superblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) and group descriptors are always at the beginning of block groups, even
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) if flex\_bg is enabled. The number of block groups that make up a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) flex\_bg is given by 2 ^ ``sb.s_log_groups_per_flex``.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) Meta Block Groups
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) -----------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) Without the option META\_BG, for safety concerns, all block group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) descriptors copies are kept in the first block group. Given the default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 128MiB(2^27 bytes) block group size and 64-byte group descriptors, ext4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) can have at most 2^27/64 = 2^21 block groups. This limits the entire
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) filesystem size to 2^21 ∗ 2^27 = 2^48bytes or 256TiB.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) The solution to this problem is to use the metablock group feature
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) (META\_BG), which is already in ext3 for all 2.6 releases. With the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) META\_BG feature, ext4 filesystems are partitioned into many metablock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) groups. Each metablock group is a cluster of block groups whose group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) descriptor structures can be stored in a single disk block. For ext4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) filesystems with 4 KB block size, a single metablock group partition
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) includes 64 block groups, or 8 GiB of disk space. The metablock group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) feature moves the location of the group descriptors from the congested
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) first block group of the whole filesystem into the first group of each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) metablock group itself. The backups are in the second and last group of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) each metablock group. This increases the 2^21 maximum block groups limit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) to the hard limit 2^32, allowing support for a 512PiB filesystem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) The change in the filesystem format replaces the current scheme where
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) the superblock is followed by a variable-length set of block group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) descriptors. Instead, the superblock and a single block group descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) block is placed at the beginning of the first, second, and last block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) groups in a meta-block group. A meta-block group is a collection of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) block groups which can be described by a single block group descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) block. Since the size of the block group descriptor structure is 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) bytes, a meta-block group contains 32 block groups for filesystems with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) a 1KB block size, and 128 block groups for filesystems with a 4KB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) blocksize. Filesystems can either be created using this new block group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) descriptor layout, or existing filesystems can be resized on-line, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) the field s\_first\_meta\_bg in the superblock will indicate the first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) block group using this new layout.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) Please see an important note about ``BLOCK_UNINIT`` in the section about
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) block and inode bitmaps.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) Lazy Block Group Initialization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) -------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) A new feature for ext4 are three block group descriptor flags that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) enable mkfs to skip initializing other parts of the block group
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) metadata. Specifically, the INODE\_UNINIT and BLOCK\_UNINIT flags mean
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) that the inode and block bitmaps for that group can be calculated and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) therefore the on-disk bitmap blocks are not initialized. This is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) generally the case for an empty block group or a block group containing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) only fixed-location block group metadata. The INODE\_ZEROED flag means
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) that the inode table has been initialized; mkfs will unset this flag and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) rely on the kernel to initialize the inode tables in the background.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) By not writing zeroes to the bitmaps and inode table, mkfs time is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) reduced considerably. Note the feature flag is RO\_COMPAT\_GDT\_CSUM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) but the dumpe2fs output prints this as “uninit\_bg”. They are the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) thing.