public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: fdmanana@kernel.org
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 12/22] btrfs: avoid researching tree when converting bits in an extent range
Date: Wed, 23 Apr 2025 15:19:52 +0100	[thread overview]
Message-ID: <169a547a4f511dfd5bc999e7a0ae984ebd045df0.1745401628.git.fdmanana@suse.com> (raw)
In-Reply-To: <cover.1745401627.git.fdmanana@suse.com>

From: Filipe Manana <fdmanana@suse.com>

When converting bits for an extent range (btrfs_convert_extent_bit()), if
the current extent state record starts after the target range, we always
do a jump to the 'search_again' label, which will cause us to do a full
tree search for the next state if the current state ends before the target
range. Unless we need to reschedule, we can just grab the next state and
process it, avoiding a full tree search, even if that next state is not
contiguous, as we'll allocate and insert a new prealloc state if needed.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
 fs/btrfs/extent-io-tree.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/fs/btrfs/extent-io-tree.c b/fs/btrfs/extent-io-tree.c
index a898a15a7854..65665c0843e6 100644
--- a/fs/btrfs/extent-io-tree.c
+++ b/fs/btrfs/extent-io-tree.c
@@ -1458,6 +1458,22 @@ int btrfs_convert_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
 		if (inserted_state == prealloc)
 			prealloc = NULL;
 		start = inserted_state->end + 1;
+
+		/* Beyond target range, stop. */
+		if (start > end)
+			goto out;
+
+		if (need_resched())
+			goto search_again;
+
+		state = next_search_state(inserted_state, end);
+		/*
+		 * If there's a next state, whether contiguous or not, we don't
+		 * need to unlock and research. If it's not contiguous we will
+		 * end up here and try to allocate a prealloc state and insert.
+		 */
+		if (state)
+			goto hit_next;
 		goto search_again;
 	}
 	/*
-- 
2.47.2


  parent reply	other threads:[~2025-04-23 14:20 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-23 14:19 [PATCH 00/22] btrfs: some io tree optimizations and cleanups fdmanana
2025-04-23 14:19 ` [PATCH 01/22] btrfs: remove duplicate error check at btrfs_clear_extent_bit_changeset() fdmanana
2025-04-23 14:19 ` [PATCH 02/22] btrfs: exit after state split error " fdmanana
2025-04-23 14:19 ` [PATCH 03/22] btrfs: add missing error return to btrfs_clear_extent_bit_changeset() fdmanana
2025-04-23 14:19 ` [PATCH 04/22] btrfs: use bools for local variables at btrfs_clear_extent_bit_changeset() fdmanana
2025-04-23 14:19 ` [PATCH 05/22] btrfs: avoid extra tree search " fdmanana
2025-04-23 14:19 ` [PATCH 06/22] btrfs: simplify last record detection " fdmanana
2025-04-23 14:19 ` [PATCH 07/22] btrfs: remove duplicate error check at btrfs_convert_extent_bit() fdmanana
2025-04-23 14:19 ` [PATCH 08/22] btrfs: exit after state split error " fdmanana
2025-04-23 14:19 ` [PATCH 09/22] btrfs: exit after state insertion failure " fdmanana
2025-04-23 14:19 ` [PATCH 10/22] btrfs: avoid unnecessary next node searches when clearing bits from extent range fdmanana
2025-04-23 14:19 ` [PATCH 11/22] btrfs: avoid repeated extent state processing when converting extent bits fdmanana
2025-04-23 14:19 ` fdmanana [this message]
2025-04-23 14:19 ` [PATCH 13/22] btrfs: simplify last record detection at btrfs_convert_extent_bit() fdmanana
2025-04-23 14:19 ` [PATCH 14/22] btrfs: exit after state insertion failure at set_extent_bit() fdmanana
2025-04-23 14:19 ` [PATCH 15/22] btrfs: exit after state split error " fdmanana
2025-04-23 14:19 ` [PATCH 16/22] btrfs: simplify last record detection " fdmanana
2025-04-23 14:19 ` [PATCH 17/22] btrfs: avoid repeated extent state processing when setting extent bits fdmanana
2025-04-23 14:19 ` [PATCH 18/22] btrfs: avoid researching tree when setting bits in an extent range fdmanana
2025-04-23 14:19 ` [PATCH 19/22] btrfs: remove unnecessary NULL checks before freeing extent state fdmanana
2025-04-23 14:20 ` [PATCH 20/22] btrfs: don't BUG_ON() when unpinning extents during transaction commit fdmanana
2025-04-23 14:20 ` [PATCH 21/22] btrfs: remove variable to track trimmed bytes at btrfs_finish_extent_commit() fdmanana
2025-04-23 14:20 ` [PATCH 22/22] btrfs: make extent unpinning more efficient when committing transaction fdmanana
2025-04-28 14:53 ` [PATCH 00/22] btrfs: some io tree optimizations and cleanups David Sterba

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=169a547a4f511dfd5bc999e7a0ae984ebd045df0.1745401628.git.fdmanana@suse.com \
    --to=fdmanana@kernel.org \
    --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