Skip to contentSkip to conversation

f2fs: fix termination of f2fs_sync_meta_caches()

PATCH Applied Seongjae Jeong 3 participants 3 messages Oct 10 – Oct 13 F2FS file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 f2fs: fix termination of f2fs_sync_meta_caches()

When __f2fs_write_meta_cache() returns false in f2fs_sync_meta_caches(), the function only exits the inner loop instead of the entire while loop. This leads to an unnecessary lookup of the next batch.

Also, when nwritten >= nr_to_write, only the inner loop terminates. This allows the function to continue processing subsequent batches after the writeback budget has been reached.

Terminate the entire while loop in both cases to avoid unnecessary batch lookups and respect the writeback budget.

---
based on the f2fs dev-test at commit ce439a2b0690

 fs/f2fs/checkpoint.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/f2fs/checkpoint.c +5 -1
index 2e5e0ee5feb2..4cafc96056ab 100644
@@ -654,7 +654,8 @@ long f2fs_sync_meta_caches(struct f2fs_sb_info *sbi, long nr_to_write,
 
 			if (!__f2fs_write_meta_cache(entry, io_type)) {
 				f2fs_unlock_cache(entry);
-				break;
+				f2fs_cache_gang_release(entries, nr);
+				goto stop;
 			}
 			nwritten++;
 			next = entry->index + 1;
@@ -663,6 +664,9 @@ long f2fs_sync_meta_caches(struct f2fs_sb_info *sbi, long nr_to_write,
 		}
 		f2fs_cache_gang_release(entries, nr);
 		cond_resched();
+
+		if (unlikely(nwritten >= nr_to_write))
+			break;
 	}
 stop:
 	if (nwritten)
Signature · 1 line
2.53.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Seongjae Jeong

When __f2fs_write_meta_cache() returns false in f2fs_sync_meta_caches(), the function only exits the inner loop instead of the entire while loop. This leads to an unnecessary lookup of the next batch.

Quoted 8 lines

Also, when nwritten >= nr_to_write, only the inner loop terminates. This allows the function to continue processing subsequent batches after the writeback budget has been reached.

Terminate the entire while loop in both cases to avoid unnecessary batch lookups and respect the writeback budget.

Thanks,

#2 lore raw
In reply to Seongjae Jeong
This patch was applied to jaegeuk/f2fs.git (dev) by Jaegeuk Kim <[email protected]>:

Hello:

This patch was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <[email protected]>:

Quoted 9 lines · On Sat, 10 Oct 2026 07:49:12 +0000 you wrote:

When __f2fs_write_meta_cache() returns false in f2fs_sync_meta_caches(), the function only exits the inner loop instead of the entire while loop. This leads to an unnecessary lookup of the next batch.

Also, when nwritten >= nr_to_write, only the inner loop terminates. This allows the function to continue processing subsequent batches after the writeback budget has been reached.

[...]

Here is the summary with links:
- [f2fs-dev] f2fs: fix termination of f2fs_sync_meta_caches()

    https://git.kernel.org/jaegeuk/f2fs/c/a45c9a0055f5

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html