From patchwork Tue Mar 21 11:13:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13182589 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 D5522C74A5B for ; Tue, 21 Mar 2023 11:14:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229653AbjCULOc (ORCPT ); Tue, 21 Mar 2023 07:14:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229923AbjCULO3 (ORCPT ); Tue, 21 Mar 2023 07:14:29 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D725A3BC58 for ; Tue, 21 Mar 2023 04:14:09 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 3C7B8B815BA for ; Tue, 21 Mar 2023 11:14:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 682F5C433EF for ; Tue, 21 Mar 2023 11:14:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679397245; bh=HmerRVofitzbkyUGKaYJAIFhEbkl+Vn7mWF/AtdFqBc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=nTVxTlulUvj7o0ToxSbcNdPztBFq8wmGezefNQcxv/NqKEXBNvRvHw9G4HNHcwo4n 8GVazsPyX7NHXtSvFuU1LBA5NuIU6YxTHYT19QZQV6p4RJedLurW3TYS+IWRME8S11 zNhPkmjRIXen5E2ZIfUZPGb6j3ozv7MlA94AsEdLORBSfD/hm8ikJsQLlQjB23YlIz q8CcFPQcKosEV/ymsQCDIJoWEWQjtYZs5akDVyq3nPHd6UilL32aRy7TI6vEMZ8X+N T6rB7108nbLyTarANjSXzPH8B1nkVn/D8OmT4ZaVJHe3NNFPnojCGTbRjvKUaxpH1q 9rQrxfEG/DMEQ== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 01/24] btrfs: pass a bool to btrfs_block_rsv_migrate() at evict_refill_and_join() Date: Tue, 21 Mar 2023 11:13:37 +0000 Message-Id: X-Mailer: git-send-email 2.25.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 last argument of btrfs_block_rsv_migrate() is a boolean, but we are passing an integer, with a value of 1, to it at evict_refill_and_join(). While this is not a bug, due to type conversion, it's a lot more clear to simply pass the boolean true value instead. So just do that. Signed-off-by: Filipe Manana Reviewed-by: Anand Jain Reviewed-by: Johannes Thumshirn --- fs/btrfs/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 76d93b9e94a9..7bae75973a4d 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -5268,7 +5268,7 @@ static struct btrfs_trans_handle *evict_refill_and_join(struct btrfs_root *root, trans->block_rsv = &fs_info->trans_block_rsv; trans->bytes_reserved = delayed_refs_extra; btrfs_block_rsv_migrate(rsv, trans->block_rsv, - delayed_refs_extra, 1); + delayed_refs_extra, true); } return trans; } From patchwork Tue Mar 21 11:13:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13182591 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 90FEBC7618D for ; Tue, 21 Mar 2023 11:14:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230372AbjCULOg (ORCPT ); Tue, 21 Mar 2023 07:14:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229958AbjCULOb (ORCPT ); Tue, 21 Mar 2023 07:14:31 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A79B47801 for ; Tue, 21 Mar 2023 04:14:08 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 530DE61AE3 for ; Tue, 21 Mar 2023 11:14:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B119C433A0 for ; Tue, 21 Mar 2023 11:14:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679397246; bh=sI7tID6Ne5nolfPec0TphsiyAVsBUeCUq9w7RbmRWxo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=B2S0JkchIIYzW+Xotmcr/kBZHPN7T/Jj+OyC/Ykvsvm5izUwrYoEXx0wTNeKg1OFG owlrF6NzBi+dcAx/tj4syIiUpRD3w6AbNr9M/mvO6kWPOaUZr/bXQI07zDzZfgSueQ UWUPsvTwYgGQhKs6tclGJrZjyPImqN57qSFaFCembIx8vYRgcM8ExEzfje3XkEUHEq IoPcy9Mqk7V6+NLc/gnj0UeNrmjteFm8xep+Sub7bVEbhx/IrIFGQhLXCeB+bPrkhl QFSE0/x9OHCUML1UuNFIqjxfgRRb4IcGnSUji26axFbghMw4jffh/iQpmdtxczsxB2 n+SGG1T2HxVjw== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 02/24] btrfs: pass a bool size update argument to btrfs_block_rsv_add_bytes() Date: Tue, 21 Mar 2023 11:13:38 +0000 Message-Id: <4e7abf7599f8d809dbdd5f9f25f376fcd1ed83f2.1679326429.git.fdmanana@suse.com> X-Mailer: git-send-email 2.25.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 btrfs_delayed_refs_rsv_refill(), we are passing a value of 0 to the 'update_size' argument of btrfs_block_rsv_add_bytes(), which is defined as a boolean. Functionally this is fine because a 0 is, implicitly, converted to a boolean false value. However it's easier to read an explicit 'false' value, so just pass 'false' instead of 0. Signed-off-by: Filipe Manana Reviewed-by: Anand Jain Reviewed-by: Johannes Thumshirn --- fs/btrfs/delayed-ref.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index 886ffb232eac..83e1e1d0ec6a 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -217,7 +217,7 @@ int btrfs_delayed_refs_rsv_refill(struct btrfs_fs_info *fs_info, ret = btrfs_reserve_metadata_bytes(fs_info, block_rsv, num_bytes, flush); if (ret) return ret; - btrfs_block_rsv_add_bytes(block_rsv, num_bytes, 0); + btrfs_block_rsv_add_bytes(block_rsv, num_bytes, false); trace_btrfs_space_reservation(fs_info, "delayed_refs_rsv", 0, num_bytes, 1); return 0; From patchwork Tue Mar 21 11:13:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13182594 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 72F3AC74A5B for ; Tue, 21 Mar 2023 11:14:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229828AbjCULOk (ORCPT ); Tue, 21 Mar 2023 07:14:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230296AbjCULOc (ORCPT ); Tue, 21 Mar 2023 07:14:32 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13F94367D8 for ; Tue, 21 Mar 2023 04:14:10 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D56A8B815B8 for ; Tue, 21 Mar 2023 11:14:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2E7F8C4339B for ; Tue, 21 Mar 2023 11:14:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679397247; bh=Qz4Nvb9iNHDAznpTD9/InGTGTZ371eFFpH8StlWErJ8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=WK+yq2g1l4g06MuXC7suaeQbrv4LQ9Rz/8W77c5sGCMDJJwngZ76/Du2mgmS2KDfh w7dypRrwxqyJ80NxHo6/i9xj8Uks4myCm6n5rgGXC6EbdF8C8f+PXbCmM4sdlDUuzr URr72erKUCPS9yedYaRFw5MHdfQW8PvvBsTguSegrIkDbjc+3Qt6KspNGAx9Ov5doY S20p2gUfIa0f8wjRMUYCd9j00XiN98yTRGpP+D7Sp6xRwTgHr+LQt6XMxlzouHsPZy 3boYdu0x+5KapTPk7qOCPeVgSUPD3kpKoL3s58Ao7D552UVeKfMEwH9MbuoPgFudi0 5/b9hH1EtgvrA== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 03/24] btrfs: remove check for NULL block reserve at btrfs_block_rsv_check() Date: Tue, 21 Mar 2023 11:13:39 +0000 Message-Id: <8a7ecbeffe854a442aacb7c5c0c97b9f44528ebe.1679326430.git.fdmanana@suse.com> X-Mailer: git-send-email 2.25.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 block reserve passed to btrfs_block_rsv_check() is never NULL, so remove the check. In case it can ever become NULL in the future, then we'll get a pretty obvious and clear NULL pointer dereference crash and stack trace. Signed-off-by: Filipe Manana Reviewed-by: Anand Jain Reviewed-by: Johannes Thumshirn --- fs/btrfs/block-rsv.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/fs/btrfs/block-rsv.c b/fs/btrfs/block-rsv.c index 5367a14d44d2..364a3d11bf88 100644 --- a/fs/btrfs/block-rsv.c +++ b/fs/btrfs/block-rsv.c @@ -232,9 +232,6 @@ int btrfs_block_rsv_check(struct btrfs_block_rsv *block_rsv, int min_percent) u64 num_bytes = 0; int ret = -ENOSPC; - if (!block_rsv) - return 0; - spin_lock(&block_rsv->lock); num_bytes = mult_perc(block_rsv->size, min_percent); if (block_rsv->reserved >= num_bytes) From patchwork Tue Mar 21 11:13:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13182592 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 80BDFC74A5B for ; Tue, 21 Mar 2023 11:14:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229671AbjCULOh (ORCPT ); Tue, 21 Mar 2023 07:14:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230259AbjCULOb (ORCPT ); Tue, 21 Mar 2023 07:14:31 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 788EA3E085 for ; Tue, 21 Mar 2023 04:14:10 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1E11961B0E for ; Tue, 21 Mar 2023 11:14:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 115E9C433EF for ; Tue, 21 Mar 2023 11:14:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679397248; bh=5xsOOuE+I4JX5ETf6m3kfOl0goPSyDQbB+stGLkr1rQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=MLfBcWUmjzYLcVEkuDYfbwecdITz9mV6+5/TfphhCcaSfrzt0o/Zila2a+tSoQ3aN esZf1jMcziLCZ4eDhJoUu5dUdNVQUyLlCig6Jr9ldnpbUCfiz3DB7Na+I4wRpwkiL8 QIwLHks0lyJ4mfk61BwNvw9vB6oFF4Yq8O/wJj8PDFFadwUe1yiJ197XaV/z27BVuC BLtCA02b0dsyfwMMK+ZNnzOflIER8fT5Z14oCOtc2XBHy0jXuZIA26tbm25xLr+WIm mFSe6dFz5gnooJrf4AQH5UB2bL2NoM6/7qNgLpupnf2vr1VN2GX2Ju4bb9W5yiE7So RYQlY5GFRQHfQ== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 04/24] btrfs: update documentation for BTRFS_RESERVE_FLUSH_EVICT flush method Date: Tue, 21 Mar 2023 11:13:40 +0000 Message-Id: <5b9ed9c2e2de13fc10236824bdc333e318e47786.1679326430.git.fdmanana@suse.com> X-Mailer: git-send-email 2.25.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 BTRFS_RESERVE_FLUSH_EVICT flush method can also commit transactions, see the definition of the evict_flush_states const array at space-info.c, but the documentation for it at space-info.h does not mention it. So update the documentation. Signed-off-by: Filipe Manana Reviewed-by: Johannes Thumshirn --- fs/btrfs/space-info.h | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/btrfs/space-info.h b/fs/btrfs/space-info.h index 2033b71b18ce..0bb9d14e60a8 100644 --- a/fs/btrfs/space-info.h +++ b/fs/btrfs/space-info.h @@ -27,6 +27,7 @@ enum btrfs_reserve_flush_enum { * - Running delayed refs * - Running delalloc and waiting for ordered extents * - Allocating a new chunk + * - Committing transaction */ BTRFS_RESERVE_FLUSH_EVICT, From patchwork Tue Mar 21 11:13:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13182593 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 ACCBEC6FD1D for ; Tue, 21 Mar 2023 11:14:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230196AbjCULOi (ORCPT ); Tue, 21 Mar 2023 07:14:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230274AbjCULOb (ORCPT ); Tue, 21 Mar 2023 07:14:31 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E02C47828 for ; Tue, 21 Mar 2023 04:14:11 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id F00B761ADB for ; Tue, 21 Mar 2023 11:14:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9A8BC4339C for ; Tue, 21 Mar 2023 11:14:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679397249; bh=GxkFgYLUkN9hiqnChOMtjYmd77c/DWBPTB5t0tWvTS0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=CTQk/2hWJFwK4cf0yWEDU4ndpgxG8XvwsH2Qp5ea0a4l87YHD0idhITB/vLJi9nVt OcVJ5dHbxHZJ6EIi6J13EKtIf0Vc3W1AuERujKBx7rVVz4hzjE4NmpPnyXrylSvMQv VZDQGpirFQ9WRh4kLHVftvvvgP7LSfwl979kAHnyxYYq9NCfyqIqd/bL2AYT7R5HgY FSL3+cstwgQFaplWPqq3QAEEmPzDeyZJjmRgGwaVmYh7iar80ymLhCRxUig9u6Q3rb U8+rj/2S3pr1Jq679iIirptnZk7epIRu8VbBJ+9BvspfS7Zs9TF3uqUIHrIOzYYPem LnEiex3l5+ePQ== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 05/24] btrfs: update flush method assertion when reserving space Date: Tue, 21 Mar 2023 11:13:41 +0000 Message-Id: X-Mailer: git-send-email 2.25.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 reserving space, at space-info.c:__reserve_bytes(), we assert that either the current task is not holding a transacion handle, or, if it is, that the flush method is not BTRFS_RESERVE_FLUSH_ALL. This is because that flush method can trigger transaction commits, and therefore could lead to a deadlock. However there are other 2 flush methods that can trigger transaction commits: 1) BTRFS_RESERVE_FLUSH_ALL_STEAL 2) BTRFS_RESERVE_FLUSH_EVICT So update the assertion to check the flush method is also not one those two methods if the current task is holding a transaction handle. Signed-off-by: Filipe Manana --- fs/btrfs/space-info.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index 3eecce86f63f..379a0e778dfb 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -1603,7 +1603,18 @@ static int __reserve_bytes(struct btrfs_fs_info *fs_info, bool pending_tickets; ASSERT(orig_bytes); - ASSERT(!current->journal_info || flush != BTRFS_RESERVE_FLUSH_ALL); + /* + * If have a transaction handle (current->journal_info != NULL), then + * the flush method can not be neither BTRFS_RESERVE_FLUSH_ALL* nor + * BTRFS_RESERVE_FLUSH_EVICT, as we could deadlock because those + * flushing methods can trigger transaction commits. + */ + if (current->journal_info) { + /* One assert per line for easier debugging. */ + ASSERT(flush != BTRFS_RESERVE_FLUSH_ALL); + ASSERT(flush != BTRFS_RESERVE_FLUSH_ALL_STEAL); + ASSERT(flush != BTRFS_RESERVE_FLUSH_EVICT); + } if (flush == BTRFS_RESERVE_FLUSH_DATA) async_work = &fs_info->async_data_reclaim_work; From patchwork Tue Mar 21 11:13:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13182595 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 5C6A2C761A6 for ; Tue, 21 Mar 2023 11:14:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229923AbjCULOl (ORCPT ); Tue, 21 Mar 2023 07:14:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230333AbjCULOd (ORCPT ); Tue, 21 Mar 2023 07:14:33 -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 1E01635ED2 for ; Tue, 21 Mar 2023 04:14:12 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D4C2A61B0F for ; Tue, 21 Mar 2023 11:14:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB6E7C433EF for ; Tue, 21 Mar 2023 11:14:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679397250; bh=8Vw4mFbmx7jusR1EQ9Wt5RVqNnWrvsptg1gIM4H8pVE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=SkVlPELOpHSmQJa3Q0NBS9qGLVCXhXxuDZc76OGKAa32aev+FhpY14ACqaPcCX83Z g9niwHZZNZdm5tOk74aFl6K/Kwc8D9Y49CzrZajQQmproc+eHtjQ08fF1fwawbnsIA oj92y4sXA9i2A4z5iFPVAcT1ea2YEZhm/au/2U3XobdY03R4seIMkkoAi9sTptJsBJ 3YyvTkZpz4sdd2d1I5P8z8ygiyP69QlGtJhkG86H9XhWHik+V3F6vxePbbs7sOS04p rwT5xgsSDArh/vw8UaTyl8PkU9eObMP42n16P1hFA/NGFZHz5u4qBBj/dcxb0l/wYE GFvTb9bzKZjIA== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 06/24] btrfs: initialize ret to -ENOSPC at __reserve_bytes() Date: Tue, 21 Mar 2023 11:13:42 +0000 Message-Id: X-Mailer: git-send-email 2.25.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 space-info.c:__reserve_bytes(), instead of initializing 'ret' to 0 when it's declared and then shortly after set it to -ENOSPC under the space info's spinlock, initialize it to -ENOSPC when declaring it. Signed-off-by: Filipe Manana Reviewed-by: Johannes Thumshirn Reviewed-by: Anand Jain --- fs/btrfs/space-info.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index 379a0e778dfb..5eb161d96e35 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -1599,7 +1599,7 @@ static int __reserve_bytes(struct btrfs_fs_info *fs_info, struct reserve_ticket ticket; u64 start_ns = 0; u64 used; - int ret = 0; + int ret = -ENOSPC; bool pending_tickets; ASSERT(orig_bytes); @@ -1622,7 +1622,6 @@ static int __reserve_bytes(struct btrfs_fs_info *fs_info, async_work = &fs_info->async_reclaim_work; spin_lock(&space_info->lock); - ret = -ENOSPC; used = btrfs_space_info_used(space_info, true); /* From patchwork Tue Mar 21 11:13:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13182596 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 F08EEC74A5B for ; Tue, 21 Mar 2023 11:14:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230184AbjCULOm (ORCPT ); Tue, 21 Mar 2023 07:14:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230172AbjCULOe (ORCPT ); Tue, 21 Mar 2023 07:14:34 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBD2028EA8 for ; Tue, 21 Mar 2023 04:14:13 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BAA2D61B10 for ; Tue, 21 Mar 2023 11:14:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ACE6BC4339B for ; Tue, 21 Mar 2023 11:14:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679397251; bh=wi8WzEaa5CZM6UYEBnIhoz1+oiXhj+nLb95eqfZaJCk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=XnIo/J5uycRRaATA9sOUT/OuHcOGFf1AXKuTQ+grZ52OLvr90hw1khlGVgaP3ZRBx LFP/rbHSnE2PIohWfXIes3ozP7wL1HSHqt3BiSC0JTqoHBwnczPTPi69/paUQWJ2Pf 1hD8tGTxlx+zT81829p9iMypNda/tjhvJ+f7Y2R+RJfVQ4NQjem+2vX+ECdNx6/7Dh 1wCVGp+8i1Tz/oR1TEirGE7qURdbJLlbgLiw8a++v5OmC7Yku3W5tzKbPXfmWzm/H7 exY+0iPbth+GnmXibUGOHqEGf7wssFeCmtdJzJgZut4fMz2k4E+g1TC+eFgFMYJFeA 98tT/Ykf/0oLw== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 07/24] btrfs: simplify btrfs_should_throttle_delayed_refs() Date: Tue, 21 Mar 2023 11:13:43 +0000 Message-Id: <5c0f23a3f7c8fe4c3c6fde9c1d0f4baa80babbfd.1679326431.git.fdmanana@suse.com> X-Mailer: git-send-email 2.25.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 btrfs_should_throttle_delayed_refs() returns 1 or 2 in case the delayed refs should be throttled, however the only caller (inode eviction and truncation path) does not care about those two different conditions, it treats the return value as a boolean. This allows us to remove one of the conditions in btrfs_should_throttle_delayed_refs() and change its return value from 'int' to 'bool'. So just do that. Signed-off-by: Filipe Manana Reviewed-by: Anand Jain --- fs/btrfs/delayed-ref.c | 6 ++---- fs/btrfs/delayed-ref.h | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index 83e1e1d0ec6a..3fdee91d8079 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -53,7 +53,7 @@ bool btrfs_check_space_for_delayed_refs(struct btrfs_fs_info *fs_info) return ret; } -int btrfs_should_throttle_delayed_refs(struct btrfs_trans_handle *trans) +bool btrfs_should_throttle_delayed_refs(struct btrfs_trans_handle *trans) { u64 num_entries = atomic_read(&trans->transaction->delayed_refs.num_entries); @@ -63,10 +63,8 @@ int btrfs_should_throttle_delayed_refs(struct btrfs_trans_handle *trans) smp_mb(); avg_runtime = trans->fs_info->avg_delayed_ref_runtime; val = num_entries * avg_runtime; - if (val >= NSEC_PER_SEC) - return 1; if (val >= NSEC_PER_SEC / 2) - return 2; + return true; return btrfs_check_space_for_delayed_refs(trans->fs_info); } diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h index 2eb34abf700f..316fed159d49 100644 --- a/fs/btrfs/delayed-ref.h +++ b/fs/btrfs/delayed-ref.h @@ -385,7 +385,7 @@ int btrfs_delayed_refs_rsv_refill(struct btrfs_fs_info *fs_info, void btrfs_migrate_to_delayed_refs_rsv(struct btrfs_fs_info *fs_info, struct btrfs_block_rsv *src, u64 num_bytes); -int btrfs_should_throttle_delayed_refs(struct btrfs_trans_handle *trans); +bool btrfs_should_throttle_delayed_refs(struct btrfs_trans_handle *trans); bool btrfs_check_space_for_delayed_refs(struct btrfs_fs_info *fs_info); /* From patchwork Tue Mar 21 11:13:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13182602 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 336E5C7618D for ; Tue, 21 Mar 2023 11:14:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230314AbjCULOw (ORCPT ); Tue, 21 Mar 2023 07:14:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229771AbjCULOt (ORCPT ); Tue, 21 Mar 2023 07:14:49 -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 2FBF66EBE for ; Tue, 21 Mar 2023 04:14:24 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9526A61AEA for ; Tue, 21 Mar 2023 11:14:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8EBBBC433D2 for ; Tue, 21 Mar 2023 11:14:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679397252; bh=FJnfQ5I3a0N1gyIn4cKHc5U7EnTETAHGI88wfL9S1KY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=GJJF9Wmn/Xf57uTw5fHOAXjsEg4T0dj7ZihyYA4HY3rItmUI0w1gDhf+D1deK9qY0 e3XafTcoH7O6mw9Bh9rqrsTi/EKTGQmecov5QJWPbJuyHgShm7EaowqYmbaH+v89hc VKITmNXwankTMzeIjTtNiCtP+T1UefTj6CBhKWV5kPDF2sHECp50RShfzwpb+fJdnC ypUu3WMpW/dgpLkeL3yIhTRcyqQCxpjfkdNgn9UBX5Ysc9qLFJmvBtKlrmTdsOAYKZ fcjOni4KBmr3+V4dm6WvmkyXfjUPmexBKGkiaDICngVMiJrQRQatBpUdwLhA7LuHOz zd87jyoSNpJjw== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 08/24] btrfs: collapse should_end_transaction() into btrfs_should_end_transaction() Date: Tue, 21 Mar 2023 11:13:44 +0000 Message-Id: <620d28d3978808483b962fc0024dda3600d45cb5.1679326431.git.fdmanana@suse.com> X-Mailer: git-send-email 2.25.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 should_end_transaction() is very short and only has one caller, which is btrfs_should_end_transaction(). So move the code from should_end_transaction() into btrfs_should_end_transaction(). Signed-off-by: Filipe Manana Reviewed-by: Anand Jain --- fs/btrfs/transaction.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index 18329ebcb1cb..c47b6838754e 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -942,16 +942,6 @@ void btrfs_throttle(struct btrfs_fs_info *fs_info) wait_current_trans(fs_info); } -static bool should_end_transaction(struct btrfs_trans_handle *trans) -{ - struct btrfs_fs_info *fs_info = trans->fs_info; - - if (btrfs_check_space_for_delayed_refs(fs_info)) - return true; - - return !!btrfs_block_rsv_check(&fs_info->global_block_rsv, 50); -} - bool btrfs_should_end_transaction(struct btrfs_trans_handle *trans) { struct btrfs_transaction *cur_trans = trans->transaction; @@ -960,7 +950,10 @@ bool btrfs_should_end_transaction(struct btrfs_trans_handle *trans) test_bit(BTRFS_DELAYED_REFS_FLUSHING, &cur_trans->delayed_refs.flags)) return true; - return should_end_transaction(trans); + if (btrfs_check_space_for_delayed_refs(trans->fs_info)) + return true; + + return !!btrfs_block_rsv_check(&trans->fs_info->global_block_rsv, 50); } static void btrfs_trans_release_metadata(struct btrfs_trans_handle *trans) From patchwork Tue Mar 21 11:13:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13182598 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 124E1C761A6 for ; Tue, 21 Mar 2023 11:14:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230143AbjCULOo (ORCPT ); Tue, 21 Mar 2023 07:14:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229685AbjCULOj (ORCPT ); Tue, 21 Mar 2023 07:14:39 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 436CD28D33 for ; Tue, 21 Mar 2023 04:14:18 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 2206DB815B3 for ; Tue, 21 Mar 2023 11:14:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70E1BC4339B for ; Tue, 21 Mar 2023 11:14:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679397252; bh=CW/m5oNvzysXc3pZlTivNIAzB60URx4rTf9tGLKvHBI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=CJ+MG5P9KzFQV9HZfcPF7CWviMHYpddS/sJhYhx6KPdIHGA+gTkrq+EDkY2ehfUMs IOi2vOuLp5z1WRGPHMCnYY1O0Cv63ImUd4E8zjuCEC5GGgF0yCf6bEJi7FLhtoN24Z Vn2XSIFiMaL/3Bat3NDwPOLtPqBJg/j1DNuOVg2fTlx7e1YekFxi8efTUH54mBoYRA kYni8H4r9/K91ZSH836PyaJhrNqOzUgdhKZQSWaQEF5ULd1RInJLkDb7yU6Uvzrv7T keKwbpiUjHLfuL+q6FHt32Dpn4SJ8Imb3u8us0ZcXqBsrOFIpPtKjsmLZgWTCaWOHG AMJeP3Gby4/pg== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 09/24] btrfs: remove bytes_used argument from btrfs_make_block_group() Date: Tue, 21 Mar 2023 11:13:45 +0000 Message-Id: <84070b134bcaab995abb46437568fdb1a5282171.1679326432.git.fdmanana@suse.com> X-Mailer: git-send-email 2.25.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 only caller of btrfs_make_block_group() always passes 0 as the value for the bytes_used argument, so remove it. Signed-off-by: Filipe Manana Reviewed-by: Anand Jain --- fs/btrfs/block-group.c | 7 ++----- fs/btrfs/block-group.h | 2 +- fs/btrfs/volumes.c | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index 46a8ca24afaa..bb6024c17db4 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -2672,7 +2672,7 @@ static u64 calculate_global_root_id(struct btrfs_fs_info *fs_info, u64 offset) } struct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *trans, - u64 bytes_used, u64 type, + u64 type, u64 chunk_offset, u64 size) { struct btrfs_fs_info *fs_info = trans->fs_info; @@ -2687,7 +2687,6 @@ struct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *tran cache->length = size; set_free_space_tree_thresholds(cache); - cache->used = bytes_used; cache->flags = type; cache->cached = BTRFS_CACHE_FINISHED; cache->global_root_id = calculate_global_root_id(fs_info, cache->start); @@ -2738,9 +2737,7 @@ struct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *tran #ifdef CONFIG_BTRFS_DEBUG if (btrfs_should_fragment_free_space(cache)) { - u64 new_bytes_used = size - bytes_used; - - cache->space_info->bytes_used += new_bytes_used >> 1; + cache->space_info->bytes_used += size >> 1; fragment_free_space(cache); } #endif diff --git a/fs/btrfs/block-group.h b/fs/btrfs/block-group.h index 6e4a0b429ac3..db729ad7315b 100644 --- a/fs/btrfs/block-group.h +++ b/fs/btrfs/block-group.h @@ -302,7 +302,7 @@ void btrfs_reclaim_bgs(struct btrfs_fs_info *fs_info); void btrfs_mark_bg_to_reclaim(struct btrfs_block_group *bg); int btrfs_read_block_groups(struct btrfs_fs_info *info); struct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *trans, - u64 bytes_used, u64 type, + u64 type, u64 chunk_offset, u64 size); void btrfs_create_pending_block_groups(struct btrfs_trans_handle *trans); int btrfs_inc_block_group_ro(struct btrfs_block_group *cache, diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 93bc45001e68..5da6f5167046 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -5421,7 +5421,7 @@ static struct btrfs_block_group *create_chunk(struct btrfs_trans_handle *trans, } write_unlock(&em_tree->lock); - block_group = btrfs_make_block_group(trans, 0, type, start, ctl->chunk_size); + block_group = btrfs_make_block_group(trans, type, start, ctl->chunk_size); if (IS_ERR(block_group)) goto error_del_extent; From patchwork Tue Mar 21 11:13:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13182601 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 A9C9BC74A5B for ; Tue, 21 Mar 2023 11:14:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230274AbjCULOu (ORCPT ); Tue, 21 Mar 2023 07:14:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230194AbjCULOq (ORCPT ); Tue, 21 Mar 2023 07:14:46 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44E9528E98 for ; Tue, 21 Mar 2023 04:14:24 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5E2E761B11 for ; Tue, 21 Mar 2023 11:14:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52587C433D2 for ; Tue, 21 Mar 2023 11:14:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679397253; bh=iY2GJZUSbtMJJX5yM6Ehw66XVEcLIM5bmyMASSpLRpY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Rr7H8EAa5zux+DX38ss4qWXBAh7n+xjZZWqKr+3g1/dEi2462adNcIqSFkXCUcxR+ qxxvWQCbcGRHnZjyNjv+7WdDx2yaShluuylgWhJ2M6U63/LhME78aj1NfgucmIH2CE +/5GUq+C9b2XwcrJ/hWvIorYQU+nXiRlct2AEuFR7PP2iFXP+GdpE/2blv/uGD1nNV Gs5yhPuyffnAwIgQ0Klk7hs8v15mAS7UZFfc8osVQ7mTTrUvK8F75zKW+6Rt7fD5wc TwpD3/M0+YBWZUl63hHf6qsalF8NMed8ZDodDyjX06VOlbWWD/gO40dFs/TWJ6v0H/ JuPGDHoDmnsQA== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 10/24] btrfs: count extents before taking inode's spinlock when reserving metadata Date: Tue, 21 Mar 2023 11:13:46 +0000 Message-Id: X-Mailer: git-send-email 2.25.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 reserving metadata space for delalloc (and direct IO too), at btrfs_delalloc_reserve_metadata(), there's no need to count the number of extents while holding the inode's spinlock, since that does not require access to any field of the inode. This section of code can be called concurrently, when we have direct IO writes against different file ranges that don't increase the inode's i_size, so it's beneficial to shorten the critical section by counting the number of extents before taking the inode's spinlock. Signed-off-by: Filipe Manana Reviewed-by: Anand Jain --- fs/btrfs/delalloc-space.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/delalloc-space.c b/fs/btrfs/delalloc-space.c index 7ddb1d104e8e..427abaf608b8 100644 --- a/fs/btrfs/delalloc-space.c +++ b/fs/btrfs/delalloc-space.c @@ -358,8 +358,8 @@ int btrfs_delalloc_reserve_metadata(struct btrfs_inode *inode, u64 num_bytes, * racing with an ordered completion or some such that would think it * needs to free the reservation we just made. */ - spin_lock(&inode->lock); nr_extents = count_max_extents(fs_info, num_bytes); + spin_lock(&inode->lock); btrfs_mod_outstanding_extents(inode, nr_extents); inode->csum_bytes += disk_num_bytes; btrfs_calculate_inode_block_rsv_size(fs_info, inode); From patchwork Tue Mar 21 11:13:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13182597 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 1826EC6FD1D for ; Tue, 21 Mar 2023 11:14:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230115AbjCULOo (ORCPT ); Tue, 21 Mar 2023 07:14:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230270AbjCULOj (ORCPT ); Tue, 21 Mar 2023 07:14:39 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 416F21207B for ; Tue, 21 Mar 2023 04:14:18 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id EA86DB815BB for ; Tue, 21 Mar 2023 11:14:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 344E5C433EF for ; Tue, 21 Mar 2023 11:14:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679397254; bh=aIF99skuJxHcx32kCBOeUKAzYYiPQuB+hjqiifdsR8w=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ovbjGtpunLTIsgHJr2lhLldJ/M79SQGv/PiM5oRh3HJkV133Ooi7/zMUztZSWj252 WzAm7FvsKukYDSptq6aXGsVqFIKCUhX3j/ya9i3P6EFGLjOxypK8K4DWEOYepm/FzN gKVLe1YrM43ofKESubTdYqdHnnV2mNm3Er1Yg7h66OzaUbzXq+hy3U+b+U4TSjZok7 p9NzTYvd/2H1oem9xvuVWcLAGPHMkkqoFiIWEXo18a7pS7RKF+sZLM4I7avp2hzt6Y /Z9r3ir0jswlJshTcqQfSW03VKyHXAzYoISmyieu+Bca9EMJODEd3LPYwT4b4SXfdz CdDFc0lYPqAkQ== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 11/24] btrfs: remove redundant counter check at btrfs_truncate_inode_items() Date: Tue, 21 Mar 2023 11:13:47 +0000 Message-Id: <0618e34a343facf5c7ee34d0021ed6476c655a55.1679326432.git.fdmanana@suse.com> X-Mailer: git-send-email 2.25.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 btrfs_truncate_inode_items(), in the while loop when we decide that we are going to delete an item, it's pointless to check that 'pending_del_nr' is non-zero in an else clause because the corresponding if statement is checking if 'pending_del_nr' has a value of zero. So just remove that condition from the else clause. Signed-off-by: Filipe Manana Reviewed-by: Anand Jain --- fs/btrfs/inode-item.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/btrfs/inode-item.c b/fs/btrfs/inode-item.c index b65c45b5d681..b27c2c560083 100644 --- a/fs/btrfs/inode-item.c +++ b/fs/btrfs/inode-item.c @@ -660,8 +660,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, /* No pending yet, add ourselves */ pending_del_slot = path->slots[0]; pending_del_nr = 1; - } else if (pending_del_nr && - path->slots[0] + 1 == pending_del_slot) { + } else if (path->slots[0] + 1 == pending_del_slot) { /* Hop on the pending chunk */ pending_del_nr++; pending_del_slot = path->slots[0]; From patchwork Tue Mar 21 11:13:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13182607 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 F1015C74A5B for ; Tue, 21 Mar 2023 11:15:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229635AbjCULPB (ORCPT ); Tue, 21 Mar 2023 07:15:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230289AbjCULOv (ORCPT ); Tue, 21 Mar 2023 07:14:51 -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 B9D2E23128 for ; Tue, 21 Mar 2023 04:14:27 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2232A61B14 for ; Tue, 21 Mar 2023 11:14:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1720FC4339B for ; Tue, 21 Mar 2023 11:14:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679397255; bh=qXB5IpSDf3tUHVO9s49XT/STj6eVrbpZe6RRNw1bR/o=; h=From:To:Subject:Date:In-Reply-To:References:From; b=TkIAINW2nkCwCHKZAsf/vR0Bv5+WMgz/f+fuocMhkHAZBNFCOuR437bkHP/ytzAC0 rMWOUziE5wW/x0Mh8a760x5FrRh3S6hIJlMRc1vKane9VOpXr4HAQbbDj8utsG9bct ZqB6ZmGT/1qQ8fvkOsf3zJgZo9bsVa/LrbhWBxW9UIR/ZZ8YzeAEtjdcJaEd1yDCXb D2+UUo+3u/3KsP5VL0HNFiN+dpB5KXo5ejZ31FYFJ5bpv+u63lKSl79Al+cA1QAAfS iwUAXlkB5cewzkhytR3pkWArDc8kbozxhCguhmrBSF8ANLOcQUG6rij5A26lhLmN+7 hP91ajkFmA3Aw== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 12/24] btrfs: simplify btrfs_block_rsv_refill() Date: Tue, 21 Mar 2023 11:13:48 +0000 Message-Id: <2ce9a65bf72584f5bb9da5e248f94ee4e104f24a.1679326433.git.fdmanana@suse.com> X-Mailer: git-send-email 2.25.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 btrfs_block_rsv_refill(), there's no point in initializing the 'num_bytes' variable to 0 and then, after taking the block reserve's spinlock, initializing it to the value of the 'min_reserved' parameter. So just get rid of the 'num_bytes' local variable and rename the 'min_reserved' parameter to 'num_bytes'. Signed-off-by: Filipe Manana Reviewed-by: Anand Jain --- fs/btrfs/block-rsv.c | 4 +--- fs/btrfs/block-rsv.h | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/block-rsv.c b/fs/btrfs/block-rsv.c index 364a3d11bf88..90b8088e8fac 100644 --- a/fs/btrfs/block-rsv.c +++ b/fs/btrfs/block-rsv.c @@ -242,17 +242,15 @@ int btrfs_block_rsv_check(struct btrfs_block_rsv *block_rsv, int min_percent) } int btrfs_block_rsv_refill(struct btrfs_fs_info *fs_info, - struct btrfs_block_rsv *block_rsv, u64 min_reserved, + struct btrfs_block_rsv *block_rsv, u64 num_bytes, enum btrfs_reserve_flush_enum flush) { - u64 num_bytes = 0; int ret = -ENOSPC; if (!block_rsv) return 0; spin_lock(&block_rsv->lock); - num_bytes = min_reserved; if (block_rsv->reserved >= num_bytes) ret = 0; else diff --git a/fs/btrfs/block-rsv.h b/fs/btrfs/block-rsv.h index 4cc41c9aaa82..6dc781709aca 100644 --- a/fs/btrfs/block-rsv.h +++ b/fs/btrfs/block-rsv.h @@ -65,7 +65,7 @@ int btrfs_block_rsv_add(struct btrfs_fs_info *fs_info, enum btrfs_reserve_flush_enum flush); int btrfs_block_rsv_check(struct btrfs_block_rsv *block_rsv, int min_percent); int btrfs_block_rsv_refill(struct btrfs_fs_info *fs_info, - struct btrfs_block_rsv *block_rsv, u64 min_reserved, + struct btrfs_block_rsv *block_rsv, u64 num_bytes, enum btrfs_reserve_flush_enum flush); int btrfs_block_rsv_migrate(struct btrfs_block_rsv *src_rsv, struct btrfs_block_rsv *dst_rsv, u64 num_bytes, From patchwork Tue Mar 21 11:13:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13182608 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 52E6AC7618D for ; Tue, 21 Mar 2023 11:15:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230005AbjCULPC (ORCPT ); Tue, 21 Mar 2023 07:15:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230296AbjCULOv (ORCPT ); Tue, 21 Mar 2023 07:14:51 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA28723129 for ; Tue, 21 Mar 2023 04:14:27 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id F3A5261B16 for ; Tue, 21 Mar 2023 11:14:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED657C4339C for ; Tue, 21 Mar 2023 11:14:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679397256; bh=vojGQL3BFYgRmrlC6eu+8Wf+TbDiHX8KzQiEPpoQrvM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=DktwGReAJ0cGUIZqq6QYpYXpMhCnPdyCMkweJ6XPIDa/vZuyo1uv9W06QeaTdI827 1NPjmai8BorHTBNL30U0aPTpOS4ojHDJ6G2FLJF9+1FPv1MjLnpAtW6LzplUcT+Uqr lTP4Wx9yMPQk3gP/qBAntrI7U1W+04jK9OrYIO3mscI8nYs3eGfP5faqz2qk7B3k6u kdfwQEY2ylUGQZ1KfTmcpZ2dSj5Yw3kqgGPReRiSdhDr8NNhBgHWJryEI4fhZ9gGUT z7nFcoBjvyeBoVtRjY5EgT7qjli+V+2PRLlh2cNgSKDDal4k64I69XEKyxHsPFHXE0 XsnqxUKosBbGw== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 13/24] btrfs: remove obsolete delayed ref throttling logic when truncating items Date: Tue, 21 Mar 2023 11:13:49 +0000 Message-Id: <851e11f4716ee1cd6284634533e8e9bbc1b52a1d.1679326433.git.fdmanana@suse.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana We have this logic encapsulated in btrfs_should_throttle_delayed_refs() where we try to estimate if running the current amount of delayed references we have will take more than half a second, and if so, the caller btrfs_should_throttle_delayed_refs() should do something to prevent more and more delayed refs from being accumulated. This logic was added in commit 0a2b2a844af6 ("Btrfs: throttle delayed refs better") and then further refined in commit a79b7d4b3e81 ("Btrfs: async delayed refs"). The idea back then was that the caller of btrfs_should_throttle_delayed_refs() would release its transaction handle (by calling btrfs_end_transaction()) when that function returned true, then btrfs_end_transaction() would trigger an async job to run delayed references in a workqueue, and later start/join a transaction again and do more work. However we don't run delayed references asynchronously anymore, that was removed in commit db2462a6ad3d ("btrfs: don't run delayed refs in the end transaction logic"). That makes the logic that tries to estimate how long we will take to run our current delayed references, at btrfs_should_throttle_delayed_refs(), pointless as we don't take any action to run delayed references anymore. We do have other type of throttling, which consists of checking the size and reserved space of the delayed and global block reserves, as well as if fluhsing delayed references for the current transaction was already started, etc - this is all done by btrfs_should_end_transaction(), and the only user of btrfs_should_throttle_delayed_refs() does periodically call btrfs_should_end_transaction(). So remove btrfs_should_throttle_delayed_refs() and the infrastructure that keeps track of the average time used for running delayed references, as well as adapting btrfs_truncate_inode_items() to call btrfs_check_space_for_delayed_refs() instead. Signed-off-by: Filipe Manana --- fs/btrfs/delayed-ref.c | 16 ---------------- fs/btrfs/delayed-ref.h | 1 - fs/btrfs/disk-io.c | 1 - fs/btrfs/extent-tree.c | 27 ++------------------------- fs/btrfs/fs.h | 1 - fs/btrfs/inode-item.c | 12 +++++------- 6 files changed, 7 insertions(+), 51 deletions(-) diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index 3fdee91d8079..bf2ce51e5086 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -53,22 +53,6 @@ bool btrfs_check_space_for_delayed_refs(struct btrfs_fs_info *fs_info) return ret; } -bool btrfs_should_throttle_delayed_refs(struct btrfs_trans_handle *trans) -{ - u64 num_entries = - atomic_read(&trans->transaction->delayed_refs.num_entries); - u64 avg_runtime; - u64 val; - - smp_mb(); - avg_runtime = trans->fs_info->avg_delayed_ref_runtime; - val = num_entries * avg_runtime; - if (val >= NSEC_PER_SEC / 2) - return true; - - return btrfs_check_space_for_delayed_refs(trans->fs_info); -} - /* * Release a ref head's reservation. * diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h index 316fed159d49..6cf1adc9a01a 100644 --- a/fs/btrfs/delayed-ref.h +++ b/fs/btrfs/delayed-ref.h @@ -385,7 +385,6 @@ int btrfs_delayed_refs_rsv_refill(struct btrfs_fs_info *fs_info, void btrfs_migrate_to_delayed_refs_rsv(struct btrfs_fs_info *fs_info, struct btrfs_block_rsv *src, u64 num_bytes); -bool btrfs_should_throttle_delayed_refs(struct btrfs_trans_handle *trans); bool btrfs_check_space_for_delayed_refs(struct btrfs_fs_info *fs_info); /* diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index bb864cf2eed6..b638e27468a7 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2951,7 +2951,6 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info) atomic64_set(&fs_info->free_chunk_space, 0); fs_info->tree_mod_log = RB_ROOT; fs_info->commit_interval = BTRFS_DEFAULT_COMMIT_INTERVAL; - fs_info->avg_delayed_ref_runtime = NSEC_PER_SEC >> 6; /* div by 64 */ btrfs_init_ref_verify(fs_info); fs_info->thread_pool_size = min_t(unsigned long, diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 6b6c59e6805c..5cd289de4e92 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -1894,8 +1894,7 @@ static struct btrfs_delayed_ref_head *btrfs_obtain_ref_head( } static int btrfs_run_delayed_refs_for_head(struct btrfs_trans_handle *trans, - struct btrfs_delayed_ref_head *locked_ref, - unsigned long *run_refs) + struct btrfs_delayed_ref_head *locked_ref) { struct btrfs_fs_info *fs_info = trans->fs_info; struct btrfs_delayed_ref_root *delayed_refs; @@ -1917,7 +1916,6 @@ static int btrfs_run_delayed_refs_for_head(struct btrfs_trans_handle *trans, return -EAGAIN; } - (*run_refs)++; ref->in_tree = 0; rb_erase_cached(&ref->ref_node, &locked_ref->ref_tree); RB_CLEAR_NODE(&ref->ref_node); @@ -1981,10 +1979,8 @@ static noinline int __btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, struct btrfs_fs_info *fs_info = trans->fs_info; struct btrfs_delayed_ref_root *delayed_refs; struct btrfs_delayed_ref_head *locked_ref = NULL; - ktime_t start = ktime_get(); int ret; unsigned long count = 0; - unsigned long actual_count = 0; delayed_refs = &trans->transaction->delayed_refs; do { @@ -2014,8 +2010,7 @@ static noinline int __btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, spin_lock(&locked_ref->lock); btrfs_merge_delayed_refs(fs_info, delayed_refs, locked_ref); - ret = btrfs_run_delayed_refs_for_head(trans, locked_ref, - &actual_count); + ret = btrfs_run_delayed_refs_for_head(trans, locked_ref); if (ret < 0 && ret != -EAGAIN) { /* * Error, btrfs_run_delayed_refs_for_head already @@ -2046,24 +2041,6 @@ static noinline int __btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, cond_resched(); } while ((nr != -1 && count < nr) || locked_ref); - /* - * We don't want to include ref heads since we can have empty ref heads - * and those will drastically skew our runtime down since we just do - * accounting, no actual extent tree updates. - */ - if (actual_count > 0) { - u64 runtime = ktime_to_ns(ktime_sub(ktime_get(), start)); - u64 avg; - - /* - * We weigh the current average higher than our current runtime - * to avoid large swings in the average. - */ - spin_lock(&delayed_refs->lock); - avg = fs_info->avg_delayed_ref_runtime * 3 + runtime; - fs_info->avg_delayed_ref_runtime = avg >> 2; /* div by 4 */ - spin_unlock(&delayed_refs->lock); - } return 0; } diff --git a/fs/btrfs/fs.h b/fs/btrfs/fs.h index abe5b3475a9d..492436e1a59e 100644 --- a/fs/btrfs/fs.h +++ b/fs/btrfs/fs.h @@ -407,7 +407,6 @@ struct btrfs_fs_info { * Must be written and read while holding btrfs_fs_info::commit_root_sem. */ u64 last_reloc_trans; - u64 avg_delayed_ref_runtime; /* * This is updated to the current trans every time a full commit is diff --git a/fs/btrfs/inode-item.c b/fs/btrfs/inode-item.c index b27c2c560083..4c322b720a80 100644 --- a/fs/btrfs/inode-item.c +++ b/fs/btrfs/inode-item.c @@ -527,7 +527,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, while (1) { u64 clear_start = 0, clear_len = 0, extent_start = 0; - bool should_throttle = false; + bool refill_delayed_refs_rsv = false; fi = NULL; leaf = path->nodes[0]; @@ -685,10 +685,8 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, btrfs_abort_transaction(trans, ret); break; } - if (be_nice) { - if (btrfs_should_throttle_delayed_refs(trans)) - should_throttle = true; - } + if (be_nice && btrfs_check_space_for_delayed_refs(fs_info)) + refill_delayed_refs_rsv = true; } if (found_type == BTRFS_INODE_ITEM_KEY) @@ -696,7 +694,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, if (path->slots[0] == 0 || path->slots[0] != pending_del_slot || - should_throttle) { + refill_delayed_refs_rsv) { if (pending_del_nr) { ret = btrfs_del_items(trans, root, path, pending_del_slot, @@ -719,7 +717,7 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, * actually allocate, so just bail if we're short and * let the normal reservation dance happen higher up. */ - if (should_throttle) { + if (refill_delayed_refs_rsv) { ret = btrfs_delayed_refs_rsv_refill(fs_info, BTRFS_RESERVE_NO_FLUSH); if (ret) { From patchwork Tue Mar 21 11:13:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13182604 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 6A65AC761AF for ; Tue, 21 Mar 2023 11:14:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230428AbjCULOz (ORCPT ); Tue, 21 Mar 2023 07:14:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230172AbjCULOu (ORCPT ); Tue, 21 Mar 2023 07:14:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C548D17CDB for ; Tue, 21 Mar 2023 04:14:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DA01561B13 for ; Tue, 21 Mar 2023 11:14:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF49FC433EF for ; Tue, 21 Mar 2023 11:14:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679397257; bh=uq4QFWAekvR44jIbqQLGG0s4VYEh3Ve6rrXqoYQW2iM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=GdA3RswWPIqnl5bG+SJqLpHBHihRCgrN1DGewkfVlY82JPNbVvOEHrsmHEg2uNPjZ KGI2fW1hikjjKLW1lGvjFm0AO7I4U4bPnJ2r8+xSWCWuSrrX3trMTyenXuO+TQYKxI S05StmPuGUa9Baq95C0KFVnQNH9O5i+H7NxtA7MMny5RbhNUh7vAdAel/L/nTA7Vtv OfPxYp1hKSsusE8qIi2P0nm06z0B/oOyRTcPyB6/amqpHSh/kufOsrTnY98dQG4Wug TAOCqbr446EZNUa63uckaKKJ3U32YqQSIQWBznOQbQ96DyStgDeYZsI043ngSh5maa HYNlHhQGE6Lbw== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 14/24] btrfs: don't throttle on delayed items when evicting deleted inode Date: Tue, 21 Mar 2023 11:13:50 +0000 Message-Id: X-Mailer: git-send-email 2.25.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 inode eviction, if we are truncating a deleted inode, we don't add delayed items for our inode, so there's no need to throttle on delayed items on each iteration of the loop that truncates inode items from its subvolume tree. But we dirty extent buffers from its subvolume tree, so we only need to throttle on btree inode dirty pages. So use btrfs_btree_balance_dirty_nodelay() in the loop that truncates inode items. Signed-off-by: Filipe Manana --- fs/btrfs/inode.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 7bae75973a4d..912d5f4aafbc 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -5350,7 +5350,12 @@ void btrfs_evict_inode(struct inode *inode) ret = btrfs_truncate_inode_items(trans, root, &control); trans->block_rsv = &fs_info->trans_block_rsv; btrfs_end_transaction(trans); - btrfs_btree_balance_dirty(fs_info); + /* + * We have not added new delayed items for our inode after we + * have flushed its delayed items, so no need to throttle on + * delayed items. However we have modified extent buffers. + */ + btrfs_btree_balance_dirty_nodelay(fs_info); if (ret && ret != -ENOSPC && ret != -EAGAIN) goto free_rsv; else if (!ret) From patchwork Tue Mar 21 11:13:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13182599 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 57495C6FD1D for ; Tue, 21 Mar 2023 11:14:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230270AbjCULOr (ORCPT ); Tue, 21 Mar 2023 07:14:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230261AbjCULOq (ORCPT ); Tue, 21 Mar 2023 07:14:46 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FEF92701 for ; Tue, 21 Mar 2023 04:14:21 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 02CBFCE17B2 for ; Tue, 21 Mar 2023 11:14:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2857C4339B for ; Tue, 21 Mar 2023 11:14:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679397258; bh=rxU3HpTfMBFi7GxSr/HKgF47MsthKMH3nTFHOGwBZsk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=llKlg7+VLNEGhuSqE2UWaFIlOkMD3SNd2UN1DyaENuCfdUjcb4N6cVRlnBAaKcaG7 XTC4mlQZ4VXgFFdey2isiu1npgkj1RGcTqCkvU0jJjOCZF+imOHcx3h5Rmo16Rx0wL FBxSSDxRwrd6uNVLWSwMqiqUgkV8ZGuuidHT8YK5FSfdEsLbKNn5LyQyV4iNTU/VtA /Zzl1N1ikIk/u/iBzJMPQ7+mfjNEhO7YvINNJwyBPnZLvkUUxyRLCWvDAZuoUnhrsk aYzqv07FTjMZUfbXl/8/UpVLmXe+AKMxjxrcmmUjcSCOcsmrp/X/RZMTfVQ4tbXFQt v+xlViwc7+AUA== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 15/24] btrfs: calculate the right space for a single delayed ref when refilling Date: Tue, 21 Mar 2023 11:13:51 +0000 Message-Id: X-Mailer: git-send-email 2.25.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 refilling the delayed block reserve we are incorrectly computing the amount of bytes for a single delayed reference if the free space tree is being used. In that case we should double the calculated amount. Everywhere else we compute the correct amount, like when updating the delayed block reserve, at btrfs_update_delayed_refs_rsv(), or when releasing space from the delayed block reserve, at btrfs_delayed_refs_rsv_release(). So fix btrfs_delayed_refs_rsv_refill() to multiply the amount of bytes for a single delayed reference by two in case the free space tree is used. Signed-off-by: Filipe Manana Reviewed-by: Anand Jain --- fs/btrfs/delayed-ref.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index bf2ce51e5086..b58a7e30d37c 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -186,6 +186,17 @@ int btrfs_delayed_refs_rsv_refill(struct btrfs_fs_info *fs_info, u64 num_bytes = 0; int ret = -ENOSPC; + /* + * We have to check the mount option here because we could be enabling + * the free space tree for the first time and don't have the compat_ro + * option set yet. + * + * We need extra reservations if we have the free space tree because + * we'll have to modify that tree as well. + */ + if (btrfs_test_opt(fs_info, FREE_SPACE_TREE)) + limit *= 2; + spin_lock(&block_rsv->lock); if (block_rsv->reserved < block_rsv->size) { num_bytes = block_rsv->size - block_rsv->reserved; From patchwork Tue Mar 21 11:13:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13182609 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 163FCC6FD1D for ; Tue, 21 Mar 2023 11:15:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230343AbjCULPE (ORCPT ); Tue, 21 Mar 2023 07:15:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230333AbjCULOw (ORCPT ); Tue, 21 Mar 2023 07:14:52 -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 C5C722E80F for ; Tue, 21 Mar 2023 04:14:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9EDB461B19 for ; Tue, 21 Mar 2023 11:14:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 949B9C433D2 for ; Tue, 21 Mar 2023 11:14:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679397259; bh=hP4vJCnFaf1FuRGwyOqw6rJoqNo8QZk65iAqXetaKls=; h=From:To:Subject:Date:In-Reply-To:References:From; b=RTf9kzw8PkYWBgop7dXW5kEiKSg1/olrFOijtLHj9BZq2x9m1dOT0wJvBY9l+q+GA /zX505SoRfMEc7HwOQJNbYedDk46t/vy+Wr/aS/mj/7gjbXVRlh6ewpTY7fuU38Dq2 HKZ5SOtAMDeoM/sPTIRAeFhmFpI/tw3OGwuPB2yj9Y0v1bCpffJEdFhMfq5f4G7U9G Tar0yN3tXBIS0UpwcA8wx4nzo1uL8HCEr9mQ4VZztyYuh8sNR3NR8/oa5Zp5N3Aqc1 2Tf8i9nT4OKpQmhp8FNIBhrZQFJGb/b4puzxscpQuDQKyCbZFjwqEyorjo/oZxbLGS ESCKaENp6cWKw== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 16/24] btrfs: accurately calculate number of delayed refs when flushing Date: Tue, 21 Mar 2023 11:13:52 +0000 Message-Id: <0ae56ee41ac09f5e6dbc4d5732f4ede73f4995e7.1679326434.git.fdmanana@suse.com> X-Mailer: git-send-email 2.25.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 a limited number of delayed references (FLUSH_DELAYED_REFS_NR state), we are assuming each delayed reference is holding a number of bytes matching the needed space for inserting for a single metadata item (the result of btrfs_calc_insert_metadata_size()). That is not correct when using the free space tree, as in that case we have to multiply that value by 2 since we need to touch the free space tree as well. This is the same computation as we do at btrfs_update_delayed_refs_rsv() and at btrfs_delayed_refs_rsv_release(). So correct the computation for the amount of delayed references we need to flush in case we have the free space tree. This does not fix a functional issue, instead it makes the flush code flush less delayed references, only the minimum necessary to satisfy a ticket. Signed-off-by: Filipe Manana --- fs/btrfs/space-info.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index 5eb161d96e35..f36b16ee0a02 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -550,6 +550,30 @@ static inline u64 calc_reclaim_items_nr(struct btrfs_fs_info *fs_info, return nr; } +static inline u64 calc_delayed_refs_nr(struct btrfs_fs_info *fs_info, + u64 to_reclaim) +{ + u64 bytes; + u64 nr; + + bytes = btrfs_calc_insert_metadata_size(fs_info, 1); + /* + * We have to check the mount option here because we could be enabling + * the free space tree for the first time and don't have the compat_ro + * option set yet. + * + * We need extra reservations if we have the free space tree because + * we'll have to modify that tree as well. + */ + if (btrfs_test_opt(fs_info, FREE_SPACE_TREE)) + bytes *= 2; + + nr = div64_u64(to_reclaim, bytes); + if (!nr) + nr = 1; + return nr; +} + #define EXTENT_SIZE_PER_ITEM SZ_256K /* @@ -727,7 +751,7 @@ static void flush_space(struct btrfs_fs_info *fs_info, break; } if (state == FLUSH_DELAYED_REFS_NR) - nr = calc_reclaim_items_nr(fs_info, num_bytes); + nr = calc_delayed_refs_nr(fs_info, num_bytes); else nr = 0; btrfs_run_delayed_refs(trans, nr); From patchwork Tue Mar 21 11:13:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13182612 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 BEFBCC7618D for ; Tue, 21 Mar 2023 11:15:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230497AbjCULPI (ORCPT ); Tue, 21 Mar 2023 07:15:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230298AbjCULPA (ORCPT ); Tue, 21 Mar 2023 07:15:00 -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 506DB2ED72 for ; Tue, 21 Mar 2023 04:14:30 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8104F61B18 for ; Tue, 21 Mar 2023 11:14:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76E68C433EF for ; Tue, 21 Mar 2023 11:14:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679397259; bh=omYWRS+633ABZzbNsfh7CvBQsTvK758ID5Da2jNK4Dc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Ca5NbL5rkgaxMrqyQjI03wkGTlC358fp1QPf7IrPLBB0LdUmRp7nop15OonK2kpNz z7l7r2YoCPJoG+veMr1ksD832o3O4YaLIXYn2EfCsGnuxuxcy+QKhk2Ff0+UBZKE4E WoYGaOFRqG2tY2kLpYB3R0nVzLX4hdhrckULxqLIm/ZHjGtFThNdSRaUJnFwVFkgz9 uzw9WQTtqzpTYAcHQtFMDF6VfMK1v2eyv5eL3pMKEMNtAaHkShzLFAlP9NWYsX+4ts 3jNgk5y5Rs/Ryz8ba/hOmCg7OfgsZvghI9hPNHNg6vMEix3FXayxkFgCS+PPB+ddzp HNzmoVJzs2Ygg== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 17/24] btrfs: constify fs_info argument of the metadata size calculation helpers Date: Tue, 21 Mar 2023 11:13:53 +0000 Message-Id: <9a763409b806ae4e3be981a554628e6f7dcb6fe6.1679326434.git.fdmanana@suse.com> X-Mailer: git-send-email 2.25.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 fs_info argument of the helpers btrfs_calc_insert_metadata_size() and btrfs_calc_metadata_size() is not modified so it can be const. This will also allow a new helper function in one of the next patches to have its fs_info argument as const. Signed-off-by: Filipe Manana Reviewed-by: Anand Jain --- fs/btrfs/fs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/fs.h b/fs/btrfs/fs.h index 492436e1a59e..0ce43318ac0e 100644 --- a/fs/btrfs/fs.h +++ b/fs/btrfs/fs.h @@ -822,7 +822,7 @@ static inline u64 btrfs_csum_bytes_to_leaves( * Use this if we would be adding new items, as we could split nodes as we cow * down the tree. */ -static inline u64 btrfs_calc_insert_metadata_size(struct btrfs_fs_info *fs_info, +static inline u64 btrfs_calc_insert_metadata_size(const struct btrfs_fs_info *fs_info, unsigned num_items) { return (u64)fs_info->nodesize * BTRFS_MAX_LEVEL * 2 * num_items; @@ -832,7 +832,7 @@ static inline u64 btrfs_calc_insert_metadata_size(struct btrfs_fs_info *fs_info, * Doing a truncate or a modification won't result in new nodes or leaves, just * what we need for COW. */ -static inline u64 btrfs_calc_metadata_size(struct btrfs_fs_info *fs_info, +static inline u64 btrfs_calc_metadata_size(const struct btrfs_fs_info *fs_info, unsigned num_items) { return (u64)fs_info->nodesize * BTRFS_MAX_LEVEL * num_items; From patchwork Tue Mar 21 11:13:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13182603 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 DA2FEC74A5B for ; Tue, 21 Mar 2023 11:14:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230305AbjCULOv (ORCPT ); Tue, 21 Mar 2023 07:14:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229685AbjCULOr (ORCPT ); Tue, 21 Mar 2023 07:14:47 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE36149DA for ; Tue, 21 Mar 2023 04:14:23 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 16E8CB815BE for ; Tue, 21 Mar 2023 11:14:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 59190C433D2 for ; Tue, 21 Mar 2023 11:14:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679397260; bh=GL2LAIGNbxHFtqbPtd7Q1PrEWzXb3gGQDrHLqta0Lyo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=aqje9iARLXT8ORJzh2Q7fW+thUXEuvXqKRmdSy4CC6rT/hjpU9lhZpXmKmp0eri/N 0i4EmdYfOvM0a6YvDSr7Vd5p+8Jl+BSH9CdGkJDcSTMORaIZx8Xe2fgxkdI8Mj25YH OhYZXofAgUKqdHApq5/z27Q1TdesiaLuYxUeBGclBCdh79dmxiE5BF/A8g20lfMCKO utUaOMolOIC7P+mhpT4DW3morl9ru7z3iwS10uXCV2NPDxJGRDr/WQS3EaZWdukEmP 1vlj4cnLLP9EM0nVQK6Xo6NzDNiDt/MahZ89as+95mlzIvVyNtj5jSP+kHY+hw8qEV uc1j/fZgfPnrQ== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 18/24] btrfs: constify fs_info argument for the reclaim items calculation helpers Date: Tue, 21 Mar 2023 11:13:54 +0000 Message-Id: <70dff2b84bb04e277e8e62ae0709d08f44eeee60.1679326434.git.fdmanana@suse.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana Now that btrfs_calc_insert_metadata_size() can take a const fs_info argument, make the fs_info argument of calc_reclaim_items_nr() and of calc_delayed_refs_nr() const as well. Signed-off-by: Filipe Manana Reviewed-by: Anand Jain --- fs/btrfs/space-info.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index f36b16ee0a02..a2e14c410416 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -537,7 +537,7 @@ void btrfs_dump_space_info(struct btrfs_fs_info *fs_info, up_read(&info->groups_sem); } -static inline u64 calc_reclaim_items_nr(struct btrfs_fs_info *fs_info, +static inline u64 calc_reclaim_items_nr(const struct btrfs_fs_info *fs_info, u64 to_reclaim) { u64 bytes; @@ -550,7 +550,7 @@ static inline u64 calc_reclaim_items_nr(struct btrfs_fs_info *fs_info, return nr; } -static inline u64 calc_delayed_refs_nr(struct btrfs_fs_info *fs_info, +static inline u64 calc_delayed_refs_nr(const struct btrfs_fs_info *fs_info, u64 to_reclaim) { u64 bytes; From patchwork Tue Mar 21 11:13:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13182600 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 A7306C7618D for ; Tue, 21 Mar 2023 11:14:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229989AbjCULOt (ORCPT ); Tue, 21 Mar 2023 07:14:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230172AbjCULOq (ORCPT ); Tue, 21 Mar 2023 07:14:46 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5BA27A94 for ; Tue, 21 Mar 2023 04:14:24 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E74D3B815BD for ; Tue, 21 Mar 2023 11:14:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3AC03C4339B for ; Tue, 21 Mar 2023 11:14:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679397261; bh=NueealvMRsK3iixCbTzLOBCzyh7/6CN9fX/gFZWst6E=; h=From:To:Subject:Date:In-Reply-To:References:From; b=qs93rlAbg1dA3YO4E5bDViyEcOJdFztJ3m+JB1tKKgHD3P4kjzgZXM/SKj5/hcStH ll1GN9IW4EbwF8dDq+wY90NZd9bAa/wm30dJYXtqloiCLSvxWAIawdkBx9/POJ/1eP I91ITnVCS2wPujAww/ZFVxXXnNXNCgkv9XF7TFGHtcKvakbE4aVf0TvNNfOdHhQ4Xd pd8s4rxhy4Ziotc+ubfkHrGGtqD4mxBm7VTv9rrXPOQlEwMxY+IRwB7DTlZgD2Nz6T QEiq7ylWHHDGpGPWIzDib9CsrPGf90kWirVpv4UybcigawjOmz1jAWs/4iBv8I8vFG hNsN3qcyXVnQg== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 19/24] btrfs: add helper to calculate space for delayed references Date: Tue, 21 Mar 2023 11:13:55 +0000 Message-Id: <9ed53459825f637db5e101eb4680a20487f84da3.1679326434.git.fdmanana@suse.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana Instead of duplicating the logic for calculating how much space is required for a given number of delayed references, add an inline helper to encapsulate that logic and use it everywhere we are calculating the space required. Signed-off-by: Filipe Manana --- fs/btrfs/delayed-ref.c | 40 ++++------------------------------------ fs/btrfs/delayed-ref.h | 21 +++++++++++++++++++++ fs/btrfs/space-info.c | 14 +------------- 3 files changed, 26 insertions(+), 49 deletions(-) diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index b58a7e30d37c..0b32432d7d56 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -65,20 +65,9 @@ bool btrfs_check_space_for_delayed_refs(struct btrfs_fs_info *fs_info) void btrfs_delayed_refs_rsv_release(struct btrfs_fs_info *fs_info, int nr) { struct btrfs_block_rsv *block_rsv = &fs_info->delayed_refs_rsv; - u64 num_bytes = btrfs_calc_insert_metadata_size(fs_info, nr); + const u64 num_bytes = btrfs_calc_delayed_ref_bytes(fs_info, nr); u64 released = 0; - /* - * We have to check the mount option here because we could be enabling - * the free space tree for the first time and don't have the compat_ro - * option set yet. - * - * We need extra reservations if we have the free space tree because - * we'll have to modify that tree as well. - */ - if (btrfs_test_opt(fs_info, FREE_SPACE_TREE)) - num_bytes *= 2; - released = btrfs_block_rsv_release(fs_info, block_rsv, num_bytes, NULL); if (released) trace_btrfs_space_reservation(fs_info, "delayed_refs_rsv", @@ -100,18 +89,8 @@ void btrfs_update_delayed_refs_rsv(struct btrfs_trans_handle *trans) if (!trans->delayed_ref_updates) return; - num_bytes = btrfs_calc_insert_metadata_size(fs_info, - trans->delayed_ref_updates); - /* - * We have to check the mount option here because we could be enabling - * the free space tree for the first time and don't have the compat_ro - * option set yet. - * - * We need extra reservations if we have the free space tree because - * we'll have to modify that tree as well. - */ - if (btrfs_test_opt(fs_info, FREE_SPACE_TREE)) - num_bytes *= 2; + num_bytes = btrfs_calc_delayed_ref_bytes(fs_info, + trans->delayed_ref_updates); spin_lock(&delayed_rsv->lock); delayed_rsv->size += num_bytes; @@ -182,21 +161,10 @@ int btrfs_delayed_refs_rsv_refill(struct btrfs_fs_info *fs_info, enum btrfs_reserve_flush_enum flush) { struct btrfs_block_rsv *block_rsv = &fs_info->delayed_refs_rsv; - u64 limit = btrfs_calc_insert_metadata_size(fs_info, 1); + u64 limit = btrfs_calc_delayed_ref_bytes(fs_info, 1); u64 num_bytes = 0; int ret = -ENOSPC; - /* - * We have to check the mount option here because we could be enabling - * the free space tree for the first time and don't have the compat_ro - * option set yet. - * - * We need extra reservations if we have the free space tree because - * we'll have to modify that tree as well. - */ - if (btrfs_test_opt(fs_info, FREE_SPACE_TREE)) - limit *= 2; - spin_lock(&block_rsv->lock); if (block_rsv->reserved < block_rsv->size) { num_bytes = block_rsv->size - block_rsv->reserved; diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h index 6cf1adc9a01a..b54261fe509b 100644 --- a/fs/btrfs/delayed-ref.h +++ b/fs/btrfs/delayed-ref.h @@ -253,6 +253,27 @@ extern struct kmem_cache *btrfs_delayed_extent_op_cachep; int __init btrfs_delayed_ref_init(void); void __cold btrfs_delayed_ref_exit(void); +static inline u64 btrfs_calc_delayed_ref_bytes(const struct btrfs_fs_info *fs_info, + int num_delayed_refs) +{ + u64 num_bytes; + + num_bytes = btrfs_calc_insert_metadata_size(fs_info, num_delayed_refs); + + /* + * We have to check the mount option here because we could be enabling + * the free space tree for the first time and don't have the compat_ro + * option set yet. + * + * We need extra reservations if we have the free space tree because + * we'll have to modify that tree as well. + */ + if (btrfs_test_opt(fs_info, FREE_SPACE_TREE)) + num_bytes *= 2; + + return num_bytes; +} + static inline void btrfs_init_generic_ref(struct btrfs_ref *generic_ref, int action, u64 bytenr, u64 len, u64 parent) { diff --git a/fs/btrfs/space-info.c b/fs/btrfs/space-info.c index a2e14c410416..75e7fa337e66 100644 --- a/fs/btrfs/space-info.c +++ b/fs/btrfs/space-info.c @@ -553,21 +553,9 @@ static inline u64 calc_reclaim_items_nr(const struct btrfs_fs_info *fs_info, static inline u64 calc_delayed_refs_nr(const struct btrfs_fs_info *fs_info, u64 to_reclaim) { - u64 bytes; + const u64 bytes = btrfs_calc_delayed_ref_bytes(fs_info, 1); u64 nr; - bytes = btrfs_calc_insert_metadata_size(fs_info, 1); - /* - * We have to check the mount option here because we could be enabling - * the free space tree for the first time and don't have the compat_ro - * option set yet. - * - * We need extra reservations if we have the free space tree because - * we'll have to modify that tree as well. - */ - if (btrfs_test_opt(fs_info, FREE_SPACE_TREE)) - bytes *= 2; - nr = div64_u64(to_reclaim, bytes); if (!nr) nr = 1; From patchwork Tue Mar 21 11:13:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13182605 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 47EC9C6FD1D for ; Tue, 21 Mar 2023 11:14:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230389AbjCULOx (ORCPT ); Tue, 21 Mar 2023 07:14:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230259AbjCULOt (ORCPT ); Tue, 21 Mar 2023 07:14:49 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91A1224C80 for ; Tue, 21 Mar 2023 04:14:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D37FDB815C2 for ; Tue, 21 Mar 2023 11:14:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1C51EC4339C for ; Tue, 21 Mar 2023 11:14:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679397262; bh=sxN2OgHqV+jAvsHFbRd7CbGMbD//bNO1W6W+F0zQ6No=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Ni/M23cQ5m+gx/Q2BH3pcXu/76rxnJUto1AwE+iOc7F9m6Tw7LaqEEjuuHEh3yDGD DTxJi0ZwOWgzj+9I6ajPUilbGUD1UPCGkdwrykMvLLWGWaiCzlsyGznwR/T8tllyNH ikwq04MSf7nBVJYI2Yra2Kyug5YwOEkO+3yxcVHKYohu9eJdZfe89KS+LAq4uqh88E SpLzF+Wq+ZMEyPCOMy3stkREkU2vJZdM5OYONiKxK3wk404HstioV2Hzhk/g/K/FwV wkIiRspETUdHLlRcGEV3v6eBIxWZQlx7StMuELKzj9oHyU6uDKAy+/y72M5DevlcE2 /x+3n2ZJ/Zxig== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 20/24] btrfs: calculate correct amount of space for delayed reference when evicting Date: Tue, 21 Mar 2023 11:13:56 +0000 Message-Id: <485fb4c5b11a2fa22426656d09ca2ab6c96504bd.1679326434.git.fdmanana@suse.com> X-Mailer: git-send-email 2.25.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 evicting an inode, we are incorrectly calculating the amount of space required for a single delayed reference in case the free space tree is enabled. We have to multiply by 2 the result of btrfs_calc_insert_metadata_size(). We should be calculating according to the size update and space release of the delayed block reserve logic at btrfs_update_delayed_refs_rsv() and btrfs_delayed_refs_rsv_release(). Fix this by using the btrfs_calc_delayed_ref_bytes() helper at evict_refill_and_join() instead of btrfs_calc_insert_metadata_size(). Signed-off-by: Filipe Manana --- fs/btrfs/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 912d5f4aafbc..2e181a0a6f37 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -5230,7 +5230,7 @@ static struct btrfs_trans_handle *evict_refill_and_join(struct btrfs_root *root, { struct btrfs_fs_info *fs_info = root->fs_info; struct btrfs_trans_handle *trans; - u64 delayed_refs_extra = btrfs_calc_insert_metadata_size(fs_info, 1); + u64 delayed_refs_extra = btrfs_calc_delayed_ref_bytes(fs_info, 1); int ret; /* From patchwork Tue Mar 21 11:13: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: 13182611 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 AC0CEC6FD1D for ; Tue, 21 Mar 2023 11:15:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229541AbjCULPH (ORCPT ); Tue, 21 Mar 2023 07:15:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230437AbjCULOz (ORCPT ); Tue, 21 Mar 2023 07:14:55 -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 505482CC66 for ; Tue, 21 Mar 2023 04:14:30 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0C28961B04 for ; Tue, 21 Mar 2023 11:14:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2690C433D2 for ; Tue, 21 Mar 2023 11:14:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679397263; bh=fgYWrVixBIstXE1DwaAX2tdD7DI2fyiLH37lLmoykHM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=dscPSf4NKz3fHVVGJQKvUx1O2xiagy140RqM/r7i80kg7yuSk7cBRAduQZvkIkUYW hLWILiFFp1siFkEvZP0mFlTQIR8y0GYsAondXReAlJ1rxw9yGH/qdbrsklNxI/Fxxi W8Rn/vXf0DLr7yLxtRpfBlzEpGeh5NZsZnxeEHhHpduXcGAelF2Fi6n4b6zWuJip+L dDZCww4/vjr4Gz28ZG9V7SZd8yIW4ht3eSCdH3vnjMoMevtxFHbbvHyWBjOlNdalpu ikd8Zr5RfZ+1oRaOpHV9svsIqUS1wOGYyKnX5/eh9f55pAyqi/oIKBgYvy9sF9DgxU YVILeWjAHldHw== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 21/24] btrfs: fix calculation of the global block reserve's size Date: Tue, 21 Mar 2023 11:13:57 +0000 Message-Id: <30080cbfbfcb835e8c1cbd6762afa464a7b6454c.1679326434.git.fdmanana@suse.com> X-Mailer: git-send-email 2.25.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 btrfs_update_global_block_rsv(), we are assuming an unlink operation uses 5 metadata units, but that's not true anymore, it uses 6 since the commit bca4ad7c0b54 ("btrfs: reserve correct number of items for unlink and rmdir"). So update the code and comments to consider 6 units. Signed-off-by: Filipe Manana --- fs/btrfs/block-rsv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/block-rsv.c b/fs/btrfs/block-rsv.c index 90b8088e8fac..6edcb32ed4c9 100644 --- a/fs/btrfs/block-rsv.c +++ b/fs/btrfs/block-rsv.c @@ -350,14 +350,14 @@ void btrfs_update_global_block_rsv(struct btrfs_fs_info *fs_info) /* * But we also want to reserve enough space so we can do the fallback - * global reserve for an unlink, which is an additional 5 items (see the + * global reserve for an unlink, which is an additional 6 items (see the * comment in __unlink_start_trans for what we're modifying.) * * But we also need space for the delayed ref updates from the unlink, - * so its 10, 5 for the actual operation, and 5 for the delayed ref + * so its 12, 6 for the actual operation, and 6 for the delayed ref * updates. */ - min_items += 10; + min_items += 12; num_bytes = max_t(u64, num_bytes, btrfs_calc_insert_metadata_size(fs_info, min_items)); From patchwork Tue Mar 21 11:13: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: 13182613 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 5AFEBC761A6 for ; Tue, 21 Mar 2023 11:15:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230454AbjCULPJ (ORCPT ); Tue, 21 Mar 2023 07:15:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230250AbjCULPD (ORCPT ); Tue, 21 Mar 2023 07:15:03 -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 3A6A936083 for ; Tue, 21 Mar 2023 04:14:30 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E120661AE3 for ; Tue, 21 Mar 2023 11:14:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4C1AC4339B for ; Tue, 21 Mar 2023 11:14:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679397264; bh=xhDIXlapDsSvaL087fSXlZVNLBMQqHq8SOQJRYoqb3I=; h=From:To:Subject:Date:In-Reply-To:References:From; b=MPOgLVOYLZJWGGKF1jtIlM5F3ZPltgTG3eZrf+edmx2+UHhabPpIX0yz8BC/Semxh t0GM9r87igfaaiUC9PAM7JgNjJ1LsFUsjVgU/tgllNrmWOfdaHrDmGODoqlU5NJJRJ 363je/MGihSEcpBgGBgzzw4ApRBtPta3UMPS/8wiXikouUHo7mL5L4rC0l1I+31DEK SBeCPuuSdiCjN5Xo1IJkLWdHYET50+NzXlfJGG8akoGF4FZSiPW6ehgsRgsTkrDq9Z nlPctaM5Nj/PGUhww3TQ6wnatGdf4T6AuEc1zDLcQcnjyrdNj/8XeckXF0gZoLvPEZ 5BmhsMFABBvQQ== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 22/24] btrfs: use a constant for the number of metadata units needed for an unlink Date: Tue, 21 Mar 2023 11:13:58 +0000 Message-Id: <25c3d88a6f706ae21fa100159e0aedacb6c75230.1679326434.git.fdmanana@suse.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana Instead of hard coding the number of metadata units for an unlink operation in a couple places, define a macro and use it instead. This eliminates the problem of one place getting out of sync with the other, such as recently fixed by the previous patch in the series ("btrfs: fix calculation of the global block reserve's size"). Signed-off-by: Filipe Manana Reviewed-by: Anand Jain --- fs/btrfs/block-rsv.c | 11 ++++++----- fs/btrfs/fs.h | 12 ++++++++++++ fs/btrfs/inode.c | 11 ++--------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/fs/btrfs/block-rsv.c b/fs/btrfs/block-rsv.c index 6edcb32ed4c9..b4a1f1bc340f 100644 --- a/fs/btrfs/block-rsv.c +++ b/fs/btrfs/block-rsv.c @@ -350,14 +350,15 @@ void btrfs_update_global_block_rsv(struct btrfs_fs_info *fs_info) /* * But we also want to reserve enough space so we can do the fallback - * global reserve for an unlink, which is an additional 6 items (see the - * comment in __unlink_start_trans for what we're modifying.) + * global reserve for an unlink, which is an additional + * BTRFS_UNLINK_METADATA_UNITS items. * * But we also need space for the delayed ref updates from the unlink, - * so its 12, 6 for the actual operation, and 6 for the delayed ref - * updates. + * so it's BTRFS_UNLINK_METADATA_UNITS * 2, BTRFS_UNLINK_METADATA_UNITS + * for the actual operation, and BTRFS_UNLINK_METADATA_UNITS more for + * the delayed ref updates. */ - min_items += 12; + min_items += BTRFS_UNLINK_METADATA_UNITS * 2; num_bytes = max_t(u64, num_bytes, btrfs_calc_insert_metadata_size(fs_info, min_items)); diff --git a/fs/btrfs/fs.h b/fs/btrfs/fs.h index 0ce43318ac0e..ca17a7fc3ac3 100644 --- a/fs/btrfs/fs.h +++ b/fs/btrfs/fs.h @@ -24,6 +24,18 @@ #define BTRFS_SUPER_INFO_SIZE 4096 static_assert(sizeof(struct btrfs_super_block) == BTRFS_SUPER_INFO_SIZE); +/* + * Number of metadata items necessary for an unlink operation: + * + * 1 for the possible orphan item + * 1 for the dir item + * 1 for the dir index + * 1 for the inode ref + * 1 for the inode + * 1 for the parent inode + */ +#define BTRFS_UNLINK_METADATA_UNITS 6 + /* * The reserved space at the beginning of each device. It covers the primary * super block and leaves space for potential use by other tools like diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 2e181a0a6f37..0b3710d47dd0 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -4248,15 +4248,8 @@ static struct btrfs_trans_handle *__unlink_start_trans(struct btrfs_inode *dir) { struct btrfs_root *root = dir->root; - /* - * 1 for the possible orphan item - * 1 for the dir item - * 1 for the dir index - * 1 for the inode ref - * 1 for the inode - * 1 for the parent inode - */ - return btrfs_start_transaction_fallback_global_rsv(root, 6); + return btrfs_start_transaction_fallback_global_rsv(root, + BTRFS_UNLINK_METADATA_UNITS); } static int btrfs_unlink(struct inode *dir, struct dentry *dentry) From patchwork Tue Mar 21 11:13: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: 13182606 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 5ED03C77B60 for ; Tue, 21 Mar 2023 11:15:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230228AbjCULO6 (ORCPT ); Tue, 21 Mar 2023 07:14:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230281AbjCULOu (ORCPT ); Tue, 21 Mar 2023 07:14:50 -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 3A61B35273 for ; Tue, 21 Mar 2023 04:14:30 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BDCCE61B1D for ; Tue, 21 Mar 2023 11:14:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B769BC433EF for ; Tue, 21 Mar 2023 11:14:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679397265; bh=T82ZI3qW9gZbESYZpnuSXwp+ZGMRGzRo3xpk6bCmppk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=p7MTf7d8GsLxaXwXp+GPy3nUHi7Oi5kujjMK/1PwX5pFtk9VQwYtyWghd8VQok6K1 ELBG0FjTdnwF/wNXQFK5xaH/6fdCqe0OYklORPDUa5lV4XgcH3Jci1LxqE1YeKhvWu fEFEdzQZHP6ylt/Ydw4YZqsNjKjFikA8/9JMEdEBtapRCtIeUVgfoQRKzFwvPf71SF fuOMS6RElY9uQtT91JQ8ZLRss5mm4nmTTJ77bU2krvR1Ov4d//+uJ470PInzsPKIIp OO4mB1bLliPP8MEe+0E2xC6ZLQQDpcXyRvXhqQOT0S6/puV7pKtbOIJheBIhhOnDJ9 08ZfTcqBgmBsg== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 23/24] btrfs: calculate the right space for delayed refs when updating global reserve Date: Tue, 21 Mar 2023 11:13:59 +0000 Message-Id: <910e0c266d33d7d7f05b2a3237d34b23ad12dde5.1679326435.git.fdmanana@suse.com> X-Mailer: git-send-email 2.25.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 updating the global block reserve, we account for the 6 items needed by an unlink operation and the 6 delayed references for each one of those items. However the calculation for the delayed references is not correct in case we have the free space tree enabled, as in that case we need to touch the free space tree as well and therefore need twice the number of bytes. So use the btrfs_calc_delayed_ref_bytes() helper to calculate the number of bytes need for the delayed references at btrfs_update_global_block_rsv(). Signed-off-by: Filipe Manana --- fs/btrfs/block-rsv.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/block-rsv.c b/fs/btrfs/block-rsv.c index b4a1f1bc340f..3ab707e26fa2 100644 --- a/fs/btrfs/block-rsv.c +++ b/fs/btrfs/block-rsv.c @@ -354,14 +354,15 @@ void btrfs_update_global_block_rsv(struct btrfs_fs_info *fs_info) * BTRFS_UNLINK_METADATA_UNITS items. * * But we also need space for the delayed ref updates from the unlink, - * so it's BTRFS_UNLINK_METADATA_UNITS * 2, BTRFS_UNLINK_METADATA_UNITS - * for the actual operation, and BTRFS_UNLINK_METADATA_UNITS more for - * the delayed ref updates. + * so add BTRFS_UNLINK_METADATA_UNITS units for delayed refs, one for + * each unlink metadata item. */ - min_items += BTRFS_UNLINK_METADATA_UNITS * 2; + min_items += BTRFS_UNLINK_METADATA_UNITS; num_bytes = max_t(u64, num_bytes, - btrfs_calc_insert_metadata_size(fs_info, min_items)); + btrfs_calc_insert_metadata_size(fs_info, min_items) + + btrfs_calc_delayed_ref_bytes(fs_info, + BTRFS_UNLINK_METADATA_UNITS)); spin_lock(&sinfo->lock); spin_lock(&block_rsv->lock); From patchwork Tue Mar 21 11:14: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: 13182610 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 51DCDC74A5B for ; Tue, 21 Mar 2023 11:15:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230450AbjCULPF (ORCPT ); Tue, 21 Mar 2023 07:15:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229685AbjCULOw (ORCPT ); Tue, 21 Mar 2023 07:14:52 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EC683B858 for ; Tue, 21 Mar 2023 04:14:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 4AF0CB815B4 for ; Tue, 21 Mar 2023 11:14:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 99144C4339B for ; Tue, 21 Mar 2023 11:14:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679397266; bh=UWqbeMMaFS3sux1zAjaQCy/q8tfylgXmh16CGfsTp84=; h=From:To:Subject:Date:In-Reply-To:References:From; b=UC9jItzqmrKhNlDklgtcBKr4iulV8BmD0wykxmAyHQ2X2Sl2HQeOI65zw8X0JWQwK u4HIP8nKjqH4+VPAiHj5e2Ecoi44godZO/0AOpEWAiUKp3IE5uBW5fUj2Yn5V3ElIz bZN7rbWdx8/+cMoUH7ikl8U9Q34uOqlhQB+QHUwdLshnh/vCm9wyNxQ3Iz2IKxdAq9 56L2fIRdP1G3aG/8u621LVBXLJJ/Qp84lZC6oVrvQc2LjYN3yntq4ezlU40cr+GTnc GhMRRN/AmgSqYHajck1a8HVSaWkyx6ZQhYTxnLS6pGkBYiMdcoJyf80jk6gmBPYBT7 ljNRQn3DHM3aA== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 24/24] btrfs: simplify exit paths of btrfs_evict_inode() Date: Tue, 21 Mar 2023 11:14:00 +0000 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Filipe Manana Instead of using two labels at btrfs_evict_inode() for exiting depending on whether we need to delete the inode items and orphan or some error happened, we can use a single exit label if we initialize the block reserve to NULL, since btrfs_free_block_rsv() ignores a NULL block reserve pointer. So just do that. It will also make an upcoming change simpler by avoiding one extra error label. Signed-off-by: Filipe Manana --- fs/btrfs/inode.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 0b3710d47dd0..865d56ff2ce1 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -5271,7 +5271,7 @@ void btrfs_evict_inode(struct inode *inode) struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); struct btrfs_trans_handle *trans; struct btrfs_root *root = BTRFS_I(inode)->root; - struct btrfs_block_rsv *rsv; + struct btrfs_block_rsv *rsv = NULL; int ret; trace_btrfs_inode_evict(inode); @@ -5288,18 +5288,18 @@ void btrfs_evict_inode(struct inode *inode) ((btrfs_root_refs(&root->root_item) != 0 && root->root_key.objectid != BTRFS_ROOT_TREE_OBJECTID) || btrfs_is_free_space_inode(BTRFS_I(inode)))) - goto no_delete; + goto out; if (is_bad_inode(inode)) - goto no_delete; + goto out; if (test_bit(BTRFS_FS_LOG_RECOVERING, &fs_info->flags)) - goto no_delete; + goto out; if (inode->i_nlink > 0) { BUG_ON(btrfs_root_refs(&root->root_item) != 0 && root->root_key.objectid != BTRFS_ROOT_TREE_OBJECTID); - goto no_delete; + goto out; } /* @@ -5308,7 +5308,7 @@ void btrfs_evict_inode(struct inode *inode) */ ret = btrfs_commit_inode_delayed_inode(BTRFS_I(inode)); if (ret) - goto no_delete; + goto out; /* * This drops any pending insert or delete operations we have for this @@ -5320,7 +5320,7 @@ void btrfs_evict_inode(struct inode *inode) rsv = btrfs_alloc_block_rsv(fs_info, BTRFS_BLOCK_RSV_TEMP); if (!rsv) - goto no_delete; + goto out; rsv->size = btrfs_calc_metadata_size(fs_info, 1); rsv->failfast = true; @@ -5336,7 +5336,7 @@ void btrfs_evict_inode(struct inode *inode) trans = evict_refill_and_join(root, rsv); if (IS_ERR(trans)) - goto free_rsv; + goto out; trans->block_rsv = rsv; @@ -5350,7 +5350,7 @@ void btrfs_evict_inode(struct inode *inode) */ btrfs_btree_balance_dirty_nodelay(fs_info); if (ret && ret != -ENOSPC && ret != -EAGAIN) - goto free_rsv; + goto out; else if (!ret) break; } @@ -5372,9 +5372,8 @@ void btrfs_evict_inode(struct inode *inode) btrfs_end_transaction(trans); } -free_rsv: +out: btrfs_free_block_rsv(fs_info, rsv); -no_delete: /* * If we didn't successfully delete, the orphan item will still be in * the tree and we'll retry on the next mount. Again, we might also want