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

bdev: add hint prints in sb_set_blocksize() for LBS dependency on THP

Support for block sizes greater than the page size depends on large
folios, which in turn require CONFIG_TRANSPARENT_HUGEPAGE to be enabled.

Because the code is wrapped in multiple layers of abstraction, this
dependency is rather obscure, so users may not realize it and may be
unsure how to enable LBS.

As suggested by Theodore, I have added hint messages in sb_set_blocksize
so that users can distinguish whether a mount failure with block size
larger than page size is due to lack of filesystem support or the absence
of CONFIG_TRANSPARENT_HUGEPAGE.

Suggested-by: Theodore Ts'o <tytso@mit.edu>
Link: https://patch.msgid.link/20251110043226.GD2988753@mit.edu
Signed-off-by: Baokun Li <libaokun1@huawei.com>
Link: https://patch.msgid.link/20251110124714.1329978-1-libaokun@huaweicloud.com
Reviewed-by: Zhang Yi <yi.zhang@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Christian Brauner <brauner@kernel.org>

authored by

Baokun Li and committed by
Christian Brauner
50b2a4f1 04f0955b

+18 -1
+18 -1
block/bdev.c
··· 217 217 218 218 EXPORT_SYMBOL(set_blocksize); 219 219 220 + static int sb_validate_large_blocksize(struct super_block *sb, int size) 221 + { 222 + const char *err_str = NULL; 223 + 224 + if (!(sb->s_type->fs_flags & FS_LBS)) 225 + err_str = "not supported by filesystem"; 226 + else if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) 227 + err_str = "is only supported with CONFIG_TRANSPARENT_HUGEPAGE"; 228 + 229 + if (!err_str) 230 + return 0; 231 + 232 + pr_warn_ratelimited("%s: block size(%d) > page size(%lu) %s\n", 233 + sb->s_type->name, size, PAGE_SIZE, err_str); 234 + return -EINVAL; 235 + } 236 + 220 237 int sb_set_blocksize(struct super_block *sb, int size) 221 238 { 222 - if (!(sb->s_type->fs_flags & FS_LBS) && size > PAGE_SIZE) 239 + if (size > PAGE_SIZE && sb_validate_large_blocksize(sb, size)) 223 240 return 0; 224 241 if (set_blocksize(sb->s_bdev_file, size)) 225 242 return 0;