All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] wait: add wq_has_multiple_sleepers helper
@ 2019-07-10 19:52 Josef Bacik
  2019-07-10 19:52 ` [PATCH 2/2] rq-qos: fix missed wake-ups in rq_qos_throttle Josef Bacik
  2019-07-10 20:23 ` [PATCH 1/2] wait: add wq_has_multiple_sleepers helper Jens Axboe
  0 siblings, 2 replies; 9+ messages in thread
From: Josef Bacik @ 2019-07-10 19:52 UTC (permalink / raw)
  To: kernel-team, axboe, linux-block

rq-qos sits in the io path so we want to take locks as sparingly as
possible.  To accomplish this we try not to take the waitqueue head lock
unless we are sure we need to go to sleep, and we have an optimization
to make sure that we don't starve out existing waiters.  Since we check
if there are existing waiters locklessly we need to be able to update
our view of the waitqueue list after we've added ourselves to the
waitqueue.  Accomplish this by adding this helper to see if there are
more than two waiters on the waitqueue.

Suggested-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 include/linux/wait.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/include/linux/wait.h b/include/linux/wait.h
index b6f77cf60dd7..89c41a7b3046 100644
--- a/include/linux/wait.h
+++ b/include/linux/wait.h
@@ -126,6 +126,27 @@ static inline int waitqueue_active(struct wait_queue_head *wq_head)
 	return !list_empty(&wq_head->head);
 }
 
+/**
+ * wq_has_multiple_sleepers - check if there are multiple waiting prcesses
+ * @wq_head: wait queue head
+ *
+ * Returns true of wq_head has multiple waiting processes.
+ *
+ * Please refer to the comment for waitqueue_active.
+ */
+static inline bool wq_has_multiple_sleepers(struct wait_queue_head *wq_head)
+{
+	/*
+	 * We need to be sure we are in sync with the
+	 * add_wait_queue modifications to the wait queue.
+	 *
+	 * This memory barrier should be paired with one on the
+	 * waiting side.
+	 */
+	smp_mb();
+	return !list_is_singular(&wq_head->head);
+}
+
 /**
  * wq_has_sleeper - check if there are any waiting processes
  * @wq_head: wait queue head
-- 
2.17.1


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

end of thread, other threads:[~2019-07-12  8:05 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-10 19:52 [PATCH 1/2] wait: add wq_has_multiple_sleepers helper Josef Bacik
2019-07-10 19:52 ` [PATCH 2/2] rq-qos: fix missed wake-ups in rq_qos_throttle Josef Bacik
2019-07-10 20:23 ` [PATCH 1/2] wait: add wq_has_multiple_sleepers helper Jens Axboe
2019-07-10 20:35   ` Peter Zijlstra
2019-07-10 20:39     ` Jens Axboe
2019-07-11 11:45       ` Oleg Nesterov
2019-07-11 13:40         ` Oleg Nesterov
2019-07-11 19:21           ` Josef Bacik
2019-07-12  8:05             ` Oleg Nesterov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.