From: Gabriel Krisman Bertazi <krisman@suse.de>
To: axboe@kernel.dk
Cc: mingo@redhat.com, peterz@infradead.org, jack@suse.cz,
linux-kernel@vger.kernel.org, linux-block@vger.kernel.org,
liusong@linux.alibaba.com, chaitanyak@nvidia.com,
Gabriel Krisman Bertazi <krisman@suse.de>
Subject: [PATCH 1/3] sbitmap: Advance the queue index before waking up a queue
Date: Tue, 15 Nov 2022 17:45:51 -0500 [thread overview]
Message-ID: <20221115224553.23594-2-krisman@suse.de> (raw)
In-Reply-To: <20221115224553.23594-1-krisman@suse.de>
When a queue is awaken, the wake_index written by sbq_wake_ptr currently
keeps pointing to the same queue. On the next wake up, it will thus
retry the same queue, which is unfair to other queues, and can lead to
starvation. This patch, moves the index update to happen before the
queue is returned, such that it will now try a different queue first on
the next wake up, improving fairness.
Fixes: 4f8126bb2308 ("sbitmap: Use single per-bitmap counting to wake up queued tags")
Reported-by: Jan Kara <jack@suse.cz>
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Gabriel Krisman Bertazi <krisman@suse.de>
---
lib/sbitmap.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/lib/sbitmap.c b/lib/sbitmap.c
index eca462cba398..bea7984f7987 100644
--- a/lib/sbitmap.c
+++ b/lib/sbitmap.c
@@ -571,13 +571,19 @@ static struct sbq_wait_state *sbq_wake_ptr(struct sbitmap_queue *sbq)
for (i = 0; i < SBQ_WAIT_QUEUES; i++) {
struct sbq_wait_state *ws = &sbq->ws[wake_index];
+ /*
+ * Advance the index before checking the current queue.
+ * It improves fairness, by ensuring the queue doesn't
+ * need to be fully emptied before trying to wake up
+ * from the next one.
+ */
+ wake_index = sbq_index_inc(wake_index);
+
if (waitqueue_active(&ws->wait)) {
if (wake_index != atomic_read(&sbq->wake_index))
atomic_set(&sbq->wake_index, wake_index);
return ws;
}
-
- wake_index = sbq_index_inc(wake_index);
}
return NULL;
--
2.35.3
next prev parent reply other threads:[~2022-11-15 22:46 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-15 22:45 [PATCH 0/3] sbitmap: Fix two issues in the per-bitmap wakeup counter code Gabriel Krisman Bertazi
2022-11-15 22:45 ` Gabriel Krisman Bertazi [this message]
2022-11-15 22:45 ` [PATCH 2/3] wait: Return number of exclusive waiters awaken Gabriel Krisman Bertazi
2022-11-16 11:06 ` Jan Kara
2022-11-16 20:22 ` Peter Zijlstra
2022-11-15 22:45 ` [PATCH 3/3] sbitmap: Try each queue to wake up at least one waiter Gabriel Krisman Bertazi
2022-11-16 11:09 ` Jan Kara
2022-11-16 18:49 ` [PATCH 0/3] sbitmap: Fix two issues in the per-bitmap wakeup counter code Jens Axboe
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=20221115224553.23594-2-krisman@suse.de \
--to=krisman@suse.de \
--cc=axboe@kernel.dk \
--cc=chaitanyak@nvidia.com \
--cc=jack@suse.cz \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liusong@linux.alibaba.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.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;
as well as URLs for NNTP newsgroup(s).