Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ext4: simplify mballoc preallocation size rounding for small files

The if-else ladder in ext4_mb_normalize_request() manually rounds up
the preallocation size to the next power of two for files up to 1MB,
enumerating each step from 16KB to 1MB individually. Replace this with
a single roundup_pow_of_two() call clamped to a 16KB minimum, which
is functionally equivalent but much more concise.

Also replace raw byte constants with SZ_1M and SZ_16K from
<linux/sizes.h> for clarity, and remove the stale "XXX: should this
table be tunable?" comment that has been there since the original
mballoc code.

No functional change.

Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Weixie Cui <cuiweixie@gmail.com>
Link: https://patch.msgid.link/tencent_E9C5F1B2E9939B3037501FD04A7E9CF0C407@qq.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>

authored by

Weixie Cui and committed by
Theodore Ts'o
af1502f9 a804ecc3

+9 -15
+9 -15
fs/ext4/mballoc.c
··· 4561 4561 (req <= (size) || max <= (chunk_size)) 4562 4562 4563 4563 /* first, try to predict filesize */ 4564 - /* XXX: should this table be tunable? */ 4565 4564 start_off = 0; 4566 - if (size <= 16 * 1024) { 4567 - size = 16 * 1024; 4568 - } else if (size <= 32 * 1024) { 4569 - size = 32 * 1024; 4570 - } else if (size <= 64 * 1024) { 4571 - size = 64 * 1024; 4572 - } else if (size <= 128 * 1024) { 4573 - size = 128 * 1024; 4574 - } else if (size <= 256 * 1024) { 4575 - size = 256 * 1024; 4576 - } else if (size <= 512 * 1024) { 4577 - size = 512 * 1024; 4578 - } else if (size <= 1024 * 1024) { 4579 - size = 1024 * 1024; 4565 + if (size <= SZ_1M) { 4566 + /* 4567 + * For files up to 1MB, round up the preallocation size to 4568 + * the next power of two, with a minimum of 16KB. 4569 + */ 4570 + if (size <= (unsigned long)SZ_16K) 4571 + size = SZ_16K; 4572 + else 4573 + size = roundup_pow_of_two(size); 4580 4574 } else if (NRL_CHECK_SIZE(size, 4 * 1024 * 1024, max, 2 * 1024)) { 4581 4575 start_off = ((loff_t)ac->ac_o_ex.fe_logical >> 4582 4576 (21 - bsbits)) << 21;