From patchwork Wed Apr 5 19:43:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 13202391 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 99B66C76188 for ; Wed, 5 Apr 2023 19:44:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234102AbjDEToO (ORCPT ); Wed, 5 Apr 2023 15:44:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233903AbjDEToN (ORCPT ); Wed, 5 Apr 2023 15:44:13 -0400 Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB57BE59 for ; Wed, 5 Apr 2023 12:44:11 -0700 (PDT) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id E04273200437; Wed, 5 Apr 2023 15:44:10 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Wed, 05 Apr 2023 15:44:11 -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=1680723850; x= 1680810250; bh=rmGIL0AcDTDb2LOU58Losv/uTenyFWn721tPNAQt+ys=; b=c DgMsKzw8QFOmYe8Ws9CLoiy2C5QrRcCd+f85ubfeZ0v2CsJvpUKuNqdCAmyjLSAM 1NwfR7U93bE4LHSIvort6Xf3mlZ2fyr5JGtIJUaKkXnCpAzBsG5Mmy9ypd6Wa5tf wOQIrq0junfd3cN2rUbounzfFw8Iqgeb1JMgvKV73m1UOt4lNskw2WX8L4zSIl1v wSiEGmF0ZLKrl02FlcBw6rTCvRK8pBsEDVU5zE1gibj659J0IdN4AEbExsZxlNFr R601JIYovNIDL4oF/06zUoymw78iSqa6WhkI0YoDyL+BYqKa/yJNRhzAFhKyRKWA v6kykI5D4P2J/gMnqzqmQ== 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=1680723850; x=1680810250; bh=r mGIL0AcDTDb2LOU58Losv/uTenyFWn721tPNAQt+ys=; b=Pv/ettvKITulmD3Co u6qq19npBOj81jk1o1NlVQUhWmtFWXwI8XgNhHCgR7qFDEdJ2nEIv90nwBo5YtB+ NjWcmoU38myy8Tni1ctgT25vs1aHZCwDEdU4dbvv4z7yOluBygOi4GoZGKgoq+yW fy36pBaylK/P5v4T+05On+dnWSI9j+8Tf5GmiwFyKynbprkLmWYy4vO+F5aF4x9w TLW9F0i+FgPj0h2X5ItKdtWMnDd5i//2Y3KVzZQP3uEr7geBBzDCRIlQ0qmGS78y XTM7HE3+B/fisjae2YhE/alYSR1RVeR1VF3x8VX3SiKKuppxp/g6jQlSAeDQHvnO +4DZg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdejuddgudegvdcutefuodetggdotefrod 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 15:44:09 -0400 (EDT) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v2 1/2] btrfs: set default discard iops_limit to 1000 Date: Wed, 5 Apr 2023 12:43:58 -0700 Message-Id: <73afd4f8e96351ffe1ba0d50d4fca75873ae3c54.1680723651.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 Reviewed-by: Neal Gompa --- 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..0bc526f5fcd9 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 (1000U) /* Monotonically decreasing minimum length filters after index 0 */ static int discard_minlen[BTRFS_NR_DISCARD_LISTS] = { From patchwork Wed Apr 5 19:43:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Burkov X-Patchwork-Id: 13202392 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 746C4C7619A for ; Wed, 5 Apr 2023 19:44:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229504AbjDEToU (ORCPT ); Wed, 5 Apr 2023 15:44:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234132AbjDEToQ (ORCPT ); Wed, 5 Apr 2023 15:44:16 -0400 Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 613B87685 for ; Wed, 5 Apr 2023 12:44:14 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 80ED932008FE; Wed, 5 Apr 2023 15:44:13 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 05 Apr 2023 15:44:13 -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=1680723853; x= 1680810253; bh=bE1jDVwqn/ONnmJjKgYS7CRF6GdrWbEPFz7zLVM+NmA=; b=u FgBSvvOf2ZXLOaAKHHbzUDGYZtbbGEu/C+NNPd5E8WOEoSS/0YKWlUM4eh9GEbc0 F8Qe4Qfz8Qy64/f6LMxtZiqvam1fU3wQlBAuZHwhhugGtE5dpunVRajC1+bbsB4d LLcghmw5Ex3idZOXm6AB0e6IcrhUDkDuqEGSMcVtkK35kMnF+LpyKTvzDQn5K7o5 eyTNy8AVWtV3SEOxZcFawuoBgQJ+rKAwk1CbkWdH2ucfr5pSviAljgJSrY00tgII rUX4lkPYPdL6LCCGdeUbaU/Wa4LX9xF0+bIw03czAWX2PB8/P5FtXeAU40hnJbLD gG5G3VYXOliRoepFjtOIQ== 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=1680723853; x=1680810253; bh=b E1jDVwqn/ONnmJjKgYS7CRF6GdrWbEPFz7zLVM+NmA=; b=iIOJ80fcI4D8rXP5M nvzPTHP41W6JAh1HF01TQBd5A7rAF2zuRdIGcxjFQW3OKELubsifo2zSuYUoYQpm jLMDA7WQAHR6CwdL+Xei9N4g0SW12IWzuGS7yPY+JAjDUQZjsmX3lNsr24uzb/RJ kF5DKLC6LrhkDAB7RwVoucnIyYtkebUrCQ+bny1wPF/tVBNJhnPXgOXN4kC3A1Va oeVWewdaVSLk2gbIdhUz+YbwR//5H7I4aMJIGJt5tVs+DaLZae1xWGHCoo51FD/S 6E8XeBwo3kd20jqW63dmIdf5OKlI2MAzZB6OJID/h1RAChae2JV7jKzBWRoIrZXt Pv7nw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdejuddgudegvdcutefuodetggdotefrod 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 15:44:12 -0400 (EDT) From: Boris Burkov To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v2 2/2] btrfs: reinterpret async discard iops_limit=0 as no delay Date: Wed, 5 Apr 2023 12:43:59 -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 Reviewed-by: Neal Gompa --- 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 0bc526f5fcd9..c48abc817ed2 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 (1000U) @@ -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);