[Concept,12/21] ext4l: Add a CONFIG_EXT4_MBALLOC_PREFETCH option

Message ID 20260108185149.1995917-13-sjg@u-boot.org
State New
Headers
Series ext4l: Add Kconfig options to reduce binary size (part P) |

Commit Message

Simon Glass Jan. 8, 2026, 6:51 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Add a Kconfig option to make mballoc prefetch support optional. The
prefetch functions (ext4_mb_prefetch, ext4_mb_prefetch_fini) are used
in Linux to optimise read performance by pre-loading block bitmaps
during lazy initialisation.

When disabled, guard the calls with IS_ENABLED() checks so gc-sections
can remove the prefetch code. This removes the prefetch functions from
the binary, reducing the external references to mballoc.

Disable this by default as U-Boot is unlikely to gain any performance
from this feature. It saves about 300 bytes.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 fs/ext4l/Kconfig   | 15 +++++++++++++++
 fs/ext4l/mballoc.c |  5 ++++-
 fs/ext4l/super.c   |  3 ++-
 3 files changed, 21 insertions(+), 2 deletions(-)
  

Patch

diff --git a/fs/ext4l/Kconfig b/fs/ext4l/Kconfig
index e494c66e8dc..3d7578f5073 100644
--- a/fs/ext4l/Kconfig
+++ b/fs/ext4l/Kconfig
@@ -110,3 +110,18 @@  config EXT4_INDIRECT
 
 	  Filesystems without the extents feature will be rejected if
 	  this is disabled. Adds about 5K. If unsure, say N.
+
+config EXT4_MBALLOC_PREFETCH
+	bool "Enable ext4 block bitmap prefetch support"
+	depends on FS_EXT4L
+	help
+	  Enable prefetching of block allocation bitmaps to improve
+	  allocation performance. When enabled, the multiblock allocator
+	  will read ahead block bitmaps during allocation and lazy
+	  initialization.
+
+	  Disabling this saves space by allowing the multiblock allocator
+	  prefetch code to be removed. Read performance may be slightly
+	  reduced during lazy initialization.
+
+	  If unsure, say Y.
diff --git a/fs/ext4l/mballoc.c b/fs/ext4l/mballoc.c
index 1643fd54f27..86ab374d686 100644
--- a/fs/ext4l/mballoc.c
+++ b/fs/ext4l/mballoc.c
@@ -2858,6 +2858,9 @@  static void ext4_mb_might_prefetch(struct ext4_allocation_context *ac,
 {
 	struct ext4_sb_info *sbi;
 
+	if (!IS_ENABLED(CONFIG_EXT4_MBALLOC_PREFETCH))
+		return;
+
 	if (ac->ac_prefetch_grp != group)
 		return;
 
@@ -3069,7 +3072,7 @@  out:
 		 ac->ac_b_ex.fe_len, ac->ac_o_ex.fe_len, ac->ac_status,
 		 ac->ac_flags, ac->ac_criteria, err);
 
-	if (ac->ac_prefetch_nr)
+	if (IS_ENABLED(CONFIG_EXT4_MBALLOC_PREFETCH) && ac->ac_prefetch_nr)
 		ext4_mb_prefetch_fini(sb, ac->ac_prefetch_grp, ac->ac_prefetch_nr);
 
 	return err;
diff --git a/fs/ext4l/super.c b/fs/ext4l/super.c
index 4bad3677db3..98785935f19 100644
--- a/fs/ext4l/super.c
+++ b/fs/ext4l/super.c
@@ -3663,7 +3663,8 @@  static int ext4_run_li_request(struct ext4_li_request *elr)
 	int nr = EXT4_SB(sb)->s_mb_prefetch;
 	u64 start_time;
 
-	if (elr->lr_mode == EXT4_LI_MODE_PREFETCH_BBITMAP) {
+	if (IS_ENABLED(CONFIG_EXT4_MBALLOC_PREFETCH) &&
+	    elr->lr_mode == EXT4_LI_MODE_PREFETCH_BBITMAP) {
 		elr->lr_next_group = ext4_mb_prefetch(sb, group, nr, &prefetch_ios);
 		ext4_mb_prefetch_fini(sb, elr->lr_next_group, nr);
 		trace_ext4_prefetch_bitmaps(sb, group, elr->lr_next_group, nr);