From patchwork Wed Jul 26 15:56:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13328312 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 185E9C41513 for ; Wed, 26 Jul 2023 15:57:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233643AbjGZP5U (ORCPT ); Wed, 26 Jul 2023 11:57:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232684AbjGZP5U (ORCPT ); Wed, 26 Jul 2023 11:57:20 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42472212B for ; Wed, 26 Jul 2023 08:57:19 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id CABD161A21 for ; Wed, 26 Jul 2023 15:57:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0F5EC433C9 for ; Wed, 26 Jul 2023 15:57:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690387038; bh=eOt4UOjAKikqABXmdlpsoRa/3r7NrEXpHWtjIynBjTw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=gPMV/EjgdQrBF/aOUlWWkmGx/x41VM6SE/fF5wy0v/YfUVgWTAzFU4b1EAyOgDFyi 7ZMAFMArbb7ZAKFEVi2bM1FJyDOwT8xL8yXrgUtNmPsMBiqJpiaeqkgblNZaAq583Z UODEO1lfr7+e904HcghE9p0jYHG3hwGYO6TGIbjEW5Ra6k5cn2sLCsfS7wOgkhzyli /BWU/kd3i/zyjipggWuGRg+Wmo4Rw5bwJrUJUm5wq1/9HJlBqUpvT95hA5NDtO+xxi Hn8hMtKqeue3+LlpbofRhtr+pu8QNZ7k5jAx5AvsmqDnAa3kbBT9ClnLgw1nJoubbk 5Mk308hIw3kPg== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 01/17] btrfs: don't start transaction when joining with TRANS_JOIN_NOSTART Date: Wed, 26 Jul 2023 16:56:57 +0100 Message-Id: <5abf5077aa70cc94346cc56b98fcd89ffde38efd.1690383587.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana When joining a transaction with TRANS_JOIN_NOSTART, if we don't find a running transaction we end up creating one. This goes against the purpose of TRANS_JOIN_NOSTART which is to join a running transaction if its state is at or below the state TRANS_STATE_COMMIT_START, otherwise return an -ENOENT error and don't start a new transaction. So fix this to not create a new transaction if there's no running transaction at or below that state. Fixes: a6d155d2e363 ("Btrfs: fix deadlock between fiemap and transaction commits") Signed-off-by: Filipe Manana --- fs/btrfs/transaction.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 815f61d6b506..6a2a12593183 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -292,10 +292,11 @@ static noinline int join_transaction(struct btrfs_fs_info *fs_info, spin_unlock(&fs_info->trans_lock); /* - * If we are ATTACH, we just want to catch the current transaction, - * and commit it. If there is no transaction, just return ENOENT. + * If we are ATTACH or TRANS_JOIN_NOSTART, we just want to catch the + * current transaction, and commit it. If there is no transaction, just + * return ENOENT. */ - if (type == TRANS_ATTACH) + if (type == TRANS_ATTACH || type == TRANS_JOIN_NOSTART) return -ENOENT; /* From patchwork Wed Jul 26 15:56:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13328313 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DC7FC001DC for ; Wed, 26 Jul 2023 15:57:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233918AbjGZP5W (ORCPT ); Wed, 26 Jul 2023 11:57:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232684AbjGZP5U (ORCPT ); Wed, 26 Jul 2023 11:57:20 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33AC92109 for ; Wed, 26 Jul 2023 08:57:20 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BD4E861AFE for ; Wed, 26 Jul 2023 15:57:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6373C433C7 for ; Wed, 26 Jul 2023 15:57:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690387039; bh=SrGPtFDNjcbHCCbLbqOkljbaKbEWwqxh3HAo0VDtYZ4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=uvlSMVVad+4TtQNJ58VjYFX9QPRhTWgfiAG6Egrd51Qp+eUuzv9piq2oSmz6ap59q 2R4fbKgYgxcaKX0xJmWI8XU3noLc9J/3eh7mX6ovTlHn4Izr3UMgDRNFpyrRfgqdz4 098F3nBxyeaQcZNQ3644o7kHHes0Gbh4jMGnIWZUqqDgy4dhPQKc7rrAjSrF8dGv0z 89x9xYhkqlrXtN3JE83nznoOu3hz+x6/3a5t5A7IMSyL3yuBPi5R/HrjQo7is/YHO5 6N1Nj01+eXKqX+9P5uv+3mw+a5FdChaA/CKUsqM9Ja8LKLgZdV0FDEWQ1HXqMUY5NK oqnU8vOX70Qbg== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 02/17] btrfs: update comment for btrfs_join_transaction_nostart() Date: Wed, 26 Jul 2023 16:56:58 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana Update the comment for btrfs_join_transaction_nostart() to be more clear about how it works and how it's different from btrfs_attach_transaction(). Signed-off-by: Filipe Manana --- fs/btrfs/transaction.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 6a2a12593183..ab09542f2170 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -799,7 +799,10 @@ struct btrfs_trans_handle *btrfs_join_transaction_spacecache(struct btrfs_root * /* * Similar to regular join but it never starts a transaction when none is - * running or after waiting for the current one to finish. + * running or when there's a running one at a state >= TRANS_STATE_UNBLOCKED. + * This is similar to btrfs_attach_transaction() but it allows the join to + * happen if the transaction commit already started but it's not yet in the + * "doing" phase (the state is < TRANS_STATE_COMMIT_DOING). */ struct btrfs_trans_handle *btrfs_join_transaction_nostart(struct btrfs_root *root) { From patchwork Wed Jul 26 15:56:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13328314 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07483C001DF for ; Wed, 26 Jul 2023 15:57:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234332AbjGZP5X (ORCPT ); Wed, 26 Jul 2023 11:57:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234010AbjGZP5W (ORCPT ); Wed, 26 Jul 2023 11:57:22 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F7E5212B for ; Wed, 26 Jul 2023 08:57:21 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B7E3561B9C for ; Wed, 26 Jul 2023 15:57:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9A765C433C9 for ; Wed, 26 Jul 2023 15:57:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690387040; bh=sinHIe0/aPeYxie4Z8WqvVnTpKpRzTGkYjoZZii1p88=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ScA1GYlTsQUi/VpMVZPJhJ4XIX0d2o0NNgA7NuId3HjCvZTYLKo8f7ZfjZmWorhzw PBcUTWz+YBuuMSPJaVRcaK2QMdtzbUFVYP1BbWvou/6d3i4jipEp53S7e5qixQDN8U 4Elxbz8iq5oHA9yZRW+XdxmIqLudEHPsyc+PaXCDeJB5zY1QTAcRIX2s/znTN0mvKQ XwFGG550gvphikNkpX3s+ciiedDqw1ZyhY5rgLtSS2g/X0Io0Df5Iv16o40WzFuxXc L+e+YFghRT9Fto9G6vroeCJxsbK6ZkR/cmqSNkALqtObQ8GqGX21lYkBUU77zHUa1D R4zsTLw6XsP5Q== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 03/17] btrfs: print target number of bytes when dumping free space Date: Wed, 26 Jul 2023 16:56:59 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana When dumping free space, with btrfs_dump_free_space(), we pass a bytes argument in order to count how many free space entries in the block group have a size greater than or equal to that number of bytes. We then print how many suitable entries we found, but we don't print the target number of bytes, we just say "bytes". Change the message to actually print the number of bytes, which makes debugging -ENOSPC issues a bit easier. Also sligthly change the odd grammar and terminology: the sentence is ending with 'is', which doesn't make sense, and the term 'blocks' is confusing as we are referring to free space entries within the block group's free space cache. Signed-off-by: Filipe Manana --- fs/btrfs/free-space-cache.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index bfc01352351c..cd5bfda2c259 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -2943,7 +2943,8 @@ void btrfs_dump_free_space(struct btrfs_block_group *block_group, btrfs_info(fs_info, "block group has cluster?: %s", list_empty(&block_group->cluster_list) ? "no" : "yes"); btrfs_info(fs_info, - "%d blocks of free space at or bigger than bytes is", count); + "%d free space entries at or bigger than %llu bytes", + count, bytes); } void btrfs_init_free_space_ctl(struct btrfs_block_group *block_group, From patchwork Wed Jul 26 15:57:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13328315 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 871C2C0015E for ; Wed, 26 Jul 2023 15:57:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234120AbjGZP5X (ORCPT ); Wed, 26 Jul 2023 11:57:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232684AbjGZP5W (ORCPT ); Wed, 26 Jul 2023 11:57:22 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E93382136 for ; Wed, 26 Jul 2023 08:57:21 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id AA88F61A21 for ; Wed, 26 Jul 2023 15:57:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 92471C433C7 for ; Wed, 26 Jul 2023 15:57:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690387041; bh=N5xEhTBBvdw+vV9C0+cXJDybHc7iTm+mPDZP5T5uuUs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=JjWgjxY/aW6g8GMbZzZh3N0Wwpna6x8Kncr3ie0Y536KwgkLr5tt5wQCz7bvDwOff 8BFtxc3gwsjoQZvOHrmDThA8++FT+05hvQNk4j/M3GPPmg1t5eQ+9S4D4nM90/WuyX GZicFvmTkNib/EdXogZ+S2FK2flWLJ9e7n3s6m/pS5Bv3Na+cr+lLTlLXrryGIV2Ip B3mnUR0Sr9VK1lEEHhEyrwywkDczK6EJPYecvzBU0UHeCu8SuYkxTVcP2d9LPzLL1X WBw3md04A6JO1I+F/XC9KQzbY/Ss3Y41F8Nz1Nut59BocXvRp6zsW1S+JnF7Nx4RAf 9Uxn79Ae8EFjg== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 04/17] btrfs: print block group super and delalloc bytes when dumping space info Date: Wed, 26 Jul 2023 16:57:00 +0100 Message-Id: <10c77455ed3cc49c334247cab26caf9c1479b322.1690383587.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana When dumping a space info's block groups, also print the number of bytes used for super blocks and delalloc. This is often useful for debugging -ENOSPC problems. Signed-off-by: Filipe Manana --- fs/btrfs/space-info.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index 75e7fa337e66..ae12a8a9cd12 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -525,10 +525,11 @@ void btrfs_dump_space_info(struct btrfs_fs_info *fs_info, list_for_each_entry(cache, &info->block_groups[index], list) { spin_lock(&cache->lock); btrfs_info(fs_info, - "block group %llu has %llu bytes, %llu used %llu pinned %llu reserved %llu zone_unusable %s", - cache->start, cache->length, cache->used, cache->pinned, - cache->reserved, cache->zone_unusable, - cache->ro ? "[readonly]" : ""); +"block group %llu has %llu bytes, %llu used %llu pinned %llu reserved %llu delalloc %llu super %llu zone_unusable %s", + cache->start, cache->length, cache->used, cache->pinned, + cache->reserved, cache->delalloc_bytes, + cache->bytes_super, cache->zone_unusable, + cache->ro ? "[readonly]" : ""); spin_unlock(&cache->lock); btrfs_dump_free_space(cache, bytes); } From patchwork Wed Jul 26 15:57:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13328316 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04EBDC001DC for ; Wed, 26 Jul 2023 15:57:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234496AbjGZP5Y (ORCPT ); Wed, 26 Jul 2023 11:57:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234407AbjGZP5X (ORCPT ); Wed, 26 Jul 2023 11:57:23 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09EBF1FDA for ; Wed, 26 Jul 2023 08:57:23 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9C61361AFE for ; Wed, 26 Jul 2023 15:57:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85D4CC433C8 for ; Wed, 26 Jul 2023 15:57:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690387042; bh=ygQtzzAhD4wbTmkKEqiPTUVAgXJxc3fa4SpmUORcqpI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=kEvaeTVhm7KwxsAO4uiRwWTC1oGpiVlg/fagWis//DNBP4cZTak5Crm3f1wI4JF92 cC7jlhblSN7oqMakLIqEdTMZEjQZF7UOB1s7C0724iaZWgAOYIREAS+0HHq7O6S/UT azxOYXx8fWZ8pszTwJ99zDwe86fbUI3PfjsMePwwMACgu8I37UZQoPlKsImhO4q3cr NOFhH35tBaiz37AH/4iBVm94bdXr+A2FLYkCwHbJ78VeZBMnqLxLY4EZYCnlE9ry2o RaH5AqzMWIXbBRs9CjUpiNNTzHJtKIcoeu0Z/ZUy1ZQ8aMgzourzyFZgIZ9vR9yV+0 b7IYhTFOuER4g== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 05/17] btrfs: print available space for a block group when dumping a space info Date: Wed, 26 Jul 2023 16:57:01 +0100 Message-Id: <2744218996a0f0d663b61bd005a2911c2e2d8801.1690383587.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana When dumping a space info, we iterate over all its block groups and then print their size and the amounts of bytes used, reserved, pinned, etc. When debugging -ENOSPC problems it's also useful to know how much space is available (free), so calculate that and print it as well. Signed-off-by: Filipe Manana --- fs/btrfs/space-info.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index ae12a8a9cd12..54d78e839c01 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -523,13 +523,18 @@ void btrfs_dump_space_info(struct btrfs_fs_info *fs_info, down_read(&info->groups_sem); again: list_for_each_entry(cache, &info->block_groups[index], list) { + u64 avail; + spin_lock(&cache->lock); + avail = cache->length - cache->used - cache->pinned - + cache->reserved - cache->delalloc_bytes - + cache->bytes_super - cache->zone_unusable; btrfs_info(fs_info, -"block group %llu has %llu bytes, %llu used %llu pinned %llu reserved %llu delalloc %llu super %llu zone_unusable %s", +"block group %llu has %llu bytes, %llu used %llu pinned %llu reserved %llu delalloc %llu super %llu zone_unusable (%llu bytes available) %s", cache->start, cache->length, cache->used, cache->pinned, cache->reserved, cache->delalloc_bytes, cache->bytes_super, cache->zone_unusable, - cache->ro ? "[readonly]" : ""); + avail, cache->ro ? "[readonly]" : ""); spin_unlock(&cache->lock); btrfs_dump_free_space(cache, bytes); } From patchwork Wed Jul 26 15:57:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13328317 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C5EB8C001DF for ; Wed, 26 Jul 2023 15:57:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233264AbjGZP5Z (ORCPT ); Wed, 26 Jul 2023 11:57:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232163AbjGZP5Y (ORCPT ); Wed, 26 Jul 2023 11:57:24 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08FE5100 for ; Wed, 26 Jul 2023 08:57:24 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 91CF961B9C for ; Wed, 26 Jul 2023 15:57:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A3FAC433C7 for ; Wed, 26 Jul 2023 15:57:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690387043; bh=3CvrCFtTtSApyEIMkrc/z16O0GuqEfTlsrH3h5jaWCQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=rSMJ9vJCLJza5rYtS49bUO4Dfe2mCzIl3e6hS+RZeRiVxGwI0zTsUvwvOLFUU52vD icNFaAj2jK3sc7JVbd4bnxbcBZfEKsEcaGeR6W6VWGEJmziGPpabSgRzFfiLjYAPLB H9eBgJ9Gv9s4pHwQfTKBIQPlm/fuNYwMRtf1hEwO11aO/47QOSRPNReJ798rY7WOPS B4RNmAAlUWcgUcMpHQlTmXvInlZxjLEbY7psUhENm4clDGF1G47zCJGa3wdRzvRsSO BFnfOnQkJu+NKVrBZ3mR/JEZTEEQvuLvuIQXGH4NnzNqEYSYb9ZhPSemDHtFkEmvbf 4r+Dm73VYNmSQ== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 06/17] btrfs: print available space across all block groups when dumping space info Date: Wed, 26 Jul 2023 16:57:02 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana When dumping a space info also sum the available space for all block groups and then print it. This often useful for debugging -ENOSPC related problems. Signed-off-by: Filipe Manana --- fs/btrfs/space-info.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index 54d78e839c01..de0044283e29 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -510,6 +510,7 @@ void btrfs_dump_space_info(struct btrfs_fs_info *fs_info, int dump_block_groups) { struct btrfs_block_group *cache; + u64 total_avail = 0; int index = 0; spin_lock(&info->lock); @@ -537,10 +538,13 @@ void btrfs_dump_space_info(struct btrfs_fs_info *fs_info, avail, cache->ro ? "[readonly]" : ""); spin_unlock(&cache->lock); btrfs_dump_free_space(cache, bytes); + total_avail += avail; } if (++index < BTRFS_NR_RAID_TYPES) goto again; up_read(&info->groups_sem); + + btrfs_info(fs_info, "%llu bytes available across all block groups", total_avail); } static inline u64 calc_reclaim_items_nr(const struct btrfs_fs_info *fs_info, From patchwork Wed Jul 26 15:57:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13328318 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73C70C001DC for ; Wed, 26 Jul 2023 15:58:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234535AbjGZP50 (ORCPT ); Wed, 26 Jul 2023 11:57:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234407AbjGZP5Z (ORCPT ); Wed, 26 Jul 2023 11:57:25 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED9C51FDA for ; Wed, 26 Jul 2023 08:57:24 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 844D461A21 for ; Wed, 26 Jul 2023 15:57:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E931C433C8 for ; Wed, 26 Jul 2023 15:57:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690387043; bh=P0A6zHjndstN7VnTAsaMIunGeVFJPx6EV03Ww7GywhU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Df8TSx3DWsCSmEjswF1jrojYWxWDRXjB5Lrquy/GAL7RXvZUQjk71Y6Mc9LjVH81Q Glk2xTxIagszlniSGnjvEfQRV1Oa+SVAhWIcmkypGQYnrYYOGM/Ux9Wszc9NElWqqf Fmnsae7pliHcYCUquTw/UxqLkUdfmTuhVtqcOTZeq3xNtP+0kZRE6dl7R0Cvv1f9s5 Ixr4CxTJK4ZI9lja/sRluMbxvDZC/7fROnUNvgSIdydYk5ZzaTddkyo/OnM8gOd7eG da7orN9M8jAjJ+NB3UmjSZoBK/snq24HiUuut8VAR3CQeiFn62IVEuGZrkka8a8ZaX 6/4mV/z6/texw== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 07/17] btrfs: don't steal space from global rsv after a transaction abort Date: Wed, 26 Jul 2023 16:57:03 +0100 Message-Id: <891cb10fe149b32e87a7297f9c45424f681b95d5.1690383587.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana When doing a priority metadata space reclaim, while we are going through the flush states and running their respective operations, it's possible that a transaction abort happened, for example when running delayed refs we hit -ENOSPC or in the critical section of transaction commit we failed with -ENOSPC or some other error. In these cases a transaction was aborted and the fs turned into error state. If that happened, then it makes no sense to steal from the global block reserve and return success to the caller if the stealing was successful - the caller will later get an error when attempting to modify the fs. Instead make the ticket fail if we have the fs in error state and don't attempt to steal from the global rsv, as it's not only it's pointless, it also simplifies debugging some -ENOSPC problems. Signed-off-by: Filipe Manana --- fs/btrfs/space-info.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index de0044283e29..5b1b71e029ad 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -1418,8 +1418,18 @@ static void priority_reclaim_metadata_space(struct btrfs_fs_info *fs_info, } } - /* Attempt to steal from the global rsv if we can. */ - if (!steal_from_global_rsv(fs_info, space_info, ticket)) { + /* + * Attempt to steal from the global rsv if we can, except if the fs was + * turned into error mode due to a transaction abort when flushing space + * above, in that case fail with -EROFS instead of returning success to + * the caller if we can steal from the global rsv - this is just to have + * caller fail immeditelly instead of later when trying to modify the + * fs, making it easier to debug -ENOSPC problems. + */ + if (BTRFS_FS_ERROR(fs_info)) { + ticket->error = -EROFS; + remove_ticket(space_info, ticket); + } else if (!steal_from_global_rsv(fs_info, space_info, ticket)) { ticket->error = -ENOSPC; remove_ticket(space_info, ticket); } From patchwork Wed Jul 26 15:57:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13328319 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EEB98C001DF for ; Wed, 26 Jul 2023 15:58:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234977AbjGZP6C (ORCPT ); Wed, 26 Jul 2023 11:58:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234556AbjGZP51 (ORCPT ); Wed, 26 Jul 2023 11:57:27 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E012D100 for ; Wed, 26 Jul 2023 08:57:25 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7E1D261B75 for ; Wed, 26 Jul 2023 15:57:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62A42C433C9 for ; Wed, 26 Jul 2023 15:57:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690387044; bh=4+n3KxUhVCZKLqWI3dldkFfStdBhGB7Ax1bGWpiopOM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=QjdqSeezjkXQpS8Rgdnke8EBSfgzR3D79e/V4rKXTCEg/8tkNjAIZrjIYiEUIG9Jb 6a/IJ6b8sP9yL/HJurdKkKl94C+d/shsuwR1k9gKHoIzNhCxVy8vo7Lu+3JzEBoWKC 8ChL/9rY4D5kHPh28eUpAexFaz5WGVHXrcpV1t45h4VCraMpp4OTMxb5w7ivG81g5N qKkEQHgG2cEuVbK8/xP1Q0jpB67elKEHQBiWdVARANZAlhzGxfuzOgDffRtuNNX4nN 1VqY0dEq+K2JDd1+IrMf8HLu6t4ZpAljFcBZ5gIJ+SzZRQ44CGWQTk6qkbbE7tnIdG /b11RW+Db7Efg== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 08/17] btrfs: store the error that turned the fs into error state Date: Wed, 26 Jul 2023 16:57:04 +0100 Message-Id: <3b4d1fdb1ce36910c59c58ec6b63c8abcba5da04.1690383587.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana Currently when we turn the fs into an error state, typically after a transaction abort, we don't store the error anywhere, we just set a bit (BTRFS_FS_STATE_ERROR) at struct btrfs_fs_info::fs_state to signal the error state. There are cases where it would be useful to have access to the specific error in order to provide a more meaningful error to users/applications. This change adds a member to struct btrfs_fs_info to store the error and removes the BTRFS_FS_STATE_ERROR bit. When there's no error, the new member (fs_error) has a value of 0, otherwise its value is a negative errno value. Followup changes will make use of this new member. Signed-off-by: Filipe Manana --- fs/btrfs/disk-io.c | 2 +- fs/btrfs/fs.h | 12 ++++++++---- fs/btrfs/messages.c | 10 +++++++--- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index b4495d4c1533..cad79d4eecdf 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -3211,7 +3211,7 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device /* check FS state, whether FS is broken. */ if (btrfs_super_flags(disk_super) & BTRFS_SUPER_FLAG_ERROR) - set_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state); + WRITE_ONCE(fs_info->fs_error, -EUCLEAN); /* * In the long term, we'll store the compression type in the super diff --git a/fs/btrfs/fs.h b/fs/btrfs/fs.h index 203d2a267828..ef07c6c252d8 100644 --- a/fs/btrfs/fs.h +++ b/fs/btrfs/fs.h @@ -46,8 +46,6 @@ static_assert(sizeof(struct btrfs_super_block) == BTRFS_SUPER_INFO_SIZE); * Runtime (in-memory) states of filesystem */ enum { - /* Global indicator of serious filesystem errors */ - BTRFS_FS_STATE_ERROR, /* * Filesystem is being remounted, allow to skip some operations, like * defrag @@ -686,6 +684,12 @@ struct btrfs_fs_info { bool qgroup_rescan_running; u8 qgroup_drop_subtree_thres; + /* + * If this is not 0, then it indicates a serious filesystem error has + * happened and it contains that error (negative errno value). + */ + int fs_error; + /* Filesystem state */ unsigned long fs_state; @@ -962,8 +966,8 @@ static inline void btrfs_wake_unfinished_drop(struct btrfs_fs_info *fs_info) clear_and_wake_up_bit(BTRFS_FS_UNFINISHED_DROPS, &fs_info->flags); } -#define BTRFS_FS_ERROR(fs_info) (unlikely(test_bit(BTRFS_FS_STATE_ERROR, \ - &(fs_info)->fs_state))) +#define BTRFS_FS_ERROR(fs_info) (READ_ONCE((fs_info)->fs_error)) + #define BTRFS_FS_LOG_CLEANUP_ERROR(fs_info) \ (unlikely(test_bit(BTRFS_FS_STATE_LOG_CLEANUP_ERROR, \ &(fs_info)->fs_state))) diff --git a/fs/btrfs/messages.c b/fs/btrfs/messages.c index 23fc11af498a..e3c9d2706341 100644 --- a/fs/btrfs/messages.c +++ b/fs/btrfs/messages.c @@ -10,14 +10,13 @@ #ifdef CONFIG_PRINTK #define STATE_STRING_PREFACE ": state " -#define STATE_STRING_BUF_LEN (sizeof(STATE_STRING_PREFACE) + BTRFS_FS_STATE_COUNT) +#define STATE_STRING_BUF_LEN (sizeof(STATE_STRING_PREFACE) + BTRFS_FS_STATE_COUNT + 1) /* * Characters to print to indicate error conditions or uncommon filesystem state. * RO is not an error. */ static const char fs_state_chars[] = { - [BTRFS_FS_STATE_ERROR] = 'E', [BTRFS_FS_STATE_REMOUNTING] = 'M', [BTRFS_FS_STATE_RO] = 0, [BTRFS_FS_STATE_TRANS_ABORTED] = 'A', @@ -37,6 +36,11 @@ static void btrfs_state_to_string(const struct btrfs_fs_info *info, char *buf) memcpy(curr, STATE_STRING_PREFACE, sizeof(STATE_STRING_PREFACE)); curr += sizeof(STATE_STRING_PREFACE) - 1; + if (BTRFS_FS_ERROR(info)) { + *curr++ = 'E'; + states_printed = true; + } + for_each_set_bit(bit, &fs_state, sizeof(fs_state)) { WARN_ON_ONCE(bit >= BTRFS_FS_STATE_COUNT); if ((bit < BTRFS_FS_STATE_COUNT) && fs_state_chars[bit]) { @@ -155,7 +159,7 @@ void __btrfs_handle_fs_error(struct btrfs_fs_info *fs_info, const char *function * Today we only save the error info to memory. Long term we'll also * send it down to the disk. */ - set_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state); + WRITE_ONCE(fs_info->fs_error, errno); /* Don't go through full error handling during mount. */ if (!(sb->s_flags & SB_BORN)) From patchwork Wed Jul 26 15:57:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13328321 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31615C001DC for ; Wed, 26 Jul 2023 15:58:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234703AbjGZP6B (ORCPT ); Wed, 26 Jul 2023 11:58:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234407AbjGZP52 (ORCPT ); Wed, 26 Jul 2023 11:57:28 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CE022109 for ; Wed, 26 Jul 2023 08:57:26 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6D3C761B5F for ; Wed, 26 Jul 2023 15:57:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 583A1C433C8 for ; Wed, 26 Jul 2023 15:57:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690387045; bh=BOmFZXlOZMj/FxLX0T8nzZe2ZJXFKPM9+twDbS3bD64=; h=From:To:Subject:Date:In-Reply-To:References:From; b=t0uUVH2T6Eime0AYF1IzrTcM9ZWL5zJ/BFfXJhmSJghisnxWL+MxGgCtObHk5pMuB dXhDQyGvjRzh+AQr5J9LwNZxH/dF8jiJvZ9/3lrzw0XKm/kcc3hKkMdECw122afoZV JGeBawZQRwBLJFyGSBL6qSTmonF6m+1L87WGD8G+tpoUJys+XXdDcr57vQhDZE6+AD ReSiT9GDb4LvGjyUPxKIaiK1akmj1Snrl+vnSAQ9FsYH5lyWo55VGC+/x6s3H8cYTv seFENjW9tY9u2latoFHBoGbVpvvExJMx44kUOjCvqCOS5BTBPXohupPV1if9tMGL20 QU3rBqFIHtz7g== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 09/17] btrfs: return real error when orphan cleanup fails due to a transaction abort Date: Wed, 26 Jul 2023 16:57:05 +0100 Message-Id: <9a483dadd6919566155fc44cbc4bf99dc794b31d.1690383587.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana During mount we will call btrfs_orphan_cleanup() to remove any inodes that were previously deleted (have a link count of 0) but for which we were not able before to remove their items from the subvolume tree. The removal of the items will happen by triggering eviction, when we do the final iput() on them at btrfs_orphan_cleanup(), which will end in the loop at btrfs_evict_inode() that truncates inode items. In a dire situation we may have a transaction abort due to -ENOSPC when attempting to truncate the inode items, and in that case the orphan item (key type BTRFS_ORPHAN_ITEM_KEY) will remain in the subvolume tree and when we hit the next iteration of the while loop at btrfs_orphan_cleanup() we will find the same orphan item as before, and then we will return -EINVAL from btrfs_orphan_cleanup() through the following if statement: if (found_key.offset == last_objectid) { btrfs_err(fs_info, "Error removing orphan entry, stopping orphan cleanup"); ret = -EINVAL; goto out; } This makes the mount operation fail with -EINVAL, when it should have been -ENOSPC. This is confusing because -EINVAL might lead a user into thinking it provided invalid mount options for example. An example where this happens: $ mount test.img /mnt mount: /mnt: wrong fs type, bad option, bad superblock on /dev/loop0, missing codepage or helper program, or other error. $ dmesg [ 2542.356934] BTRFS: device fsid 977fff75-1181-4d2b-a739-384fa710d16e devid 1 transid 47409973 /dev/loop0 scanned by mount (4459) [ 2542.357451] BTRFS info (device loop0): using crc32c (crc32c-intel) checksum algorithm [ 2542.357461] BTRFS info (device loop0): disk space caching is enabled [ 2542.742287] BTRFS info (device loop0): auto enabling async discard [ 2542.764554] BTRFS info (device loop0): checking UUID tree [ 2551.743065] ------------[ cut here ]------------ [ 2551.743068] BTRFS: Transaction aborted (error -28) [ 2551.743149] WARNING: CPU: 7 PID: 215 at fs/btrfs/block-group.c:3494 btrfs_write_dirty_block_groups+0x397/0x3d0 [btrfs] [ 2551.743311] Modules linked in: btrfs blake2b_generic (...) [ 2551.743353] CPU: 7 PID: 215 Comm: kworker/u24:5 Not tainted 6.4.0-rc6-btrfs-next-134+ #1 [ 2551.743356] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.2-0-gea1b7a073390-prebuilt.qemu.org 04/01/2014 [ 2551.743357] Workqueue: events_unbound btrfs_async_reclaim_metadata_space [btrfs] [ 2551.743405] RIP: 0010:btrfs_write_dirty_block_groups+0x397/0x3d0 [btrfs] [ 2551.743449] Code: 8b 43 0c (...) [ 2551.743451] RSP: 0018:ffff982c005a7c40 EFLAGS: 00010286 [ 2551.743452] RAX: 0000000000000000 RBX: ffff88fc6e44b400 RCX: 0000000000000000 [ 2551.743453] RDX: 0000000000000002 RSI: ffffffff8dff0878 RDI: 00000000ffffffff [ 2551.743454] RBP: ffff88fc51817208 R08: 0000000000000000 R09: ffff982c005a7ae0 [ 2551.743455] R10: 0000000000000001 R11: 0000000000000001 R12: ffff88fc43d2e570 [ 2551.743456] R13: ffff88fc43d2e400 R14: ffff88fc8fb08ee0 R15: ffff88fc6e44b530 [ 2551.743457] FS: 0000000000000000(0000) GS:ffff89035fbc0000(0000) knlGS:0000000000000000 [ 2551.743458] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 2551.743459] CR2: 00007fa8cdf2f6f4 CR3: 0000000124850003 CR4: 0000000000370ee0 [ 2551.743462] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 2551.743463] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [ 2551.743464] Call Trace: [ 2551.743472] [ 2551.743474] ? __warn+0x80/0x130 [ 2551.743478] ? btrfs_write_dirty_block_groups+0x397/0x3d0 [btrfs] [ 2551.743520] ? report_bug+0x1f4/0x200 [ 2551.743523] ? handle_bug+0x42/0x70 [ 2551.743526] ? exc_invalid_op+0x14/0x70 [ 2551.743528] ? asm_exc_invalid_op+0x16/0x20 [ 2551.743532] ? btrfs_write_dirty_block_groups+0x397/0x3d0 [btrfs] [ 2551.743574] ? _raw_spin_unlock+0x15/0x30 [ 2551.743576] ? btrfs_run_delayed_refs+0x1bd/0x200 [btrfs] [ 2551.743609] commit_cowonly_roots+0x1e9/0x260 [btrfs] [ 2551.743652] btrfs_commit_transaction+0x42e/0xfa0 [btrfs] [ 2551.743693] ? __pfx_autoremove_wake_function+0x10/0x10 [ 2551.743697] flush_space+0xf1/0x5d0 [btrfs] [ 2551.743743] ? _raw_spin_unlock+0x15/0x30 [ 2551.743745] ? finish_task_switch+0x91/0x2a0 [ 2551.743748] ? _raw_spin_unlock+0x15/0x30 [ 2551.743750] ? btrfs_get_alloc_profile+0xc9/0x1f0 [btrfs] [ 2551.743793] btrfs_async_reclaim_metadata_space+0xe1/0x230 [btrfs] [ 2551.743837] process_one_work+0x1d9/0x3e0 [ 2551.743844] worker_thread+0x4a/0x3b0 [ 2551.743847] ? __pfx_worker_thread+0x10/0x10 [ 2551.743849] kthread+0xee/0x120 [ 2551.743852] ? __pfx_kthread+0x10/0x10 [ 2551.743854] ret_from_fork+0x29/0x50 [ 2551.743860] [ 2551.743861] ---[ end trace 0000000000000000 ]--- [ 2551.743863] BTRFS info (device loop0: state A): dumping space info: [ 2551.743866] BTRFS info (device loop0: state A): space_info DATA has 126976 free, is full [ 2551.743868] BTRFS info (device loop0: state A): space_info total=13458472960, used=13458137088, pinned=143360, reserved=0, may_use=0, readonly=65536 zone_unusable=0 [ 2551.743870] BTRFS info (device loop0: state A): space_info METADATA has -51625984 free, is full [ 2551.743872] BTRFS info (device loop0: state A): space_info total=771751936, used=770146304, pinned=1605632, reserved=0, may_use=51625984, readonly=0 zone_unusable=0 [ 2551.743874] BTRFS info (device loop0: state A): space_info SYSTEM has 14663680 free, is not full [ 2551.743875] BTRFS info (device loop0: state A): space_info total=14680064, used=16384, pinned=0, reserved=0, may_use=0, readonly=0 zone_unusable=0 [ 2551.743877] BTRFS info (device loop0: state A): global_block_rsv: size 53231616 reserved 51544064 [ 2551.743878] BTRFS info (device loop0: state A): trans_block_rsv: size 0 reserved 0 [ 2551.743879] BTRFS info (device loop0: state A): chunk_block_rsv: size 0 reserved 0 [ 2551.743880] BTRFS info (device loop0: state A): delayed_block_rsv: size 0 reserved 0 [ 2551.743881] BTRFS info (device loop0: state A): delayed_refs_rsv: size 786432 reserved 0 [ 2551.743886] BTRFS: error (device loop0: state A) in btrfs_write_dirty_block_groups:3494: errno=-28 No space left [ 2551.743911] BTRFS info (device loop0: state EA): forced readonly [ 2551.743951] BTRFS warning (device loop0: state EA): could not allocate space for delete; will truncate on mount [ 2551.743962] BTRFS error (device loop0: state EA): Error removing orphan entry, stopping orphan cleanup [ 2551.743973] BTRFS warning (device loop0: state EA): Skipping commit of aborted transaction. [ 2551.743989] BTRFS error (device loop0: state EA): could not do orphan cleanup -22 So make the btrfs_orphan_cleanup() return the value of BTRFS_FS_ERROR(), if it's set, and -EINVAL otherwise. For that same example, after this change, the mount operation fails with -ENOSPC: $ mount test.img /mnt mount: /mnt: mount(2) system call failed: No space left on device. Signed-off-by: Filipe Manana --- fs/btrfs/inode.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 6daaa4fd69f2..c268c5861a24 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -3668,9 +3668,16 @@ int btrfs_orphan_cleanup(struct btrfs_root *root) */ if (found_key.offset == last_objectid) { + /* + * We found the same inode as before. This means we were + * not able to remove its items via eviction triggered + * by an iput(). A transaction abort may have happened, + * due to -ENOSPC for example, so try to grab the error + * that lead to a transaction abort, if any. + */ btrfs_err(fs_info, "Error removing orphan entry, stopping orphan cleanup"); - ret = -EINVAL; + ret = BTRFS_FS_ERROR(fs_info) ?: -EINVAL; goto out; } From patchwork Wed Jul 26 15:57:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13328322 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78D7AC04FE1 for ; Wed, 26 Jul 2023 15:58:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234985AbjGZP6F (ORCPT ); Wed, 26 Jul 2023 11:58:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234559AbjGZP52 (ORCPT ); Wed, 26 Jul 2023 11:57:28 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86E73212A for ; Wed, 26 Jul 2023 08:57:27 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 67F5561BA2 for ; Wed, 26 Jul 2023 15:57:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4C846C433C7 for ; Wed, 26 Jul 2023 15:57:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690387046; bh=kT9HJpnHdK9dOE2RzMRjqhMzZnUlmWYYtlvy65yFcMo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=rfngJjgZoXfEh3bCVMwe/x7ThnNFfS3IySxsh8TbhWpddDqnPts3tUeHXkIdPUlAs eQ0lD0yYWo/1p4P8/a7Zkc/KMyD9h8QHrA4BGTgtJK8yC9keSvpxNLzlJlmQBAeL9f OlKM3E9kepvO8IUr15kjG7v0XODpV+UO83POaHXekrdjrg/nIje2X5Utalq8qoLrS9 /qe+t2E11pea1rwGg6euv8vGRBv6PC1pSBZfbG/5nHgiNTL48vz+950XZpfg/pLuL/ sj1LaCBL/e3oF6CuHB29V1VZoUrpzoflXwqBUbheJEo1vUq3s+RH1m48GnmPGiDZOE IcuLbKhL9cUJA== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 10/17] btrfs: fail priority metadata ticket with real fs error Date: Wed, 26 Jul 2023 16:57:06 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana At priority_reclaim_metadata_space(), if we were not able to satisfy the the ticket after going through the various flushing states and we notice the fs went into an error state, likely due to a transaction abort during the flushing, set the ticket's error to the error that caused the transaction abort instead of an unconditional -EROFS. Signed-off-by: Filipe Manana --- fs/btrfs/space-info.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index 5b1b71e029ad..be5ce209b918 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -1421,13 +1421,13 @@ static void priority_reclaim_metadata_space(struct btrfs_fs_info *fs_info, /* * Attempt to steal from the global rsv if we can, except if the fs was * turned into error mode due to a transaction abort when flushing space - * above, in that case fail with -EROFS instead of returning success to - * the caller if we can steal from the global rsv - this is just to have - * caller fail immeditelly instead of later when trying to modify the - * fs, making it easier to debug -ENOSPC problems. + * above, in that case fail with the abort error instead of returning + * success to the caller if we can steal from the global rsv - this is + * just to have caller fail immeditelly instead of later when trying to + * modify the fs, making it easier to debug -ENOSPC problems. */ if (BTRFS_FS_ERROR(fs_info)) { - ticket->error = -EROFS; + ticket->error = BTRFS_FS_ERROR(fs_info); remove_ticket(space_info, ticket); } else if (!steal_from_global_rsv(fs_info, space_info, ticket)) { ticket->error = -ENOSPC; From patchwork Wed Jul 26 15:57:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13328323 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69098C04FDF for ; Wed, 26 Jul 2023 15:58:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234984AbjGZP6E (ORCPT ); Wed, 26 Jul 2023 11:58:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234740AbjGZP53 (ORCPT ); Wed, 26 Jul 2023 11:57:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CAEE2136 for ; Wed, 26 Jul 2023 08:57:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5CB9261BA6 for ; Wed, 26 Jul 2023 15:57:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40D83C433CB for ; Wed, 26 Jul 2023 15:57:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690387047; bh=QqqVnOJ/3/tMBHY//DFNWBzTWtHy6dcSDDwyZB4OPns=; h=From:To:Subject:Date:In-Reply-To:References:From; b=JLHDtx8GeEqr43mLKrjHlnVePPQBr2pjQU6yyIi8iosxxj2RTj87ynMipvSscvwhN 5q1hvEn1+lWqj/+1uJcCLQZQvzVd/q2UAcxEx4Dg4k0Vr+nFKFootqAk1jnuLOBi8/ rXbLV0OxNcQsx9v5AgU3G5ZNe8JvjzYT7hnQGvhPfZhV2OfDehs/OxUi9/3yAEoSI4 UTpVVK2hp1QJjBrkXEtnZupW2HOhKdFL4irueFoBt0kl6M80Sxyw521l897t3d5ZA+ dScPQM59lrlN1h4Eegisv7xHYykEeOO96nKSHBBeSGsHrB7hapuXGQ3+quqUDqujgi KnafLiCf4l27w== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 11/17] btrfs: make btrfs_cleanup_fs_roots() static Date: Wed, 26 Jul 2023 16:57:07 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana btrfs_cleanup_fs_roots() is not used outside disk-io.c, so make it static, remove its prototype from disk-io.h and move its definition above the where it's used in disk-io.c Signed-off-by: Filipe Manana --- fs/btrfs/disk-io.c | 100 ++++++++++++++++++++++----------------------- fs/btrfs/disk-io.h | 1 - 2 files changed, 50 insertions(+), 51 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index cad79d4eecdf..da51e5750443 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2858,6 +2858,56 @@ static int btrfs_check_uuid_tree(struct btrfs_fs_info *fs_info) return 0; } +static int btrfs_cleanup_fs_roots(struct btrfs_fs_info *fs_info) +{ + u64 root_objectid = 0; + struct btrfs_root *gang[8]; + int i = 0; + int err = 0; + unsigned int ret = 0; + + while (1) { + spin_lock(&fs_info->fs_roots_radix_lock); + ret = radix_tree_gang_lookup(&fs_info->fs_roots_radix, + (void **)gang, root_objectid, + ARRAY_SIZE(gang)); + if (!ret) { + spin_unlock(&fs_info->fs_roots_radix_lock); + break; + } + root_objectid = gang[ret - 1]->root_key.objectid + 1; + + for (i = 0; i < ret; i++) { + /* Avoid to grab roots in dead_roots. */ + if (btrfs_root_refs(&gang[i]->root_item) == 0) { + gang[i] = NULL; + continue; + } + /* Grab all the search result for later use. */ + gang[i] = btrfs_grab_root(gang[i]); + } + spin_unlock(&fs_info->fs_roots_radix_lock); + + for (i = 0; i < ret; i++) { + if (!gang[i]) + continue; + root_objectid = gang[i]->root_key.objectid; + err = btrfs_orphan_cleanup(gang[i]); + if (err) + goto out; + btrfs_put_root(gang[i]); + } + root_objectid++; + } +out: + /* Release the uncleaned roots due to error. */ + for (; i < ret; i++) { + if (gang[i]) + btrfs_put_root(gang[i]); + } + return err; +} + /* * Some options only have meaning at mount time and shouldn't persist across * remounts, or be displayed. Clear these at the end of mount and remount @@ -4125,56 +4175,6 @@ void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info, btrfs_put_root(root); } -int btrfs_cleanup_fs_roots(struct btrfs_fs_info *fs_info) -{ - u64 root_objectid = 0; - struct btrfs_root *gang[8]; - int i = 0; - int err = 0; - unsigned int ret = 0; - - while (1) { - spin_lock(&fs_info->fs_roots_radix_lock); - ret = radix_tree_gang_lookup(&fs_info->fs_roots_radix, - (void **)gang, root_objectid, - ARRAY_SIZE(gang)); - if (!ret) { - spin_unlock(&fs_info->fs_roots_radix_lock); - break; - } - root_objectid = gang[ret - 1]->root_key.objectid + 1; - - for (i = 0; i < ret; i++) { - /* Avoid to grab roots in dead_roots */ - if (btrfs_root_refs(&gang[i]->root_item) == 0) { - gang[i] = NULL; - continue; - } - /* grab all the search result for later use */ - gang[i] = btrfs_grab_root(gang[i]); - } - spin_unlock(&fs_info->fs_roots_radix_lock); - - for (i = 0; i < ret; i++) { - if (!gang[i]) - continue; - root_objectid = gang[i]->root_key.objectid; - err = btrfs_orphan_cleanup(gang[i]); - if (err) - goto out; - btrfs_put_root(gang[i]); - } - root_objectid++; - } -out: - /* release the uncleaned roots due to error */ - for (; i < ret; i++) { - if (gang[i]) - btrfs_put_root(gang[i]); - } - return err; -} - int btrfs_commit_super(struct btrfs_fs_info *fs_info) { struct btrfs_root *root = fs_info->tree_root; diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h index b03767f4d7ed..02b645744a82 100644 --- a/fs/btrfs/disk-io.h +++ b/fs/btrfs/disk-io.h @@ -77,7 +77,6 @@ struct btrfs_root *btrfs_extent_root(struct btrfs_fs_info *fs_info, u64 bytenr); struct btrfs_root *btrfs_block_group_root(struct btrfs_fs_info *fs_info); void btrfs_free_fs_info(struct btrfs_fs_info *fs_info); -int btrfs_cleanup_fs_roots(struct btrfs_fs_info *fs_info); void btrfs_btree_balance_dirty(struct btrfs_fs_info *fs_info); void btrfs_btree_balance_dirty_nodelay(struct btrfs_fs_info *fs_info); void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info, From patchwork Wed Jul 26 15:57:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13328320 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 476CCC04E69 for ; Wed, 26 Jul 2023 15:58:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234982AbjGZP6D (ORCPT ); Wed, 26 Jul 2023 11:58:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234878AbjGZP5a (ORCPT ); Wed, 26 Jul 2023 11:57:30 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 866122137 for ; Wed, 26 Jul 2023 08:57:29 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 49FC261B75 for ; Wed, 26 Jul 2023 15:57:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3585EC433C8 for ; Wed, 26 Jul 2023 15:57:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690387048; bh=48bl7ut0mASueaRqSiVX59DdtG0D2+ejmOYwNqAsQdk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ZxnbL8QiN1kLhkf9oCsvSP2qK1F1msxvweYQilHcJozKY/hdaMra7KVTBVRItKayu aw2bb6Iazbe+Qb/ofBJ6FQs/x0f1/oF3yZRvNvk/pYSpGip8zI6GhJba9rCIZySfbg +/3Z8mDRXTB45oT30CM6/jRulmwkM6vtKPi/wyeT790CBSJs8/qmPZNSO6jl8wq97z MGGvgvilD7RGv0y7PT9gqndsJg/L4gJhNfx45Z/SA/FL8+fPkmXNzpTTTlpY/KivAe zYBadwRLQfA+Xr9L8SNYN5/ALhYzQk3DUcczopLEIu384DsOGCJRi78MNq3M24SrJ5 XQs1aJv+6T0eQ== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 12/17] btrfs: make find_free_dev_extent() static Date: Wed, 26 Jul 2023 16:57:08 +0100 Message-Id: <01e3075133547a7e937f3e907218fd33a72528f7.1690383587.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana The function find_free_dev_extent() is only used within volumes.c, so make it static and remove its prototype from volumes.h. Signed-off-by: Filipe Manana --- fs/btrfs/volumes.c | 4 ++-- fs/btrfs/volumes.h | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 9df526c57c3a..e15d02f8520d 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1725,8 +1725,8 @@ static int find_free_dev_extent_start(struct btrfs_device *device, return ret; } -int find_free_dev_extent(struct btrfs_device *device, u64 num_bytes, - u64 *start, u64 *len) +static int find_free_dev_extent(struct btrfs_device *device, u64 num_bytes, + u64 *start, u64 *len) { /* FIXME use last free of some kind */ return find_free_dev_extent_start(device, num_bytes, 0, start, len); diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index b8c51f16ba86..a59898d51e9e 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -650,8 +650,6 @@ int btrfs_cancel_balance(struct btrfs_fs_info *fs_info); int btrfs_create_uuid_tree(struct btrfs_fs_info *fs_info); int btrfs_uuid_scan_kthread(void *data); bool btrfs_chunk_writeable(struct btrfs_fs_info *fs_info, u64 chunk_offset); -int find_free_dev_extent(struct btrfs_device *device, u64 num_bytes, - u64 *start, u64 *max_avail); void btrfs_dev_stat_inc_and_print(struct btrfs_device *dev, int index); int btrfs_get_dev_stats(struct btrfs_fs_info *fs_info, struct btrfs_ioctl_get_dev_stats *stats); From patchwork Wed Jul 26 15:57:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13328325 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87E0EC04FE0 for ; Wed, 26 Jul 2023 15:58:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234987AbjGZP6G (ORCPT ); Wed, 26 Jul 2023 11:58:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234954AbjGZP5b (ORCPT ); Wed, 26 Jul 2023 11:57:31 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A11D2100 for ; Wed, 26 Jul 2023 08:57:30 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3F6BA61A21 for ; Wed, 26 Jul 2023 15:57:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 29CA4C433CB for ; Wed, 26 Jul 2023 15:57:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690387049; bh=UqTyHnotFGChh78Tjzd0w6jJmADTq97xrTdADOACFkg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=sbhfkdPBtKW/olzs7iefVlXU4cGOgPYExRUAx3RQpTzgF+ZYgmpBGl60hpGtYxFRN 2rP7pJdii6N+vZoAdjRltZYR8as0XDAvKsdUiUlljSN93xBBwLPK5c1gPhxqOrZkdR 3LskZUDOqh+2GaPUZk3nIDy9/6sOoaWqrF3SOHKF3J9i8u52g3llYPhn29l9k9zlA/ eHoBEs72QSjSQDELZlIOyUVdEDKAOkAmMn4OKKieo4Sy6zo0X7ralrip3mbPkBXOO/ H2gy8B/uYfXvEAl+5ysYwr18O677sg51pbJRrgZgXscxfZIWQd7mmyvwU51M7Ejjaw k3yhCp5euVoCg== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 13/17] btrfs: merge find_free_dev_extent() and find_free_dev_extent_start() Date: Wed, 26 Jul 2023 16:57:09 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana There is no point in having find_free_dev_extent() because it's just a simple wrapper around find_free_dev_extent_start() which always passes a value of 0 for the search_start argument. Since there are no other callers of find_free_dev_extent_start(), remove find_free_dev_extent() and rename find_free_dev_extent_start() to find_free_dev_extent(), removing its search_start argument because it's always 0. Signed-off-by: Filipe Manana --- fs/btrfs/volumes.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index e15d02f8520d..6b044d61ef13 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1438,18 +1438,18 @@ static bool contains_pending_extent(struct btrfs_device *device, u64 *start, return false; } -static u64 dev_extent_search_start(struct btrfs_device *device, u64 start) +static u64 dev_extent_search_start(struct btrfs_device *device) { switch (device->fs_devices->chunk_alloc_policy) { case BTRFS_CHUNK_ALLOC_REGULAR: - return max_t(u64, start, BTRFS_DEVICE_RANGE_RESERVED); + return BTRFS_DEVICE_RANGE_RESERVED; case BTRFS_CHUNK_ALLOC_ZONED: /* * We don't care about the starting region like regular * allocator, because we anyway use/reserve the first two zones * for superblock logging. */ - return ALIGN(start, device->zone_info->zone_size); + return 0; default: BUG(); } @@ -1581,15 +1581,15 @@ static bool dev_extent_hole_check(struct btrfs_device *device, u64 *hole_start, * correct usable device space, as device extent freed in current transaction * is not reported as available. */ -static int find_free_dev_extent_start(struct btrfs_device *device, - u64 num_bytes, u64 search_start, u64 *start, - u64 *len) +static int find_free_dev_extent(struct btrfs_device *device, u64 num_bytes, + u64 *start, u64 *len) { struct btrfs_fs_info *fs_info = device->fs_info; struct btrfs_root *root = fs_info->dev_root; struct btrfs_key key; struct btrfs_dev_extent *dev_extent; struct btrfs_path *path; + u64 search_start; u64 hole_size; u64 max_hole_start; u64 max_hole_size; @@ -1599,7 +1599,7 @@ static int find_free_dev_extent_start(struct btrfs_device *device, int slot; struct extent_buffer *l; - search_start = dev_extent_search_start(device, search_start); + search_start = dev_extent_search_start(device); WARN_ON(device->zone_info && !IS_ALIGNED(num_bytes, device->zone_info->zone_size)); @@ -1725,13 +1725,6 @@ static int find_free_dev_extent_start(struct btrfs_device *device, return ret; } -static int find_free_dev_extent(struct btrfs_device *device, u64 num_bytes, - u64 *start, u64 *len) -{ - /* FIXME use last free of some kind */ - return find_free_dev_extent_start(device, num_bytes, 0, start, len); -} - static int btrfs_free_dev_extent(struct btrfs_trans_handle *trans, struct btrfs_device *device, u64 start, u64 *dev_extent_len) From patchwork Wed Jul 26 15:57:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13328324 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6795C3DA40 for ; Wed, 26 Jul 2023 15:58:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234988AbjGZP6H (ORCPT ); Wed, 26 Jul 2023 11:58:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234972AbjGZP5c (ORCPT ); Wed, 26 Jul 2023 11:57:32 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 962DD100 for ; Wed, 26 Jul 2023 08:57:31 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3318561B75 for ; Wed, 26 Jul 2023 15:57:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1EED8C433C9 for ; Wed, 26 Jul 2023 15:57:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690387050; bh=M/MEkHbyaSvP8N8A9mdoC0hnYDd/2CiyTdAoZZ2jGtc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=i9cX/6KugUqjzlNz1BmH8i2oG7hLKP6CbtF1uikR4CJcAXHcnNPdwgipCt4SiOLep CT+0OAjwVwMc8YxyaC7RLHRMdEVMxM8UpZiju6Q0AmVD0WPzYmuliBI/sa+tu3PlQ5 J+AQjz4CY3ojrRztEfUJVTVb7MVsaxUC/IQ/dleZepVBD3KhG+L3DHyYK6h7F8wXlC 1AF7hacB3pxrHf6P8Mm8OmQtClBefdBBqVso5PRqW2clpIo+nOSBHNEZE8TqvEnxAk fWw8GSD3bBS/fdgh2R9Kf27jbiGO6VnAaioA+n1/VKcDBHzmlVKEMruBvJrZslYH0E 53AbZr+5HSguw== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 14/17] btrfs: avoid starting new transaction when flushing delayed items and refs Date: Wed, 26 Jul 2023 16:57:10 +0100 Message-Id: <8d7f2507c523dddd0de8be3a5ae24cbc06836201.1690383587.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana When flushing space we join a transaction to flush delayed items and delayed references, in order to try to release space. However using btrfs_join_transaction() not only joins an existing transaction as well as it starts a new transaction if there is none open. If there is no transaction open, we don't have neither delayed items nor delayed references, so creating a new transaction is a waste of time, IO and creates an unnecessary rotation of the backup roots without gaining any benefits (including releasing space). So use btrfs_join_transaction_nostart() when attempting to flush delayed items and references. Signed-off-by: Filipe Manana --- fs/btrfs/space-info.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index be5ce209b918..2db92a201697 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -725,9 +725,11 @@ static void flush_space(struct btrfs_fs_info *fs_info, else nr = -1; - trans = btrfs_join_transaction(root); + trans = btrfs_join_transaction_nostart(root); if (IS_ERR(trans)) { ret = PTR_ERR(trans); + if (ret == -ENOENT) + ret = 0; break; } ret = btrfs_run_delayed_items_nr(trans, nr); @@ -743,9 +745,11 @@ static void flush_space(struct btrfs_fs_info *fs_info, break; case FLUSH_DELAYED_REFS_NR: case FLUSH_DELAYED_REFS: - trans = btrfs_join_transaction(root); + trans = btrfs_join_transaction_nostart(root); if (IS_ERR(trans)) { ret = PTR_ERR(trans); + if (ret == -ENOENT) + ret = 0; break; } if (state == FLUSH_DELAYED_REFS_NR) From patchwork Wed Jul 26 15:57:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13328326 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7180C05051 for ; Wed, 26 Jul 2023 15:58:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234989AbjGZP6H (ORCPT ); Wed, 26 Jul 2023 11:58:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234976AbjGZP5e (ORCPT ); Wed, 26 Jul 2023 11:57:34 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84FDF212B for ; Wed, 26 Jul 2023 08:57:32 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2331D61A21 for ; Wed, 26 Jul 2023 15:57:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12D68C433C8 for ; Wed, 26 Jul 2023 15:57:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690387051; bh=ci+v5pYze/SgbTOwXUWl2+aX/mtugpW70pThNVlwvEI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=bVw5mpUNvrTJYBRD9pql+Wo9Repn4hWCiJr2zjPwb22J8e0daK8SW8qnBL0xwBPeX xkyQFUjSX231cVoaDqA44phqArlB4sgYdnc2AAHjA+fQuTAGV1nyw1jbAb5Uh7DW0W aOKMfa5Ddy+wMecdkV+Ya1bI45drZlQtsYBd6QOX2gVHttWUHvdOBxH0eBo6HPNHRp 1YDLvq7pNLZNpNNQ53WLV4Gj4woG+NGWFBaQQIUqoeGSFII9f+IbbWFOd5UULZb4Vr 1HQMxjYU605PYnWcW8CoRlZyMsC+OWy2jKHH1jnYcCbrXfA6OGzIcVfz7L6ROH6O7u AUULXU1YO2y5Q== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 15/17] btrfs: avoid starting and committing empty transaction when flushing space Date: Wed, 26 Jul 2023 16:57:11 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana When flushing space and we are in the COMMIT_TRANS state, we join a transaction with btrfs_join_transaction() and then commit the returned transaction. However btrfs_join_transaction() starts a new transaction if there is none currently open, which is pointless since comitting a new, empty transaction, doesn't achieve anything, it only wastes time, IO and creates an unnecessary rotation of the backup roots. So use btrfs_attach_transaction_barrier() to avoid starting a new transaction. This also waits for any ongoing transaction that is committing (state >= TRANS_STATE_COMMIT_DOING) to fully complete, and therefore wait for all the extents that were pinned during the transaction's lifetime to be unpinned. Signed-off-by: Filipe Manana --- fs/btrfs/space-info.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index 2db92a201697..17c86db7b1b1 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -814,9 +814,18 @@ static void flush_space(struct btrfs_fs_info *fs_info, break; case COMMIT_TRANS: ASSERT(current->journal_info == NULL); - trans = btrfs_join_transaction(root); + /* + * We don't want to start a new transaction, just attach to the + * current one or wait it fully commits in case its commit is + * happening at the moment. Note: we don't use a nostart join + * because that does not wait for a transaction to fully commit + * (only for it to be unblocked, state TRANS_STATE_UNBLOCKED). + */ + trans = btrfs_attach_transaction_barrier(root); if (IS_ERR(trans)) { ret = PTR_ERR(trans); + if (ret == -ENOENT) + ret = 0; break; } ret = btrfs_commit_transaction(trans); From patchwork Wed Jul 26 15:57:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13328328 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA3CBC07E8A for ; Wed, 26 Jul 2023 15:58:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234990AbjGZP6I (ORCPT ); Wed, 26 Jul 2023 11:58:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234980AbjGZP5f (ORCPT ); Wed, 26 Jul 2023 11:57:35 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE88F1FDA for ; Wed, 26 Jul 2023 08:57:33 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1CFBC61B5F for ; Wed, 26 Jul 2023 15:57:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0620EC433C7 for ; Wed, 26 Jul 2023 15:57:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690387052; bh=7/Y4pGkDavGww+PdirIjvgUr0Stdn+nHSXolG87588M=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ZdDxAWXmte1y1sybFFZ84p7DZFNu4YmMk1Qy0JtMmtwbdd4UPcYj4XhnveKjASSnY rQ5SeRDD0mDeqzfoaNZZE0R2FvnMKzYv4TuKJfv0xrLPER18jFq1bXsx7pgOJYlmXG sVBKU35IN6ZK7r1ioxetEH9m+w8Ie26sEVeTAKhgBlsMoAHIrg1PAqPJZn9FehrMv5 PVcgV6UnZpEaeG0qUXWtys5Yzi8dpQzaLiOYxjelGZPyS3vwgmd29Dkx6dq8GlS7UK KoDLMdQ/lQ08uDTN4YdAejzNX4v2P4ucA2rertfrNG0RWzl3N34iDR4pqz+CIHf48d e8GqZwKsw1VKA== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 16/17] btrfs: avoid start and commit empty transaction when starting qgroup rescan Date: Wed, 26 Jul 2023 16:57:12 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana When starting a qgroup rescan, we try to join a running transaction, with btrfs_join_transaction(), and then commit the transaction. However using btrfs_join_transaction() will result in creating a new transaction in case there isn't any running or if there's an existing one already committing. This is pointless as we only need to attach to an existing one that is not committing and in case there's an existing one committing, wait for its commit to complete. Creating and committing an empty transaction is wasteful, pointless IO and unnecessary rotation of the backup roots. So use btrfs_attach_transaction_barrier() instead, to avoid creating and committing empty transactions. Signed-off-by: Filipe Manana --- fs/btrfs/qgroup.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index 2637d6b157ff..1ef60ea8f0bc 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -3590,15 +3590,16 @@ btrfs_qgroup_rescan(struct btrfs_fs_info *fs_info) * going to clear all tracking information for a clean start. */ - trans = btrfs_join_transaction(fs_info->fs_root); - if (IS_ERR(trans)) { + trans = btrfs_attach_transaction_barrier(fs_info->fs_root); + if (IS_ERR(trans) && trans != ERR_PTR(-ENOENT)) { fs_info->qgroup_flags &= ~BTRFS_QGROUP_STATUS_FLAG_RESCAN; return PTR_ERR(trans); - } - ret = btrfs_commit_transaction(trans); - if (ret) { - fs_info->qgroup_flags &= ~BTRFS_QGROUP_STATUS_FLAG_RESCAN; - return ret; + } else if (trans != ERR_PTR(-ENOENT)) { + ret = btrfs_commit_transaction(trans); + if (ret) { + fs_info->qgroup_flags &= ~BTRFS_QGROUP_STATUS_FLAG_RESCAN; + return ret; + } } qgroup_rescan_zero_tracking(fs_info); From patchwork Wed Jul 26 15:57:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13328327 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB79AC04FE2 for ; Wed, 26 Jul 2023 15:58:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234991AbjGZP6I (ORCPT ); Wed, 26 Jul 2023 11:58:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234981AbjGZP5f (ORCPT ); Wed, 26 Jul 2023 11:57:35 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34615213F for ; Wed, 26 Jul 2023 08:57:34 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1510661A21 for ; Wed, 26 Jul 2023 15:57:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EE6BDC433C8 for ; Wed, 26 Jul 2023 15:57:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690387053; bh=7nFN7Zzni+c1bl8gFdH55bcgmbG+dSp3MXqlggjBtJ4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=SS1XnTwk1ktEtCSfqIhR6pTWranieT6as+P0iD5URHDvzKTVViMT8UYIusQvEBSYL FiH+e25umB2vtgZUWZqzykF4//+SADkO9ZtTSi9+WOzoZSGyqCoPPvBMOwWQ/ibOPR t8alwxqE9P6RuTvzzsxBJc3We9VJCr85cUjqkDPOco6uPpNqIlyJipce6nI1J0T3Z7 aSoFpeC/uWQemxxc+y7vOxaygk3A/lprbMbnDN5rdWN/VduhKJaldaAxWZDHVrQ3Yp hsai9Xs/spi/E7Dn/BaxD613+FRLaSnNMCCKBcB73M6SUJf1FjnQSmzQECba6FIiHf +yLwjsRs/yquw== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 17/17] btrfs: avoid start and commit empty transaction when flushing qgroups Date: Wed, 26 Jul 2023 16:57:13 +0100 Message-Id: <347457df0613a568658e0bb4101ab19a06ba15db.1690383587.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana When flushing qgroups, we try to join a running transaction, with btrfs_join_transaction(), and then commit the transaction. However using btrfs_join_transaction() will result in creating a new transaction in case there isn't any running or if there's an existing one already committing. This is pointless as we only need to attach to an existing one that is not committing and in case there's an existing one committing, wait for its commit to complete. Creating and committing an empty transaction is wasteful, pointless IO and unnecessary rotation of the backup roots. So use btrfs_attach_transaction_barrier() instead, to avoid creating and committing empty transactions. Signed-off-by: Filipe Manana --- fs/btrfs/qgroup.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index 1ef60ea8f0bc..b99230db3c82 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -3758,9 +3758,11 @@ static int try_flush_qgroup(struct btrfs_root *root) goto out; btrfs_wait_ordered_extents(root, U64_MAX, 0, (u64)-1); - trans = btrfs_join_transaction(root); + trans = btrfs_attach_transaction_barrier(root); if (IS_ERR(trans)) { ret = PTR_ERR(trans); + if (ret == -ENOENT) + ret = 0; goto out; }