[PATCH v2 01/11] f2fs: initialize sb_info early in f2fs_fill_super

From: Xinping Zhang

Date: Sat Aug 29 2026 - 13:49:37 EST


Previously, init_sb_info() was invoked late in f2fs_fill_super(), after
processing superblock error tracking, mount options, and sb->s_maxbytes.

However, read_raw_super_block() reads the superblock folio directly
from the block device mapping using folio page offsets. This makes the
initial static sb_set_blocksize(sb, F2FS_BLKSIZE) call redundant.

Move init_sb_info() to execute immediately after sbi->raw_super is
attached, allowing the block device block size to be set dynamically via
sb_set_blocksize(sb, sbi->blocksize).

This early initialization also prepares for upcoming patches that add
dynamically computed filesystem geometry fields, such as
sbi->addrs_per_block and sbi->nids_per_block, to init_sb_info(). These
fields are required by earlier initialization steps, including mount option
consistency checks and sb->s_maxbytes computation.

Signed-off-by: Kelvin Zhang <zhangxp1998@xxxxxxxxx>
---
fs/f2fs/super.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 253a579e9d5b..2d9f5b77f815 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -5125,12 +5125,6 @@ static int f2fs_fill_super(struct super_block
*sb, struct fs_context *fc)
}
mutex_init(&sbi->flush_lock);

- /* set a block size */
- if (unlikely(!sb_set_blocksize(sb, F2FS_BLKSIZE))) {
- f2fs_err(sbi, "unable to set blocksize");
- goto free_sbi;
- }
-
err = read_raw_super_block(sbi, &raw_super, &valid_super_block,
&recovery);
if (err)
@@ -5138,6 +5132,14 @@ static int f2fs_fill_super(struct super_block
*sb, struct fs_context *fc)

sb->s_fs_info = sbi;
sbi->raw_super = raw_super;
+ init_sb_info(sbi);
+
+ /* set a block size */
+ if (!sb_set_blocksize(sb, sbi->blocksize)) {
+ f2fs_err(sbi, "unable to set blocksize %u", sbi->blocksize);
+ err = -EINVAL;
+ goto free_sb_buf;
+ }
sbi->max_atc_write_bio_size = UINT_MAX;

INIT_WORK(&sbi->s_error_work, f2fs_record_error_work);
@@ -5217,8 +5219,6 @@ static int f2fs_fill_super(struct super_block
*sb, struct fs_context *fc)
if (err)
goto free_bio_info;

- init_sb_info(sbi);
-
err = f2fs_init_iostat(sbi);
if (err)
goto free_bio_info;
--
2.53.0