Linux-f2fs-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [f2fs-dev] [PATCH] f2fs: keep atomic write retry from zeroing original data
@ 2026-05-27 12:06 Wenjie Qi
  2026-06-11  8:12 ` Chao Yu via Linux-f2fs-devel
  2026-06-15 15:30 ` patchwork-bot+f2fs--- via Linux-f2fs-devel
  0 siblings, 2 replies; 3+ messages in thread
From: Wenjie Qi @ 2026-05-27 12:06 UTC (permalink / raw)
  To: jaegeuk, chao
  Cc: qwjhust, linux-kernel, qiwenjie, daehojeong, linux-f2fs-devel

A partial atomic write reserves a block in the COW inode before reading the
original data page for the untouched bytes in that page.

If that read fails, write_begin returns an error but leaves the COW inode
entry as NEW_ADDR. A retry of the same partial write then finds the COW
entry, treats it as existing COW data, and f2fs_write_begin() zeroes the
whole folio because blkaddr is NEW_ADDR.

If the retry is committed, the bytes outside the retried write range are
committed as zeroes instead of preserving the original file contents.

Only use the COW inode as the read source when it already has a real data
block. If the COW entry is still NEW_ADDR, treat it as a reservation to
reuse: keep reading the old data from the original inode and avoid
reserving or accounting the same atomic block again.

Fixes: 3db1de0e582c ("f2fs: change the current atomic write way")
Signed-off-by: Wenjie Qi <qiwenjie@xiaomi.com>
---
 fs/f2fs/data.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index d83a21998ec2..edda2ff72073 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -3862,6 +3862,7 @@ static int prepare_atomic_write_begin(struct f2fs_sb_info *sbi,
 	pgoff_t index = folio->index;
 	int err = 0;
 	block_t ori_blk_addr = NULL_ADDR;
+	bool cow_has_reserved_block = false;
 
 	/* If pos is beyond the end of file, reserve a new block in COW inode */
 	if ((pos & PAGE_MASK) >= i_size_read(inode))
@@ -3871,9 +3872,11 @@ static int prepare_atomic_write_begin(struct f2fs_sb_info *sbi,
 	err = __find_data_block(cow_inode, index, blk_addr);
 	if (err) {
 		return err;
-	} else if (*blk_addr != NULL_ADDR) {
+	} else if (__is_valid_data_blkaddr(*blk_addr)) {
 		*use_cow = true;
 		return 0;
+	} else if (*blk_addr == NEW_ADDR) {
+		cow_has_reserved_block = true;
 	}
 
 	if (is_inode_flag_set(inode, FI_ATOMIC_REPLACE))
@@ -3886,10 +3889,13 @@ static int prepare_atomic_write_begin(struct f2fs_sb_info *sbi,
 
 reserve_block:
 	/* Finally, we should reserve a new block in COW inode for the update */
-	err = __reserve_data_block(cow_inode, index, blk_addr, node_changed);
-	if (err)
-		return err;
-	inc_atomic_write_cnt(inode);
+	if (!cow_has_reserved_block) {
+		err = __reserve_data_block(cow_inode, index, blk_addr,
+					   node_changed);
+		if (err)
+			return err;
+		inc_atomic_write_cnt(inode);
+	}
 
 	if (ori_blk_addr != NULL_ADDR)
 		*blk_addr = ori_blk_addr;

base-commit: c0b65f6129c7fbb526e921dd60261650f1b2bef9
-- 
2.43.0



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

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

* Re: [f2fs-dev] [PATCH] f2fs: keep atomic write retry from zeroing original data
  2026-05-27 12:06 [f2fs-dev] [PATCH] f2fs: keep atomic write retry from zeroing original data Wenjie Qi
@ 2026-06-11  8:12 ` Chao Yu via Linux-f2fs-devel
  2026-06-15 15:30 ` patchwork-bot+f2fs--- via Linux-f2fs-devel
  1 sibling, 0 replies; 3+ messages in thread
From: Chao Yu via Linux-f2fs-devel @ 2026-06-11  8:12 UTC (permalink / raw)
  To: Wenjie Qi, jaegeuk; +Cc: linux-kernel, qiwenjie, daehojeong, linux-f2fs-devel

On 5/27/26 20:06, Wenjie Qi wrote:
> A partial atomic write reserves a block in the COW inode before reading the
> original data page for the untouched bytes in that page.
> 
> If that read fails, write_begin returns an error but leaves the COW inode
> entry as NEW_ADDR. A retry of the same partial write then finds the COW
> entry, treats it as existing COW data, and f2fs_write_begin() zeroes the
> whole folio because blkaddr is NEW_ADDR.
> 
> If the retry is committed, the bytes outside the retried write range are
> committed as zeroes instead of preserving the original file contents.
> 
> Only use the COW inode as the read source when it already has a real data
> block. If the COW entry is still NEW_ADDR, treat it as a reservation to
> reuse: keep reading the old data from the original inode and avoid
> reserving or accounting the same atomic block again.
> 

Cc: stable@kernel.org

> Fixes: 3db1de0e582c ("f2fs: change the current atomic write way")
> Signed-off-by: Wenjie Qi <qiwenjie@xiaomi.com>

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

Thanks,


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

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

* Re: [f2fs-dev] [PATCH] f2fs: keep atomic write retry from zeroing original data
  2026-05-27 12:06 [f2fs-dev] [PATCH] f2fs: keep atomic write retry from zeroing original data Wenjie Qi
  2026-06-11  8:12 ` Chao Yu via Linux-f2fs-devel
@ 2026-06-15 15:30 ` patchwork-bot+f2fs--- via Linux-f2fs-devel
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+f2fs--- via Linux-f2fs-devel @ 2026-06-15 15:30 UTC (permalink / raw)
  To: Wenjie Qi; +Cc: daehojeong, linux-kernel, linux-f2fs-devel, qiwenjie, jaegeuk

Hello:

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

On Wed, 27 May 2026 20:06:28 +0800 you wrote:
> A partial atomic write reserves a block in the COW inode before reading the
> original data page for the untouched bytes in that page.
> 
> If that read fails, write_begin returns an error but leaves the COW inode
> entry as NEW_ADDR. A retry of the same partial write then finds the COW
> entry, treats it as existing COW data, and f2fs_write_begin() zeroes the
> whole folio because blkaddr is NEW_ADDR.
> 
> [...]

Here is the summary with links:
  - [f2fs-dev] f2fs: keep atomic write retry from zeroing original data
    https://git.kernel.org/jaegeuk/f2fs/c/b5d5ab1ebe69

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




_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

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

end of thread, other threads:[~2026-06-15 15:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-27 12:06 [f2fs-dev] [PATCH] f2fs: keep atomic write retry from zeroing original data Wenjie Qi
2026-06-11  8:12 ` Chao Yu via Linux-f2fs-devel
2026-06-15 15:30 ` patchwork-bot+f2fs--- via Linux-f2fs-devel

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