* [PATCH 0/2] btrfs: drop premature generation setting in btrfs_init_new_buffer()
@ 2025-11-20 13:57 Sun YangKai
2025-11-20 13:57 ` [PATCH 1/2] btrfs: add comment for btrfs_clear_buffer_dirty Sun YangKai
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Sun YangKai @ 2025-11-20 13:57 UTC (permalink / raw)
To: linux-btrfs; +Cc: Sun YangKai
In btrfs_init_new_buffer(), we set the buffer's generation just for the check in
btrfs_clear_buffer_dirty(). So just pass NULL to skip the check and we don't need
to set the generation before erasing the buffer.
No functional change.
See commit messages for details.
Sun YangKai (2):
btrfs: add comment for btrfs_clear_buffer_dirty
btrfs: drop premature generation setting in btrfs_init_new_buffer()
fs/btrfs/extent-tree.c | 6 ++----
fs/btrfs/extent_io.c | 20 ++++++++++++++++++++
2 files changed, 22 insertions(+), 4 deletions(-)
--
2.51.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] btrfs: add comment for btrfs_clear_buffer_dirty
2025-11-20 13:57 [PATCH 0/2] btrfs: drop premature generation setting in btrfs_init_new_buffer() Sun YangKai
@ 2025-11-20 13:57 ` Sun YangKai
2025-11-20 13:57 ` [PATCH 2/2] btrfs: drop premature generation setting in btrfs_init_new_buffer() Sun YangKai
2025-11-20 18:57 ` [PATCH 0/2] " Boris Burkov
2 siblings, 0 replies; 4+ messages in thread
From: Sun YangKai @ 2025-11-20 13:57 UTC (permalink / raw)
To: linux-btrfs; +Cc: Sun YangKai
Signed-off-by: Sun YangKai <sunk67188@gmail.com>
---
fs/btrfs/extent_io.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 23273d0e6f22..e80066fc0f02 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -3678,6 +3678,26 @@ static void btree_clear_folio_dirty_tag(struct folio *folio)
xa_unlock_irq(&folio->mapping->i_pages);
}
+/*
+ * btrfs_clear_buffer_dirty - Clear the dirty state of an extent buffer
+ * @trans: Transaction handle, may be NULL.
+ * If provided, the buffer must belong to the transaction
+ * (checked via btrfs_header_generation). If the check failed,
+ * the function returns immediately.
+ * @eb: The extent buffer to clean.
+ *
+ * This function clears the dirty flag from @eb and updates all accounting
+ * that depends on it (per-CPU counter of dirty metadata bytes, folio dirty
+ * state, address-space tags).
+ *
+ * Special behaviour in zoned mode:
+ * When the filesystem is zoned (btrfs_is_zoned) the buffer is *not*
+ * immediately cleaned. Instead the EXTENT_BUFFER_ZONED_ZEROOUT flag is
+ * set and the buffer remains conceptually dirty. The physical zero-out
+ * required by zoned devices is deferred until btree_csum_one_bio(), which
+ * preserves write-ordering constraints without forcing callers to re-dirty
+ * the buffer later.
+ */
void btrfs_clear_buffer_dirty(struct btrfs_trans_handle *trans,
struct extent_buffer *eb)
{
--
2.51.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] btrfs: drop premature generation setting in btrfs_init_new_buffer()
2025-11-20 13:57 [PATCH 0/2] btrfs: drop premature generation setting in btrfs_init_new_buffer() Sun YangKai
2025-11-20 13:57 ` [PATCH 1/2] btrfs: add comment for btrfs_clear_buffer_dirty Sun YangKai
@ 2025-11-20 13:57 ` Sun YangKai
2025-11-20 18:57 ` [PATCH 0/2] " Boris Burkov
2 siblings, 0 replies; 4+ messages in thread
From: Sun YangKai @ 2025-11-20 13:57 UTC (permalink / raw)
To: linux-btrfs; +Cc: Sun YangKai
btrfs_init_new_buffer() sets the header generation only to satisfy
btrfs_clear_buffer_dirty()'s transaction check, then immediately
cleared by memzero_extent_buffer(). This is introduced in
commit cbddcc4fa3443("btrfs: set generation before calling btrfs_clean_tree_block in btrfs_init_new_buffer").
However, after commit c4e54a6571168("btrfs: replace clearing extent buffer dirty bit with btrfs_clean_block")
we can pass NULL instead of the transaction handle to
btrfs_clear_buffer_dirty() so that the generation of the buffer is not
checked. So we can remove the generation assignment that was done only
for that check.
No functional change, just removes a redundant write.
Signed-off-by: Sun YangKai <sunk67188@gmail.com>
---
fs/btrfs/extent-tree.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index dc4ca98c3780..b22b0aaa99e4 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -5082,9 +5082,6 @@ btrfs_init_new_buffer(struct btrfs_trans_handle *trans, struct btrfs_root *root,
!test_bit(BTRFS_ROOT_RESET_LOCKDEP_CLASS, &root->state))
lockdep_owner = BTRFS_FS_TREE_OBJECTID;
- /* btrfs_clear_buffer_dirty() accesses generation field. */
- btrfs_set_header_generation(buf, trans->transid);
-
/*
* This needs to stay, because we could allocate a freed block from an
* old tree into a new tree, so we need to make sure this new block is
@@ -5093,7 +5090,8 @@ btrfs_init_new_buffer(struct btrfs_trans_handle *trans, struct btrfs_root *root,
btrfs_set_buffer_lockdep_class(lockdep_owner, buf, level);
btrfs_tree_lock_nested(buf, nest);
- btrfs_clear_buffer_dirty(trans, buf);
+ /* We don't care buf's generation here. */
+ btrfs_clear_buffer_dirty(NULL, buf);
clear_bit(EXTENT_BUFFER_STALE, &buf->bflags);
clear_bit(EXTENT_BUFFER_ZONED_ZEROOUT, &buf->bflags);
--
2.51.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 0/2] btrfs: drop premature generation setting in btrfs_init_new_buffer()
2025-11-20 13:57 [PATCH 0/2] btrfs: drop premature generation setting in btrfs_init_new_buffer() Sun YangKai
2025-11-20 13:57 ` [PATCH 1/2] btrfs: add comment for btrfs_clear_buffer_dirty Sun YangKai
2025-11-20 13:57 ` [PATCH 2/2] btrfs: drop premature generation setting in btrfs_init_new_buffer() Sun YangKai
@ 2025-11-20 18:57 ` Boris Burkov
2 siblings, 0 replies; 4+ messages in thread
From: Boris Burkov @ 2025-11-20 18:57 UTC (permalink / raw)
To: Sun YangKai; +Cc: linux-btrfs
On Thu, Nov 20, 2025 at 09:57:02PM +0800, Sun YangKai wrote:
> In btrfs_init_new_buffer(), we set the buffer's generation just for the check in
> btrfs_clear_buffer_dirty(). So just pass NULL to skip the check and we don't need
> to set the generation before erasing the buffer.
>
> No functional change.
>
> See commit messages for details.
Looks good, thanks
Reviewed-by: Boris Burkov <boris@bur.io>
>
> Sun YangKai (2):
> btrfs: add comment for btrfs_clear_buffer_dirty
> btrfs: drop premature generation setting in btrfs_init_new_buffer()
>
> fs/btrfs/extent-tree.c | 6 ++----
> fs/btrfs/extent_io.c | 20 ++++++++++++++++++++
> 2 files changed, 22 insertions(+), 4 deletions(-)
>
> --
> 2.51.2
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-11-20 18:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-20 13:57 [PATCH 0/2] btrfs: drop premature generation setting in btrfs_init_new_buffer() Sun YangKai
2025-11-20 13:57 ` [PATCH 1/2] btrfs: add comment for btrfs_clear_buffer_dirty Sun YangKai
2025-11-20 13:57 ` [PATCH 2/2] btrfs: drop premature generation setting in btrfs_init_new_buffer() Sun YangKai
2025-11-20 18:57 ` [PATCH 0/2] " Boris Burkov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox