public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Sun YangKai <sunk67188@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Sun YangKai <sunk67188@gmail.com>
Subject: [PATCH 2/2] btrfs: drop premature generation setting in btrfs_init_new_buffer()
Date: Thu, 20 Nov 2025 21:57:06 +0800	[thread overview]
Message-ID: <20251120140030.2770-6-sunk67188@gmail.com> (raw)
In-Reply-To: <20251120140030.2770-2-sunk67188@gmail.com>

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


  parent reply	other threads:[~2025-11-20 14:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2025-11-20 18:57 ` [PATCH 0/2] btrfs: drop premature generation setting in btrfs_init_new_buffer() Boris Burkov

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=20251120140030.2770-6-sunk67188@gmail.com \
    --to=sunk67188@gmail.com \
    --cc=linux-btrfs@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