From patchwork Fri Feb 9 18:00:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13551682 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 8653780C18 for ; Fri, 9 Feb 2024 18:00:56 +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=1707501656; cv=none; b=HyImtMrzz/RpdyBQ9TGTQuJ+Lqhy1qW2EBqN/gNnpny8856Ffr+LwE5ZPo5TTK4GlgXyfMTFzOFm+Lr2/dQj6BVOHGBSBz3+SkUkww0wCbAJ8v+qX6A5rzdxPhIQE3vCLwfB9qp4dxeSv5ZxfGUNpRj4SKYx7l29itD3VgZabjs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707501656; c=relaxed/simple; bh=Ofp21nVBhJDES24+EW8lDlEy07Ep3WZ260dklk9rgMQ=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=d8rDBChpcQKJn7q1e6PjoEAO50B/omMVQQ6LluAXVj3Sz9OKjPj9F5DsIDrD68YaYhxk4yzjcaeMPS5r8/9sg/phe8LRq4gcshglOUx11dESa0+dz/Jx7feZB6CCVV7YxgjjylDszrhRGmkWjoLvqtnltMeyMJtmgK6gne1dmv4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GJ5OVB/E; 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="GJ5OVB/E" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E827C43394 for ; Fri, 9 Feb 2024 18:00:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707501656; bh=Ofp21nVBhJDES24+EW8lDlEy07Ep3WZ260dklk9rgMQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=GJ5OVB/EaQ28cAwFSwDW7XK/WQ32OvGmjRKKYeudpUq2hXYRRAFF1y0ppdUzDQu7H JU5muprvZheKqqztxedGYgGU3+hMxdq63uXYTrjiaNwHqqo4VH73LV3QFz6KYLSiVX kvp8pKHnn0iVldZ2zVtAkYXZBcTnsDIXSfFMxYROM2wmkCsTLbCOjNmzf3Ul02fhsT 6NpwTIH1vgxaoDatEQJFhrehMm7xngnHvD9fFkCXCAWdg4Q0BlzUMYc8NRr1rQcmZf 03kbw2Dp5j8wGbKHntjUBXxuai9WW4oeJ82lxeEwiVEPtym/DpqCiRSbz8VQIipgYc 4XHmqTTP/JZBA== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 1/9] btrfs: stop passing root argument to btrfs_add_delalloc_inodes() Date: Fri, 9 Feb 2024 18:00:43 +0000 Message-Id: <5cfceac9f43f2e296437b01f940dd668208c4b98.1707491248.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 pass a root argument to btrfs_add_delalloc_inodes(), we can just pass the inode since the root is always the root associated to the inode in the context it's called. So remove it and have the single caller pass only the inode. Signed-off-by: Filipe Manana Reviewed-by: Qu Wenruo --- fs/btrfs/inode.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 2d16bb08e905..e3d12d8cf088 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2385,10 +2385,10 @@ void btrfs_merge_delalloc_extent(struct btrfs_inode *inode, struct extent_state spin_unlock(&inode->lock); } -static void btrfs_add_delalloc_inodes(struct btrfs_root *root, - struct btrfs_inode *inode) +static void btrfs_add_delalloc_inodes(struct btrfs_inode *inode) { - struct btrfs_fs_info *fs_info = inode->root->fs_info; + struct btrfs_root *root = inode->root; + struct btrfs_fs_info *fs_info = root->fs_info; spin_lock(&root->delalloc_lock); if (list_empty(&inode->delalloc_inodes)) { @@ -2451,7 +2451,6 @@ void btrfs_set_delalloc_extent(struct btrfs_inode *inode, struct extent_state *s * bit, which is only set or cleared with irqs on */ if (!(state->state & EXTENT_DELALLOC) && (bits & EXTENT_DELALLOC)) { - struct btrfs_root *root = inode->root; u64 len = state->end + 1 - state->start; u32 num_extents = count_max_extents(fs_info, len); bool do_list = !btrfs_is_free_space_inode(inode); @@ -2472,7 +2471,7 @@ void btrfs_set_delalloc_extent(struct btrfs_inode *inode, struct extent_state *s inode->defrag_bytes += len; if (do_list && !test_bit(BTRFS_INODE_IN_DELALLOC_LIST, &inode->runtime_flags)) - btrfs_add_delalloc_inodes(root, inode); + btrfs_add_delalloc_inodes(inode); spin_unlock(&inode->lock); } From patchwork Fri Feb 9 18:00:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13551683 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 A07988287A for ; Fri, 9 Feb 2024 18:00:57 +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=1707501657; cv=none; b=KWvWX8wZVSQVG/M/GK5a5ZncCx10/PQvlWBJxpJb63JUYxW8tgXKnINYnuUlgNgwvhzmHICpBAsyuRBvcanAqEBYaNOlx9DaFh1bdbfbnq0EZWGz+rJkEnvLIuQ+HmCowW1/D2tGEVUFsZmMKN00qB3Oie2rzhRe6J6YqtS1h+o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707501657; c=relaxed/simple; bh=UzZsENWxpdgWGpke/WxlbDL6Wcez4rfdx7sJpptjtEU=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cCri/kR7HEJZOymEmkdLdT+32qxsOo3fAixkufEKobq2DLad2T2bDiswbvUaQFYPLUBWTiUC+yiBMnbXTb420YsUaejHbC2Lk5GdTphiySvirTW/P+/TziQyXhwhxUCe3j9u06WMhbL7zTUf7UAZOtJYbHm1CPc7H+8ssRMuKag= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CE+XgMI7; 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="CE+XgMI7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80294C43399 for ; Fri, 9 Feb 2024 18:00:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707501657; bh=UzZsENWxpdgWGpke/WxlbDL6Wcez4rfdx7sJpptjtEU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=CE+XgMI7Wk3TFe+wTIVq3o4bCf1+P5OJzhLRb7M8KTYvMS6t/6HhBGjqZBBT2Ly5u aKo6ENEngqlNvuaZ/0zIj9Do+PdcPG0pM4O5q5OHOGENiR3Ol7jVX2hrwbAww4SHYn 6CZkdUEas+PBye6BcVztJtOdR2PiZYf8GoxKHSs73+cyucC1HO2SPZ8Ys6AB2b5jGh SxotCMgekJ8TZ3fON2x9rKOLvnOGmsIseux4W/TOAeOacBU94eeotGiTowlCFhRVDA Z8vMdQPMdNQLD/pOWI6sQGIErEcQXFWC9sw2jvsrkPpw+P2gq39A4HMPNrcinDRWwG ASxXePOke9HMA== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 2/9] btrfs: stop passing root argument to __btrfs_del_delalloc_inode() Date: Fri, 9 Feb 2024 18:00:44 +0000 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 There's no need to pass a root argument to __btrfs_del_delalloc_inode() and btrfs_del_delalloc_inode(), we can just pass the inode since the root is always the root associated to that inode. Some remove the root argument from these functions. Signed-off-by: Filipe Manana Reviewed-by: Qu Wenruo --- fs/btrfs/btrfs_inode.h | 2 +- fs/btrfs/disk-io.c | 2 +- fs/btrfs/inode.c | 15 +++++++-------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h index 83d78a6f3aa2..32c59c5bd94d 100644 --- a/fs/btrfs/btrfs_inode.h +++ b/fs/btrfs/btrfs_inode.h @@ -428,7 +428,7 @@ noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len, u64 *orig_start, u64 *orig_block_len, u64 *ram_bytes, bool nowait, bool strict); -void __btrfs_del_delalloc_inode(struct btrfs_root *root, struct btrfs_inode *inode); +void __btrfs_del_delalloc_inode(struct btrfs_inode *inode); struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry); int btrfs_set_inode_index(struct btrfs_inode *dir, u64 *index); int btrfs_unlink_inode(struct btrfs_trans_handle *trans, diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 4280f8e23461..8ab185182c30 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -4629,7 +4629,7 @@ static void btrfs_destroy_delalloc_inodes(struct btrfs_root *root) struct inode *inode = NULL; btrfs_inode = list_first_entry(&splice, struct btrfs_inode, delalloc_inodes); - __btrfs_del_delalloc_inode(root, btrfs_inode); + __btrfs_del_delalloc_inode(btrfs_inode); spin_unlock(&root->delalloc_lock); /* diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index e3d12d8cf088..ec8af7d0f166 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2406,9 +2406,9 @@ static void btrfs_add_delalloc_inodes(struct btrfs_inode *inode) spin_unlock(&root->delalloc_lock); } -void __btrfs_del_delalloc_inode(struct btrfs_root *root, - struct btrfs_inode *inode) +void __btrfs_del_delalloc_inode(struct btrfs_inode *inode) { + struct btrfs_root *root = inode->root; struct btrfs_fs_info *fs_info = root->fs_info; if (!list_empty(&inode->delalloc_inodes)) { @@ -2426,12 +2426,11 @@ void __btrfs_del_delalloc_inode(struct btrfs_root *root, } } -static void btrfs_del_delalloc_inode(struct btrfs_root *root, - struct btrfs_inode *inode) +static void btrfs_del_delalloc_inode(struct btrfs_inode *inode) { - spin_lock(&root->delalloc_lock); - __btrfs_del_delalloc_inode(root, inode); - spin_unlock(&root->delalloc_lock); + spin_lock(&inode->root->delalloc_lock); + __btrfs_del_delalloc_inode(inode); + spin_unlock(&inode->root->delalloc_lock); } /* @@ -2538,7 +2537,7 @@ void btrfs_clear_delalloc_extent(struct btrfs_inode *inode, if (do_list && inode->delalloc_bytes == 0 && test_bit(BTRFS_INODE_IN_DELALLOC_LIST, &inode->runtime_flags)) - btrfs_del_delalloc_inode(root, inode); + btrfs_del_delalloc_inode(inode); spin_unlock(&inode->lock); } From patchwork Fri Feb 9 18:00:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13551684 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 6AAD082888 for ; Fri, 9 Feb 2024 18:00:58 +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=1707501658; cv=none; b=dlkT80dyKxse3lkSa7j2nfvWbi6hC/Gk/xRa+yV+EWdDCVc/3g3Q3vZ77Yyl+DYwv5dyugBTWI6UQpTzjHqlzzK0V9HpoXVkE6X3ezvm3rZCI6P6VkgKc9rTg+iA7oLl/psmu8l8MiTetmTfLjZYN+UI06miawL7OBs3Ul0Ub8U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707501658; c=relaxed/simple; bh=Dijv99AoZdPKICkG+DMMMRF+CReH7ytHud7o80N94CA=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SDONpYyQWd/8axWijbK1LzwkruVwL32ucZj9DHt2VfxXVGMFOJJAJ2KuXQbpQlJufN2A4bhrUZwOFO7J+Ihbmf+5vN485349tgn5BpnFwaI/oSEOjppM/yT6pIgV3MLRSUJhh6tZahUubYm6aliHbjgBjC1mPt21BnQnW0otaOc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FyddvRgl; 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="FyddvRgl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 72BF3C433C7 for ; Fri, 9 Feb 2024 18:00:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707501658; bh=Dijv99AoZdPKICkG+DMMMRF+CReH7ytHud7o80N94CA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=FyddvRgl4ziZlTCRHSMYcRSW/gE6EIJI9tzo1cIpGJYWTe1LILXku6Ov9UNBnwaV4 bOC7IDE4567PFSZg6RNWulQ2pjMVfgDLXrcJmUkypJ7w5xaFtkcvWnh4jvh27CR2Sd 2a+8OxhmGhsfQqruFKClMKkwWe0/D0cmFW6KCtvFRv9IJgw5BXGV8e3g6Cm+F6ihLn pqm11/G0YS9KUnavB71vnhTVExfKV+x+KFF9qst/Cq4NGcKICn64+n4cugF6gzChJ3 yjBiEcLkJxaLPDCKhqltT/E8X+kMXJfQk1xz6zawMpTOoVNqhvRuvc6SlGE9KNvwCc TXnBRhXcA3oVw== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 3/9] btrfs: assert root delalloc lock is held at __btrfs_del_delalloc_inode() Date: Fri, 9 Feb 2024 18:00:45 +0000 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 This function requires the delalloc lock of the inode's root to be held, so assert it's held. Signed-off-by: Filipe Manana Reviewed-by: Qu Wenruo --- fs/btrfs/inode.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index ec8af7d0f166..3a19e30676e8 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2411,6 +2411,8 @@ void __btrfs_del_delalloc_inode(struct btrfs_inode *inode) struct btrfs_root *root = inode->root; struct btrfs_fs_info *fs_info = root->fs_info; + lockdep_assert_held(&root->delalloc_lock); + if (!list_empty(&inode->delalloc_inodes)) { list_del_init(&inode->delalloc_inodes); clear_bit(BTRFS_INODE_IN_DELALLOC_LIST, From patchwork Fri Feb 9 18:00:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13551685 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 81E4183CAA for ; Fri, 9 Feb 2024 18:00:59 +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=1707501659; cv=none; b=sGb/ZT7cc4qzf3bNr7aSbMLP1CNJdAlcIHBMSbK+FVCb0JjZd0YO7NIfImGaTPxOUwyTYQTlhujbtHAzcMAuEZnVTJYNjdGPJVOPPgxhrsCBjC+cQssozttrBMP8En4cJJwmToMEZu1cOQZeaukMPPDEhbCRNKIr+zqtTgsVG7w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707501659; c=relaxed/simple; bh=g8FIVfnxfN4OOTwx8ehxAwYyT2OBUMITeKorUcsRj1Y=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=B4TslIOLZrX8W1tFF+r5/1gDEPHvIi/BrdlbTo7vG8gdTR/QcY/XVKl78x6aeEth+gFfKerCLxUy8inds5cMTRaZTsFS/Y9NpN/8PjWfIli8OWufuL5NJFTMXHR1LDy4ADj+Y6TSVOMBSXOgAftegi4mziLJWR5h+MBy/m8voFE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=B3rZlYMD; 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="B3rZlYMD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6EE58C43390 for ; Fri, 9 Feb 2024 18:00:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707501658; bh=g8FIVfnxfN4OOTwx8ehxAwYyT2OBUMITeKorUcsRj1Y=; h=From:To:Subject:Date:In-Reply-To:References:From; b=B3rZlYMDPBDA97sJ9jPChMkA87KzIOFph/oSA1phwiJHv0IHy6b2HRCNfAhFW3e94 S0Ff3gZegWFujfP9qXT6QqMezO1UI1MKcLLvSDA4Ee276togb8r32EVtFMgAt12/ik Op607yTiPcu30NWDfaUzu5Yu8X4+ImzdI57Pamr6PNWgMldrn+wZfi6xyjwDOfOKYr +QSuvMR3sPuwMlrHlO64s0uNBACbn58RliseHd0rGqdTdCmfmO1T2KPFw8+RZiP34P F8HROKjKULmNpevf+4lrFoP4OvlQaVOKel0R1h+bkRSN2bbmXVkR5jj+eMBRTrrqT/ a4wQmrA483L+A== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 4/9] btrfs: rename btrfs_add_delalloc_inodes() to singular form Date: Fri, 9 Feb 2024 18:00:46 +0000 Message-Id: <2e26e61c8974a2c7e7ba1b2e14e771395bfa4a57.1707491248.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana The function btrfs_add_delalloc_inodes() adds a single inode its root's list of delalloc inodes, so it doesn't make any sense at all for the function's name to be plural. Rename it to the singular form btrfs_add_delalloc_inode() to avoid any confusion. Signed-off-by: Filipe Manana Reviewed-by: Qu Wenruo --- fs/btrfs/inode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 3a19e30676e8..b273fdbd63cd 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2385,7 +2385,7 @@ void btrfs_merge_delalloc_extent(struct btrfs_inode *inode, struct extent_state spin_unlock(&inode->lock); } -static void btrfs_add_delalloc_inodes(struct btrfs_inode *inode) +static void btrfs_add_delalloc_inode(struct btrfs_inode *inode) { struct btrfs_root *root = inode->root; struct btrfs_fs_info *fs_info = root->fs_info; @@ -2472,7 +2472,7 @@ void btrfs_set_delalloc_extent(struct btrfs_inode *inode, struct extent_state *s inode->defrag_bytes += len; if (do_list && !test_bit(BTRFS_INODE_IN_DELALLOC_LIST, &inode->runtime_flags)) - btrfs_add_delalloc_inodes(inode); + btrfs_add_delalloc_inode(inode); spin_unlock(&inode->lock); } From patchwork Fri Feb 9 18:00:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13551686 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 0F20D83CB9 for ; Fri, 9 Feb 2024 18:01:00 +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=1707501660; cv=none; b=kbbCsZq9bPVYyb80FY71FuKZ/Z4SqI2Z+BUn1OC8IMrtkZKcmwgCfT4v6Qyg3fFAXNLwLfDfB0OhszS2fnJL2kS3cigiNAP4MqLyyg4fgnZpzt1U0ez76rZyCiFS1t1LV8gxAjWC5lNqkbkqBhG+67lfIVMC3weVJKq7Pd41/Bc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707501660; c=relaxed/simple; bh=eeURNJFMTtSR5ctnyDW/TRS0BqdSFvnYy128iw8Vo0Y=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SFH7Q64tjpKXtXKstQDVLFNssDOwSe7uQR7uka2R9X/hCdDUu9qjULXWGtCG95ZR0xq4KuftRwHpep5FsBWI+230KD9VyLK7vDwRJskWt3R09cODkCXY7m88S3Z0GLzG5pN5Dtgm1vwjpiN5w8ZIFhr1wI5RLolgFxKyw/CX/C4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CsEW2Ejd; 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="CsEW2Ejd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5FCD2C43394 for ; Fri, 9 Feb 2024 18:00:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707501659; bh=eeURNJFMTtSR5ctnyDW/TRS0BqdSFvnYy128iw8Vo0Y=; h=From:To:Subject:Date:In-Reply-To:References:From; b=CsEW2Ejd+D6m994HOhYJfXH1WvqBVIIJ0pedTyq2ZVKzXaadLkGAkZrUNLicU/gJV QK2xbDVqp2hNg4Hfud95I2o4tnRr4V1yOSM8iah50QTs/JX4Ik35Haku2/dl+flBI5 UlfUbIZ56UsT2kAIH0KWUZ5LjK7l86gZWTg9Q0gAYFIxwip3spnVk5Btmavc88eolE WHTwoSC7wedxSgvEd97f+CqWiWz/TvMw0bMTD8B+O3xfZcLrB4sT1GMGztHMuV796B 1j73hBE/7Qw6QQ1CeKGJEG5RmxyH3fteavTC8ltrLzTp+RiGsHLec3jZmrpKaJpGF/ T2vT5YUKw86Tg== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 5/9] btrfs: reduce inode lock critical section when setting and clearing delalloc Date: Fri, 9 Feb 2024 18:00:47 +0000 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 When setting and clearing a delalloc range, at btrfs_set_delalloc_extent() and btrfs_clear_delalloc_extent(), we are adding/removing the inode to/from the root's list of delalloc inodes while under the protection of the inode's lock. This however is not needed, we can add and remove the inode to the root's list without holding the inode's lock because here we are under the protection of the io tree's lock, reducing the size of the critical section delimited by the inode's lock. The inode's lock is used in many other places such as when finishing an ordered extent (when calling btrfs_update_inode_bytes() or btrfs_delalloc_release_metadata(), or decreasing the number of outstanding extents) or when reserving space when doing a buffered or direct IO write (calls to functions from delalloc-space.c). So move the inode add/remove operations to the root's list of delalloc inodes to outside the critical section delimited by the inode's lock. This also allows us to get rid of the BTRFS_INODE_IN_DELALLOC_LIST flag since we can rely on the inode's delalloc bytes counter to determine if the inode is or is not in the list. The following fio based test, that exercises IO to multiple files in the same subvolume, was used to test: $ cat test.sh #!/bin/bash DEV=/dev/nullb0 MNT=/mnt/nullb0 MOUNT_OPTIONS="-o ssd" mkfs.btrfs -f $DEV &> /dev/null mount $MOUNT_OPTIONS $DEV $MNT fio --direct=0 --ioengine=sync --thread --directory=$MNT \ --invalidate=1 --group_reporting=1 \ --new_group --rw=randwrite --size=50m --numjobs=200 \ --bs=4k --fsync_on_close=0 --fallocate=none --end_fsync=0 \ --name=foo --filename_format=FioWorkloads.\$jobnum umount $MNT The test was run on a non-debug kernel (Debian's default kernel config) against a 16G null block device. Result before this patch: WRITE: bw=81.9MiB/s (85.9MB/s), 81.9MiB/s-81.9MiB/s (85.9MB/s-85.9MB/s), io=9.77GiB (10.5GB), run=122136-122136msec Result after this patch: WRITE: bw=86.8MiB/s (91.0MB/s), 86.8MiB/s-86.8MiB/s (91.0MB/s-91.0MB/s), io=9.77GiB (10.5GB), run=115180-115180msec Signed-off-by: Filipe Manana --- fs/btrfs/btrfs_inode.h | 1 - fs/btrfs/inode.c | 60 ++++++++++++++++++++++++++++-------------- 2 files changed, 40 insertions(+), 21 deletions(-) diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h index 32c59c5bd94d..7799d00cc5d6 100644 --- a/fs/btrfs/btrfs_inode.h +++ b/fs/btrfs/btrfs_inode.h @@ -41,7 +41,6 @@ enum { */ BTRFS_INODE_NEEDS_FULL_SYNC, BTRFS_INODE_COPY_EVERYTHING, - BTRFS_INODE_IN_DELALLOC_LIST, BTRFS_INODE_HAS_PROPS, BTRFS_INODE_SNAPSHOT_FLUSH, /* diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index b273fdbd63cd..778bb6754e00 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2391,17 +2391,14 @@ static void btrfs_add_delalloc_inode(struct btrfs_inode *inode) struct btrfs_fs_info *fs_info = root->fs_info; spin_lock(&root->delalloc_lock); - if (list_empty(&inode->delalloc_inodes)) { - list_add_tail(&inode->delalloc_inodes, &root->delalloc_inodes); - set_bit(BTRFS_INODE_IN_DELALLOC_LIST, &inode->runtime_flags); - root->nr_delalloc_inodes++; - if (root->nr_delalloc_inodes == 1) { - spin_lock(&fs_info->delalloc_root_lock); - BUG_ON(!list_empty(&root->delalloc_root)); - list_add_tail(&root->delalloc_root, - &fs_info->delalloc_roots); - spin_unlock(&fs_info->delalloc_root_lock); - } + ASSERT(list_empty(&inode->delalloc_inodes)); + list_add_tail(&inode->delalloc_inodes, &root->delalloc_inodes); + root->nr_delalloc_inodes++; + if (root->nr_delalloc_inodes == 1) { + spin_lock(&fs_info->delalloc_root_lock); + BUG_ON(!list_empty(&root->delalloc_root)); + list_add_tail(&root->delalloc_root, &fs_info->delalloc_roots); + spin_unlock(&fs_info->delalloc_root_lock); } spin_unlock(&root->delalloc_lock); } @@ -2413,10 +2410,14 @@ void __btrfs_del_delalloc_inode(struct btrfs_inode *inode) lockdep_assert_held(&root->delalloc_lock); + /* + * We may be called after the inode was already deleted from the list, + * namely in the transaction abort path btrfs_destroy_delalloc_inodes(), + * and then later through btrfs_clear_delalloc_extent() while the inode + * still has ->delalloc_bytes > 0. + */ if (!list_empty(&inode->delalloc_inodes)) { list_del_init(&inode->delalloc_inodes); - clear_bit(BTRFS_INODE_IN_DELALLOC_LIST, - &inode->runtime_flags); root->nr_delalloc_inodes--; if (!root->nr_delalloc_inodes) { ASSERT(list_empty(&root->delalloc_inodes)); @@ -2444,6 +2445,8 @@ void btrfs_set_delalloc_extent(struct btrfs_inode *inode, struct extent_state *s { struct btrfs_fs_info *fs_info = inode->root->fs_info; + lockdep_assert_held(&inode->io_tree.lock); + if ((bits & EXTENT_DEFRAG) && !(bits & EXTENT_DELALLOC)) WARN_ON(1); /* @@ -2453,6 +2456,7 @@ void btrfs_set_delalloc_extent(struct btrfs_inode *inode, struct extent_state *s */ if (!(state->state & EXTENT_DELALLOC) && (bits & EXTENT_DELALLOC)) { u64 len = state->end + 1 - state->start; + u64 prev_delalloc_bytes; u32 num_extents = count_max_extents(fs_info, len); bool do_list = !btrfs_is_free_space_inode(inode); @@ -2467,13 +2471,20 @@ void btrfs_set_delalloc_extent(struct btrfs_inode *inode, struct extent_state *s percpu_counter_add_batch(&fs_info->delalloc_bytes, len, fs_info->delalloc_batch); spin_lock(&inode->lock); + prev_delalloc_bytes = inode->delalloc_bytes; inode->delalloc_bytes += len; if (bits & EXTENT_DEFRAG) inode->defrag_bytes += len; - if (do_list && !test_bit(BTRFS_INODE_IN_DELALLOC_LIST, - &inode->runtime_flags)) - btrfs_add_delalloc_inode(inode); spin_unlock(&inode->lock); + + /* + * We don't need to be under the protection of the inode's lock, + * because we are called while holding the inode's io_tree lock + * and are therefore protected against concurrent calls of this + * function and btrfs_clear_delalloc_extent(). + */ + if (do_list && prev_delalloc_bytes == 0) + btrfs_add_delalloc_inode(inode); } if (!(state->state & EXTENT_DELALLOC_NEW) && @@ -2495,6 +2506,8 @@ void btrfs_clear_delalloc_extent(struct btrfs_inode *inode, u64 len = state->end + 1 - state->start; u32 num_extents = count_max_extents(fs_info, len); + lockdep_assert_held(&inode->io_tree.lock); + if ((state->state & EXTENT_DEFRAG) && (bits & EXTENT_DEFRAG)) { spin_lock(&inode->lock); inode->defrag_bytes -= len; @@ -2508,6 +2521,7 @@ void btrfs_clear_delalloc_extent(struct btrfs_inode *inode, */ if ((state->state & EXTENT_DELALLOC) && (bits & EXTENT_DELALLOC)) { struct btrfs_root *root = inode->root; + u64 new_delalloc_bytes; bool do_list = !btrfs_is_free_space_inode(inode); spin_lock(&inode->lock); @@ -2536,11 +2550,17 @@ void btrfs_clear_delalloc_extent(struct btrfs_inode *inode, fs_info->delalloc_batch); spin_lock(&inode->lock); inode->delalloc_bytes -= len; - if (do_list && inode->delalloc_bytes == 0 && - test_bit(BTRFS_INODE_IN_DELALLOC_LIST, - &inode->runtime_flags)) - btrfs_del_delalloc_inode(inode); + new_delalloc_bytes = inode->delalloc_bytes; spin_unlock(&inode->lock); + + /* + * We don't need to be under the protection of the inode's lock, + * because we are called while holding the inode's io_tree lock + * and are therefore protected against concurrent calls of this + * function and btrfs_set_delalloc_extent(). + */ + if (do_list && new_delalloc_bytes == 0) + btrfs_del_delalloc_inode(inode); } if ((state->state & EXTENT_DELALLOC_NEW) && From patchwork Fri Feb 9 18:00:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13551687 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 F1EF084A36 for ; Fri, 9 Feb 2024 18:01:00 +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=1707501661; cv=none; b=B4kgqdlsbB6VzyQdRYYwQR12RTaUk3zR2mmOytnHzPedZLiyN5tpyL+5k4/L+VdDmXjZD1Kv2iEwMcjVcXzZH9BQ20XFPj9mabiLucDecYuZwmq3XuH9Fe7FHmb9KBWDNVvdM23lrv885jzt+SChh5P29TaihiHwSn9KVOm9wcM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707501661; c=relaxed/simple; bh=84HnlfqRkyfyOzLphFjA1q5tLsbyOMFXpg625Ia0wl0=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PWbeAWfr1jlcOs7b/qMjwi5vrBXEpfZWtIIbCKjlEY+SJySonKFpaDnC+MTQxrtyMWoJxJ4fFXKoIDXvzt0/SjPJjNV4jIESUSbrYeh33HGaJH4ESe4puOhf/Cixrg71zplayX7C6gws8N736HWWj8LsL73z1Su3i1SqC3yJSn8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ol6Fey4T; 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="Ol6Fey4T" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 51BD6C43390 for ; Fri, 9 Feb 2024 18:01:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707501660; bh=84HnlfqRkyfyOzLphFjA1q5tLsbyOMFXpg625Ia0wl0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Ol6Fey4T+Uet4eHuLZE0TCaCaZlznRFevsTrXlZTFUVBYqQFuGY6PbFBHv7WKDima cenh8A3ln2tnS4b2JqhOF69mtkGiHWBMPmmZaEqNCjRT0M6muqpth/a+JxsU1xjixX pQnlfBtoZ8DyJBVOQaLpX8W36KkhklQGu5bkXItyB7aN9mvBKha08uWitgy7w4IbjZ 8YRhLXRF34joQe+YbAXqgp5esf/xF0lU5Vu5UmEPA1q9LeDLJBnxCrrNtwo0LxzNwl hn31D6TkJeBjCfQE0Zj3eYK1pN9e6J5ViQPYileXrcP+RpqzzCmsQ9/9iAW1hyNWds 5ddPBnv+M79Jg== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 6/9] btrfs: add lockdep assertion to remaining delalloc callbacks Date: Fri, 9 Feb 2024 18:00:48 +0000 Message-Id: <3c6359337ba942d628b989cc7458cde4d9a5373a.1707491248.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana The merge and split callbacks for an inode's io tree are supposed to be called while the io tree's spinlock is being held, so that the given extent_state records are stable, not modified or freed while the callbacks are using them. So add lockdep assertions in the callbacks. Signed-off-by: Filipe Manana Reviewed-by: Qu Wenruo --- fs/btrfs/inode.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 778bb6754e00..c7a5fb1f8b3e 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2300,6 +2300,8 @@ void btrfs_split_delalloc_extent(struct btrfs_inode *inode, struct btrfs_fs_info *fs_info = inode->root->fs_info; u64 size; + lockdep_assert_held(&inode->io_tree.lock); + /* not delalloc, ignore it */ if (!(orig->state & EXTENT_DELALLOC)) return; @@ -2338,6 +2340,8 @@ void btrfs_merge_delalloc_extent(struct btrfs_inode *inode, struct extent_state u64 new_size, old_size; u32 num_extents; + lockdep_assert_held(&inode->io_tree.lock); + /* not delalloc, ignore it */ if (!(other->state & EXTENT_DELALLOC)) return; From patchwork Fri Feb 9 18:00:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13551688 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 E5F2284A45 for ; Fri, 9 Feb 2024 18:01:01 +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=1707501662; cv=none; b=iH7sZ5QrYqLyWI0BYI/y3xC4G2ApxaaPhcg4ALMAcCQvwp6MXAY8LupH/TKwthIfK+GkgtgsYoCX4PEsGGhN/nizhpNdNHkGtSJBxmQe/6TNJusa8pwyTarpVdJJ5WtJPJmKuQpOILdMzpMMVg/5Ic21Cc3BU7BzPf1ehx7o7Ug= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707501662; c=relaxed/simple; bh=cCM9HbQFEeqEmOjSbadyL9rytYGRTwYc7B8XCs2zzKU=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fB6BHneiajPQzQt6lt+FTysI4BP6SJcueeUL73yPo6Csm9XQBqY8iswMoEZyf42CB9bGcxHyc+u3EbLDaWrOkRvjsBNsOq9cf4fHxS/PwiQKKtjOp2FWL6ZJZ4+caGf6xMjINQEZR00r4B9PtPFxR/9B21VZ09MjjY0IMAd0cCw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TlDMv7U+; 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="TlDMv7U+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42FC4C433C7 for ; Fri, 9 Feb 2024 18:01:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707501661; bh=cCM9HbQFEeqEmOjSbadyL9rytYGRTwYc7B8XCs2zzKU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=TlDMv7U+3JjtThUj26npldBjWKu/yhV2ncFQlHdEBaQ9D4cGnQgWri6/yYnDjGRlW eSfiLSuagvBKmIfYzX44AeWEc9/x3meL8+kp6OSdMBLP7qMs9Jw8am5uXvIWArjrKt MlkLB/n+/ajsKS1JjJc0BI/EWFr/zRWBIYmJXKz0qVJmLg1eJ7StxETcIJki5hjC2c YoCcXn5mbAV2N4UOu/jkRwzyJWXLNyjn0DloIR/dW2ugzqjr/C8Inyz+94uU22Q0to 48+AiEfFVG8oEH24CxiWOHfOmySA2m2GH5i8Sbr0y/BvhWtZbcKlH+xKb4oRzQextg Eo2eHnYXMWhGA== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 7/9] btrfs: use assertion instead of BUG_ON when adding/removing to delalloc list Date: Fri, 9 Feb 2024 18:00:49 +0000 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 When adding or removing and inode to/from the root's delalloc list, instead of using a BUG_ON() to validate list emptiness, use ASSERT() since this is to check logic errors rather than real errors. Signed-off-by: Filipe Manana Reviewed-by: Qu Wenruo --- fs/btrfs/inode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index c7a5fb1f8b3e..fe962a6045fd 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2400,7 +2400,7 @@ static void btrfs_add_delalloc_inode(struct btrfs_inode *inode) root->nr_delalloc_inodes++; if (root->nr_delalloc_inodes == 1) { spin_lock(&fs_info->delalloc_root_lock); - BUG_ON(!list_empty(&root->delalloc_root)); + ASSERT(list_empty(&root->delalloc_root)); list_add_tail(&root->delalloc_root, &fs_info->delalloc_roots); spin_unlock(&fs_info->delalloc_root_lock); } @@ -2426,7 +2426,7 @@ void __btrfs_del_delalloc_inode(struct btrfs_inode *inode) if (!root->nr_delalloc_inodes) { ASSERT(list_empty(&root->delalloc_inodes)); spin_lock(&fs_info->delalloc_root_lock); - BUG_ON(list_empty(&root->delalloc_root)); + ASSERT(!list_empty(&root->delalloc_root)); list_del_init(&root->delalloc_root); spin_unlock(&fs_info->delalloc_root_lock); } From patchwork Fri Feb 9 18:00:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13551689 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 D6CDA84A50 for ; Fri, 9 Feb 2024 18:01:02 +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=1707501662; cv=none; b=A3b6NUsAlvvh5qoI9I+GudR0ahbaOZH48PxICZsxqO5pIEC1LJD/oTorfeyDViddwo5bYPe4cUc8HQabINKDxa3eRyJeMJbJ4BrncjXEfUIm5VJQXTtcu7SlxRyoLXu94ihg58IW1WADkXFzfkAXtNQdt94y6na/7YewD1XrswY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707501662; c=relaxed/simple; bh=KyZYmRr35FRutdng6Fsir0uaIiWxu8JekCZB+fmcnjY=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bYTzNWZHhm0nui+qq2m/E+Dq4czWYXLv7Kjz2XgeScpdSb3hgU/BbmLRz170vyEwoTw506YALMjzxrmVCBidClwWIPN6X6DMKX2AQF3+t6bLZVVFx2CTcu6T4ejcOjjBBfn+wXRjduLpGme6StCTgi6OiTo4kTFGmYxrKgXclPg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cybKJ4QB; 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="cybKJ4QB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 34EFCC433C7 for ; Fri, 9 Feb 2024 18:01:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707501662; bh=KyZYmRr35FRutdng6Fsir0uaIiWxu8JekCZB+fmcnjY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=cybKJ4QBS3bvq3n7UMm/cSaicrnNVNY7KHjd9/ChYDr88k0nLEMpRYXwSBntm3l7f CvXbCqq3Y7gWEd/4nsLkAXDQHk1TNAN/TNQrdSvxWlCFWu/zRqGBCLDpEtqMOf+tAu CaoG8b9LPxO5pmhfytyOXdgtm8DessEPNctug+GcDu2gDXPEX7cIux85QU3WwAk/jU G5Rc+JbTMoaToNtTRCy08CenzqvNMoE7enCw4M6WJnfNfw9UV9eyJITpCjTy/hDGSU 42Pl7sYYaZNfz1GbFp1wzxDDwIapi0AYJ4OlMDbmA7A2el8skz4pZMVL/Z859jSsjA 2NGrmbQMvfQeg== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 8/9] btrfs: remove do_list variable at btrfs_set_delalloc_extent() Date: Fri, 9 Feb 2024 18:00:50 +0000 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 "do_list" variable is only used once, plus its name/meaning is a bit confusing, so remove it and directory use btrfs_is_free_space_inode(). Signed-off-by: Filipe Manana Reviewed-by: Qu Wenruo --- fs/btrfs/inode.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index fe962a6045fd..17b6ab71584a 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2462,7 +2462,6 @@ void btrfs_set_delalloc_extent(struct btrfs_inode *inode, struct extent_state *s u64 len = state->end + 1 - state->start; u64 prev_delalloc_bytes; u32 num_extents = count_max_extents(fs_info, len); - bool do_list = !btrfs_is_free_space_inode(inode); spin_lock(&inode->lock); btrfs_mod_outstanding_extents(inode, num_extents); @@ -2487,7 +2486,7 @@ void btrfs_set_delalloc_extent(struct btrfs_inode *inode, struct extent_state *s * and are therefore protected against concurrent calls of this * function and btrfs_clear_delalloc_extent(). */ - if (do_list && prev_delalloc_bytes == 0) + if (!btrfs_is_free_space_inode(inode) && prev_delalloc_bytes == 0) btrfs_add_delalloc_inode(inode); } From patchwork Fri Feb 9 18:00:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13551690 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 CAE0485299 for ; Fri, 9 Feb 2024 18:01:03 +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=1707501663; cv=none; b=V5RZg7BYmTVir6PzgLv/rWYF145OMFY8BPAfbtCrIFmOd9O2s5/eVPJ+whZ5X/YNASIpPXbD730gFkv25OvmfN9aqnLGQj3BLiHiC/t2abo8HNRQ/ItdnF2FvxybxWO8gx5wd6VKAAFZkHGyfeYEmRNQalv7eqSeWrIWwnepHO4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707501663; c=relaxed/simple; bh=2IZfJdIsVZJIUW+bdoqC1ZpNFMBcvsjpRvvn/AljRRQ=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mp4Zkndi0Tsy9llBM1rph+P0UhKNg7onfLYTHSGnHiKIE8+YFEFNe3KO0NYcsOyr/U0Jmf9zmX8H9CktY6bHXO5EOfyifUsxW6CT69M7p3lgFRTe0mGNQSTcE4oQC+N6XH1zDEDcpYa7x5Kite2JMVdcV77mTd6fdPhLEu9NM+U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=N3DEoBrV; 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="N3DEoBrV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27344C433F1 for ; Fri, 9 Feb 2024 18:01:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707501663; bh=2IZfJdIsVZJIUW+bdoqC1ZpNFMBcvsjpRvvn/AljRRQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=N3DEoBrVTvepfG7eELOpBX0i65lBs+4iV++vcoly3/ruNZDU+tqovSnDxyr7sbRo1 35sKD22PDyNbYGWbecHRM+dULhr8I79qjsKh9GUjkY6+crT7SooaGY3laQe50RV/6N BfeU6oPsvpJCV4q+0Q8r3JrpecKHUvL4dMLlsRqIKRh7nnLHbHbiLea4lL8iqARw/I ollZcxh1raysJc7UMpSvRYEssV0/yNC0QyW2ZIbYDgntcVKw55Oy/6JI8KkdfKP4ku dhwucTMr/vF7oLnNTPINvA80pFUXif51Gxd6SVUZbf92gcQdraW5VHBq1MgCEzUsg7 GHRyabyqksSUQ== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 9/9] btrfs: remove do_list variable at btrfs_clear_delalloc_extent() Date: Fri, 9 Feb 2024 18:00:51 +0000 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 "do_list" variable has a rather confusing name, so remove it and directly use btrfs_is_free_space_inode() instead. Signed-off-by: Filipe Manana Reviewed-by: Qu Wenruo --- fs/btrfs/inode.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 17b6ab71584a..5bb61d4aa2cb 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2525,7 +2525,6 @@ void btrfs_clear_delalloc_extent(struct btrfs_inode *inode, if ((state->state & EXTENT_DELALLOC) && (bits & EXTENT_DELALLOC)) { struct btrfs_root *root = inode->root; u64 new_delalloc_bytes; - bool do_list = !btrfs_is_free_space_inode(inode); spin_lock(&inode->lock); btrfs_mod_outstanding_extents(inode, -num_extents); @@ -2545,7 +2544,8 @@ void btrfs_clear_delalloc_extent(struct btrfs_inode *inode, return; if (!btrfs_is_data_reloc_root(root) && - do_list && !(state->state & EXTENT_NORESERVE) && + !btrfs_is_free_space_inode(inode) && + !(state->state & EXTENT_NORESERVE) && (bits & EXTENT_CLEAR_DATA_RESV)) btrfs_free_reserved_data_space_noquota(fs_info, len); @@ -2562,7 +2562,7 @@ void btrfs_clear_delalloc_extent(struct btrfs_inode *inode, * and are therefore protected against concurrent calls of this * function and btrfs_set_delalloc_extent(). */ - if (do_list && new_delalloc_bytes == 0) + if (!btrfs_is_free_space_inode(inode) && new_delalloc_bytes == 0) btrfs_del_delalloc_inode(inode); }