[SRU,B,v2,5/7] blk-wbt: fix has-sleeper queueing check

Message ID 20190111110757.17936-6-mfo@canonical.com
State New
Headers show
Series
  • blk-wbt: fix for LP#1810998
Related show

Commit Message

Mauricio Faria de Oliveira Jan. 11, 2019, 11:07 a.m.
From: Jens Axboe <axboe@kernel.dk>

BugLink: https://bugs.launchpad.net/bugs/1810998

We need to do this inside the loop as well, or we can allow new
IO to supersede previous IO.

Tested-by: Anchal Agarwal <anchalag@amazon.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
(backported from commit c45e6a037a536530bd25781ac7c989e52deb2a63)
[mfo: backport:
 - hunk 1: s/rq_wait_inc_below(rqw/atomic_inc_below(&rqw->inflight/]
Signed-off-by: Mauricio Faria de Oliveira <mfo@canonical.com>
---
 block/blk-wbt.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Patch

diff --git a/block/blk-wbt.c b/block/blk-wbt.c
index 036a676de09c..b2fe2682b3f9 100644
--- a/block/blk-wbt.c
+++ b/block/blk-wbt.c
@@ -523,16 +523,17 @@  static void __wbt_wait(struct rq_wb *rwb, enum wbt_flags wb_acct,
 {
 	struct rq_wait *rqw = get_rq_wait(rwb, wb_acct);
 	DECLARE_WAITQUEUE(wait, current);
+	bool has_sleeper;
 
-	if (!wq_has_sleeper(&rqw->wait) &&
-	    atomic_inc_below(&rqw->inflight, get_limit(rwb, rw)))
+	has_sleeper = wq_has_sleeper(&rqw->wait);
+	if (!has_sleeper && atomic_inc_below(&rqw->inflight, get_limit(rwb, rw)))
 		return;
 
 	add_wait_queue_exclusive(&rqw->wait, &wait);
 	do {
 		set_current_state(TASK_UNINTERRUPTIBLE);
 
-		if (atomic_inc_below(&rqw->inflight, get_limit(rwb, rw)))
+		if (!has_sleeper && atomic_inc_below(&rqw->inflight, get_limit(rwb, rw)))
 			break;
 
 		if (lock) {
@@ -541,6 +542,7 @@  static void __wbt_wait(struct rq_wb *rwb, enum wbt_flags wb_acct,
 			spin_lock_irq(lock);
 		} else
 			io_schedule();
+		has_sleeper = false;
 	} while (1);
 
 	__set_current_state(TASK_RUNNING);