All of lore.kernel.org
 help / color / mirror / Atom feed
From: fdmanana@kernel.org
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 3/6] btrfs: remove useless condition check before splitting leaf
Date: Thu,  2 Dec 2021 10:30:37 +0000	[thread overview]
Message-ID: <0f1bed5dede2ac134033ca79e899ddd5dec833b1.1638440535.git.fdmanana@suse.com> (raw)
In-Reply-To: <cover.1638440535.git.fdmanana@suse.com>

From: Filipe Manana <fdmanana@suse.com>

When inserting a key, we check if the write_lock_level is less than 1,
and if so we set it to 1, release the path and retry the tree traversal.

However that is unnecessary, because when ins_len is greater than 0, we
know that write_lock_level can never be less than 1.

The logic to retry is also buggy, because in case ins_len was decremented,
due to an exact key match and the search is not meant for item extension
(path->search_for_extension is 0), we retry without incrementing ins_len,
which would make the next retry decrement it again by the same amount.

So remove the check for write_lock_level being less than 1 and add an
assertion to assert it's always >= 1.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
 fs/btrfs/ctree.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 62066c034363..9439c8606835 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -1968,11 +1968,7 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root *root,
 				ins_len -= sizeof(struct btrfs_item);
 			}
 			if (ins_len > 0 && leaf_free_space < ins_len) {
-				if (write_lock_level < 1) {
-					write_lock_level = 1;
-					btrfs_release_path(p);
-					goto again;
-				}
+				ASSERT(write_lock_level >= 1);
 
 				err = split_leaf(trans, root, key,
 						 p, ins_len, ret == 0);
-- 
2.33.0


  parent reply	other threads:[~2021-12-02 10:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-02 10:30 [PATCH 0/6] btrfs: optimize btree insertions and some cleanups fdmanana
2021-12-02 10:30 ` [PATCH 1/6] btrfs: allow generic_bin_search() to take low boundary as an argument fdmanana
2021-12-02 10:30 ` [PATCH 2/6] btrfs: try to unlock parent nodes earlier when inserting a key fdmanana
2021-12-02 10:30 ` fdmanana [this message]
2021-12-02 10:30 ` [PATCH 4/6] btrfs: move leaf search logic out of btrfs_search_slot() fdmanana
2021-12-02 10:30 ` [PATCH 5/6] btrfs: remove BUG_ON() after splitting leaf fdmanana
2021-12-02 10:30 ` [PATCH 6/6] btrfs: remove stale comment about locking at btrfs_search_slot() fdmanana
2021-12-02 19:45 ` [PATCH 0/6] btrfs: optimize btree insertions and some cleanups Josef Bacik
2021-12-06 18:29 ` 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=0f1bed5dede2ac134033ca79e899ddd5dec833b1.1638440535.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.