mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Seongjae Jeong <jsjlee1020@gmail.com>
To: Jaegeuk Kim <jaegeuk@kernel.org>, Chao Yu <chao@kernel.org>
Cc: linux-f2fs-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org,
	Seongjae Jeong <jsjlee1020@gmail.com>
Subject: [PATCH] f2fs: batch block invalidation in f2fs_do_zero_range()
Date: Sat, 26 Sep 2026 09:46:48 +0000	[thread overview]
Message-ID: <20260926094648.12124-1-jsjlee1020@gmail.com> (raw)

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


                 reply	other threads:[~2026-09-26  9:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260926094648.12124-1-jsjlee1020@gmail.com \
    --to=jsjlee1020@gmail.com \
    --cc=chao@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®