From patchwork Wed Apr 5 16:20:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 13202204 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 3691DC7619A for ; Wed, 5 Apr 2023 16:21:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231965AbjDEQVW (ORCPT ); Wed, 5 Apr 2023 12:21:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232400AbjDEQVO (ORCPT ); Wed, 5 Apr 2023 12:21:14 -0400 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA72C7A91 for ; Wed, 5 Apr 2023 09:20:47 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 504605C0124; Wed, 5 Apr 2023 12:20:43 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 05 Apr 2023 12:20:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bur.io; h=cc :content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm2; t=1680711643; x= 1680798043; bh=rT8ps90nkz6L/i/kjjzngu3+dnvXOsBQkw2K4cCGtyM=; b=m zL5QYdRzDu+KCwa0ruZMwgnkM+9qZZUKnwffQLiyETJg4OsPsvlnyaAMNGKlhXIw pLTIAr3ZGP9GVaZJs7JU7ZBk0g++qx5qxNRRqVY1R0ZuFGzGjst1J+E9ZanmpxUK 0jIdSZoMM01E5pf9wxw4FoV2UUO03Wu1OO7ZxGy0xKxpZkXgoY/AujMcbSBQJ0iW CTKVFGxRI9soC5bdYex20qLt5Fa2qjQRku+Fvhyh5o9xgyadLFhEkylv+WoB0aYZ AF/hojphPnITENCRvQrI39cEfe6vtUVQXKsJkSDKiek6cMUIWy4Xe3G3WNp+jFaV iCahpEp6RWaZxN6bxDcng== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:date:feedback-id:feedback-id:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1680711643; x=1680798043; bh=r T8ps90nkz6L/i/kjjzngu3+dnvXOsBQkw2K4cCGtyM=; b=iBdT0MqluBsStqVve DBq6JD+Rr8fxIarSJVd/POt2a3jspyAmuvEE+yDAXmku3rYhDa5LOlA5y16Fnhc5 Nin6s8YmWXBhmchSR/BAOiqnSoTUQKimWVvMeupRXDHWbsiQCCiJQr7Tmzi55f48 /wVt4SRzi/5cRYfaeZBXZdn43S8uoMRepY8Y0XtWp1nADMSB1Vw9+0zRkaZY5Vic 4NrhV6rLTqDSwFZQM26QA2b/BMdPLvpajD8oaDEnp/zL6eKT6aKS6Tz6h/7Mjq7X RPvXx0kCiU7UKtPmIY5qvu1djm6lZCLOYI2fFe+8XRnziyyCZ63sCdZBuWJg/9rO Y+8Fg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdejuddguddtudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpeeuohhrihhsuceuuhhrkhhovhcuoegsohhrihhssegsuhhr rdhioheqnecuggftrfgrthhtvghrnhepfffggfekkeevveegudffuedvvedtkeevtdelvd efudelleegveetleekvdfhieeknecuffhomhgrihhnpehkvghrnhgvlhdrohhrghenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegsohhrihhsse gsuhhrrdhioh X-ME-Proxy: Feedback-ID: i083147f8:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 5 Apr 2023 12:20:42 -0400 (EDT) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 1/2] btrfs: set default discard iops_limit to 1000 Date: Wed, 5 Apr 2023 09:20:32 -0700 Message-Id: <45f813c5fabdb32df67ba661c396c592b863ff25.1680711209.git.boris@bur.io> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Previously, the default was a relatively conservative 10. This results in a 100ms delay, so with ~300 discards in a commit, it takes the full 30s till the next commit to finish the discards. On a workstation, this results in the disk never going idle, wasting power/battery, etc. Set the default to 1000, which results in using the smallest possible delay, currently, which is 1ms. This has shown to not pathologically keep the disk busy by the original reporter. Link: https://lore.kernel.org/linux-btrfs/ZCxKc5ZzP3Np71IC@infradead.org/T/#m6ebdeb475809ed7714b21b8143103fb7e5a966da Signed-off-by: Boris Burkov --- fs/btrfs/discard.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/discard.c b/fs/btrfs/discard.c index 317aeff6c1da..aef789bcff8f 100644 --- a/fs/btrfs/discard.c +++ b/fs/btrfs/discard.c @@ -60,7 +60,7 @@ #define BTRFS_DISCARD_TARGET_MSEC (6 * 60 * 60UL * MSEC_PER_SEC) #define BTRFS_DISCARD_MIN_DELAY_MSEC (1UL) #define BTRFS_DISCARD_MAX_DELAY_MSEC (1000UL) -#define BTRFS_DISCARD_MAX_IOPS (10U) +#define BTRFS_DISCARD_MAX_IOPS (10000U) /* Monotonically decreasing minimum length filters after index 0 */ static int discard_minlen[BTRFS_NR_DISCARD_LISTS] = { From patchwork Wed Apr 5 16:20:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 13202205 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 86E15C76188 for ; Wed, 5 Apr 2023 16:21:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232530AbjDEQV0 (ORCPT ); Wed, 5 Apr 2023 12:21:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232206AbjDEQVU (ORCPT ); Wed, 5 Apr 2023 12:21:20 -0400 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA6827DBA for ; Wed, 5 Apr 2023 09:20:50 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 014C75C012B; Wed, 5 Apr 2023 12:20:45 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Wed, 05 Apr 2023 12:20:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bur.io; h=cc :content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm2; t=1680711644; x= 1680798044; bh=HU254JURtP1xtG4Q1KJZEa/md2tlKYGqk3e6rwEAqYw=; b=L XxlgW61Pa8CpH3kNyvbCKCX0JzbO7wsfD5aKpRueCWf9agT6Mp/JL1B+yFAOEizg J4BK6qQr1ecAHLU1tCOuK3Xevd7LN3A0OEOZNTGHv/ZgPUeChtJD05ZSWNOpFHoH pcvwHUbPGN+Q1jzENJI9XC0E170frtxONLmUBDucrBOxe6UzwHCT359DnHVXeWla 7GUfMx1iAlivUVIqp4I/DDJpE5GhyF7/tHrx1wBuPDu88Rs7LfgcUmAJK1Tw97aq d9gZF0JEkHCWCKP0FOaqjvR0skoKKRciVo7/4FeBV1ziaKkUWOy5k5qsRwE7R8/j zc0Xu05OX3iAJeEpbJkLg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:date:feedback-id:feedback-id:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1680711644; x=1680798044; bh=H U254JURtP1xtG4Q1KJZEa/md2tlKYGqk3e6rwEAqYw=; b=f4/62Jr9HR2hvS5Xn z79Pb3xMtpaAZgFKEH3MeGlT9kUNW7V70n8FaosS1uNb8qnM/L0CASQzN9gkvRc1 Yc2T3J+OQ9qco63lrokWxxgEX16iYjgkAQkwZca93FzX/yuasl9M3SUBwbB45qoz Evf8VJs96VIj7jPH+0/eYJ+yWCJKIw/6EDtXPFfPzx2LGqtCx+zW+zULWk+0f6kE GYm58g3DmXVQBolQDBLFNj0egOnPNV8ThdAEdjkBNRS2d7uRLT0pHzrBXEt8JdaJ //zXyaannOegtm8M/YBvc7eavA+wryWO9eavSPsBc44t0B+f60i25A7XujI61SQK UA+WA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdejuddguddtudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpeeuohhrihhsuceuuhhrkhhovhcuoegsohhrihhssegsuhhr rdhioheqnecuggftrfgrthhtvghrnhepieeuffeuvdeiueejhfehiefgkeevudejjeejff evvdehtddufeeihfekgeeuheelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghm pehmrghilhhfrhhomhepsghorhhishessghurhdrihho X-ME-Proxy: Feedback-ID: i083147f8:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 5 Apr 2023 12:20:44 -0400 (EDT) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 2/2] btrfs: reinterpret async discard iops_limit=0 as no delay Date: Wed, 5 Apr 2023 09:20:33 -0700 Message-Id: X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Currently, a limit of 0 results in a hardcoded metering over 6 hours. Since the default is a set limit, I suspect no one truly depends on this rather arbitrary setting. Repurpose it for an arguably more useful "unlimited" mode, where the delay is 0. Note that if block groups are too new, or go fully empty, there is still a delay associated with those conditions. Those delays implement heuristics for not trimming a region we are relatively likely to fully overwrite soon. Signed-off-by: Boris Burkov --- fs/btrfs/discard.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/discard.c b/fs/btrfs/discard.c index aef789bcff8f..ac419ce9ab0a 100644 --- a/fs/btrfs/discard.c +++ b/fs/btrfs/discard.c @@ -56,8 +56,6 @@ #define BTRFS_DISCARD_DELAY (120ULL * NSEC_PER_SEC) #define BTRFS_DISCARD_UNUSED_DELAY (10ULL * NSEC_PER_SEC) -/* Target completion latency of discarding all discardable extents */ -#define BTRFS_DISCARD_TARGET_MSEC (6 * 60 * 60UL * MSEC_PER_SEC) #define BTRFS_DISCARD_MIN_DELAY_MSEC (1UL) #define BTRFS_DISCARD_MAX_DELAY_MSEC (1000UL) #define BTRFS_DISCARD_MAX_IOPS (10000U) @@ -577,6 +575,7 @@ void btrfs_discard_calc_delay(struct btrfs_discard_ctl *discard_ctl) s32 discardable_extents; s64 discardable_bytes; u32 iops_limit; + unsigned long min_delay = BTRFS_DISCARD_MIN_DELAY_MSEC; unsigned long delay; discardable_extents = atomic_read(&discard_ctl->discardable_extents); @@ -607,13 +606,16 @@ void btrfs_discard_calc_delay(struct btrfs_discard_ctl *discard_ctl) } iops_limit = READ_ONCE(discard_ctl->iops_limit); - if (iops_limit) + + if (iops_limit) { delay = MSEC_PER_SEC / iops_limit; - else - delay = BTRFS_DISCARD_TARGET_MSEC / discardable_extents; + } else { + /* unset iops_limit means go as fast as possible, so allow a delay of 0 */ + delay = 0; + min_delay = 0; + } - delay = clamp(delay, BTRFS_DISCARD_MIN_DELAY_MSEC, - BTRFS_DISCARD_MAX_DELAY_MSEC); + delay = clamp(delay, min_delay, BTRFS_DISCARD_MAX_DELAY_MSEC); discard_ctl->delay_ms = delay; spin_unlock(&discard_ctl->lock);