Skip to contentSkip to conversation

Patch "ext4: fix calculation of credits for extent tree modification" has been added to the 5.10-stable tree

PATCH [email protected] 1 participant 1 message Jun 20, 2025 ext4 file system

lore
Share & tools
lore

[email protected]

author Applied
#0 lore raw

This is a note to let you know that I've just added the patch titled

ext4: fix calculation of credits for extent tree modification

to the 5.10-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
ext4-fix-calculation-of-credits-for-extent-tree-modification.patch
and it can be found in the queue-5.10 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

From 32a93f5bc9b9812fc710f43a4d8a6830f91e4988 Mon Sep 17 00:00:00 2001
From: Jan Kara <[email protected]>
Date: Tue, 29 Apr 2025 19:55:36 +0200
Subject: ext4: fix calculation of credits for extent tree modification

From: Jan Kara <[email protected]>

commit 32a93f5bc9b9812fc710f43a4d8a6830f91e4988 upstream.

Luis and David are reporting that after running generic/750 test for 90+ hours on 2k ext4 filesystem, they are able to trigger a warning in jbd2_journal_dirty_metadata() complaining that there are not enough credits in the running transaction started in ext4_do_writepages().

Indeed the code in ext4_do_writepages() is racy and the extent tree can change between the time we compute credits necessary for extent tree computation and the time we actually modify the extent tree. Thus it may happen that the number of credits actually needed is higher. Modify ext4_ext_index_trans_blocks() to count with the worst case of maximum tree depth. This can reduce the possible number of writers that can operate in the system in parallel (because the credit estimates now won't fit in one transaction) but for reasonably sized journals this shouldn't really be an issue. So just go with a safe and simple fix.

---
 fs/ext4/extents.c |   11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
fs/ext4/extents.c +6 -5
@@ -2367,18 +2367,19 @@ int ext4_ext_calc_credits_for_single_ext
 int ext4_ext_index_trans_blocks(struct inode *inode, int extents)
 {
 	int index;
-	int depth;
 
 	/* If we are converting the inline data, only one is needed here. */
 	if (ext4_has_inline_data(inode))
 		return 1;
 
-	depth = ext_depth(inode);
-
+	/*
+	 * Extent tree can change between the time we estimate credits and
+	 * the time we actually modify the tree. Assume the worst case.
+	 */
 	if (extents <= 1)
-		index = depth * 2;
+		index = EXT4_MAX_EXTENT_DEPTH * 2;
 	else
-		index = depth * 3;
+		index = EXT4_MAX_EXTENT_DEPTH * 3;
 
 	return index;
 }

Patches currently in stable-queue which might be from [email protected] are

queue-5.10/ext4-inline-fix-len-overflow-in-ext4_prepare_inline_data.patch queue-5.10/ext4-fix-calculation-of-credits-for-extent-tree-modification.patch queue-5.10/jbd2-fix-data-race-and-null-ptr-deref-in-jbd2_journal_dirty_metadata.patch queue-5.10/ext4-ensure-i_size-is-smaller-than-maxbytes.patch queue-5.10/ext4-factor-out-ext4_get_maxbytes.patch