From patchwork Thu Oct 24 16:24:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13849372 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 675671F80C2 for ; Thu, 24 Oct 2024 16:24:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787071; cv=none; b=lb48Bt1hPH4Bkmfyem8R7rieMkwmVHiakowQn6RFXT9YdS/U/SXFUzDcUZXXgnXsFKvYiV9MPCFDM+hJOh4N80K65h2BBDFXJ1un91+juNP6AKFulf46x0cbeIH5QqW/r6/lmGS0rJYnT5KCRaqBSExWKzQakOiO5zBbImOT4os= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787071; c=relaxed/simple; bh=2TM5kw+3AMCjl212P0Xma/0fWZTxh6leN3rFH1E9BBo=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bi4TmmRvuz9diXds9t08OXLFEQxHzYnRaQ9ltq8IbeplLqbAo5tdAUiVmwX/z+eIxwqCXwY0LbyVGEioet0wM1w6VALicczjHSJfZmgASNejGn4MNgSYF6WPf3KdO1wERwEGDZZRT7WzeBLkI1S7eXo24UfrKCA86iAGGa+1NOk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mHly/SQM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mHly/SQM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62FC4C4CEE4 for ; Thu, 24 Oct 2024 16:24:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729787070; bh=2TM5kw+3AMCjl212P0Xma/0fWZTxh6leN3rFH1E9BBo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=mHly/SQMt1GDCO+UsqtGQ5FhMAV7wI7qCSEoNxkDeCeFPoWrtaQHMfiazBeuqpWio pCp14u134NoK5CHsbMdy4QH34ZNUmWN0tYFvaah9/RnYaSwiH7wpZU26AI/XwUOtMe HlsUy13xIMu9nM+IgQ1BBrdc8/OFPurtQIeqh24nXPTey2eDl5wAtdTGrsSF8Yi3dC Ibo5aH4VeZlnRhAR0X0zPOTRU0y1yRBy1NzC/0q5K97xml2b8S6b67wa7Clm44iSYu BTh/s3Ub8B3j4xZwTyuhwkPtrLDIccH/Sj5VLtX8ZHdf6u41gCiHfFHqu7MSlUDabq WCBCVhhp284Cw== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 01/18] btrfs: remove BUG_ON() at btrfs_destroy_delayed_refs() Date: Thu, 24 Oct 2024 17:24:09 +0100 Message-Id: <7b373dde44e2c2f7aacfbba08fc069bac8e5acfe.1729784712.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana At btrfs_destroy_delayed_refs() it's unexpected to not find the block group to which a delayed reference's extent belongs to, so we have this BUG_ON(), not just because it's highly unexpected but also because we don't know what to do there. Since we are in the transaction abort path, there's nothing we can do other than proceed and cleanup all used resources we can. So remove the BUG_ON() and deal with a missing block group by logging an error message and continuing to cleanup all we can related to the current delayed ref head and moving to other delayed refs. Signed-off-by: Filipe Manana --- fs/btrfs/disk-io.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index bcf6e53bc2a7..47598e525ea5 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -4571,19 +4571,30 @@ static void btrfs_destroy_delayed_refs(struct btrfs_transaction *trans, struct btrfs_block_group *cache; cache = btrfs_lookup_block_group(fs_info, head->bytenr); - BUG_ON(!cache); - - spin_lock(&cache->space_info->lock); - spin_lock(&cache->lock); - cache->pinned += head->num_bytes; - btrfs_space_info_update_bytes_pinned(fs_info, - cache->space_info, head->num_bytes); - cache->reserved -= head->num_bytes; - cache->space_info->bytes_reserved -= head->num_bytes; - spin_unlock(&cache->lock); - spin_unlock(&cache->space_info->lock); - - btrfs_put_block_group(cache); + if (WARN_ON_ONCE(cache == NULL)) { + /* + * Unexpected and there's nothing we can do here + * because we are in a transaction abort path, + * so any errors can only be ignored or reported + * while attempting to cleanup all resources. + */ + btrfs_err(fs_info, +"block group for delayed ref at %llu was not found while destroying ref head", + head->bytenr); + } else { + spin_lock(&cache->space_info->lock); + spin_lock(&cache->lock); + cache->pinned += head->num_bytes; + btrfs_space_info_update_bytes_pinned(fs_info, + cache->space_info, + head->num_bytes); + cache->reserved -= head->num_bytes; + cache->space_info->bytes_reserved -= head->num_bytes; + spin_unlock(&cache->lock); + spin_unlock(&cache->space_info->lock); + + btrfs_put_block_group(cache); + } btrfs_error_unpin_extent_range(fs_info, head->bytenr, head->bytenr + head->num_bytes - 1); From patchwork Thu Oct 24 16:24:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13849373 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 59CA21F80C5 for ; Thu, 24 Oct 2024 16:24:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787072; cv=none; b=oTaDyB3YeRlpxvs1Axs7rYXOc1V2OmTyYJ8768dLW6X4nCs6rc8l+kaK3+2U+OsNtWvEeS8uT86htQmaxFZUuXoY2N5XI+KxkwGla+YJWuemTf2p13ba4h+dhC625q21jkoxThHnibyHvK0bbOnJBIxkWcbP9F4JCk1JdKcITzg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787072; c=relaxed/simple; bh=cu95UB+UXB0wLs+7O9SjbVPLqM7KKuGS1wCjgUM5lBQ=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=E70XSzO5Urq3XgYcth3yXV8j4agYa/CrHtYEnEWrw+VvCrgIxQS2UXF8D3vUv5J1/gotjiYs8/IyZhdzpCnxB+h13U9tlpjeoV+r2M59X93eewKls9q422oPvx+16IAZtgXrw2tcvqyJAFG44c6svtJwWcHZkPiKJ5x9f5bP8nU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rBcRkI7L; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rBcRkI7L" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6AC99C4CEE5 for ; Thu, 24 Oct 2024 16:24:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729787072; bh=cu95UB+UXB0wLs+7O9SjbVPLqM7KKuGS1wCjgUM5lBQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=rBcRkI7L50k5FnAvg7mbxsFUk4+5OTj2aCVfZRVVNQI4kgabPphGmCZ9nXQxwKlh9 VrSsnR0M5pnV8aXC1VoO5Yh88Ks2MijBPhFl9TM3bJRQ+mI1G/5pR0GV7kAMsmFudv Q4/5v2tGJ0YmrCj43Iu+hNuhysZ3rJGn1TBfcnFQNqkzCtr8fAyM2HYDMr6zRRych3 lcXaHh6KMNlfSE9vA+DqHHwllQ0PwqKx2GwN6SMlLGL1EUKczUj8PFXzA2VQw3qolu BJ51EuxCYtQTKPOu1aMkAuqWInRI0Vnvdh6U72c1sy3s6kRVT71am+BqruMJVJUpIM vwZSetgnSo6rg== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 02/18] btrfs: move btrfs_destroy_delayed_refs() to delayed-ref.c Date: Thu, 24 Oct 2024 17:24:10 +0100 Message-Id: <46045d4ec41a0d522f16bd9a14913ec3d9c6dd3b.1729784712.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana It's better suited at delayed-ref.c since it's about delayed refs and contains logic to iterate over them (using the red black tree, doing all the locking, freeing, etc), so move it from disk-io.c, which is pretty big, into delayed-ref.c, hidding implementation details of how delayed refs are tracked and managed. This also facilitates the next patches in the series. This change moves the code between files but also does the following simple cleanups: 1) Rename the 'cache' variable to 'bg', since it's a block group (the 'cache' logic comes from old days where the block group structure was named 'btrfs_block_group_cache'); 2) Move the 'ref' variable declaration to the scope of the inner while loop, since it's not used outside that loop. Signed-off-by: Filipe Manana --- fs/btrfs/delayed-ref.c | 81 ++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/delayed-ref.h | 2 ++ fs/btrfs/disk-io.c | 80 ----------------------------------------- 3 files changed, 83 insertions(+), 80 deletions(-) diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index 04586aa11917..3ac2000f394d 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -9,6 +9,7 @@ #include "messages.h" #include "ctree.h" #include "delayed-ref.h" +#include "extent-tree.h" #include "transaction.h" #include "qgroup.h" #include "space-info.h" @@ -1238,6 +1239,86 @@ bool btrfs_find_delayed_tree_ref(struct btrfs_delayed_ref_head *head, return found; } +void btrfs_destroy_delayed_refs(struct btrfs_transaction *trans, + struct btrfs_fs_info *fs_info) +{ + struct rb_node *node; + struct btrfs_delayed_ref_root *delayed_refs = &trans->delayed_refs; + + spin_lock(&delayed_refs->lock); + while ((node = rb_first_cached(&delayed_refs->href_root)) != NULL) { + struct btrfs_delayed_ref_head *head; + struct rb_node *n; + bool pin_bytes = false; + + head = rb_entry(node, struct btrfs_delayed_ref_head, + href_node); + if (btrfs_delayed_ref_lock(delayed_refs, head)) + continue; + + spin_lock(&head->lock); + while ((n = rb_first_cached(&head->ref_tree)) != NULL) { + struct btrfs_delayed_ref_node *ref; + + ref = rb_entry(n, struct btrfs_delayed_ref_node, ref_node); + rb_erase_cached(&ref->ref_node, &head->ref_tree); + RB_CLEAR_NODE(&ref->ref_node); + if (!list_empty(&ref->add_list)) + list_del(&ref->add_list); + atomic_dec(&delayed_refs->num_entries); + btrfs_put_delayed_ref(ref); + btrfs_delayed_refs_rsv_release(fs_info, 1, 0); + } + if (head->must_insert_reserved) + pin_bytes = true; + btrfs_free_delayed_extent_op(head->extent_op); + btrfs_delete_ref_head(delayed_refs, head); + spin_unlock(&head->lock); + spin_unlock(&delayed_refs->lock); + mutex_unlock(&head->mutex); + + if (pin_bytes) { + struct btrfs_block_group *bg; + + bg = btrfs_lookup_block_group(fs_info, head->bytenr); + if (WARN_ON_ONCE(bg == NULL)) { + /* + * Unexpected and there's nothing we can do here + * because we are in a transaction abort path, + * so any errors can only be ignored or reported + * while attempting to cleanup all resources. + */ + btrfs_err(fs_info, +"block group for delayed ref at %llu was not found while destroying ref head", + head->bytenr); + } else { + spin_lock(&bg->space_info->lock); + spin_lock(&bg->lock); + bg->pinned += head->num_bytes; + btrfs_space_info_update_bytes_pinned(fs_info, + bg->space_info, + head->num_bytes); + bg->reserved -= head->num_bytes; + bg->space_info->bytes_reserved -= head->num_bytes; + spin_unlock(&bg->lock); + spin_unlock(&bg->space_info->lock); + + btrfs_put_block_group(bg); + } + + btrfs_error_unpin_extent_range(fs_info, head->bytenr, + head->bytenr + head->num_bytes - 1); + } + btrfs_cleanup_ref_head_accounting(fs_info, delayed_refs, head); + btrfs_put_delayed_ref_head(head); + cond_resched(); + spin_lock(&delayed_refs->lock); + } + btrfs_qgroup_destroy_extent_records(trans); + + spin_unlock(&delayed_refs->lock); +} + void __cold btrfs_delayed_ref_exit(void) { kmem_cache_destroy(btrfs_delayed_ref_head_cachep); diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h index 352921e76c74..ccc040f94264 100644 --- a/fs/btrfs/delayed-ref.h +++ b/fs/btrfs/delayed-ref.h @@ -399,6 +399,8 @@ int btrfs_delayed_refs_rsv_refill(struct btrfs_fs_info *fs_info, bool btrfs_check_space_for_delayed_refs(struct btrfs_fs_info *fs_info); bool btrfs_find_delayed_tree_ref(struct btrfs_delayed_ref_head *head, u64 root, u64 parent); +void btrfs_destroy_delayed_refs(struct btrfs_transaction *trans, + struct btrfs_fs_info *fs_info); static inline u64 btrfs_delayed_ref_owner(struct btrfs_delayed_ref_node *node) { diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 47598e525ea5..f5d30c04ba66 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -4529,86 +4529,6 @@ static void btrfs_destroy_all_ordered_extents(struct btrfs_fs_info *fs_info) btrfs_wait_ordered_roots(fs_info, U64_MAX, NULL); } -static void btrfs_destroy_delayed_refs(struct btrfs_transaction *trans, - struct btrfs_fs_info *fs_info) -{ - struct rb_node *node; - struct btrfs_delayed_ref_root *delayed_refs = &trans->delayed_refs; - struct btrfs_delayed_ref_node *ref; - - spin_lock(&delayed_refs->lock); - while ((node = rb_first_cached(&delayed_refs->href_root)) != NULL) { - struct btrfs_delayed_ref_head *head; - struct rb_node *n; - bool pin_bytes = false; - - head = rb_entry(node, struct btrfs_delayed_ref_head, - href_node); - if (btrfs_delayed_ref_lock(delayed_refs, head)) - continue; - - spin_lock(&head->lock); - while ((n = rb_first_cached(&head->ref_tree)) != NULL) { - ref = rb_entry(n, struct btrfs_delayed_ref_node, - ref_node); - rb_erase_cached(&ref->ref_node, &head->ref_tree); - RB_CLEAR_NODE(&ref->ref_node); - if (!list_empty(&ref->add_list)) - list_del(&ref->add_list); - atomic_dec(&delayed_refs->num_entries); - btrfs_put_delayed_ref(ref); - btrfs_delayed_refs_rsv_release(fs_info, 1, 0); - } - if (head->must_insert_reserved) - pin_bytes = true; - btrfs_free_delayed_extent_op(head->extent_op); - btrfs_delete_ref_head(delayed_refs, head); - spin_unlock(&head->lock); - spin_unlock(&delayed_refs->lock); - mutex_unlock(&head->mutex); - - if (pin_bytes) { - struct btrfs_block_group *cache; - - cache = btrfs_lookup_block_group(fs_info, head->bytenr); - if (WARN_ON_ONCE(cache == NULL)) { - /* - * Unexpected and there's nothing we can do here - * because we are in a transaction abort path, - * so any errors can only be ignored or reported - * while attempting to cleanup all resources. - */ - btrfs_err(fs_info, -"block group for delayed ref at %llu was not found while destroying ref head", - head->bytenr); - } else { - spin_lock(&cache->space_info->lock); - spin_lock(&cache->lock); - cache->pinned += head->num_bytes; - btrfs_space_info_update_bytes_pinned(fs_info, - cache->space_info, - head->num_bytes); - cache->reserved -= head->num_bytes; - cache->space_info->bytes_reserved -= head->num_bytes; - spin_unlock(&cache->lock); - spin_unlock(&cache->space_info->lock); - - btrfs_put_block_group(cache); - } - - btrfs_error_unpin_extent_range(fs_info, head->bytenr, - head->bytenr + head->num_bytes - 1); - } - btrfs_cleanup_ref_head_accounting(fs_info, delayed_refs, head); - btrfs_put_delayed_ref_head(head); - cond_resched(); - spin_lock(&delayed_refs->lock); - } - btrfs_qgroup_destroy_extent_records(trans); - - spin_unlock(&delayed_refs->lock); -} - static void btrfs_destroy_delalloc_inodes(struct btrfs_root *root) { struct btrfs_inode *btrfs_inode; From patchwork Thu Oct 24 16:24:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13849374 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 72A411F8182 for ; Thu, 24 Oct 2024 16:24:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787073; cv=none; b=M+SN7vf4Re8i4GJ3anc28wGEjOHiz88HjWb8E5rOzokKa0Yp+6Mp4Kq5lWZjhoJMqJqmm2CyGxSKocBkBsxv+8AnVmBIJgwBze80AxoYhV0EEi9wm3HsoGb3lFH93bAG0sMtVubYmiEN0KU67NmfuDyovug4+yP2K2dDTg4EP9Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787073; c=relaxed/simple; bh=RCmnZeF3tNkZsxaMOLbjO0zYkvZiDhN0E/39zcGBjQE=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kEmBosM6/VcgeB0uv1DRTp8OEy+Oqr4n29P73rYQN+qSNfj+/HnTHFXtX/JAhjh3MuQwHBjBfpPGDRigktnUUg3hmnqdKVB+jow+Kti8/SGtpiKzQX1EBs2S0Gw7WQqd2Kt/Uyzt2QnjWILtfxxN680OQyK+n7xiMew/pl2ihS8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=onJ61VzK; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="onJ61VzK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73B9BC4CEE4 for ; Thu, 24 Oct 2024 16:24:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729787073; bh=RCmnZeF3tNkZsxaMOLbjO0zYkvZiDhN0E/39zcGBjQE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=onJ61VzKuz2UCKlvW0T3BI9yX9Jv5ckk9Gtw7P/3tMSyn/Q+zB/izuVm1Oi/NWrpe DJKmEx/bEQKQUbs8SD5KyJqjqBZS/On4OSoxifvNUVPkQtXUWOXDMk5n7jjrnT9OXr +syGp0j+b4TTnzPtGVgkXSvyjFomgwxaQCEGAn7Nj7KBWlvCXWpidGGATciTuRzW6y DtIjJyPSHIAs2VjqF7V9IcxpZ8AHm401Z1KIu+lJnynQHLqbo479cRxIZbAyDrBns8 7j8kMHbo3/4TjNFCvshH5PVXDQkcxv1vu31TPTG8yOuib7t6jQVBtlzCbU5dnNU9Xh woLRBvTlTKmyw== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 03/18] btrfs: remove fs_info parameter from btrfs_destroy_delayed_refs() Date: Thu, 24 Oct 2024 17:24:11 +0100 Message-Id: <51b1c025d8ed8c1345b66f67f66d1401dca8bd57.1729784712.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana The fs_info parameter is redundant because it can be extracted from the transaction given as another parameter. So remove it and use the fs_info accessible from the transaction. Signed-off-by: Filipe Manana --- fs/btrfs/delayed-ref.c | 4 ++-- fs/btrfs/delayed-ref.h | 3 +-- fs/btrfs/disk-io.c | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index 3ac2000f394d..4dfb7e44507f 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -1239,11 +1239,11 @@ bool btrfs_find_delayed_tree_ref(struct btrfs_delayed_ref_head *head, return found; } -void btrfs_destroy_delayed_refs(struct btrfs_transaction *trans, - struct btrfs_fs_info *fs_info) +void btrfs_destroy_delayed_refs(struct btrfs_transaction *trans) { struct rb_node *node; struct btrfs_delayed_ref_root *delayed_refs = &trans->delayed_refs; + struct btrfs_fs_info *fs_info = trans->fs_info; spin_lock(&delayed_refs->lock); while ((node = rb_first_cached(&delayed_refs->href_root)) != NULL) { diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h index ccc040f94264..cc78395f2fcd 100644 --- a/fs/btrfs/delayed-ref.h +++ b/fs/btrfs/delayed-ref.h @@ -399,8 +399,7 @@ int btrfs_delayed_refs_rsv_refill(struct btrfs_fs_info *fs_info, bool btrfs_check_space_for_delayed_refs(struct btrfs_fs_info *fs_info); bool btrfs_find_delayed_tree_ref(struct btrfs_delayed_ref_head *head, u64 root, u64 parent); -void btrfs_destroy_delayed_refs(struct btrfs_transaction *trans, - struct btrfs_fs_info *fs_info); +void btrfs_destroy_delayed_refs(struct btrfs_transaction *trans); static inline u64 btrfs_delayed_ref_owner(struct btrfs_delayed_ref_node *node) { diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index f5d30c04ba66..2e15afa9e04c 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -4748,7 +4748,7 @@ void btrfs_cleanup_one_transaction(struct btrfs_transaction *cur_trans, list_del_init(&dev->post_commit_list); } - btrfs_destroy_delayed_refs(cur_trans, fs_info); + btrfs_destroy_delayed_refs(cur_trans); cur_trans->state = TRANS_STATE_COMMIT_START; wake_up(&fs_info->transaction_blocked_wait); From patchwork Thu Oct 24 16:24:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13849375 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 74F1B1F8187 for ; Thu, 24 Oct 2024 16:24:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787074; cv=none; b=pKly9+0V5FOP7hIjnOWXbxXQMWCRP3u6CQLrH/0XjBTx+1k8eVOk6yVNBKTCvW9owsvK6OhVDM78/GR6sRHeNGxD8usQeOS0enS6wtQA+9ENt4prMzVRzM6j2wB5/ypx91a/T06vRve2FodXmVKGnxUGam//cKyE1orm88IJXPE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787074; c=relaxed/simple; bh=lnxB6peBfbimE9wUYFhIHUtsFMrfwuXHvlaUqfWJvfQ=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=T4ExPIir2E3jXnOzMWQDpQbGvOCIb+ezfpRatrBT7yhmzk1OP0m1NLX0wMSDGW5UMhI4R4IZ1EEBIAAahecgUipeNpD97pCQ7+sVXPLHpLKtEEqHoIEdrJT15T6hfIuB4VuTAngf6tZRxq2Y+dIiF88wwmov2niJmuf8zLHgkoY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XIG2zkOl; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XIG2zkOl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7BE3FC4CEE3 for ; Thu, 24 Oct 2024 16:24:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729787074; bh=lnxB6peBfbimE9wUYFhIHUtsFMrfwuXHvlaUqfWJvfQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=XIG2zkOlncMa2rJJMhcpK1i9Zp7qPBPv9vwgJrCtn/RYiq9xKAxkW8ujL7rNLHjKJ 1qXl8XJu0UUJwrneHt1p3CxUKQSZ6X8JgfghokgGKokogsxtrEgcnxOhL1sr0UCxmx LS4DWECRrQHicsVuIg0rHkJjM3rMujKHASGHV4y/wCm3wUXrHklpIJnzzzUdEwVkSU ax7VCVpokT2TASlrC/BTDctzNZMIOWJ6Ws0nkSIhdsxjuKNZpwQWliJLGvHZkIrbMv yLLwzQ2Q31yggORX5CWQq7NzXfYjyIHE6jh27k+bIjA6/9Nz7cUhY8ByRBEem5AhQi kr0neBPhwErBg== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 04/18] btrfs: remove fs_info parameter from btrfs_cleanup_one_transaction() Date: Thu, 24 Oct 2024 17:24:12 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana The fs_info parameter is redundant because it can be extracted from the transaction given as another parameter. So remove it and use the fs_info accessible from the transaction. Signed-off-by: Filipe Manana --- fs/btrfs/disk-io.c | 8 ++++---- fs/btrfs/disk-io.h | 3 +-- fs/btrfs/transaction.c | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 2e15afa9e04c..814320948645 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -4183,7 +4183,7 @@ static void warn_about_uncommitted_trans(struct btrfs_fs_info *fs_info) btrfs_warn(fs_info, "transaction %llu (with %llu dirty metadata bytes) is not committed", trans->transid, dirty_bytes); - btrfs_cleanup_one_transaction(trans, fs_info); + btrfs_cleanup_one_transaction(trans); if (trans == fs_info->running_transaction) fs_info->running_transaction = NULL; @@ -4734,9 +4734,9 @@ static void btrfs_free_all_qgroup_pertrans(struct btrfs_fs_info *fs_info) spin_unlock(&fs_info->fs_roots_radix_lock); } -void btrfs_cleanup_one_transaction(struct btrfs_transaction *cur_trans, - struct btrfs_fs_info *fs_info) +void btrfs_cleanup_one_transaction(struct btrfs_transaction *cur_trans) { + struct btrfs_fs_info *fs_info = cur_trans->fs_info; struct btrfs_device *dev, *tmp; btrfs_cleanup_dirty_bgs(cur_trans, fs_info); @@ -4794,7 +4794,7 @@ static int btrfs_cleanup_transaction(struct btrfs_fs_info *fs_info) } else { spin_unlock(&fs_info->trans_lock); } - btrfs_cleanup_one_transaction(t, fs_info); + btrfs_cleanup_one_transaction(t); spin_lock(&fs_info->trans_lock); if (t == fs_info->running_transaction) diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h index 127e31e08347..a7051e2570c1 100644 --- a/fs/btrfs/disk-io.h +++ b/fs/btrfs/disk-io.h @@ -126,8 +126,7 @@ int btrfs_add_log_tree(struct btrfs_trans_handle *trans, struct btrfs_root *root); void btrfs_cleanup_dirty_bgs(struct btrfs_transaction *trans, struct btrfs_fs_info *fs_info); -void btrfs_cleanup_one_transaction(struct btrfs_transaction *trans, - struct btrfs_fs_info *fs_info); +void btrfs_cleanup_one_transaction(struct btrfs_transaction *trans); struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans, u64 objectid); int btrfs_get_num_tolerated_disk_barrier_failures(u64 flags); diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 0fc873af891f..e580c566f033 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -2052,7 +2052,7 @@ static void cleanup_transaction(struct btrfs_trans_handle *trans, int err) spin_unlock(&fs_info->trans_lock); - btrfs_cleanup_one_transaction(trans->transaction, fs_info); + btrfs_cleanup_one_transaction(trans->transaction); spin_lock(&fs_info->trans_lock); if (cur_trans == fs_info->running_transaction) From patchwork Thu Oct 24 16:24:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13849376 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 899C81F8195 for ; Thu, 24 Oct 2024 16:24:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787075; cv=none; b=J17AYFjp0bC60/DsxiQY+4nMw1MqE/dIxV5S16UjXOWKuuTLyTtQVo1KAB5vuwvA90tPL2Z9sCo8jZB/PTTbOeBF2FvaNQ61hzpBADp5TLlI1M9cbbSeJLQMvaVseEH/I381Gwga2RTYAX7RaZ+XUu8NpNs+Hvob4oMIE8tQqQ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787075; c=relaxed/simple; bh=7FhUZGBS3cxrPyhLKLic3Z/qwesUuDY5Z8WoFC4sbwo=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rUrRbqdTkg2weli7fnOr2irYCWBE3kNCBHjns8e9013EciZlhYLunAPKSyeJ3wX9ZwyFWK9Vt0zgrg99nusj22f5braUa/CKSRRyb+ICB/8TXWlsUO2GVxez/Z4lghdqQdoTweNQFyzbG8onR5aaj5y2zodSgN71V8h6zArzXGc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oc/eYWFa; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oc/eYWFa" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82DC2C4CEE5 for ; Thu, 24 Oct 2024 16:24:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729787075; bh=7FhUZGBS3cxrPyhLKLic3Z/qwesUuDY5Z8WoFC4sbwo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=oc/eYWFaEDTmG5t3kL1i9Ne9e3FWf9wtcWYvQAEDwy7geopByovwuHLVceS8kTXsR QQl55QQtInYQW1wVmRrG8bAUX8ZW/F2kPi+ZzsdiFNPQ8i8N/XR9Ak4zlyCM3aHOUw ZYkJwYIFLaZJ2tav/pgWpIS6vr7QG4X1x0QNGesEnPObaUAS0iPxAYPb5ySYZU23w7 DReNo0NvTyDjTekYJWXimaPmV+pEe8R3T8d3oTo2uGZ6yiMAJ1w5wxkE+8nvLkJfuU 6WrPAKvcJGEz7uD+1s8nuRlQKWqR77BhxS1BKUlhdG5PLhZsFRcy/v+YgGZ5zswddt 5EDQyx+syB8UA== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 05/18] btrfs: remove duplicated code to drop delayed ref during transaction abort Date: Thu, 24 Oct 2024 17:24:13 +0100 Message-Id: <5718d90d0fff1bc39531d71f590c9dd21e04f5c6.1729784713.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana When destroying delayed refs during a transaction abort, we have open coded the removal of a delayed ref, which is also done by the static helper function drop_delayed_ref(). So remove that duplicated code and use drop_delayed_ref() instead. Signed-off-by: Filipe Manana --- fs/btrfs/delayed-ref.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index 4dfb7e44507f..db834268faef 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -1261,13 +1261,7 @@ void btrfs_destroy_delayed_refs(struct btrfs_transaction *trans) struct btrfs_delayed_ref_node *ref; ref = rb_entry(n, struct btrfs_delayed_ref_node, ref_node); - rb_erase_cached(&ref->ref_node, &head->ref_tree); - RB_CLEAR_NODE(&ref->ref_node); - if (!list_empty(&ref->add_list)) - list_del(&ref->add_list); - atomic_dec(&delayed_refs->num_entries); - btrfs_put_delayed_ref(ref); - btrfs_delayed_refs_rsv_release(fs_info, 1, 0); + drop_delayed_ref(fs_info, delayed_refs, head, ref); } if (head->must_insert_reserved) pin_bytes = true; From patchwork Thu Oct 24 16:24:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13849377 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 793F31F81A7 for ; Thu, 24 Oct 2024 16:24:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787076; cv=none; b=HITTgC/1P3nR+3Jf59yVpFI9jvjbqQTaRX8yDjW/ahfeV4W2LjGBZ82hWRO4wJCYjPijQXN3LLl0+e6R2xYGDrVQIr88qPMsG0n7SkL5B7u+0f8QEr9o2Rn4VoUSE5roxXW+XAAM3EYUSINVeHtdi4kfhkv25S4hVuZZARPReF0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787076; c=relaxed/simple; bh=yd0jgbeMZD0ObYBXMD/TjqkrwO/GNR4bI1bELLEoihA=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OEt9o5CQQsUwejjDofdgwU5HCrlE7hunvUHs3qCF2nPZLhEWG7q2M0a2vHUy4aHyjhd5uYgCbAnb3k0hCV4OR+TdGX7vt0PMK8O7ntXaTs+Mmq+foeX9j9YXcl6Z4VZx5u+hWa8jrVxoRZVUaEKHi0YVNsO1eygNJb/e3KGiciw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VW4q5u+n; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VW4q5u+n" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8ABC5C4CEE3 for ; Thu, 24 Oct 2024 16:24:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729787076; bh=yd0jgbeMZD0ObYBXMD/TjqkrwO/GNR4bI1bELLEoihA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=VW4q5u+nacsfIU3MQ8pZaMDmHV+N/WsWJ5CUY+VLX8GTQhXxNqQ5Cz4ZrAF2HfP0t G0bJMfReYXMmjmc+CjcHoe+/x+lsBp7uiGgzP0NUg7CbbiZT7paUu4nI/c5kpr3VUa Gj7b5P2cdMCnny9pHjYXNvQ5EWEggQRLkwkwML9e0uym+p1DzVGwfEQYGVzyhClakK 9e+0pS1Ka2A+eqW0GzwSjlL1tgAQnSboKHXg7FX5ZWsP/TLvMTyppgXoaEgYYZ9z4t eoMRyYkKHhJOAwAHFHLZLOs1L8kAQ51TsthGNVOI93BOlXZR1Xm4+O9jm6MJvttiW7 qAc4hvbnkMU7Q== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 06/18] btrfs: use helper to find first ref head at btrfs_destroy_delayed_refs() Date: Thu, 24 Oct 2024 17:24:14 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana Instead of open coding it, use the find_first_ref_head() helper at btrfs_destroy_delayed_refs(). This avoids duplicating the logic, specially with the upcoming changes in subsequent patches. Signed-off-by: Filipe Manana --- fs/btrfs/delayed-ref.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index db834268faef..2b2273296246 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -1241,18 +1241,19 @@ bool btrfs_find_delayed_tree_ref(struct btrfs_delayed_ref_head *head, void btrfs_destroy_delayed_refs(struct btrfs_transaction *trans) { - struct rb_node *node; struct btrfs_delayed_ref_root *delayed_refs = &trans->delayed_refs; struct btrfs_fs_info *fs_info = trans->fs_info; spin_lock(&delayed_refs->lock); - while ((node = rb_first_cached(&delayed_refs->href_root)) != NULL) { + while (true) { struct btrfs_delayed_ref_head *head; struct rb_node *n; bool pin_bytes = false; - head = rb_entry(node, struct btrfs_delayed_ref_head, - href_node); + head = find_first_ref_head(delayed_refs); + if (!head) + break; + if (btrfs_delayed_ref_lock(delayed_refs, head)) continue; From patchwork Thu Oct 24 16:24:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13849378 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 48C861F81AC for ; Thu, 24 Oct 2024 16:24:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787077; cv=none; b=eL68yMAoMs0tysjLYNzlI8jxAp2Fb5bDnB+HiegIb4v4EtYq9zOs5lkdXLBPb8y0Z2niCT1Ie5WLd1CWXAtWCj32oTn/6HGrGvAMEEb7yKARvoVKugJMHmNXb98l9GVEQtEXVd8URHXVP4D+qkakl3bercymjCUBA3XmrabF2Wk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787077; c=relaxed/simple; bh=03BWRIt1zYx6CPcNbvvXdy6Zvw0GRgHVRWUMybXNClY=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WtIb9z+/++t20wGILyhTVGPrlV4+DxRpL9cHv2qwmHUz/Rr9m5uhj01ZeXNVQHBagaCQIOZ50gRrE87BWr+4AarFvCxhxpp4FWqOAgMEwUoLTnSP6hlxfbTH0IlEEveYTWZKL3GkXH65TO9/e7/UNJWZFpukewBkdeRTchOkeT8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dIAWBdgT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dIAWBdgT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 91B55C4CEE5 for ; Thu, 24 Oct 2024 16:24:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729787077; bh=03BWRIt1zYx6CPcNbvvXdy6Zvw0GRgHVRWUMybXNClY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=dIAWBdgTjlsQ1+q509CkZVF6veNCVPlGWE/L1g3Wj6TyZ0GfsMbxzJPdJNoKnSIAM G5wy/SYiaz+LsoRI/+jaBGsYQZI9BDBwd6Pxj5AP/+0fHE/+45ay2JNBQbIqX6zJFP ME37/gLxcOaQUSMa/UttrRkNJNn4AGvxMLmBBbJbxGMS7waWkyh2P5mzfbicFxTRE2 i07zisQyLShg2y7cdOFsqx5U93qaDVnOv0kGyfOV6OS/rqNTMrP4OJeGVjwR8ZEKRT XZnLyxXoHSIOWWlJEgWJLrugDAYxjY6ddRkrfjq6sVf68YbpoapUMoPtX6mwBT8IsN gdqF/wy6BRf1w== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 07/18] btrfs: remove num_entries atomic counter from delayed ref root Date: Thu, 24 Oct 2024 17:24:15 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana The atomic counter 'num_entries' is not used anymore, we increment it and decrement it but then we don't ever read it to use for any logic. Its last use was removed with commit 61a56a992fcf ("btrfs: delayed refs pre-flushing should only run the heads we have"). So remove it. Signed-off-by: Filipe Manana --- fs/btrfs/delayed-ref.c | 4 ---- fs/btrfs/delayed-ref.h | 5 ----- fs/btrfs/extent-tree.c | 1 - fs/btrfs/transaction.c | 1 - 4 files changed, 11 deletions(-) diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index 2b2273296246..2e14cfcb152e 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -463,7 +463,6 @@ static inline void drop_delayed_ref(struct btrfs_fs_info *fs_info, if (!list_empty(&ref->add_list)) list_del(&ref->add_list); btrfs_put_delayed_ref(ref); - atomic_dec(&delayed_refs->num_entries); btrfs_delayed_refs_rsv_release(fs_info, 1, 0); } @@ -604,7 +603,6 @@ void btrfs_delete_ref_head(struct btrfs_delayed_ref_root *delayed_refs, rb_erase_cached(&head->href_node, &delayed_refs->href_root); RB_CLEAR_NODE(&head->href_node); - atomic_dec(&delayed_refs->num_entries); delayed_refs->num_heads--; if (!head->processing) delayed_refs->num_heads_ready--; @@ -630,7 +628,6 @@ static bool insert_delayed_ref(struct btrfs_trans_handle *trans, if (!exist) { if (ref->action == BTRFS_ADD_DELAYED_REF) list_add_tail(&ref->add_list, &href->ref_add_list); - atomic_inc(&root->num_entries); spin_unlock(&href->lock); trans->delayed_ref_updates++; return false; @@ -901,7 +898,6 @@ add_delayed_ref_head(struct btrfs_trans_handle *trans, } delayed_refs->num_heads++; delayed_refs->num_heads_ready++; - atomic_inc(&delayed_refs->num_entries); } if (qrecord_inserted_ret) *qrecord_inserted_ret = qrecord_inserted; diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h index cc78395f2fcd..a97c9df19ea0 100644 --- a/fs/btrfs/delayed-ref.h +++ b/fs/btrfs/delayed-ref.h @@ -216,11 +216,6 @@ struct btrfs_delayed_ref_root { /* this spin lock protects the rbtree and the entries inside */ spinlock_t lock; - /* how many delayed ref updates we've queued, used by the - * throttling code - */ - atomic_t num_entries; - /* total number of head nodes in tree */ unsigned long num_heads; diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index e29024c66edb..9b588ce19a74 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -2009,7 +2009,6 @@ static int btrfs_run_delayed_refs_for_head(struct btrfs_trans_handle *trans, default: WARN_ON(1); } - atomic_dec(&delayed_refs->num_entries); /* * Record the must_insert_reserved flag before we drop the diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index e580c566f033..9ccf68ab53f9 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -351,7 +351,6 @@ static noinline int join_transaction(struct btrfs_fs_info *fs_info, cur_trans->delayed_refs.href_root = RB_ROOT_CACHED; xa_init(&cur_trans->delayed_refs.dirty_extents); - atomic_set(&cur_trans->delayed_refs.num_entries, 0); /* * although the tree mod log is per file system and not per transaction, From patchwork Thu Oct 24 16:24:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13849379 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F11A1F8197 for ; Thu, 24 Oct 2024 16:24:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787078; cv=none; b=YVFK1zKbtltYxqcAwC3oRgVwYFhXS+gdXDimSeySIKSUj1IPZCP60WIf4J/47FtbIsFGNc6Bif33eZ2eTyATzbnbsdWUQsoHKzCRcdCX4xaEpZ7L3JnTBIHPddn1w34BCFlL6oyMn85TR69vmvH88H28grNtzyTbY3pmwzhNhXs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787078; c=relaxed/simple; bh=WqOCq8l+5NWaTE6JNmbmNUl2tRP4V8bCYgzT8F8jzoU=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pCmM0FJHjOiBKqVPFeVShLOC3ap0xF4znm4CARhQrV3GTtqAr2l6Tq1auReeg+fXlSawn6hCqvq5uUTOhEkflHqk+yLAlUMlM9qDrffeIgWAeaxKTmSF9qjjxc9F43HfUOsifCeQfTUwI52LmtqKc+OchDrRW9h9tiv658i+2E8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=duFZ41rU; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="duFZ41rU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98E7AC4CEC7 for ; Thu, 24 Oct 2024 16:24:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729787078; bh=WqOCq8l+5NWaTE6JNmbmNUl2tRP4V8bCYgzT8F8jzoU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=duFZ41rUYlvg+e89ijiCc5GO5R/Jdha+fm2Jlnka9F5Zw+of2x3/FbsUqdqkM4d97 Eq7KYJaumsQh/egp2g6OUJUwSS11tGka/v9HJ5/81rSjPzEc45tl7fNO/V3B53cyAT md4QZcnLRnRELWouHCtmRTYW6/1VxY/uUmjG6YoJyRrTSNvU1Jin83jt7uR0kdxSYn dmE7v68zXxFH1hydHBCDYDnpo3dn43BtXTpTs9/3gDfQK6oyxSgCz3IX0TNQ6/WmGp f/Iy4RjFeiHBTpD7DZWoJ/DdfJ8TkLKt2FHIq1GEEUQoS6AnSLFDjdhZpbAydSjoEu OVnXIhzI6g6eA== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 08/18] btrfs: change return type of btrfs_delayed_ref_lock() to boolean Date: Thu, 24 Oct 2024 17:24:16 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana The function only returns 0, meaning it was able to lock the delayed ref head, or -EAGAIN in case it wasn't able to lock it. So simplify this and use a boolean return type instead, returning true if it was able to lock and false otherwise. Signed-off-by: Filipe Manana --- fs/btrfs/delayed-ref.c | 12 ++++++------ fs/btrfs/delayed-ref.h | 4 ++-- fs/btrfs/extent-tree.c | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index 2e14cfcb152e..2bfece87bcda 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -431,12 +431,12 @@ static struct btrfs_delayed_ref_head *find_ref_head( return NULL; } -int btrfs_delayed_ref_lock(struct btrfs_delayed_ref_root *delayed_refs, - struct btrfs_delayed_ref_head *head) +bool btrfs_delayed_ref_lock(struct btrfs_delayed_ref_root *delayed_refs, + struct btrfs_delayed_ref_head *head) { lockdep_assert_held(&delayed_refs->lock); if (mutex_trylock(&head->mutex)) - return 0; + return true; refcount_inc(&head->refs); spin_unlock(&delayed_refs->lock); @@ -446,10 +446,10 @@ int btrfs_delayed_ref_lock(struct btrfs_delayed_ref_root *delayed_refs, if (RB_EMPTY_NODE(&head->href_node)) { mutex_unlock(&head->mutex); btrfs_put_delayed_ref_head(head); - return -EAGAIN; + return false; } btrfs_put_delayed_ref_head(head); - return 0; + return true; } static inline void drop_delayed_ref(struct btrfs_fs_info *fs_info, @@ -1250,7 +1250,7 @@ void btrfs_destroy_delayed_refs(struct btrfs_transaction *trans) if (!head) break; - if (btrfs_delayed_ref_lock(delayed_refs, head)) + if (!btrfs_delayed_ref_lock(delayed_refs, head)) continue; spin_lock(&head->lock); diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h index a97c9df19ea0..04730c650212 100644 --- a/fs/btrfs/delayed-ref.h +++ b/fs/btrfs/delayed-ref.h @@ -369,8 +369,8 @@ void btrfs_merge_delayed_refs(struct btrfs_fs_info *fs_info, struct btrfs_delayed_ref_head * btrfs_find_delayed_ref_head(struct btrfs_delayed_ref_root *delayed_refs, u64 bytenr); -int btrfs_delayed_ref_lock(struct btrfs_delayed_ref_root *delayed_refs, - struct btrfs_delayed_ref_head *head); +bool btrfs_delayed_ref_lock(struct btrfs_delayed_ref_root *delayed_refs, + struct btrfs_delayed_ref_head *head); static inline void btrfs_delayed_ref_unlock(struct btrfs_delayed_ref_head *head) { mutex_unlock(&head->mutex); diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 9b588ce19a74..95d749cec49e 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -1939,7 +1939,7 @@ static struct btrfs_delayed_ref_head *btrfs_obtain_ref_head( struct btrfs_delayed_ref_root *delayed_refs = &trans->transaction->delayed_refs; struct btrfs_delayed_ref_head *head = NULL; - int ret; + bool locked; spin_lock(&delayed_refs->lock); head = btrfs_select_ref_head(delayed_refs); @@ -1952,7 +1952,7 @@ static struct btrfs_delayed_ref_head *btrfs_obtain_ref_head( * Grab the lock that says we are going to process all the refs for * this head */ - ret = btrfs_delayed_ref_lock(delayed_refs, head); + locked = btrfs_delayed_ref_lock(delayed_refs, head); spin_unlock(&delayed_refs->lock); /* @@ -1960,7 +1960,7 @@ static struct btrfs_delayed_ref_head *btrfs_obtain_ref_head( * that might have given someone else time to free the head. If that's * true, it has been removed from our list and we can move on. */ - if (ret == -EAGAIN) + if (!locked) head = ERR_PTR(-EAGAIN); return head; From patchwork Thu Oct 24 16:24:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13849380 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D8C2F1F80CB for ; Thu, 24 Oct 2024 16:24:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787079; cv=none; b=AapT40LNw0szO2aGf4w+a6oNikBuPDgJZ2UlmezcKEwUpjJliVOUFnqNXvh779O/LtqzwFCOwKzp45FcZi2qJ+lEOx96gCYbhXxqRwuFJBVAM1j8cvW5WjK5Odo5Dlv80MQQTdT0Qw7IQ3cKEQMmvg06MQlSUdCdfYTFFbR0PqQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787079; c=relaxed/simple; bh=7d5LUESd+DOElFD1B8mbHNTwd/K8rHoNMvoa0pfHiDg=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=R2vGlaJ+/wX0RPi+/0oSF45xJMSE+SU1krmHMMuEfQ6Js5c6mN5b/PDfFBAwBgvh5JqOCcx3hT2GIm1YZiSdZ8Aaoe5WgZZt653p3FTj7rSIYyp7E40UYyMaVMNEE6jLOECpbAEGpnZ2YQg9ZVIg5UlLS7PbNd1UUTiRp42Xw7c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IgPMKl5Z; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IgPMKl5Z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F865C4CEC7 for ; Thu, 24 Oct 2024 16:24:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729787079; bh=7d5LUESd+DOElFD1B8mbHNTwd/K8rHoNMvoa0pfHiDg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=IgPMKl5ZP0yM/g9Jhle2Z/l2zF80XQJ/FrlIOEOpWz59GoeghtVjqdqoOogQ8vXVa tgpCnOPUzgxpc0gQ+A15PeF6oC3sb/HvGdRw/OFWf1f8MYw18RJ/L+qmEr2Ct0K4e1 +iwOGuhsp4mLXHnLb1YQ4hFdmllrPUAF+ZDKC3Q9qhPwf7Uwm4Y8VUePm9qPfcFZZn aesvOvwH+HmX32wV3C9pbvYeeIYWI9vh+82wueL75v4JamPx6QH3mofMOloN+mY+Pj lM1t7uGekoCkjFxnGP2J6czg8gCES1ta39lba5m3FRIyx4wWCVQ3ZjJySoF/wMdpeb Fiu1wXDcKTWRg== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 09/18] btrfs: simplify obtaining a delayed ref head Date: Thu, 24 Oct 2024 17:24:17 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana Instead of doing it in two steps outside of delayed-ref.c, leaking low level details such as locking, move the logic entirely to delayed-ref.c under btrfs_select_ref_head(), reducing code and making things simpler for the caller. Signed-off-by: Filipe Manana --- fs/btrfs/delayed-ref.c | 27 ++++++++++++++++++++++----- fs/btrfs/delayed-ref.h | 2 -- fs/btrfs/extent-tree.c | 35 +---------------------------------- 3 files changed, 23 insertions(+), 41 deletions(-) diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index 2bfece87bcda..9174c6dbbce5 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -431,8 +431,8 @@ static struct btrfs_delayed_ref_head *find_ref_head( return NULL; } -bool btrfs_delayed_ref_lock(struct btrfs_delayed_ref_root *delayed_refs, - struct btrfs_delayed_ref_head *head) +static bool btrfs_delayed_ref_lock(struct btrfs_delayed_ref_root *delayed_refs, + struct btrfs_delayed_ref_head *head) { lockdep_assert_held(&delayed_refs->lock); if (mutex_trylock(&head->mutex)) @@ -561,8 +561,9 @@ struct btrfs_delayed_ref_head *btrfs_select_ref_head( struct btrfs_delayed_ref_root *delayed_refs) { struct btrfs_delayed_ref_head *head; + bool locked; - lockdep_assert_held(&delayed_refs->lock); + spin_lock(&delayed_refs->lock); again: head = find_ref_head(delayed_refs, delayed_refs->run_delayed_start, true); @@ -570,16 +571,20 @@ struct btrfs_delayed_ref_head *btrfs_select_ref_head( delayed_refs->run_delayed_start = 0; head = find_first_ref_head(delayed_refs); } - if (!head) + if (!head) { + spin_unlock(&delayed_refs->lock); return NULL; + } while (head->processing) { struct rb_node *node; node = rb_next(&head->href_node); if (!node) { - if (delayed_refs->run_delayed_start == 0) + if (delayed_refs->run_delayed_start == 0) { + spin_unlock(&delayed_refs->lock); return NULL; + } delayed_refs->run_delayed_start = 0; goto again; } @@ -592,6 +597,18 @@ struct btrfs_delayed_ref_head *btrfs_select_ref_head( delayed_refs->num_heads_ready--; delayed_refs->run_delayed_start = head->bytenr + head->num_bytes; + + locked = btrfs_delayed_ref_lock(delayed_refs, head); + spin_unlock(&delayed_refs->lock); + + /* + * We may have dropped the spin lock to get the head mutex lock, and + * that might have given someone else time to free the head. If that's + * true, it has been removed from our list and we can move on. + */ + if (!locked) + return ERR_PTR(-EAGAIN); + return head; } diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h index 04730c650212..956fbe5d6984 100644 --- a/fs/btrfs/delayed-ref.h +++ b/fs/btrfs/delayed-ref.h @@ -369,8 +369,6 @@ void btrfs_merge_delayed_refs(struct btrfs_fs_info *fs_info, struct btrfs_delayed_ref_head * btrfs_find_delayed_ref_head(struct btrfs_delayed_ref_root *delayed_refs, u64 bytenr); -bool btrfs_delayed_ref_lock(struct btrfs_delayed_ref_root *delayed_refs, - struct btrfs_delayed_ref_head *head); static inline void btrfs_delayed_ref_unlock(struct btrfs_delayed_ref_head *head) { mutex_unlock(&head->mutex); diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 95d749cec49e..f5320a9cdf8f 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -1933,39 +1933,6 @@ static int cleanup_ref_head(struct btrfs_trans_handle *trans, return ret; } -static struct btrfs_delayed_ref_head *btrfs_obtain_ref_head( - struct btrfs_trans_handle *trans) -{ - struct btrfs_delayed_ref_root *delayed_refs = - &trans->transaction->delayed_refs; - struct btrfs_delayed_ref_head *head = NULL; - bool locked; - - spin_lock(&delayed_refs->lock); - head = btrfs_select_ref_head(delayed_refs); - if (!head) { - spin_unlock(&delayed_refs->lock); - return head; - } - - /* - * Grab the lock that says we are going to process all the refs for - * this head - */ - locked = btrfs_delayed_ref_lock(delayed_refs, head); - spin_unlock(&delayed_refs->lock); - - /* - * We may have dropped the spin lock to get the head mutex lock, and - * that might have given someone else time to free the head. If that's - * true, it has been removed from our list and we can move on. - */ - if (!locked) - head = ERR_PTR(-EAGAIN); - - return head; -} - static int btrfs_run_delayed_refs_for_head(struct btrfs_trans_handle *trans, struct btrfs_delayed_ref_head *locked_ref, u64 *bytes_released) @@ -2072,7 +2039,7 @@ static noinline int __btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, do { if (!locked_ref) { - locked_ref = btrfs_obtain_ref_head(trans); + locked_ref = btrfs_select_ref_head(delayed_refs); if (IS_ERR_OR_NULL(locked_ref)) { if (PTR_ERR(locked_ref) == -EAGAIN) { continue; From patchwork Thu Oct 24 16:24:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13849381 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB45A1F8911 for ; Thu, 24 Oct 2024 16:24:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787080; cv=none; b=JCtkhZFzbVAs0GF6ENuLjYBDleCfqMRz5m9oNVwOGoUtM0GzZrS9B1oWybP4ftYPkKgyQDPyfTZfkbFj34KnK7bwRd13Zld8JqGQ98mjcF/8vozO/uq5UTs3aBU0MgnpnLH7VinTBeT18a77O57RA8hznfD8DGCGdbLcjpbwcxU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787080; c=relaxed/simple; bh=tIEXAMiiyzCNNviFnqKb9GcIDIuV+rg7CMCHNF70ch0=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nwbazHHlnjP5uS5cJJ4S87osBEw2+ZFEET6OyYB537baV6qVc2XmTGhUWPkuVqwxbCaA5ybNvf9yZhBqHb3BJpi03ya5qx5ehMMv6FqLTnUkZrdvOSVDeMZE0eOIMGwdKYUmK3nWcCT0v8fy/Q6v45eF/JkHDRb1ceWkfKUyEnk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EFfaIS4H; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EFfaIS4H" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A797DC4CEE3 for ; Thu, 24 Oct 2024 16:24:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729787080; bh=tIEXAMiiyzCNNviFnqKb9GcIDIuV+rg7CMCHNF70ch0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=EFfaIS4HNkx2E704j8osihBm7VPKAh5kL1tA6hhqzBk0+P46wMHiqtIKivlVKma+j l6vEJQBV6Wt77qqrC7QBsf+IC54TUQxTzqSwC5O82I29DqnQ2lRCBRielHyO/xPkMX 9eFsWO6Zu9DftUXoAAEKxuUKfbk2WCVsn4ClopSzV3Zq1oTrssHF3Q9EppSAeXIcb3 OsIU4iEiV04UQQoJCyWNSNV6hDyRUL4tYiBeBlomLlBSFtlr9+nFmTRbzcRsmESj7f GjDw9KITipj6yp85OTrdcrCwDKH3p+uJaoFHXs+Xy5AARjIxAnS5k1Ts9EsZ11qLMB fPCdURjfuvQ/A== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 10/18] btrfs: move delayed ref head unselection to delayed-ref.c Date: Thu, 24 Oct 2024 17:24:18 +0100 Message-Id: <024e3f6fb496a05a691765d97e25220f325cf4f8.1729784713.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana The unselect_delayed_ref_head() at extent-tree.c doesn't really belong in that file as it's a delayed refs specific detail and therefore should be at delayed-ref.c. Further its inverse, btrfs_select_ref_head(), is at delayed-ref.c, so it only makes sense to have it there too. So move unselect_delayed_ref_head() into delayed-ref.c and rename it to btrfs_unselect_ref_head() so that its name closely matches its inverse (btrfs_select_ref_head()). Signed-off-by: Filipe Manana --- fs/btrfs/delayed-ref.c | 10 ++++++++++ fs/btrfs/delayed-ref.h | 2 ++ fs/btrfs/extent-tree.c | 16 +++------------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index 9174c6dbbce5..ffa06f931fa8 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -612,6 +612,16 @@ struct btrfs_delayed_ref_head *btrfs_select_ref_head( return head; } +void btrfs_unselect_ref_head(struct btrfs_delayed_ref_root *delayed_refs, + struct btrfs_delayed_ref_head *head) +{ + spin_lock(&delayed_refs->lock); + head->processing = false; + delayed_refs->num_heads_ready++; + spin_unlock(&delayed_refs->lock); + btrfs_delayed_ref_unlock(head); +} + void btrfs_delete_ref_head(struct btrfs_delayed_ref_root *delayed_refs, struct btrfs_delayed_ref_head *head) { diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h index 956fbe5d6984..d70de7ee63e5 100644 --- a/fs/btrfs/delayed-ref.h +++ b/fs/btrfs/delayed-ref.h @@ -378,6 +378,8 @@ void btrfs_delete_ref_head(struct btrfs_delayed_ref_root *delayed_refs, struct btrfs_delayed_ref_head *btrfs_select_ref_head( struct btrfs_delayed_ref_root *delayed_refs); +void btrfs_unselect_ref_head(struct btrfs_delayed_ref_root *delayed_refs, + struct btrfs_delayed_ref_head *head); int btrfs_check_delayed_seq(struct btrfs_fs_info *fs_info, u64 seq); diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index f5320a9cdf8f..2e00267ad362 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -1807,16 +1807,6 @@ select_delayed_ref(struct btrfs_delayed_ref_head *head) return ref; } -static void unselect_delayed_ref_head(struct btrfs_delayed_ref_root *delayed_refs, - struct btrfs_delayed_ref_head *head) -{ - spin_lock(&delayed_refs->lock); - head->processing = false; - delayed_refs->num_heads_ready++; - spin_unlock(&delayed_refs->lock); - btrfs_delayed_ref_unlock(head); -} - static struct btrfs_delayed_extent_op *cleanup_extent_op( struct btrfs_delayed_ref_head *head) { @@ -1891,7 +1881,7 @@ static int cleanup_ref_head(struct btrfs_trans_handle *trans, ret = run_and_cleanup_extent_op(trans, head); if (ret < 0) { - unselect_delayed_ref_head(delayed_refs, head); + btrfs_unselect_ref_head(delayed_refs, head); btrfs_debug(fs_info, "run_delayed_extent_op returned %d", ret); return ret; } else if (ret) { @@ -1953,7 +1943,7 @@ static int btrfs_run_delayed_refs_for_head(struct btrfs_trans_handle *trans, if (ref->seq && btrfs_check_delayed_seq(fs_info, ref->seq)) { spin_unlock(&locked_ref->lock); - unselect_delayed_ref_head(delayed_refs, locked_ref); + btrfs_unselect_ref_head(delayed_refs, locked_ref); return -EAGAIN; } @@ -2001,7 +1991,7 @@ static int btrfs_run_delayed_refs_for_head(struct btrfs_trans_handle *trans, btrfs_free_delayed_extent_op(extent_op); if (ret) { - unselect_delayed_ref_head(delayed_refs, locked_ref); + btrfs_unselect_ref_head(delayed_refs, locked_ref); btrfs_put_delayed_ref(ref); return ret; } From patchwork Thu Oct 24 16:24:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13849382 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C6A41F8EE5 for ; Thu, 24 Oct 2024 16:24:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787081; cv=none; b=THoYNufrpG1uRE++VXm1DHrrsrD3utTm7jy6WIJqWJ+aXZU745xaioLcMOkgnkcp4k3VH8tY9wJB5/LpmowS95yF2Q6uhWpG5kaE+BZpgNJ2CaJDFH3H2+hNu0m4zNRPsIyqahLAKKVQVs8rggbG1+kdnPRCk41q/tDhVRBVnbA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787081; c=relaxed/simple; bh=3oNvzDD1N0APhcjg8LWU7bEItuMxnC7zTwqYg4DnNbU=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uvP+rwklBGu+H+k6rKf1xtOZsl7srs4mJS3UESugkgfZotyV+jgzC5f9y6xD/vfUGSoxJVAs2Ym04/He/gW6KlUoaVMrTu0e/M7N8hEPqNKki6CidbwyA7VTTc+v3Cq82EeUQenonTUjwDzLNe9QZpSKdiwjbXIXQ4lzXfTucL8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ot6BwN+f; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ot6BwN+f" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE729C4CEE4 for ; Thu, 24 Oct 2024 16:24:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729787081; bh=3oNvzDD1N0APhcjg8LWU7bEItuMxnC7zTwqYg4DnNbU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Ot6BwN+f0WOa5v3kFIA3Wst53e4g8DLGOayO/XSAHhZc+JVeA9w04zKxo0TPg5wRZ 4EEbUzZjtSTfbXkcCivxmfpvkJphNHHAOILfMrLUzw6ACMYI+99n2nd2sHEW3ih35b ZEhbtuBclNMsnisSpQAzAAehRG01kPyczGSE3F/YzBiObDUIb9nejbaikifCep/3nG 7EmPeTuiVkELzXWSF8WAtL45A+FFFywc7m82KTr7QXUu7SC5yQzpSyc+C1SVd/jh33 0fwNgHYl8Sm7uYtaiO1tepOB5LPRyhkaVtY8+C2fL7uYcpo6SAICtcuDKgf9YusBXS 53fnWp9G9ptWQ== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 11/18] btrfs: pass fs_info to functions that search for delayed ref heads Date: Thu, 24 Oct 2024 17:24:19 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana One of the following patches in the series will need to access fs_info in the function find_ref_head(), so pass a fs_info argument to it as well as to the functions btrfs_select_ref_head() and btrfs_find_delayed_ref_head() which call find_ref_head(). Signed-off-by: Filipe Manana --- fs/btrfs/backref.c | 3 ++- fs/btrfs/delayed-ref.c | 12 ++++++++---- fs/btrfs/delayed-ref.h | 4 +++- fs/btrfs/extent-tree.c | 10 +++++----- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c index f8e1d5b2c512..04f53ca548e1 100644 --- a/fs/btrfs/backref.c +++ b/fs/btrfs/backref.c @@ -1442,7 +1442,8 @@ static int find_parent_nodes(struct btrfs_backref_walk_ctx *ctx, */ delayed_refs = &ctx->trans->transaction->delayed_refs; spin_lock(&delayed_refs->lock); - head = btrfs_find_delayed_ref_head(delayed_refs, ctx->bytenr); + head = btrfs_find_delayed_ref_head(ctx->fs_info, delayed_refs, + ctx->bytenr); if (head) { if (!mutex_trylock(&head->mutex)) { refcount_inc(&head->refs); diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index ffa06f931fa8..81f7a515dd0e 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -399,6 +399,7 @@ static struct btrfs_delayed_ref_head *find_first_ref_head( * is given, the next bigger entry is returned if no exact match is found. */ static struct btrfs_delayed_ref_head *find_ref_head( + struct btrfs_fs_info *fs_info, struct btrfs_delayed_ref_root *dr, u64 bytenr, bool return_bigger) { @@ -558,6 +559,7 @@ int btrfs_check_delayed_seq(struct btrfs_fs_info *fs_info, u64 seq) } struct btrfs_delayed_ref_head *btrfs_select_ref_head( + struct btrfs_fs_info *fs_info, struct btrfs_delayed_ref_root *delayed_refs) { struct btrfs_delayed_ref_head *head; @@ -565,8 +567,8 @@ struct btrfs_delayed_ref_head *btrfs_select_ref_head( spin_lock(&delayed_refs->lock); again: - head = find_ref_head(delayed_refs, delayed_refs->run_delayed_start, - true); + head = find_ref_head(fs_info, delayed_refs, + delayed_refs->run_delayed_start, true); if (!head && delayed_refs->run_delayed_start != 0) { delayed_refs->run_delayed_start = 0; head = find_first_ref_head(delayed_refs); @@ -1188,11 +1190,13 @@ void btrfs_put_delayed_ref(struct btrfs_delayed_ref_node *ref) * head node if found, or NULL if not. */ struct btrfs_delayed_ref_head * -btrfs_find_delayed_ref_head(struct btrfs_delayed_ref_root *delayed_refs, u64 bytenr) +btrfs_find_delayed_ref_head(struct btrfs_fs_info *fs_info, + struct btrfs_delayed_ref_root *delayed_refs, + u64 bytenr) { lockdep_assert_held(&delayed_refs->lock); - return find_ref_head(delayed_refs, bytenr, false); + return find_ref_head(fs_info, delayed_refs, bytenr, false); } static int find_comp(struct btrfs_delayed_ref_node *entry, u64 root, u64 parent) diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h index d70de7ee63e5..acd142b01c12 100644 --- a/fs/btrfs/delayed-ref.h +++ b/fs/btrfs/delayed-ref.h @@ -367,7 +367,8 @@ void btrfs_merge_delayed_refs(struct btrfs_fs_info *fs_info, struct btrfs_delayed_ref_head *head); struct btrfs_delayed_ref_head * -btrfs_find_delayed_ref_head(struct btrfs_delayed_ref_root *delayed_refs, +btrfs_find_delayed_ref_head(struct btrfs_fs_info *fs_info, + struct btrfs_delayed_ref_root *delayed_refs, u64 bytenr); static inline void btrfs_delayed_ref_unlock(struct btrfs_delayed_ref_head *head) { @@ -377,6 +378,7 @@ void btrfs_delete_ref_head(struct btrfs_delayed_ref_root *delayed_refs, struct btrfs_delayed_ref_head *head); struct btrfs_delayed_ref_head *btrfs_select_ref_head( + struct btrfs_fs_info *fs_info, struct btrfs_delayed_ref_root *delayed_refs); void btrfs_unselect_ref_head(struct btrfs_delayed_ref_root *delayed_refs, struct btrfs_delayed_ref_head *head); diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 2e00267ad362..40f16deb1c0f 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -182,7 +182,7 @@ int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans, delayed_refs = &trans->transaction->delayed_refs; spin_lock(&delayed_refs->lock); - head = btrfs_find_delayed_ref_head(delayed_refs, bytenr); + head = btrfs_find_delayed_ref_head(fs_info, delayed_refs, bytenr); if (head) { if (!mutex_trylock(&head->mutex)) { refcount_inc(&head->refs); @@ -2029,7 +2029,7 @@ static noinline int __btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, do { if (!locked_ref) { - locked_ref = btrfs_select_ref_head(delayed_refs); + locked_ref = btrfs_select_ref_head(fs_info, delayed_refs); if (IS_ERR_OR_NULL(locked_ref)) { if (PTR_ERR(locked_ref) == -EAGAIN) { continue; @@ -2231,7 +2231,7 @@ static noinline int check_delayed_ref(struct btrfs_root *root, delayed_refs = &cur_trans->delayed_refs; spin_lock(&delayed_refs->lock); - head = btrfs_find_delayed_ref_head(delayed_refs, bytenr); + head = btrfs_find_delayed_ref_head(root->fs_info, delayed_refs, bytenr); if (!head) { spin_unlock(&delayed_refs->lock); btrfs_put_transaction(cur_trans); @@ -3339,7 +3339,7 @@ static noinline int check_ref_cleanup(struct btrfs_trans_handle *trans, delayed_refs = &trans->transaction->delayed_refs; spin_lock(&delayed_refs->lock); - head = btrfs_find_delayed_ref_head(delayed_refs, bytenr); + head = btrfs_find_delayed_ref_head(trans->fs_info, delayed_refs, bytenr); if (!head) goto out_delayed_unlock; @@ -5474,7 +5474,7 @@ static int check_ref_exists(struct btrfs_trans_handle *trans, */ delayed_refs = &trans->transaction->delayed_refs; spin_lock(&delayed_refs->lock); - head = btrfs_find_delayed_ref_head(delayed_refs, bytenr); + head = btrfs_find_delayed_ref_head(root->fs_info, delayed_refs, bytenr); if (!head) goto out; if (!mutex_trylock(&head->mutex)) { From patchwork Thu Oct 24 16:24:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13849383 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E9A121F80D3 for ; Thu, 24 Oct 2024 16:24:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787083; cv=none; b=C+LXR2NlESZzQCoRNcklPFSO9OnXYKb/V1ECokJ+Ka4uzDAJBKYNL8vgfTNPH528FkrAyLNsds8f44X0W9u0LXPfAilXTUW8KkYLwQdiBnfor/uiHdLwA5y0QAIlhkDprl3+5TTQXpT/crY9mca+uaQH2YJU6nGmqftRGrPQb9M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787083; c=relaxed/simple; bh=nJ5X3l70LaR3P9EOCbzGKZehTh+HlYcQrqbGYyK5nsc=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NiZoMDWq8orzZWogZGi4BH8vKYGsIjnZjh3FHHvnqw69OhKsAlxt+RHrNSrEdj3jJdllROi01BOBkRqjFU/bAEJBJn3desRbXtFEA+PzV3B/N7GLE1J6OMtNH6wwrKQwsXrFgJ+NOO0WVgwK7oC4o889qaalM8VmmGEQTbG6rn8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rI94Vxto; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rI94Vxto" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6418C4CEE4 for ; Thu, 24 Oct 2024 16:24:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729787082; bh=nJ5X3l70LaR3P9EOCbzGKZehTh+HlYcQrqbGYyK5nsc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=rI94Vxto+BH5dslkNt2F17JShggMamcsiFi06neWHcqyr/jGs+GpmGSPuIzTMiL7E gc6A64paXS/blQc3fHiXovOTHgADJJ6RVr7iYiDlIYNKY2cca8PJLkzA0otfNh44RA YbyXyqICizGhOaaBf+3X7mIEpCX3prntzCq+OuH6Ga+xsxnuUlY7C4w7qRkIfGW73C 6M6uR8Cesfgjh+eiWPqM4Rqetv+Q4kq8hagdgkEcjzOZf+teU+ZUEGvsfo06wutK// ZMgiM5RMLyTmyiYVHNaAotZbzXHtLU2s3pwpXdJnL8FyYygpzQB42wlXqMbkN18jKq 1Rk8liqLazuXA== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 12/18] btrfs: pass fs_info to btrfs_cleanup_ref_head_accounting Date: Thu, 24 Oct 2024 17:24:20 +0100 Message-Id: <5f1e86a4efb9673c2270b09aa6b87f35e0c7d113.1729784713.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana One of the following patches in the series will need to access fs_info at btrfs_cleanup_ref_head_accounting(), so pass a fs_info argument to it. Signed-off-by: Filipe Manana --- fs/btrfs/delayed-ref.c | 5 +++-- fs/btrfs/delayed-ref.h | 3 ++- fs/btrfs/extent-tree.c | 9 +++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index 81f7a515dd0e..e81aa112d137 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -624,7 +624,8 @@ void btrfs_unselect_ref_head(struct btrfs_delayed_ref_root *delayed_refs, btrfs_delayed_ref_unlock(head); } -void btrfs_delete_ref_head(struct btrfs_delayed_ref_root *delayed_refs, +void btrfs_delete_ref_head(struct btrfs_fs_info *fs_info, + struct btrfs_delayed_ref_root *delayed_refs, struct btrfs_delayed_ref_head *head) { lockdep_assert_held(&delayed_refs->lock); @@ -1294,7 +1295,7 @@ void btrfs_destroy_delayed_refs(struct btrfs_transaction *trans) if (head->must_insert_reserved) pin_bytes = true; btrfs_free_delayed_extent_op(head->extent_op); - btrfs_delete_ref_head(delayed_refs, head); + btrfs_delete_ref_head(fs_info, delayed_refs, head); spin_unlock(&head->lock); spin_unlock(&delayed_refs->lock); mutex_unlock(&head->mutex); diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h index acd142b01c12..c3749e6cc374 100644 --- a/fs/btrfs/delayed-ref.h +++ b/fs/btrfs/delayed-ref.h @@ -374,7 +374,8 @@ static inline void btrfs_delayed_ref_unlock(struct btrfs_delayed_ref_head *head) { mutex_unlock(&head->mutex); } -void btrfs_delete_ref_head(struct btrfs_delayed_ref_root *delayed_refs, +void btrfs_delete_ref_head(struct btrfs_fs_info *fs_info, + struct btrfs_delayed_ref_root *delayed_refs, struct btrfs_delayed_ref_head *head); struct btrfs_delayed_ref_head *btrfs_select_ref_head( diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 40f16deb1c0f..33f911476a4d 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -1900,7 +1900,7 @@ static int cleanup_ref_head(struct btrfs_trans_handle *trans, spin_unlock(&delayed_refs->lock); return 1; } - btrfs_delete_ref_head(delayed_refs, head); + btrfs_delete_ref_head(fs_info, delayed_refs, head); spin_unlock(&head->lock); spin_unlock(&delayed_refs->lock); @@ -3333,13 +3333,14 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans, static noinline int check_ref_cleanup(struct btrfs_trans_handle *trans, u64 bytenr) { + struct btrfs_fs_info *fs_info = trans->fs_info; struct btrfs_delayed_ref_head *head; struct btrfs_delayed_ref_root *delayed_refs; int ret = 0; delayed_refs = &trans->transaction->delayed_refs; spin_lock(&delayed_refs->lock); - head = btrfs_find_delayed_ref_head(trans->fs_info, delayed_refs, bytenr); + head = btrfs_find_delayed_ref_head(fs_info, delayed_refs, bytenr); if (!head) goto out_delayed_unlock; @@ -3357,7 +3358,7 @@ static noinline int check_ref_cleanup(struct btrfs_trans_handle *trans, if (!mutex_trylock(&head->mutex)) goto out; - btrfs_delete_ref_head(delayed_refs, head); + btrfs_delete_ref_head(fs_info, delayed_refs, head); head->processing = false; spin_unlock(&head->lock); @@ -3367,7 +3368,7 @@ static noinline int check_ref_cleanup(struct btrfs_trans_handle *trans, if (head->must_insert_reserved) ret = 1; - btrfs_cleanup_ref_head_accounting(trans->fs_info, delayed_refs, head); + btrfs_cleanup_ref_head_accounting(fs_info, delayed_refs, head); mutex_unlock(&head->mutex); btrfs_put_delayed_ref_head(head); return ret; From patchwork Thu Oct 24 16:24:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13849384 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 996091F9EA1 for ; Thu, 24 Oct 2024 16:24:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787083; cv=none; b=Cx4L8XhbxOL72mSAaKlpxpAiCBnMN/KhIfOZ+aqTKZty5vVItzgEx+3gTzvs09wy5vNJ3cHR1s2MrJ3AtPfEgue2tSws/XPjbUVtlfIf4px3z3OfIMT322yDMdUJCQxPyzIuoGBc4zOyorfWY9b4tkmV5N98NJx3bvZLKNPCkPU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787083; c=relaxed/simple; bh=YFSBtq+3ZUHRvrDCiKZPFsnciF9AJYaJLg7W8rn8exE=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZK8Io0CplvCo+9hyMWc1Hypay/S3NoSDxXrKRH7U2Bk9vtweTVWnG7Zn5VgD/JIAGj44gv0ab7ZfsJaX3HWdd6jPxqimCLhv3EMgOmQnV7uMHbp4fxYXEKuMUxiL7W/+6SD3lhYA3Q423owekrXZrgyvze5FUsZwQl8SebSVIMQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nwcr7aet; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nwcr7aet" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C106AC4CEE3 for ; Thu, 24 Oct 2024 16:24:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729787083; bh=YFSBtq+3ZUHRvrDCiKZPFsnciF9AJYaJLg7W8rn8exE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=nwcr7aetpxCAV44/ZncMdssC1sbSdn4oIwCZNbpxImGuV1srPAqc57xyvJTlwBDQN 8m/dFhF+r4r8oaK0wmxsuaTwm9fhjrH4ionwrMipxUQCXHkz/c99ayuUkjcL/VoWYN cVDTzrTgaqaMTXHmSWnz+Ggd66N8txVo6oCj8FvjFvCHK4yz03qLBlpeSPthWEOvcl nBZiP+wDzbIlqGc33ssP3n6ZbgxYDoc2fqHacM4YfnI4w97upCD5hSZeKftYB+J2uO 4Xj4fDRuKi3nllxIbgamCtCGBWx+Drk5b+DaR1PqtsMQPuSQkoVWWzoXHY/ARmCwyK zPQeP02EnqUCA== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 13/18] btrfs: assert delayed refs lock is held at find_ref_head() Date: Thu, 24 Oct 2024 17:24:21 +0100 Message-Id: <56f462d0498e3f89dd06587e2f8be803c28d29a9.1729784713.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana We have 3 callers for find_ref_head() so assert at find_ref_head() that we have the delayed refs lock held, removing the assertion from one of its callers (btrfs_find_delayed_ref_head()). Signed-off-by: Filipe Manana --- fs/btrfs/delayed-ref.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index e81aa112d137..3aeb2c79c1ae 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -407,6 +407,8 @@ static struct btrfs_delayed_ref_head *find_ref_head( struct rb_node *n; struct btrfs_delayed_ref_head *entry; + lockdep_assert_held(&dr->lock); + n = root->rb_node; entry = NULL; while (n) { @@ -1195,8 +1197,6 @@ btrfs_find_delayed_ref_head(struct btrfs_fs_info *fs_info, struct btrfs_delayed_ref_root *delayed_refs, u64 bytenr) { - lockdep_assert_held(&delayed_refs->lock); - return find_ref_head(fs_info, delayed_refs, bytenr, false); } From patchwork Thu Oct 24 16:24:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13849385 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 066E11F9EA1 for ; Thu, 24 Oct 2024 16:24:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787085; cv=none; b=KugrUecAYRnZ+H3+SFIv9vdhDS6auzhdDE3lffOTTGuq13QA3W0BfnNjvXp4eA4V56MhSnA9bwnQwhFrAYTnn36ANvp18BQLTn3yQPvNM+f98QTU6eC7n+8WB9E1d7ptTVHzlzwI8NjYTDQRWAz9UjDs2r72j/7ImQ23ph04UPU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787085; c=relaxed/simple; bh=kEKJfMzAf2JPqotlEXtVGEUpGToB83bkX1bYUVKa2XA=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TM7j1a9DLvvKVbBJ3/TYj0yoXnqQGUJGM0jgnjeXvXlya+Nzq8C15AXsqSYSppMAyuli4sl0EOscXICbzUrUqRiDQomeS+vZx0q+QkSsxFUalbBWZ8H/fjFX9tpmeplPus9UHSPRd9OgMr8KPl2TYFLI9Ow2xbL7l8tkHOPM30U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ROPDPZqE; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ROPDPZqE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C665FC4CEE4 for ; Thu, 24 Oct 2024 16:24:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729787084; bh=kEKJfMzAf2JPqotlEXtVGEUpGToB83bkX1bYUVKa2XA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ROPDPZqEZsZHwUz7a43h8goK+a2vwf7l5GFnqZ+ZwEoXLR2sGjb3x1vHZ2oxJxkMH r4TxTqrS5DfmEtLB0tg7dlba4N5bs3MdSSCtXrzwtnQxWrS7YEaCkHDXQtNI3rorkq KF7Hq1zkufneSBixCLqz5g2wA8+VZ9mdTUVZ97ttfMVq6EMkx8ADaEWdOs9yjUJG8k GP/fxAO2niDbtR2EiVuSKpMGrgx9i2YbQDGZDt/IIXFBXQ4v330gWAqH1GhWrgAFwg fCFJuU+XrtMQHg1qMSXxlenjrEv3LiUKr77s9alpw7znjjcEDOwjoN8S4spSsmI6MP kB5QTIdYRb7NA== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 14/18] btrfs: assert delayed refs lock is held at find_first_ref_head() Date: Thu, 24 Oct 2024 17:24:22 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana The delayed refs lock must be held when calling find_first_ref_head(), so assert that it's being held. Signed-off-by: Filipe Manana --- fs/btrfs/delayed-ref.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index 3aeb2c79c1ae..a8cf76f44b2b 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -384,6 +384,8 @@ static struct btrfs_delayed_ref_head *find_first_ref_head( struct rb_node *n; struct btrfs_delayed_ref_head *entry; + lockdep_assert_held(&dr->lock); + n = rb_first_cached(&dr->href_root); if (!n) return NULL; From patchwork Thu Oct 24 16:24:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13849386 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CCD831F9EB9 for ; Thu, 24 Oct 2024 16:24:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787085; cv=none; b=EGPIkEJKEFclmALicWiE50diuW9E7QyUPFoZrjBkWYrDT3bTDcVcs0xXTbEblGtpNnuhzmQIDbBAZFCwT5c0CpKbVxah+6fLdJqvSStgCq2I3tvyZk++xrPntBy+xNSdNY3Y+xmDJfzMN4Odxmq6NyI9mwT6tjR35kVHL+lj0+0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787085; c=relaxed/simple; bh=XMWUvmGYo+H1wRihXcStxnVmZvCqgjo2I0mDgTtUBDU=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=sqmTMv4CA2GfwniSkirOWaCTamuK4DIUcr2a+yNNay6HOEbVMR0Wk0jYXsP2ql6dDf6EitP5RLyx5bX4vYYos+UVCbs3UGmkiknssRb3yqarhA/kr4e1OBUAuzpnnXNsdfr1cWzACSu/B+tpaX/CE2pfyQnr1QTD7qbhBpLnBB0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RZEaH6TI; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RZEaH6TI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D5856C4CEC7 for ; Thu, 24 Oct 2024 16:24:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729787085; bh=XMWUvmGYo+H1wRihXcStxnVmZvCqgjo2I0mDgTtUBDU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=RZEaH6TIg2zLSN40fgFdeTd7wvX3peYxm14NuTdsGfmOL6465RLumq+qSRkjnEk1V FgCKgamRpfVkdCw21KxFXSVVedRf1C+5csykDj/2AtLK98kgPt1gbWd5Ysjzem+YLU 78jRqMjEypqGDghmPChwg4g2G9VBNXdii0kG6Pn7Pt/dZQtPEHxtM7fDHSwsAoaXMg /Y8fHKWXoCiD3rSHB8uJQhOqaRGt09FZkQgdZnSlruwS4TP9Iq5p1E9f/XPy1a95At 61QwXwG45Mjcgbsi4WS24JegVMNHnBv+b2sh/GBJ/FyIEGoD3P0glGehVoJl27WG1+ 2UN4/MtDyRrbQ== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 15/18] btrfs: assert delayed refs lock is held at add_delayed_ref_head() Date: Thu, 24 Oct 2024 17:24:23 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana The delayed refs lock must be held when calling add_delayed_ref_head(), so assert that it's being held. Signed-off-by: Filipe Manana --- fs/btrfs/delayed-ref.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index a8cf76f44b2b..2b6a636ba4b5 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -886,6 +886,7 @@ add_delayed_ref_head(struct btrfs_trans_handle *trans, bool qrecord_inserted = false; delayed_refs = &trans->transaction->delayed_refs; + lockdep_assert_held(&delayed_refs->lock); /* Record qgroup extent info if provided */ if (qrecord) { From patchwork Thu Oct 24 16:24:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13849387 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 021BD1F9EC7 for ; Thu, 24 Oct 2024 16:24:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787087; cv=none; b=csNVzf14RdfhZ6i2WoXcJItZjBPh+jouSfAFmJSsv+gmxRp/vK6I0gJfig/2nPoCreG7tSH4tOoZLEi1iqtqFq7m3yNbMdEc8x0mTAePNClMvp2qRXgb5cT79JHwnPORQBcrNrvyZ70QttWYq56wmtLfR/vGhzG3cmutdbULUDM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787087; c=relaxed/simple; bh=HwCcXjdhcx4SVussFAGFoWDEyo2vaeTZ0ZJA3N2ia40=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hegjzX3wrVE86IZcGKBS1yGGvTR48Z24cadsYJ/QzOhnjquk6FpGymF7LttDhBpO1S2yrZn7kGZsKXpvM0tgu6eEoomBEC5MK2U+5+hsE51iVkrFs4U5eNbAY6gFUa8jDqkBzGtBq5dnAXOjNwAJb620DWOg8eoF6VMHSYf0DZA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fvUafAcf; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fvUafAcf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E552CC4CEE5 for ; Thu, 24 Oct 2024 16:24:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729787086; bh=HwCcXjdhcx4SVussFAGFoWDEyo2vaeTZ0ZJA3N2ia40=; h=From:To:Subject:Date:In-Reply-To:References:From; b=fvUafAcfJvkRwEQGQd/4Zlh4Rnh17oIAeT2+spWtW8nDPtvmz+5NZdyl2CRoDSlNe Z8bkcQGR/J1iZOhCcMEQwaZBnXBW0blaDpxwz+E0N+wAEmhKJ9ie9IeEV61Y/a5eSK HC48cb/OC+OdLx4trClwuSDPJqx4dK1Q0UzDXA46EYCj+gAAPzL9C7SzRE3kKxs/yA KtqtElVhDV2/0zn6sxOu93CLNVe6F+uCmvyF32FrwI+h9XWFPX86kgWFdjfHtf4Rjl lz6iCfNNYfn2cwmDr428Qn1k5wJu/zTNMkS7APxnpaak3vVq0yVqu3/R4EBonXHIio WEgocF3hCdj5Q== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 16/18] btrfs: add comments regarding locking to struct btrfs_delayed_ref_root Date: Thu, 24 Oct 2024 17:24:24 +0100 Message-Id: <47b682443436ae1533393fc0bfc25deef1f92366.1729784713.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana Add some comments to struct btrfs_delayed_ref_root's fields to mention what its spinlock protects. Signed-off-by: Filipe Manana --- fs/btrfs/delayed-ref.h | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h index c3749e6cc374..0a9f4d7dd87b 100644 --- a/fs/btrfs/delayed-ref.h +++ b/fs/btrfs/delayed-ref.h @@ -213,19 +213,33 @@ struct btrfs_delayed_ref_root { */ struct xarray dirty_extents; - /* this spin lock protects the rbtree and the entries inside */ + /* + * Protects the rbtree href_root, its entries and the following fields: + * num_heads, num_heads_ready, pending_csums and run_delayed_start. + */ spinlock_t lock; - /* total number of head nodes in tree */ + /* Total number of head refs, protected by the spinlock 'lock'. */ unsigned long num_heads; - /* total number of head nodes ready for processing */ + /* + * Total number of head refs ready for processing, protected by the + * spinlock 'lock'. + */ unsigned long num_heads_ready; + /* + * Track space reserved for deleting csums of data extents. + * Protected by the spinlock 'lock'. + */ u64 pending_csums; unsigned long flags; + /* + * Track from which bytenr to start searching ref heads. + * Protected by the spinlock 'lock'. + */ u64 run_delayed_start; /* From patchwork Thu Oct 24 16:24:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13849388 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 310CD1F9EC7 for ; Thu, 24 Oct 2024 16:24:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787088; cv=none; b=LLqZB1RkGBw5sIpGx+7s8rdVodBC8apCLvML+KgUBC900JT4JcgdrfUvBywlp9ebT356Da6pXyhQfhRQPvYSThwYSPRR9SXxznPqY/qcviOzviImzkmljhnOP9t7qypDklrkRdNGHyGRGO9DYUd6MxyuNcA3k95dxUrP5AbhwEU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787088; c=relaxed/simple; bh=SY9+aA1kkF03N+4qsNp8tyGlTlYB/6kFF0AcDWyPtb8=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AobKlfsWmvgMEruH+WpYVuReJVvDrRYmR0Co1Rm07/JSgsYUJvRW/lvI3ytQKKFHp5nu/uVtRiORGEG0gVD8HJjvRFoK0M1B3ahit1usAsCLkblfWr5DcYOTT6Ji8xqiI1tWIbKi36A1+aKcum0GbJlajwgVrDylJvKyclPOX8I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=StYQKkOo; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="StYQKkOo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EFE17C4CEE3 for ; Thu, 24 Oct 2024 16:24:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729787087; bh=SY9+aA1kkF03N+4qsNp8tyGlTlYB/6kFF0AcDWyPtb8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=StYQKkOo/5ol7WejYcmbB2dev5LX10hXR5NzZtBrixKFF1/y4uFimbq/7S1H2cM8w cXqWcKgdHRbtBhX3gINxvtcWdoquq/hnMCgpdxj20kb467DX1+6byI+KJHDfanOyJt rq/IZqm/gzPPnJmkyw1/XQ2bPMysBMuPsRgcthXPMlys3k5M5VQ4hVYMPQ+thHur/F Z/jEhrlCOx+HgrigXcXNW+0gnq5PcpwwdZDOAvrHdWIr3q8pJiyV6U9vMspYpfmTMj WBmQJMj6WSl1YgGsu+yKFUGJ/Imj2RDdpNNegZchngiw51Sp813TaLpT6f84PZIeRi qMLbymouRco8g== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 17/18] btrfs: track delayed ref heads in an xarray Date: Thu, 24 Oct 2024 17:24:25 +0100 Message-Id: <529e3a34a057b4389dd779bc6cddfb075d9c5c34.1729784713.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana Currently we use a red black tree (rb-tree) to track the delayed ref heads (in struct btrfs_delayed_ref_root::href_root). This however is not very efficient when the number of delayed ref heads is large (and it's very common to be at least in the order of thousands) since rb-trees are binary trees. For example for 10K delayed ref heads, the tree has a depth of 13. Besides that, inserting into the tree requires navigating through it and pulling useless cache lines in the process since the red black tree nodes are embedded within the delayed ref head structure - on the other hand, by being embedded, it requires no extra memory allocations. We can improve this by using an xarray instead which has a much higher branching factor than a red black tree (binary balanced tree) and is more cache friendly and behaves like a resizable array, with a much better search and insertion complexity than a red black tree. This only has one small disadvantage which is that insertion will sometimes require allocating memory for the xarray - which may fail (not that often since it uses a kmem_cache) - but on the other hand we can reduce the delayed ref head structure size by 24 bytes (from 152 down to 128 bytes) after removing the embedded red black tree node, meaning than we can now fit 32 delayed ref heads per 4K page instead of 26, and that gain compensates for the occasional memory allocations needed for the xarray nodes. We also end up using only 2 cache lines instead of 3 per delayed ref head. Running the following fs_mark test showed some improvements: $ cat test.sh #!/bin/bash DEV=/dev/nullb0 MNT=/mnt/nullb0 MOUNT_OPTIONS="-o ssd" FILES=100000 THREADS=$(nproc --all) echo "performance" | \ tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor mkfs.btrfs -f $DEV mount $MOUNT_OPTIONS $DEV $MNT OPTS="-S 0 -L 5 -n $FILES -s 0 -t $THREADS -k" for ((i = 1; i <= $THREADS; i++)); do OPTS="$OPTS -d $MNT/d$i" done fs_mark $OPTS umount $MNT Before this patch: FSUse% Count Size Files/sec App Overhead 10 1200000 0 171845.7 12253839 16 2400000 0 230898.7 12308254 23 3600000 0 212292.9 12467768 30 4800000 0 195737.8 12627554 46 6000000 0 171055.2 12783329 After this patch: FSUse% Count Size Files/sec App Overhead 10 1200000 0 173835.0 12246131 16 2400000 0 233537.8 12271746 23 3600000 0 220398.7 12307737 30 4800000 0 204483.6 12392318 40 6000000 0 182923.3 12771843 Signed-off-by: Filipe Manana --- fs/btrfs/delayed-ref.c | 192 +++++++++++++++++++---------------------- fs/btrfs/delayed-ref.h | 26 +++--- fs/btrfs/extent-tree.c | 2 +- fs/btrfs/transaction.c | 5 +- 4 files changed, 106 insertions(+), 119 deletions(-) diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index 2b6a636ba4b5..e4ca5285e614 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -314,39 +314,6 @@ static int comp_refs(struct btrfs_delayed_ref_node *ref1, return 0; } -/* insert a new ref to head ref rbtree */ -static struct btrfs_delayed_ref_head *htree_insert(struct rb_root_cached *root, - struct rb_node *node) -{ - struct rb_node **p = &root->rb_root.rb_node; - struct rb_node *parent_node = NULL; - struct btrfs_delayed_ref_head *entry; - struct btrfs_delayed_ref_head *ins; - u64 bytenr; - bool leftmost = true; - - ins = rb_entry(node, struct btrfs_delayed_ref_head, href_node); - bytenr = ins->bytenr; - while (*p) { - parent_node = *p; - entry = rb_entry(parent_node, struct btrfs_delayed_ref_head, - href_node); - - if (bytenr < entry->bytenr) { - p = &(*p)->rb_left; - } else if (bytenr > entry->bytenr) { - p = &(*p)->rb_right; - leftmost = false; - } else { - return entry; - } - } - - rb_link_node(node, parent_node, p); - rb_insert_color_cached(node, root, leftmost); - return NULL; -} - static struct btrfs_delayed_ref_node* tree_insert(struct rb_root_cached *root, struct btrfs_delayed_ref_node *ins) { @@ -381,18 +348,11 @@ static struct btrfs_delayed_ref_node* tree_insert(struct rb_root_cached *root, static struct btrfs_delayed_ref_head *find_first_ref_head( struct btrfs_delayed_ref_root *dr) { - struct rb_node *n; - struct btrfs_delayed_ref_head *entry; + unsigned long from = 0; lockdep_assert_held(&dr->lock); - n = rb_first_cached(&dr->href_root); - if (!n) - return NULL; - - entry = rb_entry(n, struct btrfs_delayed_ref_head, href_node); - - return entry; + return xa_find(&dr->head_refs, &from, ULONG_MAX, XA_PRESENT); } /* @@ -405,35 +365,22 @@ static struct btrfs_delayed_ref_head *find_ref_head( struct btrfs_delayed_ref_root *dr, u64 bytenr, bool return_bigger) { - struct rb_root *root = &dr->href_root.rb_root; - struct rb_node *n; + const unsigned long target_index = (bytenr >> fs_info->sectorsize_bits); + unsigned long found_index = target_index; struct btrfs_delayed_ref_head *entry; lockdep_assert_held(&dr->lock); - n = root->rb_node; - entry = NULL; - while (n) { - entry = rb_entry(n, struct btrfs_delayed_ref_head, href_node); + entry = xa_find(&dr->head_refs, &found_index, ULONG_MAX, XA_PRESENT); + if (!entry) + return NULL; + + ASSERT(found_index >= target_index); - if (bytenr < entry->bytenr) - n = n->rb_left; - else if (bytenr > entry->bytenr) - n = n->rb_right; - else - return entry; - } - if (entry && return_bigger) { - if (bytenr > entry->bytenr) { - n = rb_next(&entry->href_node); - if (!n) - return NULL; - entry = rb_entry(n, struct btrfs_delayed_ref_head, - href_node); - } - return entry; - } - return NULL; + if (found_index != target_index && !return_bigger) + return NULL; + + return entry; } static bool btrfs_delayed_ref_lock(struct btrfs_delayed_ref_root *delayed_refs, @@ -448,7 +395,7 @@ static bool btrfs_delayed_ref_lock(struct btrfs_delayed_ref_root *delayed_refs, mutex_lock(&head->mutex); spin_lock(&delayed_refs->lock); - if (RB_EMPTY_NODE(&head->href_node)) { + if (!head->tracked) { mutex_unlock(&head->mutex); btrfs_put_delayed_ref_head(head); return false; @@ -567,35 +514,27 @@ struct btrfs_delayed_ref_head *btrfs_select_ref_head( struct btrfs_delayed_ref_root *delayed_refs) { struct btrfs_delayed_ref_head *head; + unsigned long start_index; + unsigned long found_index; + bool found_head = false; bool locked; spin_lock(&delayed_refs->lock); again: - head = find_ref_head(fs_info, delayed_refs, - delayed_refs->run_delayed_start, true); - if (!head && delayed_refs->run_delayed_start != 0) { - delayed_refs->run_delayed_start = 0; - head = find_first_ref_head(delayed_refs); - } - if (!head) { - spin_unlock(&delayed_refs->lock); - return NULL; + start_index = (delayed_refs->run_delayed_start >> fs_info->sectorsize_bits); + xa_for_each_start(&delayed_refs->head_refs, found_index, head, start_index) { + if (!head->processing) { + found_head = true; + break; + } } - - while (head->processing) { - struct rb_node *node; - - node = rb_next(&head->href_node); - if (!node) { - if (delayed_refs->run_delayed_start == 0) { - spin_unlock(&delayed_refs->lock); - return NULL; - } - delayed_refs->run_delayed_start = 0; - goto again; + if (!found_head) { + if (delayed_refs->run_delayed_start == 0) { + spin_unlock(&delayed_refs->lock); + return NULL; } - head = rb_entry(node, struct btrfs_delayed_ref_head, - href_node); + delayed_refs->run_delayed_start = 0; + goto again; } head->processing = true; @@ -632,11 +571,13 @@ void btrfs_delete_ref_head(struct btrfs_fs_info *fs_info, struct btrfs_delayed_ref_root *delayed_refs, struct btrfs_delayed_ref_head *head) { + const unsigned long index = (head->bytenr >> fs_info->sectorsize_bits); + lockdep_assert_held(&delayed_refs->lock); lockdep_assert_held(&head->lock); - rb_erase_cached(&head->href_node, &delayed_refs->href_root); - RB_CLEAR_NODE(&head->href_node); + xa_erase(&delayed_refs->head_refs, index); + head->tracked = false; delayed_refs->num_heads--; if (!head->processing) delayed_refs->num_heads_ready--; @@ -845,7 +786,7 @@ static void init_delayed_ref_head(struct btrfs_delayed_ref_head *head_ref, head_ref->is_system = (generic_ref->ref_root == BTRFS_CHUNK_TREE_OBJECTID); head_ref->ref_tree = RB_ROOT_CACHED; INIT_LIST_HEAD(&head_ref->ref_add_list); - RB_CLEAR_NODE(&head_ref->href_node); + head_ref->tracked = false; head_ref->processing = false; head_ref->total_ref_mod = count_mod; spin_lock_init(&head_ref->lock); @@ -883,11 +824,24 @@ add_delayed_ref_head(struct btrfs_trans_handle *trans, struct btrfs_fs_info *fs_info = trans->fs_info; struct btrfs_delayed_ref_head *existing; struct btrfs_delayed_ref_root *delayed_refs; + const unsigned long index = (head_ref->bytenr >> fs_info->sectorsize_bits); bool qrecord_inserted = false; delayed_refs = &trans->transaction->delayed_refs; lockdep_assert_held(&delayed_refs->lock); +#if BITS_PER_LONG == 32 + if (head_ref->bytenr >= MAX_LFS_FILESIZE) { + if (qrecord) + xa_release(&delayed_refs->dirty_extents, index); + btrfs_err_rl(fs_info, +"delayed ref head %llu is beyond 32bit page cache and xarray index limit", + head_ref->bytenr); + btrfs_err_32bit_limit(fs_info); + return ERR_PTR(-EOVERFLOW); + } +#endif + /* Record qgroup extent info if provided */ if (qrecord) { int ret; @@ -896,8 +850,7 @@ add_delayed_ref_head(struct btrfs_trans_handle *trans, head_ref->bytenr); if (ret) { /* Clean up if insertion fails or item exists. */ - xa_release(&delayed_refs->dirty_extents, - head_ref->bytenr >> fs_info->sectorsize_bits); + xa_release(&delayed_refs->dirty_extents, index); /* Caller responsible for freeing qrecord on error. */ if (ret < 0) return ERR_PTR(ret); @@ -909,8 +862,7 @@ add_delayed_ref_head(struct btrfs_trans_handle *trans, trace_add_delayed_ref_head(fs_info, head_ref, action); - existing = htree_insert(&delayed_refs->href_root, - &head_ref->href_node); + existing = xa_load(&delayed_refs->head_refs, index); if (existing) { update_existing_head_ref(trans, existing, head_ref); /* @@ -920,6 +872,19 @@ add_delayed_ref_head(struct btrfs_trans_handle *trans, kmem_cache_free(btrfs_delayed_ref_head_cachep, head_ref); head_ref = existing; } else { + existing = xa_store(&delayed_refs->head_refs, index, head_ref, GFP_ATOMIC); + if (xa_is_err(existing)) { + /* Memory was preallocated by the caller. */ + ASSERT(xa_err(existing) != -ENOMEM); + return ERR_CAST(existing); + } else if (WARN_ON(existing)) { + /* + * Shouldn't happen we just did a lookup before under + * delayed_refs->lock. + */ + return ERR_PTR(-EEXIST); + } + head_ref->tracked = true; /* * We reserve the amount of bytes needed to delete csums when * adding the ref head and not when adding individual drop refs @@ -1040,6 +1005,8 @@ static int add_delayed_ref(struct btrfs_trans_handle *trans, struct btrfs_delayed_ref_head *new_head_ref; struct btrfs_delayed_ref_root *delayed_refs; struct btrfs_qgroup_extent_record *record = NULL; + const unsigned long index = (generic_ref->bytenr >> fs_info->sectorsize_bits); + bool qrecord_reserved = false; bool qrecord_inserted; int action = generic_ref->action; bool merged; @@ -1055,25 +1022,32 @@ static int add_delayed_ref(struct btrfs_trans_handle *trans, goto free_node; } + delayed_refs = &trans->transaction->delayed_refs; + if (btrfs_qgroup_full_accounting(fs_info) && !generic_ref->skip_qgroup) { record = kzalloc(sizeof(*record), GFP_NOFS); if (!record) { ret = -ENOMEM; goto free_head_ref; } - if (xa_reserve(&trans->transaction->delayed_refs.dirty_extents, - generic_ref->bytenr >> fs_info->sectorsize_bits, - GFP_NOFS)) { + if (xa_reserve(&delayed_refs->dirty_extents, index, GFP_NOFS)) { ret = -ENOMEM; goto free_record; } + qrecord_reserved = true; + } + + ret = xa_reserve(&delayed_refs->head_refs, index, GFP_NOFS); + if (ret) { + if (qrecord_reserved) + xa_release(&delayed_refs->dirty_extents, index); + goto free_record; } init_delayed_ref_common(fs_info, node, generic_ref); init_delayed_ref_head(head_ref, generic_ref, record, reserved); head_ref->extent_op = extent_op; - delayed_refs = &trans->transaction->delayed_refs; spin_lock(&delayed_refs->lock); /* @@ -1083,6 +1057,7 @@ static int add_delayed_ref(struct btrfs_trans_handle *trans, new_head_ref = add_delayed_ref_head(trans, head_ref, record, action, &qrecord_inserted); if (IS_ERR(new_head_ref)) { + xa_release(&delayed_refs->head_refs, index); spin_unlock(&delayed_refs->lock); ret = PTR_ERR(new_head_ref); goto free_record; @@ -1145,6 +1120,7 @@ int btrfs_add_delayed_extent_op(struct btrfs_trans_handle *trans, u64 bytenr, u64 num_bytes, u8 level, struct btrfs_delayed_extent_op *extent_op) { + const unsigned long index = (bytenr >> trans->fs_info->sectorsize_bits); struct btrfs_delayed_ref_head *head_ref; struct btrfs_delayed_ref_head *head_ref_ret; struct btrfs_delayed_ref_root *delayed_refs; @@ -1155,6 +1131,7 @@ int btrfs_add_delayed_extent_op(struct btrfs_trans_handle *trans, .num_bytes = num_bytes, .tree_ref.level = level, }; + int ret; head_ref = kmem_cache_alloc(btrfs_delayed_ref_head_cachep, GFP_NOFS); if (!head_ref) @@ -1164,16 +1141,23 @@ int btrfs_add_delayed_extent_op(struct btrfs_trans_handle *trans, head_ref->extent_op = extent_op; delayed_refs = &trans->transaction->delayed_refs; - spin_lock(&delayed_refs->lock); + ret = xa_reserve(&delayed_refs->head_refs, index, GFP_NOFS); + if (ret) { + kmem_cache_free(btrfs_delayed_ref_head_cachep, head_ref); + return ret; + } + + spin_lock(&delayed_refs->lock); head_ref_ret = add_delayed_ref_head(trans, head_ref, NULL, BTRFS_UPDATE_DELAYED_HEAD, NULL); - spin_unlock(&delayed_refs->lock); - if (IS_ERR(head_ref_ret)) { + xa_release(&delayed_refs->head_refs, index); + spin_unlock(&delayed_refs->lock); kmem_cache_free(btrfs_delayed_ref_head_cachep, head_ref); return PTR_ERR(head_ref_ret); } + spin_unlock(&delayed_refs->lock); /* * Need to update the delayed_refs_rsv with any changes we may have diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h index 0a9f4d7dd87b..c7c4d62744b4 100644 --- a/fs/btrfs/delayed-ref.h +++ b/fs/btrfs/delayed-ref.h @@ -122,12 +122,6 @@ struct btrfs_delayed_extent_op { struct btrfs_delayed_ref_head { u64 bytenr; u64 num_bytes; - /* - * For insertion into struct btrfs_delayed_ref_root::href_root. - * Keep it in the same cache line as 'bytenr' for more efficient - * searches in the rbtree. - */ - struct rb_node href_node; /* * the mutex is held while running the refs, and it is also * held when checking the sum of reference modifications. @@ -191,6 +185,11 @@ struct btrfs_delayed_ref_head { bool is_data; bool is_system; bool processing; + /* + * Indicate if it's currently in the data structure that tracks head + * refs (struct btrfs_delayed_ref_root::head_refs). + */ + bool tracked; }; enum btrfs_delayed_ref_flags { @@ -199,22 +198,27 @@ enum btrfs_delayed_ref_flags { }; struct btrfs_delayed_ref_root { - /* head ref rbtree */ - struct rb_root_cached href_root; - /* - * Track dirty extent records. + * Track head references. * The keys correspond to the logical address of the extent ("bytenr") * right shifted by fs_info->sectorsize_bits. This is both to get a more * dense index space (optimizes xarray structure) and because indexes in * xarrays are of "unsigned long" type, meaning they are 32 bits wide on * 32 bits platforms, limiting the extent range to 4G which is too low * and makes it unusable (truncated index values) on 32 bits platforms. + * Protected by the spinlock 'lock' defined below. + */ + struct xarray head_refs; + + /* + * Track dirty extent records. + * The keys correspond to the logical address of the extent ("bytenr") + * right shifted by fs_info->sectorsize_bits, for same reasons as above. */ struct xarray dirty_extents; /* - * Protects the rbtree href_root, its entries and the following fields: + * Protects the xarray head_refs, its entries and the following fields: * num_heads, num_heads_ready, pending_csums and run_delayed_start. */ spinlock_t lock; diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 33f911476a4d..1571b5a1d905 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -2176,7 +2176,7 @@ int btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, u64 min_bytes) btrfs_create_pending_block_groups(trans); spin_lock(&delayed_refs->lock); - if (RB_EMPTY_ROOT(&delayed_refs->href_root.rb_root)) { + if (xa_empty(&delayed_refs->head_refs)) { spin_unlock(&delayed_refs->lock); return 0; } diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 9ccf68ab53f9..dc0b837efd5d 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -141,8 +141,7 @@ void btrfs_put_transaction(struct btrfs_transaction *transaction) WARN_ON(refcount_read(&transaction->use_count) == 0); if (refcount_dec_and_test(&transaction->use_count)) { BUG_ON(!list_empty(&transaction->list)); - WARN_ON(!RB_EMPTY_ROOT( - &transaction->delayed_refs.href_root.rb_root)); + WARN_ON(!xa_empty(&transaction->delayed_refs.head_refs)); WARN_ON(!xa_empty(&transaction->delayed_refs.dirty_extents)); if (transaction->delayed_refs.pending_csums) btrfs_err(transaction->fs_info, @@ -349,7 +348,7 @@ static noinline int join_transaction(struct btrfs_fs_info *fs_info, memset(&cur_trans->delayed_refs, 0, sizeof(cur_trans->delayed_refs)); - cur_trans->delayed_refs.href_root = RB_ROOT_CACHED; + xa_init(&cur_trans->delayed_refs.head_refs); xa_init(&cur_trans->delayed_refs.dirty_extents); /* From patchwork Thu Oct 24 16:24:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13849389 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1EA911FAEE2 for ; Thu, 24 Oct 2024 16:24:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787089; cv=none; b=qphqchXRmxhxKHcBwRv8YF+ZQrlXsWlO80ge4M5Fmm2FHPnhxNfBj5VSmmp1Yx9YigIkx347RCyXGSn+69m+OPSUqvon92JXdJZ6zwpXpx4FZP5D1qNOU+4/VY4dbd2tshg5m7jLXo0QyS66zaYSg8sHmUO0AScxW4kPvXHDty4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729787089; c=relaxed/simple; bh=nLGP1wPsHV/4naMJ4rKWrETcfNOA1CvzMFGob5RbxR0=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tEOPdiH74I4RnK9v7WqaMaqHrVTLqoVrCZsQjjjIWM8WHKk91qPbdB5mOn8kt9cjG5vc69AoowDgZquZ89ZE624Ifbm1S7QYqwcH5eauSwY3OTWFZb8j0vWQXyfVic/7T/UQvd58sqL7nbRify6aqBnrAVhlu6FAeuT/ylVXJX8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YIiXpNsI; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YIiXpNsI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 335A1C4CEC7 for ; Thu, 24 Oct 2024 16:24:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729787088; bh=nLGP1wPsHV/4naMJ4rKWrETcfNOA1CvzMFGob5RbxR0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=YIiXpNsI95bbGJInydmiYADzj7JeY0KIUkfEaXvDPBTqcclnKIfTsYpPET+AhfEB+ gkSxI+3DXXUjU1C61/fpa04K0VNCzGsP1MPA9jYVAXAXboJC10evWLHKoOvauJa+Vq ITFFWg0LJlHTO6Ywitc+95GJJczt2RcMArSD+6KX1U1JBmrtBZuoYdqZBel1YkAPd8 YMvV+aCV/SfLQIOUpY9QcGUo3BhYH6Bd727n53FoWm4FF1ypwpGgW3UlXz8E/U3GDa zqlWa+jv0Svf65uTUNTNlm4UkRnKldLI2QqWiZeGX0DXq20aaUanVO24BUY5b15/1a tMJtdVDvIDxLQ== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 18/18] btrfs: remove no longer used delayed ref head search functionality Date: Thu, 24 Oct 2024 17:24:26 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana After the previous patch, which converted the rb-tree used to track delayed ref heads into an xarray, the find_ref_head() function is now used only by one caller which always passes false to the 'return_bigger' argument. So remove the 'return_bigger' logic, simplifying the function, and move all the function code to the single caller. Signed-off-by: Filipe Manana --- fs/btrfs/delayed-ref.c | 34 +++++----------------------------- 1 file changed, 5 insertions(+), 29 deletions(-) diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index e4ca5285e614..7399be5fddaf 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -355,34 +355,6 @@ static struct btrfs_delayed_ref_head *find_first_ref_head( return xa_find(&dr->head_refs, &from, ULONG_MAX, XA_PRESENT); } -/* - * Find a head entry based on bytenr. This returns the delayed ref head if it - * was able to find one, or NULL if nothing was in that spot. If return_bigger - * is given, the next bigger entry is returned if no exact match is found. - */ -static struct btrfs_delayed_ref_head *find_ref_head( - struct btrfs_fs_info *fs_info, - struct btrfs_delayed_ref_root *dr, u64 bytenr, - bool return_bigger) -{ - const unsigned long target_index = (bytenr >> fs_info->sectorsize_bits); - unsigned long found_index = target_index; - struct btrfs_delayed_ref_head *entry; - - lockdep_assert_held(&dr->lock); - - entry = xa_find(&dr->head_refs, &found_index, ULONG_MAX, XA_PRESENT); - if (!entry) - return NULL; - - ASSERT(found_index >= target_index); - - if (found_index != target_index && !return_bigger) - return NULL; - - return entry; -} - static bool btrfs_delayed_ref_lock(struct btrfs_delayed_ref_root *delayed_refs, struct btrfs_delayed_ref_head *head) { @@ -1184,7 +1156,11 @@ btrfs_find_delayed_ref_head(struct btrfs_fs_info *fs_info, struct btrfs_delayed_ref_root *delayed_refs, u64 bytenr) { - return find_ref_head(fs_info, delayed_refs, bytenr, false); + const unsigned long index = (bytenr >> fs_info->sectorsize_bits); + + lockdep_assert_held(&delayed_refs->lock); + + return xa_load(&delayed_refs->head_refs, index); } static int find_comp(struct btrfs_delayed_ref_node *entry, u64 root, u64 parent)