Linux EXT4 FS development
 help / color / mirror / Atom feed
From: Baokun Li <libaokun@linux.alibaba.com>
To: linux-ext4@vger.kernel.org
Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz,
	yi.zhang@huawei.com, ojaswin@linux.ibm.com,
	ritesh.list@gmail.com, libaokun@linux.alibaba.com
Subject: [PATCH v2] ext4: enable mballoc kunit tests for blocksize > PAGE_SIZE
Date: Thu,  7 May 2026 16:37:54 +0800	[thread overview]
Message-ID: <20260507083754.1646636-1-libaokun@linux.alibaba.com> (raw)

With Large Block Size (LBS) support, ext4 can now use block sizes larger
than PAGE_SIZE. The mballoc kunit tests previously skipped three test
cases (test_mb_mark_used, test_mb_free_blocks, test_mb_mark_used_cost)
under this configuration because the buddy cache inode's folio mapping
order was never initialized in the test harness.

The real mount path configures s_min_folio_order and s_max_folio_order
in ext4_fill_super(), which allows ext4_set_inode_mapping_order() to
set up the correct folio order for the buddy cache inode. The kunit
test bypasses ext4_fill_super(), so the mapping order stayed at zero
and __filemap_get_folio() allocated order-0 folios too small for LBS.

Initialize s_min_folio_order and s_max_folio_order in mbt_init_sb_layout()
to mirror ext4_fill_super() behavior, enabling properly sized folio
allocations and removing the three blocksize > PAGE_SIZE skips.

Add mbt_check_lbs_support() to skip tests that use
ext4_mb_load_buddy_test() when blocksize > PAGE_SIZE without
CONFIG_TRANSPARENT_HUGEPAGE.  Without THP, mapping_set_folio_order_range()
is a no-op and __filemap_get_folio() allocates order-0 folios (PAGE_SIZE),
which are too small for the buddy cache bitmap/buddy data.

Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Baokun Li <libaokun@linux.alibaba.com>
---
Changes since v1:
 * Add mbt_check_lbs_support() to skip tests when blocksize > PAGE_SIZE
   without CONFIG_TRANSPARENT_HUGEPAGE. (Reported by sashiko.)

v1: https://patch.msgid.link/20260506075900.3649944-1-libaokun@linux.alibaba.com

 fs/ext4/mballoc-test.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/fs/ext4/mballoc-test.c b/fs/ext4/mballoc-test.c
index 90ed505fa4b1..72820bb2dcd4 100644
--- a/fs/ext4/mballoc-test.c
+++ b/fs/ext4/mballoc-test.c
@@ -206,6 +206,8 @@ static void mbt_init_sb_layout(struct super_block *sb,
 	sbi->s_desc_per_block_bits =
 		sb->s_blocksize_bits - (fls(layout->desc_size) - 1);
 	sbi->s_desc_per_block = 1 << sbi->s_desc_per_block_bits;
+	sbi->s_min_folio_order = get_order(sb->s_blocksize);
+	sbi->s_max_folio_order = sbi->s_min_folio_order;
 
 	es->s_first_data_block = cpu_to_le32(0);
 	es->s_blocks_count_lo = cpu_to_le32(layout->blocks_per_group *
@@ -781,6 +783,16 @@ test_mb_mark_used_range(struct kunit *test, struct ext4_buddy *e4b,
 	mbt_validate_group_info(test, grp, e4b->bd_info);
 }
 
+/*
+ * Skip if blocksize > PAGE_SIZE without THP.  The buddy cache folio
+ * allocation requires CONFIG_TRANSPARENT_HUGEPAGE for large blocks.
+ */
+static void mbt_check_lbs_support(struct kunit *test, struct super_block *sb)
+{
+	if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && sb->s_blocksize > PAGE_SIZE)
+		kunit_skip(test, "blocksize > PAGE_SIZE requires CONFIG_TRANSPARENT_HUGEPAGE");
+}
+
 static void test_mb_mark_used(struct kunit *test)
 {
 	struct ext4_buddy e4b;
@@ -791,9 +803,7 @@ static void test_mb_mark_used(struct kunit *test)
 	struct test_range ranges[TEST_RANGE_COUNT];
 	int i;
 
-	/* buddy cache assumes that each page contains at least one block */
-	if (sb->s_blocksize > PAGE_SIZE)
-		kunit_skip(test, "blocksize exceeds pagesize");
+	mbt_check_lbs_support(test, sb);
 
 	bitmap = kunit_kzalloc(test, sb->s_blocksize, GFP_KERNEL);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, bitmap);
@@ -858,9 +868,7 @@ static void test_mb_free_blocks(struct kunit *test)
 	int i;
 	struct test_range ranges[TEST_RANGE_COUNT];
 
-	/* buddy cache assumes that each page contains at least one block */
-	if (sb->s_blocksize > PAGE_SIZE)
-		kunit_skip(test, "blocksize exceeds pagesize");
+	mbt_check_lbs_support(test, sb);
 
 	bitmap = kunit_kzalloc(test, sb->s_blocksize, GFP_KERNEL);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, bitmap);
@@ -905,9 +913,7 @@ static void test_mb_mark_used_cost(struct kunit *test)
 	int i, j;
 	unsigned long start, end, all = 0;
 
-	/* buddy cache assumes that each page contains at least one block */
-	if (sb->s_blocksize > PAGE_SIZE)
-		kunit_skip(test, "blocksize exceeds pagesize");
+	mbt_check_lbs_support(test, sb);
 
 	ret = ext4_mb_load_buddy_test(sb, TEST_GOAL_GROUP, &e4b);
 	KUNIT_ASSERT_EQ(test, ret, 0);
-- 
2.43.7


                 reply	other threads:[~2026-05-07  8:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260507083754.1646636-1-libaokun@linux.alibaba.com \
    --to=libaokun@linux.alibaba.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=jack@suse.cz \
    --cc=linux-ext4@vger.kernel.org \
    --cc=ojaswin@linux.ibm.com \
    --cc=ritesh.list@gmail.com \
    --cc=tytso@mit.edu \
    --cc=yi.zhang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox