From patchwork Thu Sep 26 09:33: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: 13813119 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 C73F61AC8A8 for ; Thu, 26 Sep 2024 09:33:26 +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=1727343206; cv=none; b=rc13c34VC8IEu2V20DA/ePg5yWt2fchuXWkiZGvsPbtW2CTpwKn4Ucupmrd2tdreJCxxRsbenD1fgqhjJS7dLRPZcI4y6iSC61G3NidqAoc/HR8P5FeEHv3SqeqF5OfXHNLijWiUqBNJKDdd2AgFvDo7gKsxGwGB/TC6v5FHzUk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727343206; c=relaxed/simple; bh=i9LAUyxUoA3OaQjX49pEGHwxBjafYA88ls6ZvpUwszU=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iEZyEaFuxZdATAxZv/gb9sWaE/v5GyRUF09dc+67xsx/nvvfra8M4y/yzRpggVue4nHHsgkTm5mNFnTQaRjY2YfDbmJ2gj2Bg6z+pNkitW6l1x3cUYdwU0imYuOBxfkENVgDPSJtzhAE+O0e5OoAYFfFB4/VIVE1a3y0wMtf988= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ooYOgNrS; 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="ooYOgNrS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C60C5C4CECD for ; Thu, 26 Sep 2024 09:33:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727343206; bh=i9LAUyxUoA3OaQjX49pEGHwxBjafYA88ls6ZvpUwszU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ooYOgNrSpEMSXUPmovTks0C2wRnQnvq3EOmbvaHa/KRJham9mwiOMGF8iFTUnBxDI ufdLkbSAsWn3P+FwB/GzCjwniVpvo3eCc2jvJJha7qTKrk0pDRTMKmjhXet2XlbrWr V+57aLv2cEsIiydlfOAY+/KVyjz3kPKuWX/OdxQgNhiJ/4GCu2ZytYZOH6pEdZ2Mru gmnsB4c0iUxeCTTgFzOi400HJPR57QBR4P09b+tJsgdDh4WvSEFNx7lUXxecLU1VGg LddUDeijPlrv5FyqASCLpR8Fa9vya4uO2KSPZw8x1BgMTkmg7KMsCpyyVAIyc9C3pc PtGgYZFZo3slw== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH v2 1/8] btrfs: fix missing error handling when adding delayed ref with qgroups enabled Date: Thu, 26 Sep 2024 10:33:15 +0100 Message-Id: <7e4b248dad75a0f0dd3a41b4a3af138a418b05d8.1727342969.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 Thu Sep 26 09:33: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: 13813120 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 8AACE1AC432 for ; Thu, 26 Sep 2024 09:33:27 +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=1727343207; cv=none; b=L+hVHAHgYZu9obXWUS5EIUDYlI2U0Z8BzYow1cmqky3QxOtKJ3xGyZadMZlgp6+oKrb6QAH/9DhlLM2UMjwjIxNEnXEj++Me9yz4tGQJl+ktvr7Jvu1mLnFO2ZHNqpktmDz4sHO/YAFHWFHNragDuJm16I2HlWy7KtA6RbIT5Ts= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727343207; c=relaxed/simple; bh=kJyzxzcIXzlN04316pS3P8jjVJBgxAS+ro6+UtPVnxw=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bPvqn12259A6vKmd3Kzd1PT48rZaM7vkqK04V827phtW1xYYhV2jqVOC8FBwP8IuAuvN/l9EmVDXWUk2BoPwHo0Wo7Ksk48DsWXQ5NGAB7ZbN3SETz/czuHB4iJUAIWoIdHBcb5iiHAw4n4FtjQmrv1yuzfgMqk1JHCpf5zSC1E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Nr8fk+aT; 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="Nr8fk+aT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CEA8FC4CEC9 for ; Thu, 26 Sep 2024 09:33:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727343207; bh=kJyzxzcIXzlN04316pS3P8jjVJBgxAS+ro6+UtPVnxw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Nr8fk+aTCgmCoFMtc24wg9L2jG09iRiyrZ162VSURX/CtiPxA5iPqA1OEDfJXw5rT 17TTAb5UmSw3IAN5Rm0Q0ljNeFNR4y4wtq2j9HaKgvU9w4Gcm1Y1ZBP8UM/9JSAonB sA+DJLmCvxOyQe3BV+Yw8n4gebVpBGiuZ1DIxSdn6SUfEeTWSGJlJ0gtkJw11dkxIv 96/IaxNC1a4Q5J1epHL1d+lRCAaLaqXftEKpfbmm4LEtvKg0V7IZfgqQeuo7qSOAuO EfaHLl8wWosM0puqWoONj22+Ppo9okufXn8AnyJUAh5HxV/SeDgn4WUYP8Gpc0t6/z 2sIVdgPDDUU6g== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH v2 2/8] btrfs: use sector numbers as keys for the dirty extents xarray Date: Thu, 26 Sep 2024 10:33:16 +0100 Message-Id: <8c86bd27dfe0be1750d9c44ade5d3c87cf17a1d8.1727342969.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 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 | 21 ++++++++++++++++----- 3 files changed, 33 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..152a43ae62c4 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -2005,16 +2005,26 @@ 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; +#if BITS_PER_LONG == 32 + if (bytenr >= MAX_LFS_FILESIZE) { + btrfs_err_rl(fs_info, +"qgroup record for extent at %llu is beyond 32bit page cache and xarray index limit", + bytenr); + btrfs_err_32bit_limit(fs_info); + return -EOVERFLOW; + } +#endif + lockdep_assert_held(&delayed_refs->lock); 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 +2034,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 +2139,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 +2148,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 +2163,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 Thu Sep 26 09:33: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: 13813121 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 D94541AC432 for ; Thu, 26 Sep 2024 09:33:28 +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=1727343208; cv=none; b=BEG34sz/lcSIPiTDXmkfIH0twZPw5HlZzARJUsO6Js4f8zt2idiFlIeSCnGwYLNcwvWAISW2Z6qdEi6V2ulhqoQNmoZmG6DCqz0Zlvrc4ALPVNm8+K5AjtIVffsRoMS4fTcNx06lZGRyOk4R7SQvRnmI2+OAzyviIy85JQ6kFBY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727343208; c=relaxed/simple; bh=xe0CaZGexeg+F1ShuXAjjpGJqRApENXWnCEFmZ7ALOE=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SDYg1a4xxEpO7af8q3OAKYuqlgsX54JR9hz0AfjO9QnQQZ/IBOt3AuLiBP8ZNDEMTWzwXRslz1stn6UttRnZwV4L1PPSVVL3WuDrWBGKM9qiy6Tombb9yvYmEvZ9eBr+ugxjKOYUPFTv3F4ofxotNzjOh7MysHYvL7hveHdyEM0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qyufy7kR; 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="qyufy7kR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6690C4CECD for ; Thu, 26 Sep 2024 09:33:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727343208; bh=xe0CaZGexeg+F1ShuXAjjpGJqRApENXWnCEFmZ7ALOE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=qyufy7kR79RLqgH4qp34h4mDAh+UWTg7ePyK5D5sZUHvPpu3dUQb/6PbmGcStwMbs 8acXVHFa1od/g5XWTo4f0Vo4fkF0AatgCZGw+pF3uiIMOOaSch6YKtSRDsybnIdW8e Q+v5WMqqtzxx9HCIW8v0H/fQf5AJpnc2xhO89oHYAA8ETy3XogTSn7uv2tfphBEDpg xkwcAD2fCHFu6FYpyn2VnAG/H2J3FDmA0AfPdnXMml/B4jhM5vInyAAgANK95BFOnp SYIDay0MMaoZs4Il2rUKFI/gJzxDwMqkvUigDL/njr176aaOZjIbkrjuIMugb2VhlD ExXKr38OWZJkQ== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH v2 3/8] btrfs: end assignment with semicolon at btrfs_qgroup_extent event class Date: Thu, 26 Sep 2024 10:33:17 +0100 Message-Id: <2fa0c4f84a98eafe62a13ca552d7810f86fc57dc.1727342969.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 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 Thu Sep 26 09:33: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: 13813122 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 98C441ACDF9 for ; Thu, 26 Sep 2024 09:33:29 +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=1727343209; cv=none; b=HVHDkdlXrSEDgLqJ70LtqcLvsbDoU7HhttO3xLV+Sd3WOlFJV9P1wgqdB9TueMDAJVS17iOBvsHeY+2jj/V8agliF8VoASSVaH1ogq9rgrzDmby8YmoOpaSoR2Ay0S3lwJ6vtTc3nL6lk0GunWczpIEKWN4Lf9nSnyUkkkHbDBk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727343209; c=relaxed/simple; bh=rE40N36gYUokkR1pfL+jdPwYoQs7o+p6+cO2cT4aM40=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CI7Sn/zJW0YaddY0wkBXRMcIW3wblV7CP8gPog3EQRWbMy0pM0TOFkl/b+3D6CeuC40Qyy9rCI1BKrB//kMA4EkXxVSKVcLu8rNN+pogtMFPBsvV2I5QQRTNT9Y+VEg9zmcFMP4kfm+B8i0HASkwAi12znZhfDmBTiPf7Soc4mI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Lbnomrlr; 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="Lbnomrlr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DEE7CC4CEC5 for ; Thu, 26 Sep 2024 09:33:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727343209; bh=rE40N36gYUokkR1pfL+jdPwYoQs7o+p6+cO2cT4aM40=; h=From:To:Subject:Date:In-Reply-To:References:From; b=LbnomrlrFNj1YghHVK5f/gHRW8V939d2gxizULtE2HNya9F09cBydzR4R2AwWoWwY JQ4JkNLceOaUexyVhjCt48h0AoUvb27UUsxPgwr0WxbFa2s7lkMT9BqhQheNPPR9NA I9QaRwuPVGsNipo+lk/2qp7EIXU/8Ncs4xkWOfyZB5mnSu5N0+/PNtRva6LRjxh3oU uIgZ+z+61BcfMfJyM0zF7+tN5ZqvadIpEqfZcMnPhgszRicrQcD2XhgLe1XNnjIGJF hhwFHdAAyPkFJam3oqbRsSoETrKNlIDKlJ2iq3bGlRFt85EZ1fA542q543pIm6junQ oHA/Tk0Vq+o2Q== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH v2 4/8] btrfs: qgroups: remove bytenr field from struct btrfs_qgroup_extent_record Date: Thu, 26 Sep 2024 10:33:18 +0100 Message-Id: <2167c3e6782da893f558c594b2e81354f712594c.1727342969.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 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 152a43ae62c4..722edb04b78f 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -2001,11 +2001,12 @@ 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; @@ -2021,7 +2022,7 @@ int btrfs_qgroup_trace_extent_nolock(struct btrfs_fs_info *fs_info, #endif 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); @@ -2066,7 +2067,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; @@ -2097,7 +2099,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); @@ -2154,12 +2156,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. */ @@ -2167,7 +2168,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); } /* @@ -3043,14 +3044,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; /* @@ -3092,7 +3095,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 Thu Sep 26 09:33: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: 13813123 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 EB13C1ACDF9 for ; Thu, 26 Sep 2024 09:33:30 +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=1727343211; cv=none; b=qCir9qQMcxI3OmJIqj9i3SUT7+7DflQMD8Cfx0hnASBYAD7NLgWcbHbQ/+2OuuC02gVDKY9BZAmB6bOkFfGrAiuaVu6yrTUE/AD42AkxLvhjUdg5T/6/fV0mRlgJvqbMTPXQ3Mnr7wjvNbIgnQ/CvXTkdGPcw8mZ9cIG+MCmBpU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727343211; c=relaxed/simple; bh=SUn/vvrncCE0nhQgNheq+rKNJo1IJc30uF6+NgEanTs=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HGOHu546DLVgrSgZ2H35Mi9/4eXdjMj1J4NpCPqQ8Vh4umsi/oC9lKyCkttRKzZu3u1Jb6egqdoeucc+dUhB31Skq7RioggErTLCMdfwxP5PL8o/I7R3kjlegUwVSW5W0kg4e8Fi4Zca0rC2ZwEdMkM8Ue/RYlLyNORE1x91ydM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OhhJlhqd; 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="OhhJlhqd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E50A1C4CEC5 for ; Thu, 26 Sep 2024 09:33:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727343210; bh=SUn/vvrncCE0nhQgNheq+rKNJo1IJc30uF6+NgEanTs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=OhhJlhqdgF/cMHxeRgdRFtSQL5vrIK85xsGTwwL4vxauvDwG1c/Vk4a/7cI3kH/aD CIxGJByOZ3rLeZUe6Y8/sJbruRTuuse8AIjR6oweL+/dpv+tRciQ5IY3lWDEqCvHBW 3jEFO/HDt4XS9ewfiCMJO3v71IcqxcUOv2O5Q3aWPIQcQF04DeuOX4BhlygeRf4px5 vrZFJJvETA+0tfKfELvkkXZWLzxl5KOZROVVoHnSc2SH/pmVI3ac+pVHo4KJFJDBzI XnKCEyADLSrVptJDi2P+nA1LW/hf3bM65Mka8DlRnk+QgrOY8GTMwvJ7HHNpwyB5ca j+bjZrayjyi2g== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH v2 5/8] btrfs: store fs_info in a local variable at btrfs_qgroup_trace_extent_post() Date: Thu, 26 Sep 2024 10:33:19 +0100 Message-Id: <864cd8ab499ea61d43b5bef36bb3b2210a60c224.1727342969.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 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 722edb04b78f..8d000a9d35af 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -2070,10 +2070,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 @@ -2096,16 +2100,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 Thu Sep 26 09:33: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: 13813124 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 9F6A11ACE00 for ; Thu, 26 Sep 2024 09:33: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=1727343211; cv=none; b=cUhUc5KZWImoWqVTfPfCU7Kj+7h/ZV/Nn54DsSFhsfoxC9lTcTpFBdY6/MewzwkBnTEiEbmOWUtHnG2wJTeTZWfyF7dVH0vweyQYy+O/nNToPBCiH5/qQYWuqmLmOqQdUj3v2uuG3E1+5COdpUsvEdJSucNCGNv/bt2KRuxaPCQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727343211; c=relaxed/simple; bh=V/SZqRascJ77vL6ehG1hjZCIMectILQwn69vqsidYjY=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=W1j9wcZfs+C6p09jc/NHGjbV6TNWj+wSNxUKqGFtp5/fBF5h6XtyGSyQtiySoP/ioxlMVW66MKDhTuH6Ck8M1j1yw8YNaP2b7HCoo5twZKWyyZNFswzyTv0T5jWVc83Km3qM+u9MQPY9K1281R/a/LctsnGnhbgdLQK8usKZ14c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=om4tngvU; 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="om4tngvU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EDA8CC4CECD for ; Thu, 26 Sep 2024 09:33:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727343211; bh=V/SZqRascJ77vL6ehG1hjZCIMectILQwn69vqsidYjY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=om4tngvUlKxcxRRZINjTJgk5Y/CUFR6XsDRfa1BlGF5WUJoLGzBp5xc/Sg+CPx+/q Q9DVn8T/ZWra3oUhJw8/+vs9YTz13tNoOEJS8hWdMOnsUED5UTWKVtpH1fm+OVDEkZ kHRkAQ+90T1s/XlpYDboBWS4l4G9VFIXy6TJ9nuxKHSyPOgO6CKJ9kPD7j7+9bhm10 zEMqRrSfiy93ckrfKvNOynAVW0fnS887sXvB4H7QSsRhe5Gd6iOjMzOj87QJgb+0oM /4lWFrpWh0x+0HMJuVdYLE0PGC9WZB8bLj/LVeGcAxEbAoXtYeD/Nx6FqJ3b42idBq EDie8v8XkvG0Q== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH v2 6/8] btrfs: remove unnecessary delayed refs locking at btrfs_qgroup_trace_extent() Date: Thu, 26 Sep 2024 10:33:20 +0100 Message-Id: <6d772cdeeb6f3991578be43a0e0c741694e8b677.1727342969.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 8d000a9d35af..3574af6d25ef 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -2021,7 +2021,6 @@ int btrfs_qgroup_trace_extent_nolock(struct btrfs_fs_info *fs_info, } #endif - lockdep_assert_held(&delayed_refs->lock); trace_btrfs_qgroup_trace_extent(fs_info, record, bytenr); xa_lock(&delayed_refs->dirty_extents); @@ -2160,9 +2159,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 Thu Sep 26 09:33: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: 13813125 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 A97AD1AD402 for ; Thu, 26 Sep 2024 09:33: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=1727343212; cv=none; b=jZ9knRCaBdairVfXPiL0P+jYOXPuI5Tm2W1PSTHrXq7JXMBhYEaCFZ+o8BHv6ExysrtqtH//Rcx3Y2UCdJMtLS/llJwkqtOUMXumeyLIgsHCcLDr1JQpz6HvMdctgMPu4igRcyKz6dPa0FRts4TTEczLCx1oofpYE49gNQN40Ng= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727343212; c=relaxed/simple; bh=3a+ScunoTmR1MC/PQB4DsstH/bqmcKQEc2I+1ZR71YY=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uHhCHaG3jfIDcRcALiqSxPF305krPUFtrt+SZLdafUetkzNjzjyqr9zXVu5VvDkLYjquePPayhNixvBjzy3dOdA5yNi+bkf8BTrXZH6D0XNj1X87U7XL/mqcvcwdip/v0R64eojQzncJlo6OMmoIn4zdobzHkIMIbguXER92zPo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FjjIhhYa; 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="FjjIhhYa" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 00F90C4CECD for ; Thu, 26 Sep 2024 09:33:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727343212; bh=3a+ScunoTmR1MC/PQB4DsstH/bqmcKQEc2I+1ZR71YY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=FjjIhhYa9IzUsEnZ/ThN8T8A6bc9Rgi5Srsi3OGdH6OVSb1/uP4rrBTIoY6vl721A wId0ZFvoP21AbFryv2/YaWxAZr628XbQ7/zKKvVpN+nGczXUqHRxQuUFgoRAOYTNks jacNW1W+Rx+OqdnN6SIGjZRw7JNZZHs+ksnlWPKPo7llHbovEjr4h2Tf5R5VUy453x lpLeYW/JJNpTl5VyDWZSYTe17chIyDluaMOXYzaZp6IBGx7DWgGDtgKggAW3wmT/4k aZjCaVt6cNWsTlM20870pkK40k4H2eunvXUxj/hF63koY4QnNPmbypIFwic+WvxA1O l7j02jOzstGhg== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH v2 7/8] btrfs: always use delayed_refs local variable at btrfs_qgroup_trace_extent() Date: Thu, 26 Sep 2024 10:33:21 +0100 Message-Id: <87fc06f72674c45c840878c382480d84e2020b54.1727342969.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 3574af6d25ef..6294f949417c 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -2140,7 +2140,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; @@ -2150,12 +2150,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 Thu Sep 26 09:33: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: 13813126 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 172991AD40B for ; Thu, 26 Sep 2024 09:33: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=1727343214; cv=none; b=QiQYsb5JSSFFSwaHBckE2yqfyliupWhS4Lc7yPmX+b6tSUsnypEFfGkiDcqgXpTyxDpT6ssCZXiugt/P493U6TTbG07rNscNtwKB3Hka7o3rf9BxBBw/nWF/2QPEaB+6xSumIdKmYdIcSJI+913NxTlKC4/MgtPWyojCZZmeaIQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727343214; c=relaxed/simple; bh=PmCuqlkBwRJ/CtJL/Pv/p+nK8Bv6KuEA5EBdVqLWoSI=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SmBtbLfNM2iodMcmpRYIXvQHcjaSCqBMNyLC3kEF+23egF5mbJ0qb7NcB7ZLmfqKOez7opWhTDef0FqycSdmk2EkXcKpMmKMZ3NV70ySZKKx0VTbCLJYmF7RW7kOGdEPqjG6FYD37OJfm0oL3BkdW2Wqm0fuqFyg63qe4s/HfGo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=c9a2M1A4; 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="c9a2M1A4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B7B2C4CEC9 for ; Thu, 26 Sep 2024 09:33:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727343213; bh=PmCuqlkBwRJ/CtJL/Pv/p+nK8Bv6KuEA5EBdVqLWoSI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=c9a2M1A4V69fjtbSSCX/HGBZsw72JNDNhkbdDSh1moB6gxe2VFigfrJWjAHyHjTiD U6zvKd28frTwvKSwUOX1XXkPyZdTAUUtsfNx3QyO4PPF9vzNC9KilCimwS+3CCb1kb POx7UUhUoT2BrlPGz7sbtnUPAuiXBYGyqlK21X/ZPBEXyvgAaaJZ9GfTXNhOOTe6f5 nKMMZhaa+k5ZhsBiNQ/jv7zbOZbuJZDHFOMqiXncDLClOBWrOMsKJf2OoF2Whfq4TB OFC3cDFimOc6ylWSwC57s2qvZe17MthbR5ldLLnAVNSAxZsGIQV9MS3EraTySjTZNL cuoAF1tsjWN7A== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH v2 8/8] btrfs: remove pointless initialization at btrfs_qgroup_trace_extent() Date: Thu, 26 Sep 2024 10:33: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 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 6294f949417c..34bb72f32ec4 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -2156,7 +2156,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) {