diff mbox series

[3/6] btrfs: remove useless condition check before splitting leaf

Message ID 0f1bed5dede2ac134033ca79e899ddd5dec833b1.1638440535.git.fdmanana@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs: optimize btree insertions and some cleanups | expand

Commit Message

Filipe Manana Dec. 2, 2021, 10:30 a.m. UTC
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 mbox series

Patch

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);