162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci
362306a36Sopenharmony_ciBigalloc
462306a36Sopenharmony_ci--------
562306a36Sopenharmony_ci
662306a36Sopenharmony_ciAt the moment, the default size of a block is 4KiB, which is a commonly
762306a36Sopenharmony_cisupported page size on most MMU-capable hardware. This is fortunate, as
862306a36Sopenharmony_ciext4 code is not prepared to handle the case where the block size
962306a36Sopenharmony_ciexceeds the page size. However, for a filesystem of mostly huge files,
1062306a36Sopenharmony_ciit is desirable to be able to allocate disk blocks in units of multiple
1162306a36Sopenharmony_ciblocks to reduce both fragmentation and metadata overhead. The
1262306a36Sopenharmony_cibigalloc feature provides exactly this ability.
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ciThe bigalloc feature (EXT4_FEATURE_RO_COMPAT_BIGALLOC) changes ext4 to
1562306a36Sopenharmony_ciuse clustered allocation, so that each bit in the ext4 block allocation
1662306a36Sopenharmony_cibitmap addresses a power of two number of blocks. For example, if the
1762306a36Sopenharmony_cifile system is mainly going to be storing large files in the 4-32
1862306a36Sopenharmony_cimegabyte range, it might make sense to set a cluster size of 1 megabyte.
1962306a36Sopenharmony_ciThis means that each bit in the block allocation bitmap now addresses
2062306a36Sopenharmony_ci256 4k blocks. This shrinks the total size of the block allocation
2162306a36Sopenharmony_cibitmaps for a 2T file system from 64 megabytes to 256 kilobytes. It also
2262306a36Sopenharmony_cimeans that a block group addresses 32 gigabytes instead of 128 megabytes,
2362306a36Sopenharmony_cialso shrinking the amount of file system overhead for metadata.
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ciThe administrator can set a block cluster size at mkfs time (which is
2662306a36Sopenharmony_cistored in the s_log_cluster_size field in the superblock); from then
2762306a36Sopenharmony_cion, the block bitmaps track clusters, not individual blocks. This means
2862306a36Sopenharmony_cithat block groups can be several gigabytes in size (instead of just
2962306a36Sopenharmony_ci128MiB); however, the minimum allocation unit becomes a cluster, not a
3062306a36Sopenharmony_ciblock, even for directories. TaoBao had a patchset to extend the “use
3162306a36Sopenharmony_ciunits of clusters instead of blocks” to the extent tree, though it is
3262306a36Sopenharmony_cinot clear where those patches went-- they eventually morphed into
3362306a36Sopenharmony_ci“extent tree v2” but that code has not landed as of May 2015.
3462306a36Sopenharmony_ci
35