dm rq: leverage blk_mq_queue_busy() to check for outstanding IO

This change “dm rq: leverage blk_mq_queue_busy() to check for outstanding IO” in Linux kernel is authored by Mike Snitzer <snitzer [at]> on Thu Dec 6 11:41:17 2018 -0500.

dm rq: leverage blk_mq_queue_busy() to check for outstanding IO

Now that request-based dm-multipath only supports blk-mq, make use of
the newly introduced blk_mq_queue_busy() to check for outstanding IO --
rather than (ab)using the block core's in_flight counters.

Signed-off-by: Mike Snitzer <>
Signed-off-by: Jens Axboe <>

This Linux change may have been applied to various maintained Linux releases and you can find Linux releases including commit dbd3bbd.

There are 9 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 drivers/md/dm-rq.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/md/dm-rq.c b/drivers/md/dm-rq.c
index 1f1fe9a..d2397d8 100644
--- a/drivers/md/dm-rq.c
+++ b/drivers/md/dm-rq.c
@@ -130,11 +130,11 @@ static void rq_end_stats(struct mapped_device *md, struct request *orig)
 static void rq_completed(struct mapped_device *md, int rw, bool run_queue)
-	atomic_dec(&md->pending[rw]);
 	/* nudge anyone waiting on suspend queue */
-	if (!md_in_flight(md))
-		wake_up(&md->wait);
+	if (unlikely(waitqueue_active(&md->wait))) {
+		if (!blk_mq_queue_busy(md->queue))
+			wake_up(&md->wait);
+	}
 	 * dm_put() must be at the end of this function. See the comment above
@@ -436,7 +436,6 @@ ssize_t dm_attr_rq_based_seq_io_merge_deadline_store(struct mapped_device *md,
 static void dm_start_request(struct mapped_device *md, struct request *orig)
-	atomic_inc(&md->pending[rq_data_dir(orig)]);
 	if (unlikely(dm_stats_used(&md->stats))) {
 		struct dm_rq_target_io *tio = tio_from_request(orig);

The commit for this change in Linux stable tree is dbd3bbd (patch).

Leave a Reply

Your email address will not be published. Required fields are marked *