Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Pavel Begunkov <asml.silence@gmail.com>
To: Chris Mason <clm@fb.com>, Josef Bacik <josef@toxicpanda.com>,
	David Sterba <dsterba@suse.com>,
	linux-btrfs@vger.kernel.org
Subject: [PATCH v2 1/3] btrfs: fix async discard stall
Date: Wed,  2 Dec 2020 19:39:41 +0000	[thread overview]
Message-ID: <f281023a1df3246d227a3af226eb6d612b4c3a4a.1606937659.git.asml.silence@gmail.com> (raw)
In-Reply-To: <cover.1606937659.git.asml.silence@gmail.com>

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 <asml.silence@gmail.com>
---
 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];
-- 
2.24.0


  reply	other threads:[~2020-12-02 19:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-02 19:39 [PATCH v2 0/3] btrfs async discard fixes & improvements Pavel Begunkov
2020-12-02 19:39 ` Pavel Begunkov [this message]
2020-12-02 19:39 ` [PATCH v2 2/3] btrfs: fix racy access to discard_ctl data Pavel Begunkov
2020-12-02 19:39 ` [PATCH v2 3/3] btrfs: don't overabuse discard lock Pavel Begunkov
2020-12-02 21:51 ` [PATCH v2 0/3] btrfs async discard fixes & improvements Josef Bacik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f281023a1df3246d227a3af226eb6d612b4c3a4a.1606937659.git.asml.silence@gmail.com \
    --to=asml.silence@gmail.com \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox