mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] f2fs: batch block invalidation in f2fs_do_zero_range()
@ 2026-09-26  9:46 Seongjae Jeong
  0 siblings, 0 replies; only message in thread
From: Seongjae Jeong @ 2026-09-26  9:46 UTC (permalink / raw)
  To: Jaegeuk Kim, Chao Yu; +Cc: linux-f2fs-devel, linux-kernel, Seongjae Jeong

f2fs_do_zero_range() calls f2fs_invalidate_blocks() for each mapped
data block. Each call acquires the SIT sentry write lock and updates
segment information.

Batch contiguous physical block addresses into a single invalidation
call. A NEW_ADDR slot does not end a run if the subsequent physical
addresses are contiguous.

In a microbenchmark on an F2FS loop device, a fresh 64 MiB file was
written and fsynced before timing fallocate with FALLOC_FL_ZERO_RANGE
flag over the whole file. Across 20 runs, mean syscall time
decreased from 16.436 ms to 10.011 ms (39%).

Signed-off-by: Seongjae Jeong <jsjlee1020@gmail.com>
---
 fs/f2fs/file.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index b0bdc7a977b9..c227b7603731 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -1713,6 +1713,8 @@ static int f2fs_do_zero_range(struct dnode_of_data *dn, pgoff_t start,
 	unsigned int ofs_in_node = dn->ofs_in_node;
 	blkcnt_t count = 0;
 	int ret;
+	block_t blkstart = 0;
+	unsigned int blklen = 0;
 
 	for (; index < end; index++, dn->ofs_in_node++) {
 		if (f2fs_data_blkaddr(dn) == NULL_ADDR)
@@ -1739,16 +1741,30 @@ static int f2fs_do_zero_range(struct dnode_of_data *dn, pgoff_t start,
 		if (dn->data_blkaddr == NEW_ADDR)
 			continue;
 
+		/*
+		 * Flush before validation so a repeated block address
+		 * can be detected through the SIT bitmap.
+		 */
+		if (blklen && blkstart + blklen != dn->data_blkaddr) {
+			f2fs_invalidate_blocks(sbi, blkstart, blklen);
+			blklen = 0;
+		}
+
 		if (!f2fs_is_valid_blkaddr(sbi, dn->data_blkaddr,
 					DATA_GENERIC_ENHANCE)) {
 			ret = -EFSCORRUPTED;
 			break;
 		}
 
-		f2fs_invalidate_blocks(sbi, dn->data_blkaddr, 1);
+		if (!blklen)
+			blkstart = dn->data_blkaddr;
+		blklen++;
 		f2fs_set_data_blkaddr(dn, NEW_ADDR);
 	}
 
+	if (blklen)
+		f2fs_invalidate_blocks(sbi, blkstart, blklen);
+
 	if (index > start) {
 		f2fs_update_read_extent_cache_range(dn, start, 0,
 							index - start);
-- 
2.53.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-09-26  9:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-26  9:46 [PATCH] f2fs: batch block invalidation in f2fs_do_zero_range() Seongjae Jeong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®