public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] sbitmap: fix batching wakeup
@ 2023-07-21  9:57 Ming Lei
  2023-07-21 10:40 ` Keith Busch
                   ` (6 more replies)
  0 siblings, 7 replies; 13+ messages in thread
From: Ming Lei @ 2023-07-21  9:57 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-block, David Jeffery, Kemeng Shi, Gabriel Krisman Bertazi,
	Chengming Zhou, Jan Kara, Ming Lei

From: David Jeffery <djeffery@redhat.com>

Current code supposes that it is enough to provide forward progress by just
waking up one wait queue after one completion batch is done.

Unfortunately this way isn't enough, cause waiter can be added to
wait queue just after it is woken up.

Follows one example(64 depth, wake_batch is 8)

1) all 64 tags are active

2) in each wait queue, there is only one single waiter

3) each time one completion batch(8 completions) wakes up just one waiter in each wait
queue, then immediately one new sleeper is added to this wait queue

4) after 64 completions, 8 waiters are wakeup, and there are still 8 waiters in each
wait queue

5) after another 8 active tags are completed, only one waiter can be wakeup, and the other 7
can't be waken up anymore.

Turns out it isn't easy to fix this problem, so simply wakeup enough waiters for
single batch.

Cc: David Jeffery <djeffery@redhat.com>
Cc: Kemeng Shi <shikemeng@huaweicloud.com>
Cc: Gabriel Krisman Bertazi <krisman@suse.de>
Cc: Chengming Zhou <zhouchengming@bytedance.com>
Cc: Jan Kara <jack@suse.cz>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 lib/sbitmap.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/lib/sbitmap.c b/lib/sbitmap.c
index eff4e42c425a..d0a5081dfd12 100644
--- a/lib/sbitmap.c
+++ b/lib/sbitmap.c
@@ -550,7 +550,7 @@ EXPORT_SYMBOL_GPL(sbitmap_queue_min_shallow_depth);
 
 static void __sbitmap_queue_wake_up(struct sbitmap_queue *sbq, int nr)
 {
-	int i, wake_index;
+	int i, wake_index, woken;
 
 	if (!atomic_read(&sbq->ws_active))
 		return;
@@ -567,13 +567,12 @@ static void __sbitmap_queue_wake_up(struct sbitmap_queue *sbq, int nr)
 		 */
 		wake_index = sbq_index_inc(wake_index);
 
-		/*
-		 * It is sufficient to wake up at least one waiter to
-		 * guarantee forward progress.
-		 */
-		if (waitqueue_active(&ws->wait) &&
-		    wake_up_nr(&ws->wait, nr))
-			break;
+		if (waitqueue_active(&ws->wait)) {
+			woken = wake_up_nr(&ws->wait, nr);
+			if (woken == nr)
+				break;
+			nr -= woken;
+		}
 	}
 
 	if (wake_index != atomic_read(&sbq->wake_index))
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2024-01-15  9:51 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-21  9:57 [RFC PATCH] sbitmap: fix batching wakeup Ming Lei
2023-07-21 10:40 ` Keith Busch
2023-07-21 10:50   ` Ming Lei
2023-07-21 17:38     ` David Jeffery
2023-07-21 11:51 ` Keith Busch
2023-07-21 16:35 ` Gabriel Krisman Bertazi
2023-07-22  2:42   ` Ming Lei
2023-07-21 17:29 ` Jens Axboe
2023-07-21 17:40 ` Jens Axboe
2023-08-02 16:05 ` Jan Kara
2023-08-08  8:18   ` Ming Lei
2023-08-08 10:30     ` Jan Kara
2024-01-15  9:51 ` Kemeng Shi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox