From patchwork Wed Dec 2 19:39:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 11946875 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 56CDAC64E7C for ; Wed, 2 Dec 2020 19:44:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EA52622201 for ; Wed, 2 Dec 2020 19:44:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729184AbgLBTnt (ORCPT ); Wed, 2 Dec 2020 14:43:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728940AbgLBTnt (ORCPT ); Wed, 2 Dec 2020 14:43:49 -0500 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC764C0613D4 for ; Wed, 2 Dec 2020 11:43:08 -0800 (PST) Received: by mail-wm1-x342.google.com with SMTP id k10so10625899wmi.3 for ; Wed, 02 Dec 2020 11:43:08 -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=fJhESfHKiNX8SD67hnYRudkmIYhXIzdckGtb1EU5s5Q=; b=OykHbB1NCRYPbBa2DJCcIQT6BQTGBTcGoOBzVDxCYVfT0erZEMHOQhOS2kyujx4QVL 8OIxZQL7O6BPuPq6wCIP5ja5A1ddnYATJdh6ZdCtabReyfndM7+G4+2Nf3IG3FF5yD3U A3IIYTkGMmZyhg6I/B5zJVbOH2E2wo3p7t1DKNKM/N0fkpdH8UsA4OHKNLPLUypKUeIV rNk6tcdc+s6f6sM3IN/v9lbkzIbvJuYItIcRrZuF2wVowrbqJjM0TrsJxbVu0dMvPDh/ B+rgVHWkHJBvDAKFAPDNj2dnKj4L1TiIP1M4YF9g9gxKp3azLAR1pEL872+znC2ee80M hyjA== 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=fJhESfHKiNX8SD67hnYRudkmIYhXIzdckGtb1EU5s5Q=; b=IUkQGxHu61PtDzG33FH8v98rXPj2MDkyvM5V4lXlsFQ8oMmn6w3ljQLOvYDfhOPojS /4v0+lCHWvfU7oifA8hHv58tbEm+o8Uf9xj+h2siQ0pu2QGoXtMlMg5S9sRNkL34z1Iz xOJ4OMgbUnTT/S5OU9iqPzaVnnnh+z9E43kESNKAf9J1Z3rJvYgzE3vuaiRzTcmLRDjb 5hTpXqsrlC7+3JvhoarplNQKdsnBHHIHclpiNqYt+o2NVoD1v/GTTb+XLhLgrL1T+g1S ONQOmhM9GISMtkkqPwOVNdvK01snTnY7KzRzEAcsFJHDg2ERdpIjakmRH1jhbzEnyAlG KUNw== X-Gm-Message-State: AOAM5301ZxNcHkAKQOauMOsFNyJXHUAwym/79PudIfUDFNYmnTBKM9/C K2BLxkZ10+WqNkofBBiZJng= X-Google-Smtp-Source: ABdhPJxBf5XVQGhwpPw2uBIhNiw/IeTcvDqqJ1Z14Ik6wATuH1y4fdEsYKa3zXnzbHEnlYJ3kel51Q== X-Received: by 2002:a1c:3d55:: with SMTP id k82mr4664752wma.57.1606938187470; Wed, 02 Dec 2020 11:43:07 -0800 (PST) Received: from localhost.localdomain (host109-152-100-189.range109-152.btcentralplus.com. [109.152.100.189]) by smtp.gmail.com with ESMTPSA id q16sm3251540wrn.13.2020.12.02.11.43.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2020 11:43:07 -0800 (PST) From: Pavel Begunkov To: Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org Subject: [PATCH v2 1/3] btrfs: fix async discard stall Date: Wed, 2 Dec 2020 19:39:41 +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 It might happen that bg->discard_eligible_time was changed without rescheduling, so btrfs_discard_workfn() would be awaken before that eligible time, peek_discard_list() returns null, and all discarding going to sleep until somewhat else calls for rescheduling again. Fix the stall by keeping btrfs_discard_workfn() going by always calling btrfs_discard_schedule_work() when there is any block group in the discard lists. Signed-off-by: Pavel Begunkov --- fs/btrfs/discard.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/discard.c b/fs/btrfs/discard.c index 1db966bf85b2..4ca852445873 100644 --- a/fs/btrfs/discard.c +++ b/fs/btrfs/discard.c @@ -199,10 +199,9 @@ static struct btrfs_block_group *find_next_block_group( static struct btrfs_block_group *peek_discard_list( struct btrfs_discard_ctl *discard_ctl, enum btrfs_discard_state *discard_state, - int *discard_index) + int *discard_index, u64 now) { struct btrfs_block_group *block_group; - const u64 now = ktime_get_ns(); spin_lock(&discard_ctl->lock); again: @@ -224,10 +223,7 @@ static struct btrfs_block_group *peek_discard_list( discard_ctl->block_group = block_group; *discard_state = block_group->discard_state; *discard_index = block_group->discard_index; - } else { - block_group = NULL; } - spin_unlock(&discard_ctl->lock); return block_group; @@ -438,13 +434,18 @@ static void btrfs_discard_workfn(struct work_struct *work) int discard_index = 0; u64 trimmed = 0; u64 minlen = 0; + u64 now = ktime_get_ns(); discard_ctl = container_of(work, struct btrfs_discard_ctl, work.work); block_group = peek_discard_list(discard_ctl, &discard_state, - &discard_index); + &discard_index, now); if (!block_group || !btrfs_run_discard_work(discard_ctl)) return; + if (now < block_group->discard_eligible_time) { + btrfs_discard_schedule_work(discard_ctl, false); + return; + } /* Perform discarding */ minlen = discard_minlen[discard_index]; From patchwork Wed Dec 2 19:39:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 11946881 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 C45D7C8300F for ; Wed, 2 Dec 2020 19:44:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 26A0B22203 for ; Wed, 2 Dec 2020 19:44:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387556AbgLBTnu (ORCPT ); Wed, 2 Dec 2020 14:43:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728940AbgLBTnu (ORCPT ); Wed, 2 Dec 2020 14:43:50 -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 BD370C0613D6 for ; Wed, 2 Dec 2020 11:43:09 -0800 (PST) Received: by mail-wm1-x341.google.com with SMTP id w206so1373799wma.0 for ; Wed, 02 Dec 2020 11:43: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=s86X+eDA8hhIRjHaeal4jt/BLgtlzaWk2iIqWYJYm2c=; b=Yct0I5GVqizswyKwHh8qjjsxAvQDF1UCyie1Igu72dLZBRpODT03kRtvusoVdLkJmB dvf9ig0ALNYvLncg6aMYcAue92id3FnoH+w2yVFEpDdoQCMVR8dlxnKSGKg7r8YBEaLt p3mzU0hD+vgcNQZi/+1yaNd+5xXbyWmvGx/znSXbiIVHhd/RvQoHE36OdBLUkCpP/P2d nB9+wIOLboumOfgNsyCRSPlC6XLM7oOFWhFsaxT1JN7VFEWFBq5RRgT7mwOUm3q/Aubo Zi2DcPDjVwaRp0mQyVO4oAFyp59YXB0EjCObFGI/LrzYe/f9KtpvZ9x5pv59JzqGQwiy T89A== 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=s86X+eDA8hhIRjHaeal4jt/BLgtlzaWk2iIqWYJYm2c=; b=Aos+4esOuQMfE9v1I21NQd5dj0WDh5a/S140a2rO/s3xt/JuRWtDLPsB7Z1lOVxsXu Cj6m+pHk4xGI50AGl70A5Zny9pFRV9XeQqUsW2efpFzeoKE2ooLzJwkb6AmzZ66P19fg rzW4ed0Ik5yqKlo+MV8u8AczyNQw2w26f9tLlKQKaWbUO6kkgrV0dAdxtPJciv9NaedT Dk1uLMMIvCNIsrp7IuQl+q+cEWfHN0bxPZDEfMNZorXO0HFBvhVtD1iC0xMr0oxuF/0m bOpa3ircJD3JRLOxFJGNkhhO+DxAHaHl8MHfCcPCKGiSxa+nfupqBQ4JFuHKyYbvGCuD yUbQ== X-Gm-Message-State: AOAM533lUgoGKMgY3oo1PjIXbUteeg8sWT46rihQ8+uMxdu89O4m1w7A BRV70/m7e4FhcdcWBrgLtvA= X-Google-Smtp-Source: ABdhPJzx6b6n4tRhd8ZH4g9XdmAmoMfdgmBIYOYSTUWSXLbVLQgj8TPxmPm0zmYSC/2oW0PcKa8u2w== X-Received: by 2002:a1c:43c5:: with SMTP id q188mr4704810wma.163.1606938188496; Wed, 02 Dec 2020 11:43:08 -0800 (PST) Received: from localhost.localdomain (host109-152-100-189.range109-152.btcentralplus.com. [109.152.100.189]) by smtp.gmail.com with ESMTPSA id q16sm3251540wrn.13.2020.12.02.11.43.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2020 11:43:07 -0800 (PST) From: Pavel Begunkov To: Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org Subject: [PATCH v2 2/3] btrfs: fix racy access to discard_ctl data Date: Wed, 2 Dec 2020 19:39:42 +0000 Message-Id: <0f03c766b7e04ba87d81c7764fe2d1d820818b4a.1606937659.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 Because only one discard worker may be running at any given point, it could have been safe to modify ->prev_discard, etc. without synchronisation, if not for @override flag in btrfs_discard_schedule_work() and delayed_work_pending() returning false while workfn is running. That may lead lead to torn reads of u64 for some architectures, but that's not a big problem as only slightly affects the discard rate. Suggested-by: Josef Bacik Signed-off-by: Pavel Begunkov --- fs/btrfs/discard.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/discard.c b/fs/btrfs/discard.c index 4ca852445873..a338f44fec3b 100644 --- a/fs/btrfs/discard.c +++ b/fs/btrfs/discard.c @@ -475,13 +475,6 @@ static void btrfs_discard_workfn(struct work_struct *work) discard_ctl->discard_extent_bytes += trimmed; } - /* - * Updated without locks as this is inside the workfn and nothing else - * is reading the values - */ - 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)) { if (discard_state == BTRFS_DISCARD_BITMAPS) { @@ -497,7 +490,10 @@ static void btrfs_discard_workfn(struct work_struct *work) } } + now = ktime_get_ns(); spin_lock(&discard_ctl->lock); + discard_ctl->prev_discard = trimmed; + discard_ctl->prev_discard_time = now; discard_ctl->block_group = NULL; spin_unlock(&discard_ctl->lock); From patchwork Wed Dec 2 19:39:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 11946877 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 AD308C71156 for ; Wed, 2 Dec 2020 19:44:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5472322240 for ; Wed, 2 Dec 2020 19:44:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387700AbgLBTnz (ORCPT ); Wed, 2 Dec 2020 14:43:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728940AbgLBTnu (ORCPT ); Wed, 2 Dec 2020 14:43:50 -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 725F2C0617A6 for ; Wed, 2 Dec 2020 11:43:10 -0800 (PST) Received: by mail-wm1-x341.google.com with SMTP id a3so11635808wmb.5 for ; Wed, 02 Dec 2020 11:43: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=gNZgsOWM9NDBdswoYPntOxq+y+gsmXrFaIyzBe2LZb8=; b=R/2Zu9FmNMqMduZaHXQzicYBT/XC/p9LnmGZQlZF+DPMfigtZHLa75Z7mUXOhveTEV ElhbUtSZnZvElFPjoRwuB717D7VmaO0pUViVS2Szz0XTkbo/E09dQkfWXTy9oxHYZNdC MwycOAbuqKZZDs0kwWsH0HbqiBFhGSMxMHOVxMy7BGYD35+PfeT/TAFFp2gzNiVLSMjb SEJ56cA3+jrNvP8/z2dw/6seZ2dMCYor83nX0gHET1b42GVwz/YQEiXCaprHFg3+31Je OLtmB10UETBzBeIXNt/ncufIAdFLkDf7yBpD7GA+iANzkEmMRXwivJEtPgFmDlOFn9Qn bXJg== 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=gNZgsOWM9NDBdswoYPntOxq+y+gsmXrFaIyzBe2LZb8=; b=MFoXatmMqACM7wAi1jh9X2sOim3Do9dsP9ccdlEAwePVGDKvqRpFLsFOwjPtk87kM/ xrTlqfU55bfxRc2ljHv4ZE+1JSBsTBaNXD0TYVOGFJOXQBf1gnexUoLT94JDLSCdj+0b 1vdZUnQoLSiOEbQBTNK0tsGsYrxCeLfDAcDss7nQzt5CeLeK1HCSdo8dhhoBoS+cpPgk bfVjHLw3Kk5PwYGZhDfxVg6JL31ZdzmjUV0d3JQpX65fkYxwye4IxmhLNv81FBY3fAN3 qsqmM385kaAgtaL+7UlTRd1YclxrFKURePrwJLsNQhyKMh/hh5TAiz4NImxSej2zk8VX XbxQ== X-Gm-Message-State: AOAM532h7dNiwxD6PRaLqxQS8Q8vct+0xfyD9U1c4aFQzVwvMW7h1Sox BrGQywbbwh0fekdG6j58NPB+81ZqPdxbiw== X-Google-Smtp-Source: ABdhPJzkNj/hUfQ2I1OBQt+1z9rUv0RumFfT1ddM2cRBfdYhDAQm0dsCYKdJTLXbmeYCEcXVU4Rb8w== X-Received: by 2002:a1c:e907:: with SMTP id q7mr4672186wmc.161.1606938189211; Wed, 02 Dec 2020 11:43:09 -0800 (PST) Received: from localhost.localdomain (host109-152-100-189.range109-152.btcentralplus.com. [109.152.100.189]) by smtp.gmail.com with ESMTPSA id q16sm3251540wrn.13.2020.12.02.11.43.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2020 11:43:08 -0800 (PST) From: Pavel Begunkov To: Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org Subject: [PATCH v2 3/3] btrfs: don't overabuse discard lock Date: Wed, 2 Dec 2020 19:39:43 +0000 Message-Id: <6c0f1ab37e18683331468ca2f9aab519680e54fc.1606937659.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 btrfs_discard_workfn() drops discard_ctl->lock just to take it again in a moment in btrfs_discard_schedule_work(). Avoid that and also reuse ktime. Signed-off-by: Pavel Begunkov --- fs/btrfs/discard.c | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/fs/btrfs/discard.c b/fs/btrfs/discard.c index a338f44fec3b..cd3b23f7ceb2 100644 --- a/fs/btrfs/discard.c +++ b/fs/btrfs/discard.c @@ -326,28 +326,15 @@ void btrfs_discard_queue_work(struct btrfs_discard_ctl *discard_ctl, btrfs_discard_schedule_work(discard_ctl, false); } -/** - * btrfs_discard_schedule_work - responsible for scheduling the discard work - * @discard_ctl: discard control - * @override: override the current timer - * - * Discards are issued by a delayed workqueue item. @override is used to - * update the current delay as the baseline delay interval is reevaluated on - * transaction commit. This is also maxed with any other rate limit. - */ -void btrfs_discard_schedule_work(struct btrfs_discard_ctl *discard_ctl, - bool override) +static void __btrfs_discard_schedule_work(struct btrfs_discard_ctl *discard_ctl, + u64 now, bool override) { struct btrfs_block_group *block_group; - const u64 now = ktime_get_ns(); - - spin_lock(&discard_ctl->lock); if (!btrfs_run_discard_work(discard_ctl)) - goto out; - + return; if (!override && delayed_work_pending(&discard_ctl->work)) - goto out; + return; block_group = find_next_block_group(discard_ctl, now); if (block_group) { @@ -389,7 +376,24 @@ void btrfs_discard_schedule_work(struct btrfs_discard_ctl *discard_ctl, mod_delayed_work(discard_ctl->discard_workers, &discard_ctl->work, nsecs_to_jiffies(delay)); } -out: +} + +/** + * btrfs_discard_schedule_work - responsible for scheduling the discard work + * @discard_ctl: discard control + * @override: override the current timer + * + * Discards are issued by a delayed workqueue item. @override is used to + * update the current delay as the baseline delay interval is reevaluated on + * transaction commit. This is also maxed with any other rate limit. + */ +void btrfs_discard_schedule_work(struct btrfs_discard_ctl *discard_ctl, + bool override) +{ + u64 now = ktime_get_ns(); + + spin_lock(&discard_ctl->lock); + __btrfs_discard_schedule_work(discard_ctl, now, override); spin_unlock(&discard_ctl->lock); } @@ -495,9 +499,8 @@ static void btrfs_discard_workfn(struct work_struct *work) discard_ctl->prev_discard = trimmed; discard_ctl->prev_discard_time = now; discard_ctl->block_group = NULL; + __btrfs_discard_schedule_work(discard_ctl, now, false); spin_unlock(&discard_ctl->lock); - - btrfs_discard_schedule_work(discard_ctl, false); } /**