From patchwork Wed Sep 25 10:50: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: 13811872 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 259C1165F1C for ; Wed, 25 Sep 2024 10:50: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=1727261435; cv=none; b=Rs7odB36sbmqlB51dFZSsEPejQ6jFrS2YYzqvuRMWMQ8dxr6OwoQdxUsBUSV+s7qwxlfJpaP7RwMHlJlYAPlyJGo7IOt78VylyW0+wioLcT614Hq9lFYXOzpdV+V+p1ucJEUQcNfEvdRvCeHc8RbIEd/+sv1/fTaikkRtxHaj2w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727261435; c=relaxed/simple; bh=i9LAUyxUoA3OaQjX49pEGHwxBjafYA88ls6ZvpUwszU=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nUrP21sLSACkd47EHlYOGv+yB8fnUsU4AmtjOLSPN+JMkFScSsmDiGHGWB2kWuGtUZHVvQ6YBYNTaOjneeopU1SxAE2YizJ466LDOqHkvNVM0ILkcg3xLeSTirE7wNTmxHTv2DRWQCxYHDVAan7UeUz6sxivfQhmmM9uBsMZhs0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qg6iTW/a; 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="qg6iTW/a" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 214FDC4CEC7 for ; Wed, 25 Sep 2024 10:50:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727261434; bh=i9LAUyxUoA3OaQjX49pEGHwxBjafYA88ls6ZvpUwszU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=qg6iTW/agcspezI3C2TmkXYXS2r3k8F2adCbdZ7j2FlAjF71n6xk6LsFSP8hns0+b FQskPAqaVT1jzKMg6ypj8ipZuYBxWej+34YDQ8isRk8hZhqvvsKiSM5AdIG4Rkzovo pOyuNcsmRp+TQR4EADUReYxdk69LtnLaWk3Rvo4E/+19TBIPUN/CRsI3FfESNHYCbW yLCrGmYV00u6Jbv0swjOCWf5KQvTb3/oqC0TkzfMY3nqIWvzzeqCixW1bE7N2g6JOV hE614IloWVAQTivp3zDUbOURlkOF1CtqooU+BMWEtfzlk0DOOnUtSpcvWx5jQp/B6N PsDvHo+yXNXZA== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 1/8] btrfs: fix missing error handling when adding delayed ref with qgroups enabled Date: Wed, 25 Sep 2024 11:50:23 +0100 Message-Id: <7e4b248dad75a0f0dd3a41b4a3af138a418b05d8.1727261112.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 adding a delayed ref head, at delayed-ref.c:add_delayed_ref_head(), if we fail to insert the qgroup record we don't error out, we ignore it. In fact we treat it as if there was no error and there was already an existing record - we don't distinguish between the cases where btrfs_qgroup_trace_extent_nolock() returns 1, meaning a record already existed and we can free the given record, and the case where it returns a negative error value, meaning the insertion into the xarray that is used to track records failed. Effectively we end up ignoring that we are lacking qgroup record in the dirty extents xarray, resulting in incorrect qgroup accounting. Fix this by checking for errors and return them to the callers. Fixes: 3cce39a8ca4e ("btrfs: qgroup: use xarray to track dirty extents in transaction") Signed-off-by: Filipe Manana --- fs/btrfs/delayed-ref.c | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index ad9ef8312e41..32f719b9e661 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -840,6 +840,8 @@ static void init_delayed_ref_head(struct btrfs_delayed_ref_head *head_ref, * helper function to actually insert a head node into the rbtree. * this does all the dirty work in terms of maintaining the correct * overall modification count. + * + * Returns an error pointer in case of an error. */ static noinline struct btrfs_delayed_ref_head * add_delayed_ref_head(struct btrfs_trans_handle *trans, @@ -862,6 +864,9 @@ add_delayed_ref_head(struct btrfs_trans_handle *trans, if (ret) { /* Clean up if insertion fails or item exists. */ xa_release(&delayed_refs->dirty_extents, qrecord->bytenr); + /* Caller responsible for freeing qrecord on error. */ + if (ret < 0) + return ERR_PTR(ret); kfree(qrecord); } else { qrecord_inserted = true; @@ -1000,27 +1005,35 @@ static int add_delayed_ref(struct btrfs_trans_handle *trans, struct btrfs_fs_info *fs_info = trans->fs_info; struct btrfs_delayed_ref_node *node; struct btrfs_delayed_ref_head *head_ref; + struct btrfs_delayed_ref_head *new_head_ref; struct btrfs_delayed_ref_root *delayed_refs; struct btrfs_qgroup_extent_record *record = NULL; bool qrecord_inserted; int action = generic_ref->action; bool merged; + int ret; node = kmem_cache_alloc(btrfs_delayed_ref_node_cachep, GFP_NOFS); if (!node) return -ENOMEM; head_ref = kmem_cache_alloc(btrfs_delayed_ref_head_cachep, GFP_NOFS); - if (!head_ref) + if (!head_ref) { + ret = -ENOMEM; goto free_node; + } if (btrfs_qgroup_full_accounting(fs_info) && !generic_ref->skip_qgroup) { record = kzalloc(sizeof(*record), GFP_NOFS); - if (!record) + if (!record) { + ret = -ENOMEM; goto free_head_ref; + } if (xa_reserve(&trans->transaction->delayed_refs.dirty_extents, - generic_ref->bytenr, GFP_NOFS)) + generic_ref->bytenr, GFP_NOFS)) { + ret = -ENOMEM; goto free_record; + } } init_delayed_ref_common(fs_info, node, generic_ref); @@ -1034,8 +1047,14 @@ static int add_delayed_ref(struct btrfs_trans_handle *trans, * insert both the head node and the new ref without dropping * the spin lock */ - head_ref = add_delayed_ref_head(trans, head_ref, record, - action, &qrecord_inserted); + new_head_ref = add_delayed_ref_head(trans, head_ref, record, + action, &qrecord_inserted); + if (IS_ERR(new_head_ref)) { + spin_unlock(&delayed_refs->lock); + ret = PTR_ERR(new_head_ref); + goto free_record; + } + head_ref = new_head_ref; merged = insert_delayed_ref(trans, head_ref, node); spin_unlock(&delayed_refs->lock); @@ -1063,7 +1082,7 @@ static int add_delayed_ref(struct btrfs_trans_handle *trans, kmem_cache_free(btrfs_delayed_ref_head_cachep, head_ref); free_node: kmem_cache_free(btrfs_delayed_ref_node_cachep, node); - return -ENOMEM; + return ret; } /* @@ -1094,6 +1113,7 @@ int btrfs_add_delayed_extent_op(struct btrfs_trans_handle *trans, struct btrfs_delayed_extent_op *extent_op) { struct btrfs_delayed_ref_head *head_ref; + struct btrfs_delayed_ref_head *head_ref_ret; struct btrfs_delayed_ref_root *delayed_refs; struct btrfs_ref generic_ref = { .type = BTRFS_REF_METADATA, @@ -1113,11 +1133,15 @@ int btrfs_add_delayed_extent_op(struct btrfs_trans_handle *trans, delayed_refs = &trans->transaction->delayed_refs; spin_lock(&delayed_refs->lock); - add_delayed_ref_head(trans, head_ref, NULL, BTRFS_UPDATE_DELAYED_HEAD, - NULL); - + 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)) { + kmem_cache_free(btrfs_delayed_ref_head_cachep, head_ref); + return PTR_ERR(head_ref_ret); + } + /* * Need to update the delayed_refs_rsv with any changes we may have * made. From patchwork Wed Sep 25 10:50: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: 13811873 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 1ECDB1865FE for ; Wed, 25 Sep 2024 10:50: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=1727261436; cv=none; b=TyhtD+mPuoOUlvlQFw2e4BEr/oeK6BpUIgWu1OLJ6ofulWzmAUU+upYnhsomP2N/ehl6JDhdQp+PxCm4uyH6dCj+S5+FC+XiKw8oXJZkCwEDfmK/293WgZZ5XdCVvH2mORPSHdtbUh08j82zYHOV22QfJlTgHLT4vq2xMdIKAAY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727261436; c=relaxed/simple; bh=1xrE7oPYDS4MhboW1kuohfb4WqAWO4oH65GMJ78QYJ4=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=e+yb22iSd8Q4R5UI8E9Dza7VHuBunFmfVe/0RZSXHqxOvnyxgKWLPWZdSqZoOpbj3cCsD9T1oV+0wHiACQjb0nXMCsviCQj1PGAmLc2j5pb+I5PVnnJjXVi6lxxErahaPWwUfh+l4bkHTp1zK6Cv204TPasj1UvnpQbdFGx10JQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DohFJUp2; 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="DohFJUp2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1D80CC4CEC3 for ; Wed, 25 Sep 2024 10:50:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727261435; bh=1xrE7oPYDS4MhboW1kuohfb4WqAWO4oH65GMJ78QYJ4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=DohFJUp2Bu980VBnP006/M+oApdDCTVOyEp6GYNwNctknGJfmwwZzROLy1Z8Frjd7 DvVsAEwJaYOd10fdOt27QmkMyPgvFXg3R5wz5AY+ItCHScvkwWppe7Esp+0iIu7Vl5 SSs8jcocJLSkn9o7CB2UwzygV6JKUrRjARZDglQ3OXx166606aAZN8fa1kg0u01mvf BDOP0hbhdMXdcANACYuTvI02sEWQ3TU5DZ+mi7Jb5iAZaowOH9HXZFv1Rzq0FC1+dx 5wYl05uXqN4iAXoC03U5do73tf1qjhmmdmJ/jvxMQM3jBD7AFKjrr/EKb23nMyanqQ boqUm7Xaq+axA== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 2/8] btrfs: use sector numbers as keys for the dirty extents xarray Date: Wed, 25 Sep 2024 11:50:24 +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 We are using the logical address ("bytenr") of an extent as the key for qgroup records in the dirty extents xarray. This is a problem because the xarrays use "unsigned long" for keys/indices, meaning that on a 32 bits platform any extent starting at or beyond 4G is truncated, which is a too low limitation as virtually everyone is using storage with more than 4G of space. This means a "bytenr" of 4G gets truncated to 0, and so does 8G and 16G for example, resulting in incorrect qgroup accounting. Fix this by using sector numbers as keys instead, that is, using keys that match the logical address right shifted by fs_info->sectorsize_bits, which is what we do for the fs_info->buffer_radix that tracks extent buffers (radix trees also use an "unsigned long" type for keys). This also makes the index space more dense which helps optimize the xarray (as mentioned at Documentation/core-api/xarray.rst). Fixes: 3cce39a8ca4e ("btrfs: qgroup: use xarray to track dirty extents in transaction") Signed-off-by: Filipe Manana --- fs/btrfs/delayed-ref.c | 13 ++++++++----- fs/btrfs/delayed-ref.h | 10 +++++++++- fs/btrfs/qgroup.c | 11 ++++++----- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index 32f719b9e661..f075ac11e51c 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -849,6 +849,7 @@ add_delayed_ref_head(struct btrfs_trans_handle *trans, struct btrfs_qgroup_extent_record *qrecord, int action, bool *qrecord_inserted_ret) { + struct btrfs_fs_info *fs_info = trans->fs_info; struct btrfs_delayed_ref_head *existing; struct btrfs_delayed_ref_root *delayed_refs; bool qrecord_inserted = false; @@ -859,11 +860,12 @@ add_delayed_ref_head(struct btrfs_trans_handle *trans, if (qrecord) { int ret; - ret = btrfs_qgroup_trace_extent_nolock(trans->fs_info, + ret = btrfs_qgroup_trace_extent_nolock(fs_info, delayed_refs, qrecord); if (ret) { /* Clean up if insertion fails or item exists. */ - xa_release(&delayed_refs->dirty_extents, qrecord->bytenr); + xa_release(&delayed_refs->dirty_extents, + qrecord->bytenr >> fs_info->sectorsize_bits); /* Caller responsible for freeing qrecord on error. */ if (ret < 0) return ERR_PTR(ret); @@ -873,7 +875,7 @@ add_delayed_ref_head(struct btrfs_trans_handle *trans, } } - trace_add_delayed_ref_head(trans->fs_info, head_ref, action); + trace_add_delayed_ref_head(fs_info, head_ref, action); existing = htree_insert(&delayed_refs->href_root, &head_ref->href_node); @@ -895,7 +897,7 @@ add_delayed_ref_head(struct btrfs_trans_handle *trans, if (head_ref->is_data && head_ref->ref_mod < 0) { delayed_refs->pending_csums += head_ref->num_bytes; trans->delayed_ref_csum_deletions += - btrfs_csum_bytes_to_leaves(trans->fs_info, + btrfs_csum_bytes_to_leaves(fs_info, head_ref->num_bytes); } delayed_refs->num_heads++; @@ -1030,7 +1032,8 @@ static int add_delayed_ref(struct btrfs_trans_handle *trans, goto free_head_ref; } if (xa_reserve(&trans->transaction->delayed_refs.dirty_extents, - generic_ref->bytenr, GFP_NOFS)) { + generic_ref->bytenr >> fs_info->sectorsize_bits, + GFP_NOFS)) { ret = -ENOMEM; goto free_record; } diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h index 085f30968aba..352921e76c74 100644 --- a/fs/btrfs/delayed-ref.h +++ b/fs/btrfs/delayed-ref.h @@ -202,7 +202,15 @@ struct btrfs_delayed_ref_root { /* head ref rbtree */ struct rb_root_cached href_root; - /* Track dirty extent records. */ + /* + * Track dirty extent records. + * 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. + */ struct xarray dirty_extents; /* this spin lock protects the rbtree and the entries inside */ diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index c297909f1506..a76e4610fe80 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -2005,7 +2005,7 @@ int btrfs_qgroup_trace_extent_nolock(struct btrfs_fs_info *fs_info, struct btrfs_qgroup_extent_record *record) { struct btrfs_qgroup_extent_record *existing, *ret; - unsigned long bytenr = record->bytenr; + const unsigned long index = (record->bytenr >> fs_info->sectorsize_bits); if (!btrfs_qgroup_full_accounting(fs_info)) return 1; @@ -2014,7 +2014,7 @@ int btrfs_qgroup_trace_extent_nolock(struct btrfs_fs_info *fs_info, trace_btrfs_qgroup_trace_extent(fs_info, record); xa_lock(&delayed_refs->dirty_extents); - existing = xa_load(&delayed_refs->dirty_extents, bytenr); + existing = xa_load(&delayed_refs->dirty_extents, index); if (existing) { if (record->data_rsv && !existing->data_rsv) { existing->data_rsv = record->data_rsv; @@ -2024,7 +2024,7 @@ int btrfs_qgroup_trace_extent_nolock(struct btrfs_fs_info *fs_info, return 1; } - ret = __xa_store(&delayed_refs->dirty_extents, record->bytenr, record, GFP_ATOMIC); + ret = __xa_store(&delayed_refs->dirty_extents, index, record, GFP_ATOMIC); xa_unlock(&delayed_refs->dirty_extents); if (xa_is_err(ret)) { qgroup_mark_inconsistent(fs_info); @@ -2129,6 +2129,7 @@ int btrfs_qgroup_trace_extent(struct btrfs_trans_handle *trans, u64 bytenr, struct btrfs_fs_info *fs_info = trans->fs_info; struct btrfs_qgroup_extent_record *record; struct btrfs_delayed_ref_root *delayed_refs; + const unsigned long index = (bytenr >> fs_info->sectorsize_bits); int ret; if (!btrfs_qgroup_full_accounting(fs_info) || bytenr == 0 || num_bytes == 0) @@ -2137,7 +2138,7 @@ int btrfs_qgroup_trace_extent(struct btrfs_trans_handle *trans, u64 bytenr, if (!record) return -ENOMEM; - if (xa_reserve(&trans->transaction->delayed_refs.dirty_extents, bytenr, GFP_NOFS)) { + if (xa_reserve(&trans->transaction->delayed_refs.dirty_extents, index, GFP_NOFS)) { kfree(record); return -ENOMEM; } @@ -2152,7 +2153,7 @@ int btrfs_qgroup_trace_extent(struct btrfs_trans_handle *trans, u64 bytenr, spin_unlock(&delayed_refs->lock); if (ret) { /* Clean up if insertion fails or item exists. */ - xa_release(&delayed_refs->dirty_extents, record->bytenr); + xa_release(&delayed_refs->dirty_extents, index); kfree(record); return 0; } From patchwork Wed Sep 25 10:50: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: 13811874 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 B5747188A01 for ; Wed, 25 Sep 2024 10:50: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=1727261436; cv=none; b=CwA2jqxdbgrNivPcsJ2R8rrjiwzG/hkiyfZtPJyXevRTTzIa3zWJEqMsDzYoky9jN9JlSidq7zTtDfSVYWCav1H8ZuBDpg4K9GAe7iNh1brqD2T5XGBxgnE4BMq6m/aM+VaN+QUeE+MtRgPOxqZYJ5Wdh9PQBabx9eRPrUQhZzI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727261436; c=relaxed/simple; bh=Ys1tQqvHmLxakzsIiAp3aWhuC3EjVvatzB5nxvJTTxM=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mTjpRX58pfAAxqQ+Y11CAg90AvOcF6BMTYFMxuoTynIgcBx7ofYjT9sKECJ0xkDIGB+IExBHLsh9ZSqmlcQXQk07xlvW3LqRHDWF46lxqhLA37QKOedlTls697TW38cg9M6IeGTPJ5TlLIvQsXJAgIg+aSNHYvvsmK8pl0mj4Zo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=N+K1QI3e; 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="N+K1QI3e" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 196ADC4CECE for ; Wed, 25 Sep 2024 10:50:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727261436; bh=Ys1tQqvHmLxakzsIiAp3aWhuC3EjVvatzB5nxvJTTxM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=N+K1QI3e7PmW3cUPevLjAY2cWlZ7L0xJusSS2stBfKTLbITlIy4UA7Nmm4FYznOkE uL6JTcq/xbXBdksFptkfjjH7j5KIsVionaL7FOGJX80IN1zyx0hVPlynDwe1hC+hvK pb8nV4gm9MlXxonz9vCkJcxndIlJ4fXWbq2eqRLEpBGcSOjB7jEAbqqb1eA2JsjRdb 7CtsfC/tOyvUOTdLm9t4q+0kv9JXfOiLTThSWmDYPr2/PyaOp8Enzv8G1xBgKOKsjW KJwD119j2RJzYunD0ppSoCQ18yjFqlurUPmtzz7pO2kEzPXB4WNVaZImMr7ZuEAcsK x72qeEj+540Ig== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 3/8] btrfs: end assignment with semicolon at btrfs_qgroup_extent event class Date: Wed, 25 Sep 2024 11:50:25 +0100 Message-Id: <124b1f06a8d12f0206fc38e398f707d43acf01b7.1727261112.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 While running checkpatch against against a patch that modifies the btrfs_qgroup_extent event class, it complained about using a comma instead of a semicolon: $ ./scripts/checkpatch.pl qgroups/0003-btrfs-qgroups-remove-bytenr-field-from-struct-btrfs_.patch WARNING: Possible comma where semicolon could be used #215: FILE: include/trace/events/btrfs.h:1720: + __entry->bytenr = bytenr, __entry->num_bytes = rec->num_bytes; total: 0 errors, 1 warnings, 184 lines checked So replace the comma with a semicolon to silence checkpatch and possibly other tools. It also makes the code consistent with the rest. Signed-off-by: Filipe Manana --- include/trace/events/btrfs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/trace/events/btrfs.h b/include/trace/events/btrfs.h index bf60ad50011e..af6b3827fb1d 100644 --- a/include/trace/events/btrfs.h +++ b/include/trace/events/btrfs.h @@ -1716,7 +1716,7 @@ DECLARE_EVENT_CLASS(btrfs_qgroup_extent, ), TP_fast_assign_btrfs(fs_info, - __entry->bytenr = rec->bytenr, + __entry->bytenr = rec->bytenr; __entry->num_bytes = rec->num_bytes; ), From patchwork Wed Sep 25 10:50: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: 13811875 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 F33AC188A01 for ; Wed, 25 Sep 2024 10:50: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=1727261438; cv=none; b=acTy804r5pjD6FjHOJicPcNAlOwyoUzY+ZGkgJtco/3G9r0sGb7SxPZdusA8aQGq2p+JX/IJAzYlN4XbxhUwtJLtmHW2XvWmsYdAvvbL27Ah9qi3pk+lqWgayJAKC2Wt4CIxziVh5s7+v1BdaPHzWg3rPl6p5Pp98yS/+uWjuJs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727261438; c=relaxed/simple; bh=rvWSUwEoWz/C7IqadlEhJnRkPXsQXf3Y+gu/k8AQSK4=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=X+qr3wHyP1UMwed6Iqs858CpnyfdXuRDShtLBNiIt5oKyTlZrzTsaIBapJvcvCLG07gaNeqJ9DSjEs2jCDJcvyRxYHP+cFEo56lvl9XtBMMGcS15k5YHoHmL/YZBxx+iRYZc35ijOUz+c5eY0O3yg+4csb53UZ8+zd6SLEvzRJs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lRHgC37j; 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="lRHgC37j" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1472CC4CECD for ; Wed, 25 Sep 2024 10:50:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727261437; bh=rvWSUwEoWz/C7IqadlEhJnRkPXsQXf3Y+gu/k8AQSK4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=lRHgC37jY047rsU7hAMER5LAv8wGPn7DJs5IIj+tiP+B8+JublCLU3VoJeQLNXVcN jErTYtKdxPuU4ZbA4Y1+C2g+9Vesj6KHdHRtmavJf0KlvRXwNytQ2Nvcq8Y3rEyQA0 yayRv0Xrr1eMoM6/fs3JgIeFg7jJyzXZYgSwwzBpevtUEo0DCUF1/OMqe4drnnRTC2 I6smbSd7ORlL/+gx0uvHVElY29M6rv+kbRTYxa+gipRCE2lhpX7VlA4QDEAAkny6LN /qvnJpFa8quzqQyTojMos23GLfmzGErZ/GlvJEdfkPZUj9ax4kKth+rr/6bE3+8YQX K4T3ull/m5eWg== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 4/8] btrfs: qgroups: remove bytenr field from struct btrfs_qgroup_extent_record Date: Wed, 25 Sep 2024 11:50: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 Now that we track qgroup extent records in a xarray we don't need to have a "bytenr" field in struct btrfs_qgroup_extent_record, since we can get it from the index of the record in the xarray. So remove the field and grab the bytenr from either the index key or any other place where it's available (delayed refs). This reduces the size of struct btrfs_qgroup_extent_record from 40 bytes down to 32 bytes, meaning that we now can store 128 instances of this structure instead of 102 per 4K page. Signed-off-by: Filipe Manana --- fs/btrfs/delayed-ref.c | 8 ++++---- fs/btrfs/qgroup.c | 27 +++++++++++++++------------ fs/btrfs/qgroup.h | 13 ++++++++++--- include/trace/events/btrfs.h | 17 ++++++++++------- 4 files changed, 39 insertions(+), 26 deletions(-) diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index f075ac11e51c..388d4ed1938e 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -830,7 +830,6 @@ static void init_delayed_ref_head(struct btrfs_delayed_ref_head *head_ref, qrecord->data_rsv = reserved; qrecord->data_rsv_refroot = generic_ref->ref_root; } - qrecord->bytenr = generic_ref->bytenr; qrecord->num_bytes = generic_ref->num_bytes; qrecord->old_roots = NULL; } @@ -861,11 +860,12 @@ add_delayed_ref_head(struct btrfs_trans_handle *trans, int ret; ret = btrfs_qgroup_trace_extent_nolock(fs_info, - delayed_refs, qrecord); + delayed_refs, qrecord, + head_ref->bytenr); if (ret) { /* Clean up if insertion fails or item exists. */ xa_release(&delayed_refs->dirty_extents, - qrecord->bytenr >> fs_info->sectorsize_bits); + head_ref->bytenr >> fs_info->sectorsize_bits); /* Caller responsible for freeing qrecord on error. */ if (ret < 0) return ERR_PTR(ret); @@ -1076,7 +1076,7 @@ static int add_delayed_ref(struct btrfs_trans_handle *trans, kmem_cache_free(btrfs_delayed_ref_node_cachep, node); if (qrecord_inserted) - return btrfs_qgroup_trace_extent_post(trans, record); + return btrfs_qgroup_trace_extent_post(trans, record, head_ref->bytenr); return 0; free_record: diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index a76e4610fe80..4eaeea5f2241 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -2001,17 +2001,18 @@ int btrfs_limit_qgroup(struct btrfs_trans_handle *trans, u64 qgroupid, * Return <0 for insertion failure, caller can free @record safely. */ int btrfs_qgroup_trace_extent_nolock(struct btrfs_fs_info *fs_info, - struct btrfs_delayed_ref_root *delayed_refs, - struct btrfs_qgroup_extent_record *record) + struct btrfs_delayed_ref_root *delayed_refs, + struct btrfs_qgroup_extent_record *record, + u64 bytenr) { struct btrfs_qgroup_extent_record *existing, *ret; - const unsigned long index = (record->bytenr >> fs_info->sectorsize_bits); + const unsigned long index = (bytenr >> fs_info->sectorsize_bits); if (!btrfs_qgroup_full_accounting(fs_info)) return 1; lockdep_assert_held(&delayed_refs->lock); - trace_btrfs_qgroup_trace_extent(fs_info, record); + trace_btrfs_qgroup_trace_extent(fs_info, record, bytenr); xa_lock(&delayed_refs->dirty_extents); existing = xa_load(&delayed_refs->dirty_extents, index); @@ -2056,7 +2057,8 @@ int btrfs_qgroup_trace_extent_nolock(struct btrfs_fs_info *fs_info, * transaction committing, but not now as qgroup accounting will be wrong again. */ int btrfs_qgroup_trace_extent_post(struct btrfs_trans_handle *trans, - struct btrfs_qgroup_extent_record *qrecord) + struct btrfs_qgroup_extent_record *qrecord, + u64 bytenr) { struct btrfs_backref_walk_ctx ctx = { 0 }; int ret; @@ -2087,7 +2089,7 @@ int btrfs_qgroup_trace_extent_post(struct btrfs_trans_handle *trans, if (trans->fs_info->qgroup_flags & BTRFS_QGROUP_RUNTIME_FLAG_NO_ACCOUNTING) return 0; - ctx.bytenr = qrecord->bytenr; + ctx.bytenr = bytenr; ctx.fs_info = trans->fs_info; ret = btrfs_find_all_roots(&ctx, true); @@ -2144,12 +2146,11 @@ int btrfs_qgroup_trace_extent(struct btrfs_trans_handle *trans, u64 bytenr, } delayed_refs = &trans->transaction->delayed_refs; - record->bytenr = bytenr; record->num_bytes = num_bytes; record->old_roots = NULL; spin_lock(&delayed_refs->lock); - ret = btrfs_qgroup_trace_extent_nolock(fs_info, delayed_refs, record); + ret = btrfs_qgroup_trace_extent_nolock(fs_info, delayed_refs, record, bytenr); spin_unlock(&delayed_refs->lock); if (ret) { /* Clean up if insertion fails or item exists. */ @@ -2157,7 +2158,7 @@ int btrfs_qgroup_trace_extent(struct btrfs_trans_handle *trans, u64 bytenr, kfree(record); return 0; } - return btrfs_qgroup_trace_extent_post(trans, record); + return btrfs_qgroup_trace_extent_post(trans, record, bytenr); } /* @@ -3033,14 +3034,16 @@ int btrfs_qgroup_account_extents(struct btrfs_trans_handle *trans) delayed_refs = &trans->transaction->delayed_refs; qgroup_to_skip = delayed_refs->qgroup_to_skip; xa_for_each(&delayed_refs->dirty_extents, index, record) { + const u64 bytenr = (index << fs_info->sectorsize_bits); + num_dirty_extents++; - trace_btrfs_qgroup_account_extents(fs_info, record); + trace_btrfs_qgroup_account_extents(fs_info, record, bytenr); if (!ret && !(fs_info->qgroup_flags & BTRFS_QGROUP_RUNTIME_FLAG_NO_ACCOUNTING)) { struct btrfs_backref_walk_ctx ctx = { 0 }; - ctx.bytenr = record->bytenr; + ctx.bytenr = bytenr; ctx.fs_info = fs_info; /* @@ -3082,7 +3085,7 @@ int btrfs_qgroup_account_extents(struct btrfs_trans_handle *trans) ulist_del(record->old_roots, qgroup_to_skip, 0); } - ret = btrfs_qgroup_account_extent(trans, record->bytenr, + ret = btrfs_qgroup_account_extent(trans, bytenr, record->num_bytes, record->old_roots, new_roots); diff --git a/fs/btrfs/qgroup.h b/fs/btrfs/qgroup.h index 98adf4ec7b01..836e9f59ec84 100644 --- a/fs/btrfs/qgroup.h +++ b/fs/btrfs/qgroup.h @@ -125,7 +125,12 @@ struct btrfs_inode; * Record a dirty extent, and info qgroup to update quota on it */ struct btrfs_qgroup_extent_record { - u64 bytenr; + /* + * The bytenr of the extent is given by its index in the dirty_extents + * xarray of struct btrfs_delayed_ref_root left shifted by + * fs_info->sectorsize_bits. + */ + u64 num_bytes; /* @@ -343,9 +348,11 @@ void btrfs_free_qgroup_config(struct btrfs_fs_info *fs_info); int btrfs_qgroup_trace_extent_nolock( struct btrfs_fs_info *fs_info, struct btrfs_delayed_ref_root *delayed_refs, - struct btrfs_qgroup_extent_record *record); + struct btrfs_qgroup_extent_record *record, + u64 bytenr); int btrfs_qgroup_trace_extent_post(struct btrfs_trans_handle *trans, - struct btrfs_qgroup_extent_record *qrecord); + struct btrfs_qgroup_extent_record *qrecord, + u64 bytenr); int btrfs_qgroup_trace_extent(struct btrfs_trans_handle *trans, u64 bytenr, u64 num_bytes); int btrfs_qgroup_trace_leaf_items(struct btrfs_trans_handle *trans, diff --git a/include/trace/events/btrfs.h b/include/trace/events/btrfs.h index af6b3827fb1d..8d2ff32fb3b0 100644 --- a/include/trace/events/btrfs.h +++ b/include/trace/events/btrfs.h @@ -1706,9 +1706,10 @@ DEFINE_EVENT(btrfs__qgroup_rsv_data, btrfs_qgroup_release_data, DECLARE_EVENT_CLASS(btrfs_qgroup_extent, TP_PROTO(const struct btrfs_fs_info *fs_info, - const struct btrfs_qgroup_extent_record *rec), + const struct btrfs_qgroup_extent_record *rec, + u64 bytenr), - TP_ARGS(fs_info, rec), + TP_ARGS(fs_info, rec, bytenr), TP_STRUCT__entry_btrfs( __field( u64, bytenr ) @@ -1716,7 +1717,7 @@ DECLARE_EVENT_CLASS(btrfs_qgroup_extent, ), TP_fast_assign_btrfs(fs_info, - __entry->bytenr = rec->bytenr; + __entry->bytenr = bytenr; __entry->num_bytes = rec->num_bytes; ), @@ -1727,17 +1728,19 @@ DECLARE_EVENT_CLASS(btrfs_qgroup_extent, DEFINE_EVENT(btrfs_qgroup_extent, btrfs_qgroup_account_extents, TP_PROTO(const struct btrfs_fs_info *fs_info, - const struct btrfs_qgroup_extent_record *rec), + const struct btrfs_qgroup_extent_record *rec, + u64 bytenr), - TP_ARGS(fs_info, rec) + TP_ARGS(fs_info, rec, bytenr) ); DEFINE_EVENT(btrfs_qgroup_extent, btrfs_qgroup_trace_extent, TP_PROTO(const struct btrfs_fs_info *fs_info, - const struct btrfs_qgroup_extent_record *rec), + const struct btrfs_qgroup_extent_record *rec, + u64 bytenr), - TP_ARGS(fs_info, rec) + TP_ARGS(fs_info, rec, bytenr) ); TRACE_EVENT(qgroup_num_dirty_extents, From patchwork Wed Sep 25 10:50:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13811876 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 0D4C8189BA0 for ; Wed, 25 Sep 2024 10:50: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=1727261439; cv=none; b=P4YWOXk/u8B72vFtFPkZa1d54WnydDF3W7e5fUb6NY3gWZ1U32uSc1xTrZ7TQ0uKqVRVcEECMPN9SaZiYP9odeEu3APLmiaSsZnxnTOmxA6pAI1Xv3oI8W7vyxC/+7goK+9SKRFe3hBSBqKrlmm4t0QmPAht5WA3XeO7bMEA5ls= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727261439; c=relaxed/simple; bh=PE5610vDFykwGSsOuVMsKT7kF0OwoCdMroW536x3e9Y=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ixxmw3x5ADqb2K7LiXAWp9DLb7qTQu1s5/BA+9EcJyv2+jrjq4+usuyM3Zbt5rffeRDVd05szzap94b9IyEJyE5SfGEmha87RIy0wc2kVqx+U118fnZM3uLf4rPvkZGXw00uFQjlv6e4v6mvgey0lEjP591sFkgvrln+0l5Jhl4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IQwBKJM3; 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="IQwBKJM3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 10C6BC4CEC7 for ; Wed, 25 Sep 2024 10:50:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727261438; bh=PE5610vDFykwGSsOuVMsKT7kF0OwoCdMroW536x3e9Y=; h=From:To:Subject:Date:In-Reply-To:References:From; b=IQwBKJM3Hn6E4iQY44ogAYZLKzlZuclLjO0qKeCrXwR0lh9XHBS+cEg9ATVyTyijt gU8KKSP/giV74zDzpHIqlwQpHmGUcUuukiuKWcyGVOkA2r9JV40aMzkMOtw4IC0DJx HiSBtlMe2dcaaHxRk5yeTCIdum/Es/F7zSV/DjJti3vY2nZtqiv/wlvSDxtovW89Wi p6GHz6lN5PO3Nc80K7wgCEZFWAm9lpbSapr+rbPik7BM1hZo8nHka4bx4x21GCl3Is iqAlG9Kn25DGhgTzq9ug3sVkTqGCcJCm7zQZaAXHhRH3VGDaAkqEHKkOBOVRM2qBuh dITaGN9yIXe/A== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 5/8] btrfs: store fs_info in a local variable at btrfs_qgroup_trace_extent_post() Date: Wed, 25 Sep 2024 11:50:27 +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 extracting fs_info from the transaction multiples times, store it in a local variable and use it. Signed-off-by: Filipe Manana --- fs/btrfs/qgroup.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index 4eaeea5f2241..8f9f2828c46e 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -2060,10 +2060,14 @@ int btrfs_qgroup_trace_extent_post(struct btrfs_trans_handle *trans, struct btrfs_qgroup_extent_record *qrecord, u64 bytenr) { - struct btrfs_backref_walk_ctx ctx = { 0 }; + struct btrfs_fs_info *fs_info = trans->fs_info; + struct btrfs_backref_walk_ctx ctx = { + .bytenr = bytenr, + .fs_info = fs_info, + }; int ret; - if (!btrfs_qgroup_full_accounting(trans->fs_info)) + if (!btrfs_qgroup_full_accounting(fs_info)) return 0; /* * We are always called in a context where we are already holding a @@ -2086,16 +2090,13 @@ int btrfs_qgroup_trace_extent_post(struct btrfs_trans_handle *trans, */ ASSERT(trans != NULL); - if (trans->fs_info->qgroup_flags & BTRFS_QGROUP_RUNTIME_FLAG_NO_ACCOUNTING) + if (fs_info->qgroup_flags & BTRFS_QGROUP_RUNTIME_FLAG_NO_ACCOUNTING) return 0; - ctx.bytenr = bytenr; - ctx.fs_info = trans->fs_info; - ret = btrfs_find_all_roots(&ctx, true); if (ret < 0) { - qgroup_mark_inconsistent(trans->fs_info); - btrfs_warn(trans->fs_info, + qgroup_mark_inconsistent(fs_info); + btrfs_warn(fs_info, "error accounting new delayed refs extent (err code: %d), quota inconsistent", ret); return 0; From patchwork Wed Sep 25 10:50:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13811877 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 EE681189BB8 for ; Wed, 25 Sep 2024 10:50: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=1727261440; cv=none; b=pU7EUPuap+93M4tKvgP1D2RIB3Nm9eFcs+T0kfj8daTf0y5TftSRo9uz1OTVAhMgX/Kx+poTNSLJqXBVWxF8c/YwmGmOO7xsyRQmCokybDSuQAPogbJTtfZQQgh8sa+85L+A+wtd0p6cRCnIfk9j3z0rrvuUuVDh36IQwarUSR8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727261440; c=relaxed/simple; bh=a0IzNfJLwvrrJbWwwr0HKKOw0RcoZpaH3EShlTJt7Yo=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=piIDGo9r3zo2w5Su+imts15r0e/j4aG0FofJsY/sEY+w9nN9GVhdgT9n5PAF1qvqeQSRnMB6TTKE6YzOupNtFPWYj29+fUfAJdfvRcIpcFy1PCh8SZbEkSej9ds86jHaWpkWhX1fO+aphOmM1zaHnhuzDGBf+0QstkzZ7X7qyDE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qT76ybj7; 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="qT76ybj7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0BB85C4CECD for ; Wed, 25 Sep 2024 10:50:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727261439; bh=a0IzNfJLwvrrJbWwwr0HKKOw0RcoZpaH3EShlTJt7Yo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=qT76ybj77XPc4J2vKu05xZKd2cAP0HXtUZsKKYdeiduU/FWKnKzf+sGV/Ml3k5nk3 r5FVPvkLCUmZwEhgiDn/KR8F2p7e86Od8xfW6Bqs/dMhrPE3ULIk3Rdt/Fy3iYH3TC 6iurb63cNXsN1MrTqHxBORgyG0vJXl1DE5OToQXrSJ/7XFEvXWybNevDoXngUBcdDi wxrnYvyTDIwOS41EsK5nyqkXdM437u9sq167C9AQaJsWe2F1IT1iGc/Y7xy17emr7N +RCld6Du+Q2m5sC8x/Hn55TwTWZ9L1OOnvcA/8se1OsEy6PWR4gq+SbfSvW4Kg0HcR G/8ytuqVC0e/w== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 6/8] btrfs: remove unnecessary delayed refs locking at btrfs_qgroup_trace_extent() Date: Wed, 25 Sep 2024 11:50:28 +0100 Message-Id: <9805b109b83260a62df501650d6a37b6576f46bb.1727261112.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 There's no need to hold the delayed refs spinlock when calling btrfs_qgroup_trace_extent_nolock() from btrfs_qgroup_trace_extent(), since it doesn't change anything in delayed refs and it only changes the xarray used to track qgroup extent records, which is protected by the xarray's lock. Holding the lock is only adding unnecessary lock contention with other tasks that actually need to take the lock to add/remove/change delayed references. So remove the locking. Signed-off-by: Filipe Manana --- fs/btrfs/qgroup.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index 8f9f2828c46e..c847b3223e7f 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -2011,7 +2011,6 @@ int btrfs_qgroup_trace_extent_nolock(struct btrfs_fs_info *fs_info, if (!btrfs_qgroup_full_accounting(fs_info)) return 1; - lockdep_assert_held(&delayed_refs->lock); trace_btrfs_qgroup_trace_extent(fs_info, record, bytenr); xa_lock(&delayed_refs->dirty_extents); @@ -2150,9 +2149,7 @@ int btrfs_qgroup_trace_extent(struct btrfs_trans_handle *trans, u64 bytenr, record->num_bytes = num_bytes; record->old_roots = NULL; - spin_lock(&delayed_refs->lock); ret = btrfs_qgroup_trace_extent_nolock(fs_info, delayed_refs, record, bytenr); - spin_unlock(&delayed_refs->lock); if (ret) { /* Clean up if insertion fails or item exists. */ xa_release(&delayed_refs->dirty_extents, index); From patchwork Wed Sep 25 10:50:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13811878 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 1A0B015C136 for ; Wed, 25 Sep 2024 10:50: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=1727261441; cv=none; b=j8js6xqSxkuEk8a0pU+k7PmNcvT6LLUqyOqodiF3/NVvWPQ7aQUc2PLTPUSa+YE10zb536HGQvnMGSwsmkZkr4sTQohVMcZF9O2F4kUTQKEk025CsF/9u3/KtHXVZHAQt6lXiLoqVu6kfr8Cj8iTLjhetEdI/Vd9mJxUzLCE27Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727261441; c=relaxed/simple; bh=SNRkobYYDFwF59NZNWk1eSJhH+nLW/FMHtpQrZVTDQk=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kl/Y6Mk/pmK82skrMv2ZRsu+BZnzaUUv53kGVskm6yvc+gKnfPST6vz9oCZ1pOClExkiQxRbY79UrIlTnC9ubYS3qAmm8V9+eqSGMRog/1eYXkMJKqmrjKQsL3HqQJ0C7gwiKw9h6npd3w6kAYlYR8gkWB+1k/nv1+BxEOjRsRY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RoOBJkim; 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="RoOBJkim" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0736AC4CEC3 for ; Wed, 25 Sep 2024 10:50:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727261440; bh=SNRkobYYDFwF59NZNWk1eSJhH+nLW/FMHtpQrZVTDQk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=RoOBJkimtL9qsXFeM8gqGZb+9jQuDgyM3G6jSlJrHzVaV1pc/kPFHp42L0mRxH6OB ZQ+05XFFhqdUC5ug8yCXVfNu9FIDRlMyBA3X5906EgnJg+JvewCWIZvXbuY16/shsa qA9dnRyYUXnU7F5zeQAYqma0fUqpNwl5yQkH3UYihVuDrT7iA2hrZiV5I7nrDm6eU3 TmFE3XJcs6ACpR1TgbGHZnnizvCbASLG2gcLHET5jAD2i6VlO7puGLEAzUJia3UWS9 zTQVYSspkQYnSkoFC2Rh74jQqUtIaeM2gcYkpZSQaveprjpSeNVMobkNyfLmr/NsOs ZGoLY5Rpce4zg== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 7/8] btrfs: always use delayed_refs local variable at btrfs_qgroup_trace_extent() Date: Wed, 25 Sep 2024 11:50:29 +0100 Message-Id: <85c1544f70dc783d68353cc83697ef432facf6c2.1727261112.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 Instead of dereferecing the delayed refs from the transaction multiple times, store it early in the local variable and then always use the variable. Signed-off-by: Filipe Manana --- fs/btrfs/qgroup.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index c847b3223e7f..ce7641fdc900 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -2130,7 +2130,7 @@ int btrfs_qgroup_trace_extent(struct btrfs_trans_handle *trans, u64 bytenr, { struct btrfs_fs_info *fs_info = trans->fs_info; struct btrfs_qgroup_extent_record *record; - struct btrfs_delayed_ref_root *delayed_refs; + struct btrfs_delayed_ref_root *delayed_refs = &trans->transaction->delayed_refs; const unsigned long index = (bytenr >> fs_info->sectorsize_bits); int ret; @@ -2140,12 +2140,11 @@ int btrfs_qgroup_trace_extent(struct btrfs_trans_handle *trans, u64 bytenr, if (!record) return -ENOMEM; - if (xa_reserve(&trans->transaction->delayed_refs.dirty_extents, index, GFP_NOFS)) { + if (xa_reserve(&delayed_refs->dirty_extents, index, GFP_NOFS)) { kfree(record); return -ENOMEM; } - delayed_refs = &trans->transaction->delayed_refs; record->num_bytes = num_bytes; record->old_roots = NULL; From patchwork Wed Sep 25 10:50:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13811879 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 D93A2189F52 for ; Wed, 25 Sep 2024 10:50: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=1727261441; cv=none; b=p8LsUDdOBREXdvYIAteCjGBBDSl97+9d77n8d0r50neY2BKT/YlJOXXtCPWB+fTtZKJyqWueFs4tPL8d+CBiDTeRzDb82M/I6d/qq3dxoeb7Q2JguoqZHbOptjBOZSHEi1AV5Wh9KVfvEPx3Xp248nw0pxVEKSafgCgPRbF8Wxw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727261441; c=relaxed/simple; bh=AMjAsloxBtPntjh6SXe+5cJD1nh8j5fiexMLdhBZMPY=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iycrvCjfeHsldP8VtLnuthFfcq8tEGvF4wTe7kD0oWHopofqapc+ggQ8YCtRx4WIt8G1XUkP4v+xDdOrdqoHYhUHunUO71ssC6eo4J6V6V2u4n6ef7TJTZUZJuRjV4KuR4H2vfgQNlysLv66zV8F9MzNkGLQuoq/Q2/lWXPGU4w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WShXoe8v; 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="WShXoe8v" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 00EBCC4CECE for ; Wed, 25 Sep 2024 10:50:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727261441; bh=AMjAsloxBtPntjh6SXe+5cJD1nh8j5fiexMLdhBZMPY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=WShXoe8vlUjp8ipVsqPyneEPqtZzbcDUg/MaR3c4yL62sOUiX37uG2cDRmhjo5NJV O7O5zK2NG+E5gM2nJSO/vNHnaMATlN8tBNWm+GvXPFPoPZHk3dpKmFNPQcwMZlEzSq mnZK6c5wQPbOD6Y2j0snAG1MCNJE9jz8wD9ksftbX0w1r9VNnVkVXXzOLWtWOTMzVZ drJaTWTdXw6OXjst7Nx67reODFnpqTnNpBOgr3XtLszLqEmgB6zyaAOQ92GdQfodvU tKA7UAiS3VgV5UrPe5+ddS6e9juS3Pgsb1FwD7FZGxNccYHOGrLLfaoEWmKV+3C91R OoZ4o++ZY8WGA== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 8/8] btrfs: remove pointless initialization at btrfs_qgroup_trace_extent() Date: Wed, 25 Sep 2024 11:50:30 +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 qgroup record was allocated with kzalloc(), so it's pointless to set its old_roots member to NULL. Remove the assignment. Signed-off-by: Filipe Manana --- fs/btrfs/qgroup.c | 1 - 1 file changed, 1 deletion(-) diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index ce7641fdc900..9e10c1190df9 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -2146,7 +2146,6 @@ int btrfs_qgroup_trace_extent(struct btrfs_trans_handle *trans, u64 bytenr, } record->num_bytes = num_bytes; - record->old_roots = NULL; ret = btrfs_qgroup_trace_extent_nolock(fs_info, delayed_refs, record, bytenr); if (ret) {