public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v5] f2fs: Optimize f2fs_truncate_data_blocks_range()
@ 2025-01-15  5:39 Yi Sun
  2025-01-16 10:47 ` Chao Yu
  2025-01-17 21:10 ` [f2fs-dev] " patchwork-bot+f2fs
  0 siblings, 2 replies; 3+ messages in thread
From: Yi Sun @ 2025-01-15  5:39 UTC (permalink / raw)
  To: chao, jaegeuk
  Cc: linux-f2fs-devel, linux-kernel, yi.sun, Hao_hao.Wang, Ke.Wang,
	zhiguo.niu

Function f2fs_invalidate_blocks() can process consecutive
blocks at a time, so f2fs_truncate_data_blocks_range() is
optimized to use the new functionality of
f2fs_invalidate_blocks().

Add two variables @blkstart and @blklen, @blkstart records
the first address of the consecutive blocks, and @blkstart
records the number of consecutive blocks.

Signed-off-by: Yi Sun <yi.sun@unisoc.com>
---
 fs/f2fs/file.c | 29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index c43d64898d8b..00fcac45f1bb 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -621,8 +621,11 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count)
 	int cluster_index = 0, valid_blocks = 0;
 	int cluster_size = F2FS_I(dn->inode)->i_cluster_size;
 	bool released = !atomic_read(&F2FS_I(dn->inode)->i_compr_blocks);
+	block_t blkstart;
+	int blklen = 0;
 
 	addr = get_dnode_addr(dn->inode, dn->node_page) + ofs;
+	blkstart = le32_to_cpu(*addr);
 
 	/* Assumption: truncation starts with cluster */
 	for (; count > 0; count--, addr++, dn->ofs_in_node++, cluster_index++) {
@@ -638,26 +641,44 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count)
 		}
 
 		if (blkaddr == NULL_ADDR)
-			continue;
+			goto next;
 
 		f2fs_set_data_blkaddr(dn, NULL_ADDR);
 
 		if (__is_valid_data_blkaddr(blkaddr)) {
 			if (time_to_inject(sbi, FAULT_BLKADDR_CONSISTENCE))
-				continue;
+				goto next;
 			if (!f2fs_is_valid_blkaddr_raw(sbi, blkaddr,
 						DATA_GENERIC_ENHANCE))
-				continue;
+				goto next;
 			if (compressed_cluster)
 				valid_blocks++;
 		}
 
-		f2fs_invalidate_blocks(sbi, blkaddr, 1);
+		if (blkstart + blklen == blkaddr) {
+			blklen++;
+		} else {
+			f2fs_invalidate_blocks(sbi, blkstart, blklen);
+			blkstart = blkaddr;
+			blklen = 1;
+		}
 
 		if (!released || blkaddr != COMPRESS_ADDR)
 			nr_free++;
+
+		continue;
+
+next:
+		if (blklen)
+			f2fs_invalidate_blocks(sbi, blkstart, blklen);
+
+		blkstart = le32_to_cpu(*(addr + 1));
+		blklen = 0;
 	}
 
+	if (blklen)
+		f2fs_invalidate_blocks(sbi, blkstart, blklen);
+
 	if (compressed_cluster)
 		f2fs_i_compr_blocks_update(dn->inode, valid_blocks, false);
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v5] f2fs: Optimize f2fs_truncate_data_blocks_range()
  2025-01-15  5:39 [PATCH v5] f2fs: Optimize f2fs_truncate_data_blocks_range() Yi Sun
@ 2025-01-16 10:47 ` Chao Yu
  2025-01-17 21:10 ` [f2fs-dev] " patchwork-bot+f2fs
  1 sibling, 0 replies; 3+ messages in thread
From: Chao Yu @ 2025-01-16 10:47 UTC (permalink / raw)
  To: Yi Sun, jaegeuk
  Cc: chao, linux-f2fs-devel, linux-kernel, Hao_hao.Wang, Ke.Wang,
	zhiguo.niu

On 1/15/25 13:39, Yi Sun wrote:
> Function f2fs_invalidate_blocks() can process consecutive
> blocks at a time, so f2fs_truncate_data_blocks_range() is
> optimized to use the new functionality of
> f2fs_invalidate_blocks().
> 
> Add two variables @blkstart and @blklen, @blkstart records
> the first address of the consecutive blocks, and @blkstart
> records the number of consecutive blocks.
> 
> Signed-off-by: Yi Sun <yi.sun@unisoc.com>

Reviewed-by: Chao Yu <chao@kernel.org>

Thanks,

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [f2fs-dev] [PATCH v5] f2fs: Optimize f2fs_truncate_data_blocks_range()
  2025-01-15  5:39 [PATCH v5] f2fs: Optimize f2fs_truncate_data_blocks_range() Yi Sun
  2025-01-16 10:47 ` Chao Yu
@ 2025-01-17 21:10 ` patchwork-bot+f2fs
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+f2fs @ 2025-01-17 21:10 UTC (permalink / raw)
  To: Yi Sun
  Cc: chao, jaegeuk, Ke.Wang, linux-kernel, zhiguo.niu,
	linux-f2fs-devel, Hao_hao.Wang

Hello:

This patch was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <jaegeuk@kernel.org>:

On Wed, 15 Jan 2025 13:39:43 +0800 you wrote:
> Function f2fs_invalidate_blocks() can process consecutive
> blocks at a time, so f2fs_truncate_data_blocks_range() is
> optimized to use the new functionality of
> f2fs_invalidate_blocks().
> 
> Add two variables @blkstart and @blklen, @blkstart records
> the first address of the consecutive blocks, and @blkstart
> records the number of consecutive blocks.
> 
> [...]

Here is the summary with links:
  - [f2fs-dev,v5] f2fs: Optimize f2fs_truncate_data_blocks_range()
    https://git.kernel.org/jaegeuk/f2fs/c/120ac1dc322f

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-01-17 21:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-15  5:39 [PATCH v5] f2fs: Optimize f2fs_truncate_data_blocks_range() Yi Sun
2025-01-16 10:47 ` Chao Yu
2025-01-17 21:10 ` [f2fs-dev] " patchwork-bot+f2fs

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