From patchwork Wed Nov 4 09:45:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 11880091 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE106C388F7 for ; Wed, 4 Nov 2020 09:49:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7A53620781 for ; Wed, 4 Nov 2020 09:49:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hWzZtVHt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728715AbgKDJtL (ORCPT ); Wed, 4 Nov 2020 04:49:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726564AbgKDJtJ (ORCPT ); Wed, 4 Nov 2020 04:49:09 -0500 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D7F0C0613D3 for ; Wed, 4 Nov 2020 01:49:09 -0800 (PST) Received: by mail-wm1-x344.google.com with SMTP id p22so1719985wmg.3 for ; Wed, 04 Nov 2020 01:49:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=dpDzE2UyGfIguEs3GGU0K39vcuPe/uRjpnfE0e+NLNE=; b=hWzZtVHtC2R+1k6U/MDX70yiuF/g8wZO3wMwJswgV9io0RImWBMKVw2gDzlDXd7M9s Zu6afGQCJeOOjLTPCKUxBY2LQej6B1wNDZrMWlJIHf/W3KKMFFRth6+1/1WIZrfNbF2J m8H6BauKQ+TpvHOVXSemePAXyQRiLhJywqAAMuA05zAQq3FQkBEGSqmr+VrjN4S0YDY/ jQqUVFm90ByWWTfvgNOykDErEwm9iMCC0xl7zVitK8znCkNB5fACsSc1n4fBo4SuJWTZ inmGkFDWJenvdVbMy55t1b/Z5EIMUgGJlEuCj+lcNEq46PTBH6SdhM4cFU+YhTA7/O+R LgzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dpDzE2UyGfIguEs3GGU0K39vcuPe/uRjpnfE0e+NLNE=; b=QUfueNmnEnxY5whq3LIjWFzjCSbjBXPoptJCu7o0Uoc8QOwHXDnhS8IHXnEFmZ1l2x booEHPm/cldP5oxzbKQTkUzUEWaRqlm2bto8MmBs1vKdUDEYDDpZcqOOYifQm0cPdhyx GfR/Ges8LF2i9hMKJ8nsYTIQl6tvXp3znC83uTNLkVZDY2SIevQB465UtPBWIOt9tkNm vo/uw9Y9eiaMdr6clLUJuILON5HwzHHtuMHT7YEc2MtkmUG+VM88hKmZXfE+tTFzFwtg /JpbXhq5O13DimWceBZ7pZwV8GBViHIbGj8+gevFFPUx+/dQHd+0tFO0gB91bx8R93cS a0Eg== X-Gm-Message-State: AOAM533KZLSp4QIFuMMx20B9T2BFZb6b4aH+YkXm1fMb1mqeiifmVqgb 6oKlkxMiYenpfQGKNo8Ulr9ym5G1DwUWPw== X-Google-Smtp-Source: ABdhPJz9rI25H1azGMRvCsacin2WjRIAZ8zdxa2SWXRPBUf7BhOPEmetJElJEl+07kH50HlL+2wM8w== X-Received: by 2002:a1c:1d92:: with SMTP id d140mr3631150wmd.48.1604483347872; Wed, 04 Nov 2020 01:49:07 -0800 (PST) Received: from localhost.localdomain (host109-152-100-228.range109-152.btcentralplus.com. [109.152.100.228]) by smtp.gmail.com with ESMTPSA id 3sm1478081wmd.19.2020.11.04.01.49.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2020 01:49:07 -0800 (PST) From: Pavel Begunkov To: Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org Subject: [PATCH 1/4] btrfs: discard: speed up discard up to iops_limit Date: Wed, 4 Nov 2020 09:45:51 +0000 Message-Id: <2a3d84dfc9384eed8659963d1dafedabb3f17c75.1604444952.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Instead of using iops_limit only for cutting off extremes, calculate the discard delay directly from it, so it closely follows iops_limit and doesn't under-discarding even though quotas are not saturated. Signed-off-by: Pavel Begunkov Reviewed-by: Josef Bacik --- fs/btrfs/discard.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/discard.c b/fs/btrfs/discard.c index 741c7e19c32f..76796a90e88d 100644 --- a/fs/btrfs/discard.c +++ b/fs/btrfs/discard.c @@ -519,7 +519,6 @@ void btrfs_discard_calc_delay(struct btrfs_discard_ctl *discard_ctl) s64 discardable_bytes; u32 iops_limit; unsigned long delay; - unsigned long lower_limit = BTRFS_DISCARD_MIN_DELAY_MSEC; discardable_extents = atomic_read(&discard_ctl->discardable_extents); if (!discardable_extents) @@ -550,11 +549,12 @@ void btrfs_discard_calc_delay(struct btrfs_discard_ctl *discard_ctl) iops_limit = READ_ONCE(discard_ctl->iops_limit); if (iops_limit) - lower_limit = max_t(unsigned long, lower_limit, - MSEC_PER_SEC / iops_limit); + delay = MSEC_PER_SEC / iops_limit; + else + delay = BTRFS_DISCARD_TARGET_MSEC / discardable_extents; - delay = BTRFS_DISCARD_TARGET_MSEC / discardable_extents; - delay = clamp(delay, lower_limit, BTRFS_DISCARD_MAX_DELAY_MSEC); + delay = clamp(delay, BTRFS_DISCARD_MIN_DELAY_MSEC, + BTRFS_DISCARD_MAX_DELAY_MSEC); discard_ctl->delay = msecs_to_jiffies(delay); spin_unlock(&discard_ctl->lock); From patchwork Wed Nov 4 09:45:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 11880089 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0565C2D0A3 for ; Wed, 4 Nov 2020 09:49:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5D3A320781 for ; Wed, 4 Nov 2020 09:49:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dNAcZpvZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728865AbgKDJtL (ORCPT ); Wed, 4 Nov 2020 04:49:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728607AbgKDJtK (ORCPT ); Wed, 4 Nov 2020 04:49:10 -0500 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0681AC061A4A for ; Wed, 4 Nov 2020 01:49:10 -0800 (PST) Received: by mail-wm1-x344.google.com with SMTP id v5so1727948wmh.1 for ; Wed, 04 Nov 2020 01:49:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=whDSf4Tz1Xq7gfrWNMCMjK8THmT23tBpaXB1TzI9T+s=; b=dNAcZpvZhSsi1I7RXzUlof9YxA16yostaBuxRdCbaBLvG/m3xmfgTZzOyXsBUX1Zex 23E/UC/OZIPJ038V84wHRPxCIEsSoHPWYEvqSdsx7n+O87QBu8/Ppm0AzxxURB7sX0FX mTnhvQv7NfxYpatBoiv+7cJj8D97PLKCu8vwL4ycyQ28F2E/ln/sAkfwGRCNIR/C1PnW KhL7yi12bnx+G0qvuRaA2Azh2laKnI9v/CbZ/Q+FvP7WeCZaSV2u91tFYTGbSFlACbld 665wuOVa00/Frkon41vwWl6vgK5cKR3pVuY2HNyZLZYHpK3JFshzGyKrkVulrsUmGeEc QfRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=whDSf4Tz1Xq7gfrWNMCMjK8THmT23tBpaXB1TzI9T+s=; b=iXxvRhAklTOfieeK3qpotwAhoxIwZcX6DHLh7LCZxtaPQkS7W/3VoHGtfy+lQM0PnP KmYV8beoni2OLbSSKZH+AKAMp5VTWmN1FVjj5EjuoGJf1VvQFr2hp5wTpUBEjXQd2QbJ u8Fp4nyO+uEtmvrI1u3Sii4ll41kO16i+ABvStI+bSsGX2T57Z8GfT1Eb7FKOW5lu8Tb jdUKcpLc7IgF+Xpt3wxAUFhCUACGQZ0c2KkngaeNcmjuUzeqBL3NK/xtb4aSQ4BjSy3Y o0B5xFu06fGSjo/vB7Gkky+N7ImAW0E3hiGqHuPXtT0jTyryCGqxlk6SMVcF+BKdYQFm EcVQ== X-Gm-Message-State: AOAM533Bf7Q5PjbwxY6XbFGsj74J8brGOsav6b3ZnYHPVQoY4K4lZP// ZYlwCUiSi6MHXxdCS4Vi/HUFTmZRhpuVkw== X-Google-Smtp-Source: ABdhPJxONh463ZJDTBN1Zbi0/riLyzNLbULJrF8F3PpHF4CRqE1inB4iFdi9FlgiLMrZ+opf52jW9w== X-Received: by 2002:a1c:7303:: with SMTP id d3mr3872935wmb.152.1604483348811; Wed, 04 Nov 2020 01:49:08 -0800 (PST) Received: from localhost.localdomain (host109-152-100-228.range109-152.btcentralplus.com. [109.152.100.228]) by smtp.gmail.com with ESMTPSA id 3sm1478081wmd.19.2020.11.04.01.49.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2020 01:49:08 -0800 (PST) From: Pavel Begunkov To: Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org Subject: [PATCH 2/4] btrfs: discard: save discard delay as ns not jiffy Date: Wed, 4 Nov 2020 09:45:52 +0000 Message-Id: <5be2ccce4a6ebe7c96274f63091a04aeba9af9d8.1604444952.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Most of calculations are done in ns or ms, so store discard_ctl->delay in ms and convert the final delay to jiffies only in the end. Signed-off-by: Pavel Begunkov Reviewed-by: Josef Bacik --- fs/btrfs/ctree.h | 2 +- fs/btrfs/discard.c | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index aac3d6f4e35b..d43a82dcdfc0 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -472,7 +472,7 @@ struct btrfs_discard_ctl { atomic_t discardable_extents; atomic64_t discardable_bytes; u64 max_discard_size; - unsigned long delay; + u64 delay_ms; u32 iops_limit; u32 kbps_limit; u64 discard_extent_bytes; diff --git a/fs/btrfs/discard.c b/fs/btrfs/discard.c index 76796a90e88d..b6c68e5711f0 100644 --- a/fs/btrfs/discard.c +++ b/fs/btrfs/discard.c @@ -355,7 +355,7 @@ void btrfs_discard_schedule_work(struct btrfs_discard_ctl *discard_ctl, block_group = find_next_block_group(discard_ctl, now); if (block_group) { - unsigned long delay = discard_ctl->delay; + u64 delay = discard_ctl->delay_ms * NSEC_PER_MSEC; u32 kbps_limit = READ_ONCE(discard_ctl->kbps_limit); /* @@ -366,9 +366,9 @@ void btrfs_discard_schedule_work(struct btrfs_discard_ctl *discard_ctl, if (kbps_limit && discard_ctl->prev_discard) { u64 bps_limit = ((u64)kbps_limit) * SZ_1K; u64 bps_delay = div64_u64(discard_ctl->prev_discard * - MSEC_PER_SEC, bps_limit); + NSEC_PER_SEC, bps_limit); - delay = max(delay, msecs_to_jiffies(bps_delay)); + delay = max(delay, bps_delay); } /* @@ -378,11 +378,11 @@ void btrfs_discard_schedule_work(struct btrfs_discard_ctl *discard_ctl, if (now < block_group->discard_eligible_time) { u64 bg_timeout = block_group->discard_eligible_time - now; - delay = max(delay, nsecs_to_jiffies(bg_timeout)); + delay = max(delay, bg_timeout); } mod_delayed_work(discard_ctl->discard_workers, - &discard_ctl->work, delay); + &discard_ctl->work, nsecs_to_jiffies(delay)); } out: spin_unlock(&discard_ctl->lock); @@ -555,7 +555,7 @@ void btrfs_discard_calc_delay(struct btrfs_discard_ctl *discard_ctl) delay = clamp(delay, BTRFS_DISCARD_MIN_DELAY_MSEC, BTRFS_DISCARD_MAX_DELAY_MSEC); - discard_ctl->delay = msecs_to_jiffies(delay); + discard_ctl->delay_ms = delay; spin_unlock(&discard_ctl->lock); } @@ -687,7 +687,7 @@ void btrfs_discard_init(struct btrfs_fs_info *fs_info) atomic_set(&discard_ctl->discardable_extents, 0); atomic64_set(&discard_ctl->discardable_bytes, 0); discard_ctl->max_discard_size = BTRFS_ASYNC_DISCARD_DEFAULT_MAX_SIZE; - discard_ctl->delay = BTRFS_DISCARD_MAX_DELAY_MSEC; + discard_ctl->delay_ms = BTRFS_DISCARD_MAX_DELAY_MSEC; discard_ctl->iops_limit = BTRFS_DISCARD_MAX_IOPS; discard_ctl->kbps_limit = 0; discard_ctl->discard_extent_bytes = 0; From patchwork Wed Nov 4 09:45:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 11880095 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24610C2D0A3 for ; Wed, 4 Nov 2020 09:49:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BF4E520781 for ; Wed, 4 Nov 2020 09:49:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="M0m+zR1+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728534AbgKDJtN (ORCPT ); Wed, 4 Nov 2020 04:49:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726564AbgKDJtL (ORCPT ); Wed, 4 Nov 2020 04:49:11 -0500 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4B45C0613D3 for ; Wed, 4 Nov 2020 01:49:10 -0800 (PST) Received: by mail-wm1-x341.google.com with SMTP id e2so1716824wme.1 for ; Wed, 04 Nov 2020 01:49:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=MfL0IVzOtW8kG8x+4UbiPZ3P/QlhiK+FFaHbYZjD+Dg=; b=M0m+zR1++MmibrNIuWkXV0nwZD8XKftcL+bu10CeaXQmZMBadLFzHbSkg+Q2DX8bUe Nj4eWh+THOmHkcjTbDauU/aEVV/sS2nwlKMfhhXzvcAVbsTsiCjV/wofGI6Y4tsll9HP AOMF2UYmJ4C+B643rZlcby0Xu/p9o14dxB01voYrgUknnNnTdTrYo4KpTCsVBWDe+0xf DwqzXk2oIg9ePBJiZh0RTWCR2nw4T6p5Q2lOzbIvGzBLC1y8wI2U+POwLkYInI+Mrvjd DYjAiQlGKH+KU1HMccNh0OedD9EePLHsz/mIW/n4x5Slsg+hT4eKp9ZSZ9UAXnZwR7Jd iGHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MfL0IVzOtW8kG8x+4UbiPZ3P/QlhiK+FFaHbYZjD+Dg=; b=ozGh77juToJ2AwEKj6vZhF7NwQAY+HDbgDBg0BVeRL7/wHk+vkTgwWh9E32zEWH4S2 jbxGIG69qQ40gHlK7ZVb4YhEmrSwd/rl1utQukNfWWq+JeGh23MpcvXCh5YUhuO5hv4/ n9ZujYoSicup1StQoOjiH+BT+BoERxZNeMkD1RVlZHiF/YtjCXH97VyEkmnZzWVtCK0h TCo2J1VwzcT89GrVWxYs8OEsxU2Rg/mXiJjr1Hx7zKF+8SaaspeK3VQmBrFRkfBCjkFc uXrG601jj1BWjpPaul0d8ahiDw5v7PKbLEnG6uwPArQYICqh7xN1twrac/idbTcwmXmg a6iw== X-Gm-Message-State: AOAM5333VMO9eL9W3SAEYW6/ecU1SXUwZqOXNuxZNwtgzKuQlF65Sy4u /C++45gfIW4T4CtOSke5E+9jR9NZsInPxg== X-Google-Smtp-Source: ABdhPJyj4SAVGkiU6N9NpNI4Ws1om1+sn+PUBVnk9yaNhTHCDFXwOOeF+3FV33T/vVpensTb8lGbgA== X-Received: by 2002:a1c:b746:: with SMTP id h67mr3554525wmf.43.1604483349734; Wed, 04 Nov 2020 01:49:09 -0800 (PST) Received: from localhost.localdomain (host109-152-100-228.range109-152.btcentralplus.com. [109.152.100.228]) by smtp.gmail.com with ESMTPSA id 3sm1478081wmd.19.2020.11.04.01.49.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2020 01:49:09 -0800 (PST) From: Pavel Begunkov To: Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org Subject: [PATCH 3/4] btrfs: don't miss discards after override-schedule Date: Wed, 4 Nov 2020 09:45:53 +0000 Message-Id: X-Mailer: git-send-email 2.24.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org If btrfs_discard_schedule_work() is called with override=true, it sets delay anew regardless how much time left until the timer should have fired. If delays are long (that can happen, for example, with low kbps_limit), they might be constantly overriden without having a chance to run the discard work. Signed-off-by: Pavel Begunkov Reviewed-by: Josef Bacik --- fs/btrfs/ctree.h | 1 + fs/btrfs/discard.c | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index d43a82dcdfc0..ad71c8c769de 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -469,6 +469,7 @@ struct btrfs_discard_ctl { struct btrfs_block_group *block_group; struct list_head discard_list[BTRFS_NR_DISCARD_LISTS]; u64 prev_discard; + u64 prev_discard_time; atomic_t discardable_extents; atomic64_t discardable_bytes; u64 max_discard_size; diff --git a/fs/btrfs/discard.c b/fs/btrfs/discard.c index b6c68e5711f0..c9018b9ccf99 100644 --- a/fs/btrfs/discard.c +++ b/fs/btrfs/discard.c @@ -381,6 +381,15 @@ void btrfs_discard_schedule_work(struct btrfs_discard_ctl *discard_ctl, delay = max(delay, bg_timeout); } + if (override && discard_ctl->prev_discard) { + u64 elapsed = now - discard_ctl->prev_discard_time; + + if (delay > elapsed) + delay -= elapsed; + else + delay = 0; + } + mod_delayed_work(discard_ctl->discard_workers, &discard_ctl->work, nsecs_to_jiffies(delay)); } @@ -466,6 +475,7 @@ static void btrfs_discard_workfn(struct work_struct *work) } discard_ctl->prev_discard = trimmed; + discard_ctl->prev_discard_time = ktime_get_ns(); /* Determine next steps for a block_group */ if (block_group->discard_cursor >= btrfs_block_group_end(block_group)) { @@ -684,6 +694,7 @@ void btrfs_discard_init(struct btrfs_fs_info *fs_info) INIT_LIST_HEAD(&discard_ctl->discard_list[i]); discard_ctl->prev_discard = 0; + discard_ctl->prev_discard_time = 0; atomic_set(&discard_ctl->discardable_extents, 0); atomic64_set(&discard_ctl->discardable_bytes, 0); discard_ctl->max_discard_size = BTRFS_ASYNC_DISCARD_DEFAULT_MAX_SIZE; From patchwork Wed Nov 4 09:45:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 11880097 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 709B9C4741F for ; Wed, 4 Nov 2020 09:49:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0A72F221F9 for ; Wed, 4 Nov 2020 09:49:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JC48eaF+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728899AbgKDJtO (ORCPT ); Wed, 4 Nov 2020 04:49:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728607AbgKDJtM (ORCPT ); Wed, 4 Nov 2020 04:49:12 -0500 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20E73C061A4D for ; Wed, 4 Nov 2020 01:49:12 -0800 (PST) Received: by mail-wm1-x343.google.com with SMTP id 205so1698873wma.4 for ; Wed, 04 Nov 2020 01:49:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=HRRIJgk/zWJ4ZCBL2Kbxl4BCQyn4rhE91KyNlOJr9Ug=; b=JC48eaF+fFQO+zggUay5zvmqIDqRxpk5keTaEyCOVv/L1U880N0QxAym6iSpk4yI0T m7b/71PLHzEN5NztOrktUmaeKrr2CaGOsW2oP38IVG5H5OOOmzYSp4suJr/TZ4uvftLd GINp++kMMXC71n09+lBO/PZ4redK5e7Jp9sH1I77g0TjkyB6bfvxZLH2l8xth41IOaVF eT3DdxFfNJihNU4cdPuOYJH9ElMUNPt6c7XdrECOJ9dl0kz0iwQe3IBKR5da5Cdzizdm deV5Z2tL/RLzVW3V9SRYv4oTVTmpciEhnbqGuJsoPDTyXk/V5znSxk8bdypOyZOCrCv8 SMYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HRRIJgk/zWJ4ZCBL2Kbxl4BCQyn4rhE91KyNlOJr9Ug=; b=rnrHISE1vM+ynpaQNapjEXTLZqQ4NHjUcsiRKqqJrOTNIqqKDfmRafmzSEXKLjJ0Ii Lv4GRymjK9zK7VuMZoG5YIkMaqwEMO28TshAPR3j2QVpNXSYTOOp1b4/gtfOKPszZxeR 0FZr8jeDwXemmMQantlgVDEDY+XdS+A7JnnhMeYk4niauRzrYd0KIOuwO2FcTwfJw6kC eoOw6eNvpd9jy88H2NxigGFfkvcNJHeH52yccOt3LFffuoeJcJJomPN3zu3VoaET1+Ln kRVwvUKP47QOLSWtsroD9GsIjPHtsZVI84thwBYGh4hGyWBqugJOrWqnQbACAiSDjSOw tFIw== X-Gm-Message-State: AOAM532KAM4HgtDCWrllOVCPmegyDm0MGnJvAd1AtOpp3s5xbH+OcNh2 ganiobsSgorzd4NYJlS33sI= X-Google-Smtp-Source: ABdhPJxI3WJnbVhHFijpWYozDazwQZA1GOJ+nRWQ7hVTAl686Si3vi3HTDWqpwWFXVZj2sXuOS4HKw== X-Received: by 2002:a1c:1b85:: with SMTP id b127mr3789978wmb.163.1604483350881; Wed, 04 Nov 2020 01:49:10 -0800 (PST) Received: from localhost.localdomain (host109-152-100-228.range109-152.btcentralplus.com. [109.152.100.228]) by smtp.gmail.com with ESMTPSA id 3sm1478081wmd.19.2020.11.04.01.49.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2020 01:49:10 -0800 (PST) From: Pavel Begunkov To: Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org Subject: [PATCH 4/4] btrfs: discard: reschedule work after param update Date: Wed, 4 Nov 2020 09:45:54 +0000 Message-Id: <6114f7d2699147186adf70c4e82a9a22de7a78aa.1604444952.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org After sysfs updates discard's iops_limit or kbps_limit it also needs to adjust current timer through rescheduling, otherwise the discard work may wait for a long time for the previous timer to expier or bumped by someone else. Signed-off-by: Pavel Begunkov Reviewed-by: Josef Bacik --- fs/btrfs/sysfs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 279d9262b676..65410d3939f2 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -433,7 +433,8 @@ static ssize_t btrfs_discard_iops_limit_store(struct kobject *kobj, return -EINVAL; WRITE_ONCE(discard_ctl->iops_limit, iops_limit); - + btrfs_discard_calc_delay(discard_ctl); + btrfs_discard_schedule_work(discard_ctl, true); return len; } BTRFS_ATTR_RW(discard, iops_limit, btrfs_discard_iops_limit_show, @@ -463,7 +464,7 @@ static ssize_t btrfs_discard_kbps_limit_store(struct kobject *kobj, return -EINVAL; WRITE_ONCE(discard_ctl->kbps_limit, kbps_limit); - + btrfs_discard_schedule_work(discard_ctl, true); return len; } BTRFS_ATTR_RW(discard, kbps_limit, btrfs_discard_kbps_limit_show,