Skip to contentSkip to conversation

dm-rq: improve sequential I/O performance

PATCH In review Ming Lei 4 participants 38 messages Jan 11, 2018 – Jan 13, 2018

Subsystems (2)
lore
Share & tools
lore

Ming Lei

author
#0 lore raw

v3 cover dm-rq: improve sequential I/O performance

Hi Guys,

The 1st patch removes the workaround of blk_mq_delay_run_hw_queue() in case of requeue, this way isn't necessary, and more worse, it makes BLK_MQ_S_SCHED_RESTART not working, and degarde I/O performance.

The 2nd patch return DM_MAPIO_REQUEUE to dm-rq if underlying request allocation fails, then we can return BLK_STS_RESOURCE from dm-rq to blk-mq, so that blk-mq can hold the requests to be dequeued.

The other 3 paches changes the blk-mq part of blk_insert_cloned_request(), in which we switch to blk_mq_try_issue_directly(), so that both dm-rq and blk-mq can get the dispatch result of underlying queue, and with this information, blk-mq can handle IO merge much better, then sequential I/O performance is improved much.

In my dm-mpath over virtio-scsi test, this whole patchset improves sequential IO by 3X ~ 5X.

V3:
- rebase on the latest for-4.16/block of block tree
- add missed pg_init_all_paths() in patch 1, according to Bart's review

V2:
- drop 'dm-mpath: cache ti->clone during requeue', which is a bit too complicated, and not see obvious performance improvement.
- make change on blk-mq part cleaner

Ming Lei (5):
dm-mpath: don't call blk_mq_delay_run_hw_queue() in case of
BLK_STS_RESOURCE
dm-mpath: return DM_MAPIO_REQUEUE in case of rq allocation failure
blk-mq: move actual issue into one helper
blk-mq: return dispatch result to caller in blk_mq_try_issue_directly
blk-mq: issue request directly for blk_insert_cloned_request

 block/blk-core.c      |  3 +-
 block/blk-mq.c        | 86 +++++++++++++++++++++++++++++++++++++++------------
 block/blk-mq.h        |  3 ++
 drivers/md/dm-mpath.c | 19 +++++++++---
 drivers/md/dm-rq.c    | 20 +++++++++---
 5 files changed, 101 insertions(+), 30 deletions(-)
Signature · 1 line
2.9.5
author
#1 lore raw

PATCH v3 1/5 dm-mpath: don't call blk_mq_delay_run_hw_queue() in case of BLK_STS_RESOURCE

If .queue_rq() returns BLK_STS_RESOURCE, blk-mq will rerun the queue in the three situations:

1) if BLK_MQ_S_SCHED_RESTART is set
- queue is rerun after one rq is completed, see blk_mq_sched_restart() which is run from blk_mq_free_request()

2) run out of driver tag
- queue is rerun after one tag is freed

3) otherwise
- queue is run immediately in blk_mq_dispatch_rq_list()

This random dealy of running hw queue is introduced by commit 6077c2d706097c0 (dm rq: Avoid that request processing stalls sporadically), which claimed one request processing stalling is fixed, but never explained the behind idea, and it is a workaound at most. Even the question isn't explained by anyone in recent discussion.

Also calling blk_mq_delay_run_hw_queue() inside .queue_rq() is a horrible hack because it makes BLK_MQ_S_SCHED_RESTART not working, and degrades I/O peformance a lot.

Finally this patch makes sure that dm-rq returns BLK_STS_RESOURCE to blk-mq only when underlying queue is out of resource, so we switch to return DM_MAPIO_DELAY_REQUEU if either MPATHF_QUEUE_IO or MPATHF_PG_INIT_REQUIRED is set in multipath_clone_and_map().

---
 drivers/md/dm-mpath.c | 5 ++---
 drivers/md/dm-rq.c    | 1 -
 2 files changed, 2 insertions(+), 4 deletions(-)
drivers/md/dm-mpath.c +2 -3
index f7810cc869ac..86bf502a8e51 100644
@@ -516,9 +516,8 @@ static int multipath_clone_and_map(struct dm_target *ti, struct request *rq,
 		return DM_MAPIO_KILL;
 	} else if (test_bit(MPATHF_QUEUE_IO, &m->flags) ||
 		   test_bit(MPATHF_PG_INIT_REQUIRED, &m->flags)) {
-		if (pg_init_all_paths(m))
-			return DM_MAPIO_DELAY_REQUEUE;
-		return DM_MAPIO_REQUEUE;
+		pg_init_all_paths(m);
+		return DM_MAPIO_DELAY_REQUEUE;
 	}
 
 	memset(mpio, 0, sizeof(*mpio));
drivers/md/dm-rq.c +0 -1
index 3b319776d80c..4d157b14d302 100644
@@ -755,7 +755,6 @@ static blk_status_t dm_mq_queue_rq(struct blk_mq_hw_ctx *hctx,
 		/* Undo dm_start_request() before requeuing */
 		rq_end_stats(md, rq);
 		rq_completed(md, rq_data_dir(rq), false);
-		blk_mq_delay_run_hw_queue(hctx, 100/*ms*/);
 		return BLK_STS_RESOURCE;
 	}
 
Signature · 1 line
2.9.5
author
#2 lore raw

PATCH v3 2/5 dm-mpath: return DM_MAPIO_REQUEUE in case of rq allocation failure

In reply to Ming Lei

blk-mq will rerun queue via RESTART or dispatch wake after one request is completed, so not necessary to wait random time for requeuing, we should trust blk-mq to do it.

More importantly, we need return BLK_STS_RESOURCE to blk-mq so that dequeue from I/O scheduler can be stopped, then I/O merge gets improved.

---
 drivers/md/dm-mpath.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/md/dm-mpath.c +13 -1
index 86bf502a8e51..fcddf5a62581 100644
@@ -533,8 +533,20 @@ static int multipath_clone_and_map(struct dm_target *ti, struct request *rq,
 		if (queue_dying) {
 			atomic_inc(&m->pg_init_in_progress);
 			activate_or_offline_path(pgpath);
+			return DM_MAPIO_DELAY_REQUEUE;
 		}
-		return DM_MAPIO_DELAY_REQUEUE;
+
+		/*
+		 * blk-mq's SCHED_RESTART can cover this requeue, so
+		 * we needn't to deal with it by DELAY_REQUEUE. More
+		 * importantly, we have to return DM_MAPIO_REQUEUE
+		 * so that blk-mq can get the queue busy feedback,
+		 * otherwise I/O merge can be hurt.
+		 */
+		if (q->mq_ops)
+			return DM_MAPIO_REQUEUE;
+		else
+			return DM_MAPIO_DELAY_REQUEUE;
 	}
 	clone->bio = clone->biotail = NULL;
 	clone->rq_disk = bdev->bd_disk;
Signature · 1 line
2.9.5
#3 lore raw

Re: [PATCH V3 2/5] dm-mpath: return DM_MAPIO_REQUEUE in case of rq allocation failure

Quoted 14 lines · Ming Lei
drivers/md/dm-mpath.c +4 -1
index 86bf502a8e51..fcddf5a62581 100644
@@ -533,8 +533,20 @@ static int multipath_clone_and_map(struct dm_target *ti, struct request *rq,
 		if (queue_dying) {
 			atomic_inc(&m->pg_init_in_progress);
 			activate_or_offline_path(pgpath);
+			return DM_MAPIO_DELAY_REQUEUE;
 		}
-		return DM_MAPIO_DELAY_REQUEUE;
+
+		/*
+		 * blk-mq's SCHED_RESTART can cover this requeue, so

drivers/md/dm-mpath.c static int multipath_clone_and_map(struct dm_target *ti, struct request *rq, · line 550

Quoted 10 lines
drivers/md/dm-mpath.c +9 -0
+		 * we needn't to deal with it by DELAY_REQUEUE. More
+		 * importantly, we have to return DM_MAPIO_REQUEUE
+		 * so that blk-mq can get the queue busy feedback,
+		 * otherwise I/O merge can be hurt.
+		 */
+		if (q->mq_ops)
+			return DM_MAPIO_REQUEUE;
+		else
+			return DM_MAPIO_DELAY_REQUEUE;
 	}

Sorry but the approach of this patch looks wrong to me. I'm afraid that this approach will cause 100% CPU consumption if the underlying .queue_rq() function returns BLK_STS_RESOURCE for another reason than what can be detected by the .get_budget() call. This can happen if e.g. a SCSI LLD .queuecommand() implementation returns SCSI_MLQUEUE_HOST_BUSY. Many SCSI LLDs can do this:

$ git grep 'SCSI_MLQUEUE_[^_]*_BUSY' | wc -l
204

Isn't this a severe regression?

Bart.

author
#4 lore raw

Re: [PATCH V3 2/5] dm-mpath: return DM_MAPIO_REQUEUE in case of rq allocation failure

Quoted 31 lines · Bart Van Assche
Quoted 14 lines · Ming Lei
drivers/md/dm-mpath.c +4 -1
index 86bf502a8e51..fcddf5a62581 100644
@@ -533,8 +533,20 @@ static int multipath_clone_and_map(struct dm_target *ti, struct request *rq,
 		if (queue_dying) {
 			atomic_inc(&m->pg_init_in_progress);
 			activate_or_offline_path(pgpath);
+			return DM_MAPIO_DELAY_REQUEUE;
 		}
-		return DM_MAPIO_DELAY_REQUEUE;
+
+		/*
+		 * blk-mq's SCHED_RESTART can cover this requeue, so

drivers/md/dm-mpath.c static int multipath_clone_and_map(struct dm_target *ti, struct request *rq, · line 550

Quoted 10 lines
drivers/md/dm-mpath.c +9 -0
+		 * we needn't to deal with it by DELAY_REQUEUE. More
+		 * importantly, we have to return DM_MAPIO_REQUEUE
+		 * so that blk-mq can get the queue busy feedback,
+		 * otherwise I/O merge can be hurt.
+		 */
+		if (q->mq_ops)
+			return DM_MAPIO_REQUEUE;
+		else
+			return DM_MAPIO_DELAY_REQUEUE;
 	}

Sorry but the approach of this patch looks wrong to me. I'm afraid that this approach will cause 100% CPU consumption if the underlying .queue_rq() function returns BLK_STS_RESOURCE for another reason than what can be detected by the .get_budget() call. This can happen if e.g. a SCSI LLD .queuecommand() implementation returns SCSI_MLQUEUE_HOST_BUSY. Many SCSI LLDs can do this:

Quoted 4 lines
$ git grep 'SCSI_MLQUEUE_[^_]*_BUSY' | wc -l
204

Isn't this a severe regression?

No, it is not.

This DM_MAPIO_REQUEUE will be converted to BLK_STS_RESOURCE in dm-rq, then it is returned to blk-mq. That means when running out of resource for dispatching the underlying request, we tell blk-mq the truth. This way has been used for other blk-mq drivers, such NVMe,..., more importantly we have to provide this real feedback to blk-mq for fixing the performance issue.

The blk_get_request(GFP_ATOMIC) is just like a kmalloc(ATOMIC),
and memory is shared system-wide too. You can see there are lots kmalloc(ATOMIC) in NVMe IO path, when it fails, BLK_STS_RESOURCE is returned to blk-mq.

blk-mq has built-in SCHED_RESTART mechanism to handle out of RESOURCE when BLK_STS_RESOURCE is observed.

We only implements .get_bugdet() in SCSI only, and other blk-mq drivers: NVMe, ..., often returns BLK_STS_RESOURCE to blk-mq too, so wrt. this usage there isn't any difference between dm-mpath and other cases, right?

Thanks,
Ming

author
#5 lore raw

PATCH v3 3/5 blk-mq: move actual issue into one helper

In reply to Ming Lei

No functional change, just to clean up code a bit, so that the following change of using direct issue for blk_mq_request_bypass_insert() which is needed by DM can be easier to do.

---
 block/blk-mq.c | 39 +++++++++++++++++++++++++++------------
 1 file changed, 27 insertions(+), 12 deletions(-)
block/blk-mq.c +27 -12
index 9aa24c9508f9..d27c1a265d54 100644
@@ -1684,15 +1684,38 @@ static blk_qc_t request_to_qc_t(struct blk_mq_hw_ctx *hctx, struct request *rq)
 	return blk_tag_to_qc_t(rq->internal_tag, hctx->queue_num, true);
 }
 
-static void __blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx,
-					struct request *rq,
-					blk_qc_t *cookie)
+/* return true if insert is needed */
+static bool __blk_mq_issue_req(struct blk_mq_hw_ctx *hctx,
+			       struct request *rq,
+			       blk_qc_t *new_cookie,
+			       blk_status_t *ret)
 {
 	struct request_queue *q = rq->q;
 	struct blk_mq_queue_data bd = {
 		.rq = rq,
 		.last = true,
 	};
+
+	if (!blk_mq_get_driver_tag(rq, NULL, false))
+		return true;
+
+	if (!blk_mq_get_dispatch_budget(hctx)) {
+		blk_mq_put_driver_tag(rq);
+		return true;
+	}
+
+	*new_cookie = request_to_qc_t(hctx, rq);
+
+	*ret = q->mq_ops->queue_rq(hctx, &bd);
+
+	return false;
+}
+
+static void __blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx,
+					struct request *rq,
+					blk_qc_t *cookie)
+{
+	struct request_queue *q = rq->q;
 	blk_qc_t new_cookie;
 	blk_status_t ret;
 	bool run_queue = true;
@@ -1706,22 +1729,14 @@ static void __blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx,
 	if (q->elevator)
 		goto insert;
 
-	if (!blk_mq_get_driver_tag(rq, NULL, false))
+	if (__blk_mq_issue_req(hctx, rq, &new_cookie, &ret))
 		goto insert;
 
-	if (!blk_mq_get_dispatch_budget(hctx)) {
-		blk_mq_put_driver_tag(rq);
-		goto insert;
-	}
-
-	new_cookie = request_to_qc_t(hctx, rq);
-
 	/*
 	 * For OK queue, we are done. For error, kill it. Any other
 	 * error (busy), just add it to our list as we previously
 	 * would have done
 	 */
-	ret = q->mq_ops->queue_rq(hctx, &bd);
 	switch (ret) {
 	case BLK_STS_OK:
 		*cookie = new_cookie;
Signature · 1 line
2.9.5
Reviewed-by on v3 3/5
#6 lore raw

Re: [PATCH V3 3/5] blk-mq: move actual issue into one helper

Quoted 5 lines · Ming Lei

No functional change, just to clean up code a bit, so that the following change of using direct issue for blk_mq_request_bypass_insert() which is needed by DM can be easier to do.

author
#7 lore raw

PATCH v3 4/5 blk-mq: return dispatch result to caller in blk_mq_try_issue_directly

In reply to Ming Lei

In the following patch, we will use blk_mq_try_issue_directly() for DM to return the dispatch result, and DM need this informatin to improve IO merge.

---
 block/blk-mq.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
block/blk-mq.c +14 -9
index d27c1a265d54..444a4bf9705f 100644
@@ -1711,13 +1711,13 @@ static bool __blk_mq_issue_req(struct blk_mq_hw_ctx *hctx,
 	return false;
 }
 
-static void __blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx,
-					struct request *rq,
-					blk_qc_t *cookie)
+static blk_status_t __blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx,
+						struct request *rq,
+						blk_qc_t *cookie)
 {
 	struct request_queue *q = rq->q;
 	blk_qc_t new_cookie;
-	blk_status_t ret;
+	blk_status_t ret = BLK_STS_OK;
 	bool run_queue = true;
 
 	/* RCU or SRCU read lock is needed before checking quiesced flag */
@@ -1740,31 +1740,36 @@ static void __blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx,
 	switch (ret) {
 	case BLK_STS_OK:
 		*cookie = new_cookie;
-		return;
+		return ret;
 	case BLK_STS_RESOURCE:
 		__blk_mq_requeue_request(rq);
 		goto insert;
 	default:
 		*cookie = BLK_QC_T_NONE;
 		blk_mq_end_request(rq, ret);
-		return;
+		return ret;
 	}
 
 insert:
 	blk_mq_sched_insert_request(rq, false, run_queue, false,
 					hctx->flags & BLK_MQ_F_BLOCKING);
+	return ret;
 }
 
-static void blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx,
-		struct request *rq, blk_qc_t *cookie)
+static blk_status_t blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx,
+					      struct request *rq,
+					      blk_qc_t *cookie)
 {
 	int srcu_idx;
+	blk_status_t ret;
 
 	might_sleep_if(hctx->flags & BLK_MQ_F_BLOCKING);
 
 	hctx_lock(hctx, &srcu_idx);
-	__blk_mq_try_issue_directly(hctx, rq, cookie);
+	ret = __blk_mq_try_issue_directly(hctx, rq, cookie);
 	hctx_unlock(hctx, srcu_idx);
+
+	return ret;
 }
 
 static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
Signature · 1 line
2.9.5
Reviewed-by on v3 4/5
#8 lore raw

Re: [PATCH V3 4/5] blk-mq: return dispatch result to caller in blk_mq_try_issue_directly

Quoted 5 lines · Ming Lei

In the following patch, we will use blk_mq_try_issue_directly() for DM to return the dispatch result, and DM need this informatin to improve IO merge.

author
#9 lore raw

PATCH v3 5/5 blk-mq: issue request directly for blk_insert_cloned_request

In reply to Ming Lei

blk_insert_cloned_request() is called in fast path of dm-rq driver, and in this function we append request to hctx->dispatch_list of the underlying queue directly.

1) This way isn't efficient enough because hctx lock is always required

2) With blk_insert_cloned_request(), we bypass underlying queue's IO scheduler totally, and depend on DM rq driver to do IO schedule completely. But DM rq driver can't get underlying queue's dispatch feedback at all, and this information is extreamly useful for IO merge. Without that IO merge can't be done basically by blk-mq, and causes very bad sequential IO performance.

This patch makes use of blk_mq_try_issue_directly() to dispatch rq to underlying queue and provides disptch result to dm-rq and blk-mq, and improves the above situations very much.

With this patch, seqential IO is improved by 3X in my test over mpath/virtio-scsi.

---
 block/blk-core.c   |  3 +--
 block/blk-mq.c     | 34 ++++++++++++++++++++++++++++++----
 block/blk-mq.h     |  3 +++
 drivers/md/dm-rq.c | 19 ++++++++++++++++---
 4 files changed, 50 insertions(+), 9 deletions(-)
block/blk-core.c +1 -2
index f843ae4f858d..30759fcc93e5 100644
@@ -2500,8 +2500,7 @@ blk_status_t blk_insert_cloned_request(struct request_queue *q, struct request *
 		 * bypass a potential scheduler on the bottom device for
 		 * insert.
 		 */
-		blk_mq_request_bypass_insert(rq, true);
-		return BLK_STS_OK;
+		return blk_mq_request_direct_issue(rq);
 	}
 
 	spin_lock_irqsave(q->queue_lock, flags);
block/blk-mq.c +30 -4
index 444a4bf9705f..9bfca039d526 100644
@@ -1719,6 +1719,12 @@ static blk_status_t __blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx,
 	blk_qc_t new_cookie;
 	blk_status_t ret = BLK_STS_OK;
 	bool run_queue = true;
+	/*
+	 * This function is called from blk_insert_cloned_request() if
+	 * 'cookie' is NULL, and for dispatching this request only.
+	 */
+	bool dispatch_only = !cookie;
+	bool need_insert;
 
 	/* RCU or SRCU read lock is needed before checking quiesced flag */
 	if (blk_mq_hctx_stopped(hctx) || blk_queue_quiesced(q)) {
@@ -1726,10 +1732,19 @@ static blk_status_t __blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx,
 		goto insert;
 	}
 
-	if (q->elevator)
+	if (q->elevator && !dispatch_only)
 		goto insert;
 
-	if (__blk_mq_issue_req(hctx, rq, &new_cookie, &ret))
+	need_insert = __blk_mq_issue_req(hctx, rq, &new_cookie, &ret);
+	if (dispatch_only) {
+		if (need_insert)
+			return BLK_STS_RESOURCE;
+		if (ret == BLK_STS_RESOURCE)
+			__blk_mq_requeue_request(rq);
+		return ret;
+	}
+
+	if (need_insert)
 		goto insert;
 
 	/*
@@ -1751,8 +1766,11 @@ static blk_status_t __blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx,
 	}
 
 insert:
-	blk_mq_sched_insert_request(rq, false, run_queue, false,
-					hctx->flags & BLK_MQ_F_BLOCKING);
+	if (!dispatch_only)
+		blk_mq_sched_insert_request(rq, false, run_queue, false,
+				hctx->flags & BLK_MQ_F_BLOCKING);
+	else
+		blk_mq_request_bypass_insert(rq, run_queue);
 	return ret;
 }
 
@@ -1772,6 +1790,14 @@ static blk_status_t blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx,
 	return ret;
 }
 
+blk_status_t blk_mq_request_direct_issue(struct request *rq)
+{
+	struct blk_mq_ctx *ctx = rq->mq_ctx;
+	struct blk_mq_hw_ctx *hctx = blk_mq_map_queue(rq->q, ctx->cpu);
+
+	return blk_mq_try_issue_directly(hctx, rq, NULL);
+}
+
 static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
 {
 	const int is_sync = op_is_sync(bio->bi_opf);
block/blk-mq.h +3 -0
index 8591a54d989b..bd98864d8e38 100644
@@ -74,6 +74,9 @@ void blk_mq_request_bypass_insert(struct request *rq, bool run_queue);
 void blk_mq_insert_requests(struct blk_mq_hw_ctx *hctx, struct blk_mq_ctx *ctx,
 				struct list_head *list);
 
+/* Used by DM for issuing req directly */
+blk_status_t blk_mq_request_direct_issue(struct request *rq);
+
 /*
  * CPU -> queue mappings
  */
drivers/md/dm-rq.c +16 -3
index 4d157b14d302..6b01298fba06 100644
@@ -395,7 +395,7 @@ static void end_clone_request(struct request *clone, blk_status_t error)
 	dm_complete_request(tio->orig, error);
 }
 
-static void dm_dispatch_clone_request(struct request *clone, struct request *rq)
+static blk_status_t dm_dispatch_clone_request(struct request *clone, struct request *rq)
 {
 	blk_status_t r;
 
@@ -404,9 +404,10 @@ static void dm_dispatch_clone_request(struct request *clone, struct request *rq)
 
 	clone->start_time = jiffies;
 	r = blk_insert_cloned_request(clone->q, clone);
-	if (r)
+	if (r != BLK_STS_OK && r != BLK_STS_RESOURCE)
 		/* must complete clone in terms of original request */
 		dm_complete_request(rq, r);
+	return r;
 }
 
 static int dm_rq_bio_constructor(struct bio *bio, struct bio *bio_orig,
@@ -476,8 +477,10 @@ static int map_request(struct dm_rq_target_io *tio)
 	struct mapped_device *md = tio->md;
 	struct request *rq = tio->orig;
 	struct request *clone = NULL;
+	blk_status_t ret;
 
 	r = ti->type->clone_and_map_rq(ti, rq, &tio->info, &clone);
+ check_again:
 	switch (r) {
 	case DM_MAPIO_SUBMITTED:
 		/* The target has taken the I/O to submit by itself later */
@@ -492,7 +495,17 @@ static int map_request(struct dm_rq_target_io *tio)
 		/* The target has remapped the I/O so dispatch it */
 		trace_block_rq_remap(clone->q, clone, disk_devt(dm_disk(md)),
 				     blk_rq_pos(rq));
-		dm_dispatch_clone_request(clone, rq);
+		ret = dm_dispatch_clone_request(clone, rq);
+		if (ret == BLK_STS_RESOURCE) {
+			blk_rq_unprep_clone(clone);
+			tio->ti->type->release_clone_rq(clone);
+			tio->clone = NULL;
+			if (!rq->q->mq_ops)
+				r = DM_MAPIO_DELAY_REQUEUE;
+			else
+				r = DM_MAPIO_REQUEUE;
+			goto check_again;
+		}
 		break;
 	case DM_MAPIO_REQUEUE:
 		/* The target wants to requeue the I/O */
Signature · 1 line
2.9.5
Tested-by Reviewed-by on v3 5/5
#10 lore raw

Re: [PATCH V3 5/5] blk-mq: issue request directly for blk_insert_cloned_request

Quoted 12 lines · Ming Lei

blk_insert_cloned_request() is called in fast path of dm-rq driver, and in this function we append request to hctx->dispatch_list of the underlying queue directly.

1) This way isn't efficient enough because hctx lock is always required

2) With blk_insert_cloned_request(), we bypass underlying queue's IO scheduler totally, and depend on DM rq driver to do IO schedule completely. But DM rq driver can't get underlying queue's dispatch feedback at all, and this information is extreamly useful for IO merge. Without that IO merge can't be done basically by blk-mq, and causes very bad sequential IO performance.

Quoted 8 lines

This patch makes use of blk_mq_try_issue_directly() to dispatch rq to underlying queue and provides disptch result to dm-rq and blk-mq, and improves the above situations very much.

With this patch, seqential IO is improved by 3X in my test over mpath/virtio-scsi.

#11 lore raw
In reply to Ming Lei
Quoted 9 lines · Ming Lei

Hi Guys,

The 1st patch removes the workaround of blk_mq_delay_run_hw_queue() in case of requeue, this way isn't necessary, and more worse, it makes BLK_MQ_S_SCHED_RESTART not working, and degarde I/O performance.

The 2nd patch return DM_MAPIO_REQUEUE to dm-rq if underlying request allocation fails, then we can return BLK_STS_RESOURCE from dm-rq to blk-mq, so that blk-mq can hold the requests to be dequeued.

In general the delayed requeue was meant to cope (slightly better) with queue_if_no_path and no paths being available. I think patch 1 respect that intent. And patch 2 looks right to me, BLK_STS_RESOURCE definitely should be returned if blk_get_request() fails.

So I picked these up for dm-4.16 (and staged them in linux-next). I reworded both headers and the 2nd patch's block comment, see:
https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git/commit/?h=dm-4.16&id=64e4e12bf474cf3aaaf59245bbeba3057d2fedf9
https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git/commit/?h=dm-4.16&id=c50de17c1cc7d5910df58aba9b950e99579e239d

Bart, if for some reason we regress for some workload you're able to more readily test we can deal with it. But I'm too encouraged by Ming's performance improvements to hold these changes back any further.

Quoted 8 lines

The other 3 paches changes the blk-mq part of blk_insert_cloned_request(), in which we switch to blk_mq_try_issue_directly(), so that both dm-rq and blk-mq can get the dispatch result of underlying queue, and with this information, blk-mq can handle IO merge much better, then sequential I/O performance is improved much.

In my dm-mpath over virtio-scsi test, this whole patchset improves sequential IO by 3X ~ 5X.

I've merged dm-4.16 and for-4.16/block and patched 3 - 5 apply cleanly (so we won't have any merge conflicts during 4.16), resulting git branch is here:
https://git.kernel.org/pub/scm/linux/kernel/git/snitzer/linux.git/log/?h=block-4.16_dm-4.16

I'll reply to patches 3 - 5 individually with my Reviewed-by. Jens, please feel free to pick them up for 4.16.

Thanks,
Mike

#12 lore raw
Quoted 3 lines · Mike Snitzer

Bart, if for some reason we regress for some workload you're able to more readily test we can deal with it. But I'm too encouraged by Ming's performance improvements to hold these changes back any further.

Sorry Mike but I think Ming's measurement results are not sufficient to motivate upstreaming of these patches. What I remember from previous versions of this patch series is that Ming measured the performance impact of this patch series only for the Emulex FC driver (lpfc). That driver limits queue depth to 3. Instead of modifying the dm code, that driver needs to be fixed such that it allows larger queue depths.

Additionally, some time ago I had explained in detail why I think that patch 2/5 in this series is wrong and why it will introduce fairness regressions in multi-LUN workloads. I think we need performance measurements for this patch series for at least the following two configurations before this patch series can be considered for upstream inclusion:
* The performance impact of this patch series for SCSI devices with a realistic queue depth (e.g. 64 or 128).
* The performance impact for this patch series for a SCSI host with which multiple LUNs are associated and for which the target system often replies with the SCSI "BUSY" status.

Bart.

#13 lore raw
Quoted 11 lines · Bart Van Assche
Quoted 3 lines · Mike Snitzer

Bart, if for some reason we regress for some workload you're able to more readily test we can deal with it. But I'm too encouraged by Ming's performance improvements to hold these changes back any further.

Sorry Mike but I think Ming's measurement results are not sufficient to motivate upstreaming of these patches. What I remember from previous versions of this patch series is that Ming measured the performance impact of this patch series only for the Emulex FC driver (lpfc). That driver limits queue depth to 3. Instead of modifying the dm code, that driver needs to be fixed such that it allows larger queue depths.

Sorry Bart but even in my test (using null_blk with queue depth of 8, 12 hw queues on 12 cpu system, with 12 fio jobs) it is yielding performance improvement. Going from 1350K iops to 1420K iops. And 5275MB/s to 5532MB/s. For sequential fio workload.

This test has been a staple of mine for a very long time. The improvement is very real (and hard to come by). The iops improvement is a bellweather for improved efficiency in the fast path.

So all your concern about Ming's testing is fine. But you'd really help me out a lot if you could give these changes a test.

Quoted 3 lines

Additionally, some time ago I had explained in detail why I think that patch 2/5 in this series is wrong and why it will introduce fairness regressions in multi-LUN workloads.

You may think you explained it.. but IIRC it was very hand-wavvy. If you can provide a pointer to what you think was a compelling argument then please do.

But I'm left very much unconvinced with your argument given what I see in patch 2. If blk_get_request() fails it follows that BLK_STS_RESOURCE should be returned. Why is the 100ms delay meaningful in that case for SCSI?

Quoted 8 lines

I think we need performance measurements for this
patch series for at least the following two configurations before this patch series can be considered for upstream inclusion:
* The performance impact of this patch series for SCSI devices with a realistic queue depth (e.g. 64 or 128).
* The performance impact for this patch series for a SCSI host with which multiple LUNs are associated and for which the target system often replies with the SCSI "BUSY" status.

OK, so please test it.

The changes are pretty easy to review. This notion that these changes are problematic rings very hollow given your lack of actual numbers (or some other concerning observation rooted in testing fact) to back up your position.

Mike

#14 lore raw
Quoted 4 lines · Mike Snitzer

The changes are pretty easy to review. This notion that these changes are problematic rings very hollow given your lack of actual numbers (or some other concerning observation rooted in testing fact) to back up your position.

It's not my job to run the multi-LUN test. That's the job of the people who want these patches upstream. Since I asked for these test results for the first time several months ago I'm surprised that nobody has run these tests yet.

Bart.

#15 lore raw
Quoted 9 lines · Bart Van Assche
Quoted 4 lines · Mike Snitzer

The changes are pretty easy to review. This notion that these changes are problematic rings very hollow given your lack of actual numbers (or some other concerning observation rooted in testing fact) to back up your position.

It's not my job to run the multi-LUN test. That's the job of the people who want these patches upstream. Since I asked for these test results for the first time several months ago I'm surprised that nobody has run these tests yet.

I've reasoned through a few different ways to respond to this. Fact is you're not giving me much to work with. AFAIK you _are_ charted with supporting the types of storage configs that you've requested performance results from.

Your dm-rq.c commit 6077c2d706097c0 ("dm rq: Avoid that request processing stalls sporadically") silently went in through Jens:
https://www.redhat.com/archives/dm-devel/2017-April/msg00157.html
Not sure why that happened to begin with honestly.

But at the end of that post I meant to say:
"If this dm-mq specific commit is justified the case certainly is _not_ spelled out in the commit header."

Anyway, I've split this contentious removal of dm_mq_queue_rq's blk_mq_delay_run_hw_queue(hctx, 100/*ms*/) into a separate patch; but at this point I'm still inclined to accept it for 4.16.

I'll hopefully look closer at understanding the need for commit 6077c2d706097c0 tomorrow.

In the meantime, I'd _really_ appreciate it if you'd give the rest of the changes Ming has proposed in this patchset a much more open mind!

Thanks,
Mike

author
#16 lore raw
In reply to Bart Van Assche
Quoted 12 lines · Bart Van Assche
Quoted 3 lines · Mike Snitzer

Bart, if for some reason we regress for some workload you're able to more readily test we can deal with it. But I'm too encouraged by Ming's performance improvements to hold these changes back any further.

Sorry Mike but I think Ming's measurement results are not sufficient to motivate upstreaming of these patches. What I remember from previous versions of this patch series is that Ming measured the performance impact of this patch series only for the Emulex FC driver (lpfc). That driver limits queue depth to 3. Instead of modifying the dm code, that driver needs to be fixed such that it allows larger queue depths.

Quoted 7 lines

Additionally, some time ago I had explained in detail why I think that patch 2/5 in this series is wrong and why it will introduce fairness regressions in multi-LUN workloads. I think we need performance measurements for this patch series for at least the following two configurations before this patch series can be considered for upstream inclusion:
* The performance impact of this patch series for SCSI devices with a realistic queue depth (e.g. 64 or 128).

Please look at the cover letter or patch 5's commit log, it mentions that dm-mpath over virtio-scsi is tested, and the default queue depth of virito-scsi is 128.

Quoted 3 lines

* The performance impact for this patch series for a SCSI host with which multiple LUNs are associated and for which the target system often replies with the SCSI "BUSY" status.

I don't think this patch is related with this case, this patch just provides the BUSY feedback from underlying queue to blk-mq via dm-rq.

Thanks,
Ming

#17 lore raw
Quoted 25 lines · Ming Lei
Quoted 12 lines · Bart Van Assche
Quoted 3 lines · Mike Snitzer

Bart, if for some reason we regress for some workload you're able to more readily test we can deal with it. But I'm too encouraged by Ming's performance improvements to hold these changes back any further.

Sorry Mike but I think Ming's measurement results are not sufficient to motivate upstreaming of these patches. What I remember from previous versions of this patch series is that Ming measured the performance impact of this patch series only for the Emulex FC driver (lpfc). That driver limits queue depth to 3. Instead of modifying the dm code, that driver needs to be fixed such that it allows larger queue depths.

Quoted 7 lines

Additionally, some time ago I had explained in detail why I think that patch 2/5 in this series is wrong and why it will introduce fairness regressions in multi-LUN workloads. I think we need performance measurements for this patch series for at least the following two configurations before this patch series can be considered for upstream inclusion:
* The performance impact of this patch series for SCSI devices with a realistic queue depth (e.g. 64 or 128).

Please look at the cover letter or patch 5's commit log, it mentions that dm-mpath over virtio-scsi is tested, and the default queue depth of virito-scsi is 128.

Quoted 6 lines
Quoted 3 lines

* The performance impact for this patch series for a SCSI host with which multiple LUNs are associated and for which the target system often replies with the SCSI "BUSY" status.

I don't think this patch is related with this case, this patch just provides the BUSY feedback from underlying queue to blk-mq via dm-rq.

Hi Ming,

Please see https://www.redhat.com/archives/dm-devel/2017-April/msg00190.html

Specifically:
"That patch [commit 6077c2d706] can be considered as a first step that can be refined further, namely by modifying the dm-rq code further such that dm-rq queues are only rerun after the busy condition has been cleared. The patch at the start of this thread is easier to review and easier to test than any patch that would only rerun dm-rq queues after the busy condition has been cleared."

Do you have time to reason through Bart's previous proposal for how to better address the specific issue that was documented to be fixed in the header for commit 6077c2d706 ?

Otherwise I fear we'll just keep hitting a wall with Bart...

Thanks,
Mike

author
#18 lore raw
Quoted 47 lines · Mike Snitzer
Quoted 25 lines · Ming Lei
Quoted 12 lines · Bart Van Assche
Quoted 3 lines · Mike Snitzer

Bart, if for some reason we regress for some workload you're able to more readily test we can deal with it. But I'm too encouraged by Ming's performance improvements to hold these changes back any further.

Sorry Mike but I think Ming's measurement results are not sufficient to motivate upstreaming of these patches. What I remember from previous versions of this patch series is that Ming measured the performance impact of this patch series only for the Emulex FC driver (lpfc). That driver limits queue depth to 3. Instead of modifying the dm code, that driver needs to be fixed such that it allows larger queue depths.

Quoted 7 lines

Additionally, some time ago I had explained in detail why I think that patch 2/5 in this series is wrong and why it will introduce fairness regressions in multi-LUN workloads. I think we need performance measurements for this patch series for at least the following two configurations before this patch series can be considered for upstream inclusion:
* The performance impact of this patch series for SCSI devices with a realistic queue depth (e.g. 64 or 128).

Please look at the cover letter or patch 5's commit log, it mentions that dm-mpath over virtio-scsi is tested, and the default queue depth of virito-scsi is 128.

Quoted 6 lines
Quoted 3 lines

* The performance impact for this patch series for a SCSI host with which multiple LUNs are associated and for which the target system often replies with the SCSI "BUSY" status.

I don't think this patch is related with this case, this patch just provides the BUSY feedback from underlying queue to blk-mq via dm-rq.

Hi Ming,

Please see https://www.redhat.com/archives/dm-devel/2017-April/msg00190.html

Specifically:
"That patch [commit 6077c2d706] can be considered as a first step that can be refined further, namely by modifying the dm-rq code further such that dm-rq queues are only rerun after the busy condition has been cleared. The patch at the start of this thread is easier to review and easier to test than any patch that would only rerun dm-rq queues after the busy condition has been cleared."

Quoted 3 lines

Do you have time to reason through Bart's previous proposal for how to better address the specific issue that was documented to be fixed in the header for commit 6077c2d706 ?

Hi Mike,

Recently we fixed one such issue in blk-mq (eb619fdb2d4cb8b3d34), and I highly guess that may fix Bart's case.

Let's see this commit 6077c2d706 again, I don't know the idea behind the fix, which just adds random of 100ms, and this delay degrades performance a lot, since no hctx can be scheduled any more during the delay.

So again it is definitely a workaround, no any reasoning, no any theory, just say it is a fix. Are there anyone who can explain the story?

IMO, the blk_get_request() in dm-mpath is just like a kmalloc(ATOMIC) which is used in other blk-mq drivers' IO path too, so don't know why dm-mq is so strange to require such ugly 100ms delay.

So I suggest to remove it, let's see if there are reports, and if there are, I am quite confident we can root cause that and fix that.

Quoted 2 lines

Otherwise I fear we'll just keep hitting a wall with Bart...

I do test dm-mq over scsi-debug which is setup as two LUNs, and set can_queue as 1, and this patchset just works well, not any IO hang. And anyone can try and play with it.

Thanks,
Ming

#19 lore raw
Quoted 48 lines · Ming Lei
Quoted 47 lines · Mike Snitzer
Quoted 25 lines · Ming Lei
Quoted 12 lines · Bart Van Assche
Quoted 3 lines · Mike Snitzer

Bart, if for some reason we regress for some workload you're able to more readily test we can deal with it. But I'm too encouraged by Ming's performance improvements to hold these changes back any further.

Sorry Mike but I think Ming's measurement results are not sufficient to motivate upstreaming of these patches. What I remember from previous versions of this patch series is that Ming measured the performance impact of this patch series only for the Emulex FC driver (lpfc). That driver limits queue depth to 3. Instead of modifying the dm code, that driver needs to be fixed such that it allows larger queue depths.

Quoted 7 lines

Additionally, some time ago I had explained in detail why I think that patch 2/5 in this series is wrong and why it will introduce fairness regressions in multi-LUN workloads. I think we need performance measurements for this patch series for at least the following two configurations before this patch series can be considered for upstream inclusion:
* The performance impact of this patch series for SCSI devices with a realistic queue depth (e.g. 64 or 128).

Please look at the cover letter or patch 5's commit log, it mentions that dm-mpath over virtio-scsi is tested, and the default queue depth of virito-scsi is 128.

Quoted 6 lines
Quoted 3 lines

* The performance impact for this patch series for a SCSI host with which multiple LUNs are associated and for which the target system often replies with the SCSI "BUSY" status.

I don't think this patch is related with this case, this patch just provides the BUSY feedback from underlying queue to blk-mq via dm-rq.

Hi Ming,

Please see https://www.redhat.com/archives/dm-devel/2017-April/msg00190.html

Specifically:
"That patch [commit 6077c2d706] can be considered as a first step that can be refined further, namely by modifying the dm-rq code further such that dm-rq queues are only rerun after the busy condition has been cleared. The patch at the start of this thread is easier to review and easier to test than any patch that would only rerun dm-rq queues after the busy condition has been cleared."

Quoted 8 lines
Quoted 3 lines

Do you have time to reason through Bart's previous proposal for how to better address the specific issue that was documented to be fixed in the header for commit 6077c2d706 ?

Hi Mike,

Recently we fixed one such issue in blk-mq (eb619fdb2d4cb8b3d34), and I highly guess that may fix Bart's case.

Wow, kind of staggering that there was no mention of this fix prior to now. Seems _very_ relevant (like the real fix).

Quoted 3 lines

Let's see this commit 6077c2d706 again, I don't know the idea behind the fix, which just adds random of 100ms, and this delay degrades performance a lot, since no hctx can be scheduled any more during the delay.

I'd love to try to reproduce the issue documented in commit 6077c2d706 but sadly I cannot get that srp-test to work on my system. Just fails with:

# while srp-test/run_tests -d -r 30 -t 02-mq; do :; done
Unloaded the ib_srpt kernel module
Unloaded the rdma_rxe kernel module
Zero-initializing /dev/ram0 ... done
Zero-initializing /dev/ram1 ... done
Configured SRP target driver
Running test srp-test/tests/02-mq ...
Test file I/O on top of multipath concurrently with logout and login (0 min; mq)
SRP login failed
Test srp-test/tests/02-mq failed

Think the login is failing due to target not being setup properly? Yeap, now from reading this thread, it is clear that srp-test only works if you have an IB HCA:
https://patchwork.kernel.org/patch/10041381/

Quoted 6 lines

So again it is definitely a workaround, no any reasoning, no any theory, just say it is a fix. Are there anyone who can explain the story?

IMO, the blk_get_request() in dm-mpath is just like a kmalloc(ATOMIC) which is used in other blk-mq drivers' IO path too, so don't know why dm-mq is so strange to require such ugly 100ms delay.

The header for commit 6077c2d706 notes that same action that Jens took to unwedge the request stalls (in the patchwork thread I referenced above), with:

echo run > /sys/kernel/debug/block/nullb1/state
vs what Bart noted in commit 6077c2d706:
echo run >/sys/kernel/debug/block/dm-0/state

Really does feel like the issue Jens' shared tags fix addressed _is_ the root cause that commit 6077c2d706 worked around.

Quoted 2 lines

So I suggest to remove it, let's see if there are reports, and if there are, I am quite confident we can root cause that and fix that.

Yeah, it really is rediculous that we're getting this kind of pushback for something that was/is so poorly justified. And especially given that dm_mq_queue_rq() _still_ has this:

        if (ti->type->busy && ti->type->busy(ti))
                return BLK_STS_RESOURCE;

yet our desire to avoid blk_mq_delay_run_hw_queue(hctx, 100/*ms*/) in response to blk_get_request() failure, just prior to returning BLK_STS_RESOURCE in dm_mq_queue_rq(), is met with hellfire.

I refuse to submit to this highly unexpected cargo cult programming.

This is going upstream for 4.16:
https://git.kernel.org/pub/scm/linux/kernel/git/snitzer/linux.git/commit/?h=dm-4.16&id=5b18cff4baedde77e0d69bd62a13ae78f9488d89

I've lost patience with the unwillingness to reassess/justify the need for commit 6077c2d706 ; SO it is just getting removed and we'll debug and fix any future reported blk-mq stalls (and/or high cpu load) in a much more precise manner -- provided the reporter is willing to work with us!

Mike

#20 lore raw
Quoted 2 lines · Mike Snitzer

This is going upstream for 4.16:
https://git.kernel.org/pub/scm/linux/kernel/git/snitzer/linux.git/commit/?h=dm-4.16&id=5b18cff4baedde77e0d69bd62a13ae78f9488d89

That is really gross. I have explained many times in detail on the dm-devel list why that blk_mq_delay_run_hw_queue() call is necessary. So I think it is wrong if you remove it. Isn't the responsibility of you as the device mapper kernel maintainer to avoid regressions instead of introducing regressions?

Bart.

#21 lore raw
Quoted 8 lines · Bart Van Assche
Quoted 2 lines · Mike Snitzer

This is going upstream for 4.16:
https://git.kernel.org/pub/scm/linux/kernel/git/snitzer/linux.git/commit/?h=dm-4.16&id=5b18cff4baedde77e0d69bd62a13ae78f9488d89

That is really gross. I have explained many times in detail on the dm-devel list why that blk_mq_delay_run_hw_queue() call is necessary. So I think it is wrong if you remove it. Isn't the responsibility of you as the device mapper kernel maintainer to avoid regressions instead of introducing regressions?

Please stop, seriously.

You've not explained it many times. We cannot get a straight answer from you. No analysis that establishes that if an underlying dm-mq multipath path is out of tags (shared or otherwise) that dm-rq core _must_ run the hw queue after a delay.

Commit 6077c2d7060 just papers over a real blk-mq problem (that may now be fixed). Your assertions that blk-mq would need to otherwise poll (and waste resources so it can immediately retry) ignores that blk-mq _should_ make progress as requests complete or if/when a path is recovered, etc. So I'm not going to accept your dysfuctional reasoning on this, sorry. _THAT_ is my job as a maintainer.

#22 lore raw
Quoted 1 line · Mike Snitzer

You've not explained it many times.

That's not correct. I have already several times posted a detailed and easy to understand explanation

Quoted 1 line

We cannot get a straight answer from you.

That is a gross and incorrect statement. Please calm down.

Bart.

#23 lore raw
Quoted 5 lines · Bart Van Assche
Quoted 1 line · Mike Snitzer

You've not explained it many times.

That's not correct. I have already several times posted a detailed and easy to understand explanation

OK, you have the stage: please give me a pointer to your best explaination of the several.

Quoted 3 lines
Quoted 1 line

We cannot get a straight answer from you.

That is a gross and incorrect statement. Please calm down.

I'm perfectly calm. I'm just tired of how you sow controversy.

#24 lore raw
Quoted 2 lines · Mike Snitzer

OK, you have the stage: please give me a pointer to your best explaination of the several.

Since the previous discussion about this topic occurred more than a month ago it could take more time to look up an explanation than to explain it again. Anyway, here we go. As you know a block layer request queue needs to be rerun if one or more requests are waiting and a previous condition that prevented the request to be executed has been cleared. For the dm-mpath driver, examples of such conditions are no tags available, a path that is busy (see also pgpath_busy()), path initialization that is in progress (pg_init_in_progress) or a request completes with status, e.g. if the SCSI core calls __blk_mq_end_request(req, error) with error != 0. For some of these conditions, e.g. path initialization completes, a callback function in the dm-mpath driver is called and it is possible to explicitly rerun the queue. I agree that for such scenario's a delayed queue run should not be triggered. For other scenario's, e.g. if a SCSI initiator submits a SCSI request over a fabric and the SCSI target replies with "BUSY" then the SCSI core will end the I/O request with status BLK_STS_RESOURCE after the maximum number of retries has been reached (see also scsi_io_completion()). In that last case, if a SCSI target sends a "BUSY" reply over the wire back to the initiator, there is no other approach for the SCSI initiator to figure out whether it can queue another request than to resubmit the request. The worst possible strategy is to resubmit a request immediately because that will cause a significant fraction of the fabric bandwidth to be used just for replying "BUSY" to requests that can't be processed immediately.

The intention of commit 6077c2d706097c0 was to address the last mentioned case. It may be possible to move the delayed queue rerun from the dm_queue_rq() into dm_requeue_original_request(). But I think it would be wrong to rerun the queue immediately in case a SCSI target system returns "BUSY".

Bart.

#25 lore raw
Quoted 28 lines · Bart Van Assche
Quoted 2 lines · Mike Snitzer

OK, you have the stage: please give me a pointer to your best explaination of the several.

Since the previous discussion about this topic occurred more than a month ago it could take more time to look up an explanation than to explain it again. Anyway, here we go. As you know a block layer request queue needs to be rerun if one or more requests are waiting and a previous condition that prevented the request to be executed has been cleared. For the dm-mpath driver, examples of such conditions are no tags available, a path that is busy (see also pgpath_busy()), path initialization that is in progress (pg_init_in_progress) or a request completes with status, e.g. if the SCSI core calls __blk_mq_end_request(req, error) with error != 0. For some of these conditions, e.g. path initialization completes, a callback function in the dm-mpath driver is called and it is possible to explicitly rerun the queue. I agree that for such scenario's a delayed queue run should not be triggered. For other scenario's, e.g. if a SCSI initiator submits a SCSI request over a fabric and the SCSI target replies with "BUSY" then the SCSI core will end the I/O request with status BLK_STS_RESOURCE after the maximum number of retries has been reached (see also scsi_io_completion()). In that last case, if a SCSI target sends a "BUSY" reply over the wire back to the initiator, there is no other approach for the SCSI initiator to figure out whether it can queue another request than to resubmit the request. The worst possible strategy is to resubmit a request immediately because that will cause a significant fraction of the fabric bandwidth to be used just for replying "BUSY" to requests that can't be processed immediately.

Quoted 5 lines

The intention of commit 6077c2d706097c0 was to address the last mentioned case. It may be possible to move the delayed queue rerun from the dm_queue_rq() into dm_requeue_original_request(). But I think it would be wrong to rerun the queue immediately in case a SCSI target system returns "BUSY".

OK, thank you very much for this. Really helps.

For starters multipath_clone_and_map() could do a fair amount more with the insight that a SCSI "BUSY" was transmitted back. If both blk-mq being out of tags and SCSI "BUSY" simply return BLK_STS_RESOURCE then dm-mpath doesn't have the ability to behave more intelligently.

Anyway, armed with this info I'll have a think about what we might do to tackle this problem head on.

Thanks,
Mike

#26 lore raw
In reply to Bart Van Assche
Quoted 5 lines

-----Original Message-----
From: [email protected] [mailto:linux-block- [email protected]] On Behalf Of Bart Van Assche

...

Quoted 5 lines

The intention of commit 6077c2d706097c0 was to address the last mentioned case. It may be possible to move the delayed queue rerun from the dm_queue_rq() into dm_requeue_original_request(). But I think it would be wrong to rerun the queue immediately in case a SCSI target system returns "BUSY".

Seeing SCSI BUSY mentioned here...

On its own, patch 6077c2d706 seems to be adding an arbitrarily selected magic value of 100 ms without explanation in the patch description or in the added code.

But, dm_request_original_request() already seems to have chosen that value for similar purposes:

        unsigned long delay_ms = delay_requeue ? 100 : 0;

So, making them share a #define would indicate there's a reason for that particular value. Any change to the value would be picked up everywhere.

All the other callers of blk_mq_delay_run_hw_queue() use macros:

drivers/md/dm-rq.c:             blk_mq_delay_run_hw_queue(hctx, 100/*ms*/);
drivers/nvme/host/fc.c:         blk_mq_delay_run_hw_queue(queue->hctx, NVMEFC_QUEUE_DELAY);
drivers/scsi/scsi_lib.c:                blk_mq_delay_run_hw_queue(hctx, SCSI_QUEUE_DELAY);
drivers/scsi/scsi_lib.c:                        blk_mq_delay_run_hw_queue(hctx, SCSI_QUEUE_DELAY);

Those both happen to be set to 3 (ms).

---
Robert Elliott, HPE Persistent Memory

#27 lore raw
Quoted 12 lines · Robert (Persistent Memory)
Quoted 5 lines

-----Original Message-----
From: [email protected] [mailto:linux-block- [email protected]] On Behalf Of Bart Van Assche

...

Quoted 5 lines

The intention of commit 6077c2d706097c0 was to address the last mentioned case. It may be possible to move the delayed queue rerun from the dm_queue_rq() into dm_requeue_original_request(). But I think it would be wrong to rerun the queue immediately in case a SCSI target system returns "BUSY".

Quoted 5 lines

Seeing SCSI BUSY mentioned here...

On its own, patch 6077c2d706 seems to be adding an arbitrarily selected magic value of 100 ms without explanation in the patch description or in the added code.

It was 50 ms before it was 100 ms. No real explaination for these values other than they seem to make Bart's IB SRP testbed happy?

Quoted 4 lines

But, dm_request_original_request() already seems to have chosen that value for similar purposes:

        unsigned long delay_ms = delay_requeue ? 100 : 0;
Quoted 8 lines

So, making them share a #define would indicate there's a reason for that particular value. Any change to the value would be picked up everywhere.

All the other callers of blk_mq_delay_run_hw_queue() use macros:

drivers/md/dm-rq.c:             blk_mq_delay_run_hw_queue(hctx, 100/*ms*/);
drivers/nvme/host/fc.c:         blk_mq_delay_run_hw_queue(queue->hctx, NVMEFC_QUEUE_DELAY);
drivers/scsi/scsi_lib.c:                blk_mq_delay_run_hw_queue(hctx, SCSI_QUEUE_DELAY);
drivers/scsi/scsi_lib.c:                        blk_mq_delay_run_hw_queue(hctx, SCSI_QUEUE_DELAY);

Sure, I'll add a #define.

Quoted 1 line

Those both happen to be set to 3 (ms).

As for the value of 100, we're dealing with path faults so retrying them extremely fast could be wasted effort. But there is obviously no once size fits all. As storage gets faster 100 ms could prove to be very bad.

But without tests to verify a change, there won't be one.

Thanks,
Mike

#28 lore raw
Quoted 2 lines · Mike Snitzer

It was 50 ms before it was 100 ms. No real explaination for these values other than they seem to make Bart's IB SRP testbed happy?

But that constant was not introduced by me in the dm code. See e.g. the following commits:

commit d548b34b062b60b4f4df295a0b4823dfda1f1fc4

Author: Mike Snitzer <[email protected]>
Date:   Thu Mar 5 22:21:10 2015 -0500

dm: reduce the queue delay used in dm_request_fn from 100ms to 10ms

Commit 7eaceaccab ("block: remove per-queue plugging") didn't justify DM's use of a 100ms delay; such an extended delay is a liability when there is reason to re-kick the queue.

commit 7eaceaccab5f40bbfda044629a6298616aeaed50

Author: Jens Axboe <[email protected]>
Date:   Thu Mar 10 08:52:07 2011 +0100

block: remove per-queue plugging

Code has been converted over to the new explicit on-stack plugging, and delay users have been converted to use the new API for that. So lets kill off the old plugging along with aops->sync_page().

Bart.

#29 lore raw
Quoted 5 lines · Bart Van Assche
Quoted 2 lines · Mike Snitzer

It was 50 ms before it was 100 ms. No real explaination for these values other than they seem to make Bart's IB SRP testbed happy?

But that constant was not introduced by me in the dm code.

No actually it was (not that there's anything wrong with that):

commit 06eb061f48594aa369f6e852b352410298b317a8

Author: Bart Van Assche <[email protected]>
Date:   Fri Apr 7 16:50:44 2017 -0700

dm mpath: requeue after a small delay if blk_get_request() fails

If blk_get_request() returns ENODEV then multipath_clone_and_map() causes a request to be requeued immediately. This can cause a kworker thread to spend 100% of the CPU time of a single core in __blk_mq_run_hw_queue() and also can cause device removal to never finish.

Avoid this by only requeuing after a delay if blk_get_request() fails. Additionally, reduce the requeue delay.

Note that this commit actually details a different case where a blk_get_request() (in existing code) return of -ENODEV is a very compelling case to use DM_MAPIO_DELAY_REQUEUE.

SO I'll revisit what is appropriate in multipath_clone_and_map() on Monday.

I need a break... have a good weekend Bart.

#30 lore raw
Quoted 30 lines · Mike Snitzer
Quoted 5 lines · Bart Van Assche
Quoted 2 lines · Mike Snitzer

It was 50 ms before it was 100 ms. No real explaination for these values other than they seem to make Bart's IB SRP testbed happy?

But that constant was not introduced by me in the dm code.

No actually it was (not that there's anything wrong with that):

commit 06eb061f48594aa369f6e852b352410298b317a8

Author: Bart Van Assche <[email protected]>
Date:   Fri Apr 7 16:50:44 2017 -0700

dm mpath: requeue after a small delay if blk_get_request() fails

If blk_get_request() returns ENODEV then multipath_clone_and_map() causes a request to be requeued immediately. This can cause a kworker thread to spend 100% of the CPU time of a single core in __blk_mq_run_hw_queue() and also can cause device removal to never finish.

Avoid this by only requeuing after a delay if blk_get_request() fails. Additionally, reduce the requeue delay.

Quoted 6 lines

Note that this commit actually details a different case where a blk_get_request() (in existing code) return of -ENODEV is a very compelling case to use DM_MAPIO_DELAY_REQUEUE.

SO I'll revisit what is appropriate in multipath_clone_and_map() on Monday.

Sleep helped. I had another look and it is only the old .request_fn blk_get_request() code that even sets -ENODEV (if blk_queue_dying).

But thankfully the blk_get_request() error handling in multipath_clone_and_map() checks for blk_queue_dying() and will return DM_MAPIO_DELAY_REQUEUE.

So we're all set for this case.

Mike

#31 lore raw
In reply to Bart Van Assche
Quoted 19 lines · Bart Van Assche
Quoted 2 lines · Mike Snitzer

OK, you have the stage: please give me a pointer to your best explaination of the several.

Since the previous discussion about this topic occurred more than a month ago it could take more time to look up an explanation than to explain it again. Anyway, here we go. As you know a block layer request queue needs to be rerun if one or more requests are waiting and a previous condition that prevented the request to be executed has been cleared. For the dm-mpath driver, examples of such conditions are no tags available, a path that is busy (see also pgpath_busy()), path initialization that is in progress (pg_init_in_progress) or a request completes with status, e.g. if the SCSI core calls __blk_mq_end_request(req, error) with error != 0. For some of these conditions, e.g. path initialization completes, a callback function in the dm-mpath driver is called and it is possible to explicitly rerun the queue. I agree that for such scenario's a delayed queue run should not be triggered. For other scenario's, e.g. if a SCSI initiator submits a SCSI request over a fabric and the SCSI target replies with "BUSY" then the SCSI core will end the I/O request with status BLK_STS_RESOURCE after the

Quoted 8 lines

maximum number of retries has been reached (see also scsi_io_completion()). In that last case, if a SCSI target sends a "BUSY" reply over the wire back to the initiator, there is no other approach for the SCSI initiator to figure out whether it can queue another request than to resubmit the request. The worst possible strategy is to resubmit a request immediately because that will cause a significant fraction of the fabric bandwidth to be used just for replying "BUSY" to requests that can't be processed immediately.

The thing is, the 2 scenarios you are most concerned about have _nothing_ to do with dm_mq_queue_rq() at all. They occur as an error in the IO path _after_ the request is successfully retrieved with blk_get_request() and then submitted.

Quoted 2 lines

The intention of commit 6077c2d706097c0 was to address the last mentioned case.

So it really makes me question why you think commit 6077c2d706097c0 addresses the issue you think it does. And gives me more conviction to remove 6077c2d706097c0.

It may help just by virtue of blindly kicking the queue if blk_get_request() fails (regardless of the target is responding with BUSY or not). Very unsatisfying to say the least.

I think it'd be much more beneficial for dm-mpath.c:multipath_end_io() to be trained to be respond more intelligently to BLK_STS_RESOURCE.

E.g. set BLK_MQ_S_SCHED_RESTART if requests are known to be outstanding on the path. This is one case where Ming said the queue would be re-run, as detailed in this header:
https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git/commit/?h=dm-4.16&id=5b18cff4baedde77e0d69bd62a13ae78f9488d89

And Jens has reinforced to me that BLK_MQ_S_SCHED_RESTART is a means to kicking the queue more efficiently. _BUT_ I'm not seeing any external blk-mq interface that exposes this capability to a blk-mq driver. As is BLK_MQ_S_SCHED_RESTART gets set very much in the bowels of blk-mq (blk_mq_sched_mark_restart_hctx).

SO I have to do more homework here...

Ming or Jens: might you be able to shed some light on how dm-mpath would/could set BLK_MQ_S_SCHED_RESTART? A new function added that can be called from q->softirq_done_fn in response to BLK_STS_RESOURCE? Or is this level of control (and blk-mq detail) something that a blk-mq driver should need to care about?

Anyway, we may need to get to that level of blk-mq driver controlled retry optimization.

But Bart: again this is a vastly different feedback loop than the stabbing in the dark your commit 6077c2d706097c0 is doing.

Mike

author
#32 lore raw
Quoted 61 lines · Mike Snitzer
Quoted 19 lines · Bart Van Assche
Quoted 2 lines · Mike Snitzer

OK, you have the stage: please give me a pointer to your best explaination of the several.

Since the previous discussion about this topic occurred more than a month ago it could take more time to look up an explanation than to explain it again. Anyway, here we go. As you know a block layer request queue needs to be rerun if one or more requests are waiting and a previous condition that prevented the request to be executed has been cleared. For the dm-mpath driver, examples of such conditions are no tags available, a path that is busy (see also pgpath_busy()), path initialization that is in progress (pg_init_in_progress) or a request completes with status, e.g. if the SCSI core calls __blk_mq_end_request(req, error) with error != 0. For some of these conditions, e.g. path initialization completes, a callback function in the dm-mpath driver is called and it is possible to explicitly rerun the queue. I agree that for such scenario's a delayed queue run should not be triggered. For other scenario's, e.g. if a SCSI initiator submits a SCSI request over a fabric and the SCSI target replies with "BUSY" then the SCSI core will end the I/O request with status BLK_STS_RESOURCE after the

Quoted 8 lines

maximum number of retries has been reached (see also scsi_io_completion()). In that last case, if a SCSI target sends a "BUSY" reply over the wire back to the initiator, there is no other approach for the SCSI initiator to figure out whether it can queue another request than to resubmit the request. The worst possible strategy is to resubmit a request immediately because that will cause a significant fraction of the fabric bandwidth to be used just for replying "BUSY" to requests that can't be processed immediately.

The thing is, the 2 scenarios you are most concerned about have _nothing_ to do with dm_mq_queue_rq() at all. They occur as an error in the IO path _after_ the request is successfully retrieved with blk_get_request() and then submitted.

Quoted 2 lines

The intention of commit 6077c2d706097c0 was to address the last mentioned case.

So it really makes me question why you think commit 6077c2d706097c0 addresses the issue you think it does. And gives me more conviction to remove 6077c2d706097c0.

It may help just by virtue of blindly kicking the queue if blk_get_request() fails (regardless of the target is responding with BUSY or not). Very unsatisfying to say the least.

I think it'd be much more beneficial for dm-mpath.c:multipath_end_io() to be trained to be respond more intelligently to BLK_STS_RESOURCE.

E.g. set BLK_MQ_S_SCHED_RESTART if requests are known to be outstanding on the path. This is one case where Ming said the queue would be re-run, as detailed in this header:
https://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm.git/commit/?h=dm-4.16&id=5b18cff4baedde77e0d69bd62a13ae78f9488d89

And Jens has reinforced to me that BLK_MQ_S_SCHED_RESTART is a means to kicking the queue more efficiently. _BUT_ I'm not seeing any external blk-mq interface that exposes this capability to a blk-mq driver. As is BLK_MQ_S_SCHED_RESTART gets set very much in the bowels of blk-mq (blk_mq_sched_mark_restart_hctx).

Quoted 4 lines

SO I have to do more homework here...

Ming or Jens: might you be able to shed some light on how dm-mpath would/could set BLK_MQ_S_SCHED_RESTART? A new function added that can

When BLK_STS_RESOURCE is returned from .queue_rq(), blk_mq_dispatch_rq_list() will check if BLK_MQ_S_SCHED_RESTART is set.

If it has been set, the queue won't be rerun for this request, and the queue will be rerun until one in-flight request is completed, see blk_mq_sched_restart() which is called from blk_mq_free_request().

If BLK_MQ_S_SCHED_RESTART isn't set, queue is rerun in blk_mq_dispatch_rq_list(), and BLK_MQ_S_SCHED_RESTART is set before calling .queue_rq(), see blk_mq_sched_mark_restart_hctx() which is called in blk_mq_sched_dispatch_requests().

This mechanism can avoid continuous running queue in case of STS_RESOURCE, that means drivers wouldn't worry about that by adding random delay.

Signature · 1 line
Ming
#33 lore raw
Quoted 12 lines · Ming Lei
Quoted 3 lines · Mike Snitzer

Ming or Jens: might you be able to shed some light on how dm-mpath would/could set BLK_MQ_S_SCHED_RESTART? A new function added that can

When BLK_STS_RESOURCE is returned from .queue_rq(), blk_mq_dispatch_rq_list() will check if BLK_MQ_S_SCHED_RESTART is set.

If it has been set, the queue won't be rerun for this request, and the queue will be rerun until one in-flight request is completed, see blk_mq_sched_restart() which is called from blk_mq_free_request().

Quoted 6 lines

If BLK_MQ_S_SCHED_RESTART isn't set, queue is rerun in blk_mq_dispatch_rq_list(), and BLK_MQ_S_SCHED_RESTART is set before calling .queue_rq(), see blk_mq_sched_mark_restart_hctx() which is called in blk_mq_sched_dispatch_requests().

This mechanism can avoid continuous running queue in case of STS_RESOURCE, that means drivers wouldn't worry about that by adding random delay.

Great, thanks for the overview. Really appreciate it.

Mike

#34 lore raw
In reply to Bart Van Assche
Quoted 5 lines · Bart Van Assche

The intention of commit 6077c2d706097c0 was to address the last mentioned case. It may be possible to move the delayed queue rerun from the dm_queue_rq() into dm_requeue_original_request(). But I think it would be wrong to rerun the queue immediately in case a SCSI target system returns "BUSY".

This is my 3rd reply to this email.. 3rd time's the charm? ;)

Here is a patch that will kick the hw queues via blk_mq_requeue_work(), indirectly from dm-rq.c:__dm_mq_kick_requeue_list(), after a delay if BLK_STS_RESOURCE is returned from the target.

Your thoughts on this patch as an alternative to commit 6077c2d7060 ?

Thanks,
Mike

drivers/md/dm-mpath.c +4 -1
index d8c7259..ab2cfdc 100644
@@ -1570,7 +1570,10 @@ static int multipath_end_io(struct dm_target *ti, struct request *clone,
 	if (error && blk_path_error(error)) {
 		struct multipath *m = ti->private;
 
-		r = DM_ENDIO_REQUEUE;
+		if (r == BLK_STS_RESOURCE)
+			r = DM_ENDIO_DELAY_REQUEUE;
+		else
+			r = DM_ENDIO_REQUEUE;
 
 		if (pgpath)
 			fail_path(pgpath);
drivers/md/dm-rq.c +4 -0
index 6b01298..ab0ed2d 100644
@@ -315,6 +315,10 @@ static void dm_done(struct request *clone, blk_status_t error, bool mapped)
 		/* The target wants to requeue the I/O */
 		dm_requeue_original_request(tio, false);
 		break;
+	case DM_ENDIO_DELAY_REQUEUE:
+		/* The target wants to requeue the I/O after a delay */
+		dm_requeue_original_request(tio, true);
+		break;
 	default:
 		DMWARN("unimplemented target endio return value: %d", r);
 		BUG();
include/linux/device-mapper.h +2 -1
index 9ba8453..da83f64 100644
@@ -550,6 +550,7 @@ struct dm_table *dm_swap_table(struct mapped_device *md,
 #define DM_ENDIO_DONE		0
 #define DM_ENDIO_INCOMPLETE	1
 #define DM_ENDIO_REQUEUE	2
+#define DM_ENDIO_DELAY_REQUEUE	3
 
 /*
  * Definitions of return values from target map function.
@@ -557,7 +558,7 @@ struct dm_table *dm_swap_table(struct mapped_device *md,
 #define DM_MAPIO_SUBMITTED	0
 #define DM_MAPIO_REMAPPED	1
 #define DM_MAPIO_REQUEUE	DM_ENDIO_REQUEUE
-#define DM_MAPIO_DELAY_REQUEUE	3
+#define DM_MAPIO_DELAY_REQUEUE	DM_ENDIO_DELAY_REQUEUE
 #define DM_MAPIO_KILL		4
 
 #define dm_sector_div64(x, y)( \
#35 lore raw

drivers/md/dm-mpath.c static int multipath_end_io(struct dm_target *ti, struct request *clone, · line 1576

Quoted 9 lines · Mike Snitzer
drivers/md/dm-mpath.c +4 -1
@@ -1570,7 +1570,10 @@ static int multipath_end_io(struct dm_target *ti, struct request *clone,
 	if (error && blk_path_error(error)) {
 		struct multipath *m = ti->private;
 
-		r = DM_ENDIO_REQUEUE;
+		if (r == BLK_STS_RESOURCE)
+			r = DM_ENDIO_DELAY_REQUEUE;
+		else
+			r = DM_ENDIO_REQUEUE;

Did you perhaps intend "error == BLK_STS_RESOURCE"?

Quoted 13 lines
include/linux/device-mapper.h +1 -0
index 9ba8453..da83f64 100644
@@ -550,6 +550,7 @@ struct dm_table *dm_swap_table(struct mapped_device *md,
 #define DM_ENDIO_DONE		0
 #define DM_ENDIO_INCOMPLETE	1
 #define DM_ENDIO_REQUEUE	2
+#define DM_ENDIO_DELAY_REQUEUE	3
 
 /*
  * Definitions of return values from target map function.

include/linux/device-mapper.h struct dm_table *dm_swap_table(struct mapped_device *md, · line 564

Quoted 8 lines
include/linux/device-mapper.h +1 -1
@@ -557,7 +558,7 @@ struct dm_table *dm_swap_table(struct mapped_device *md,
 #define DM_MAPIO_SUBMITTED	0
 #define DM_MAPIO_REMAPPED	1
 #define DM_MAPIO_REQUEUE	DM_ENDIO_REQUEUE
-#define DM_MAPIO_DELAY_REQUEUE	3
+#define DM_MAPIO_DELAY_REQUEUE	DM_ENDIO_DELAY_REQUEUE
 #define DM_MAPIO_KILL		4
 
 #define dm_sector_div64(x, y)( \

Please consider to introduce enumeration types for the DM_ENDIO_* and the DM_MAPIO_* constants such that the compiler can catch what I reported above. Otherwise this patch looks fine to me.

Thanks,

Bart.

#36 lore raw
Quoted 5 lines · Bart Van Assche
Quoted 4 lines · Mike Snitzer
drivers/md/dm-mpath.c +0 -0
@@ -1570,7 +1570,10 @@ static int multipath_end_io(struct dm_target *ti, struct request *clone,
 	if (error && blk_path_error(error)) {
 		struct multipath *m = ti->private;
 
Quoted 7 lines

drivers/md/dm-mpath.c static int multipath_end_io(struct dm_target *ti, struct request *clone, · line 1576

Quoted 5 lines
drivers/md/dm-mpath.c +4 -1
-		r = DM_ENDIO_REQUEUE;
+		if (r == BLK_STS_RESOURCE)
+			r = DM_ENDIO_DELAY_REQUEUE;
+		else
+			r = DM_ENDIO_REQUEUE;

Did you perhaps intend "error == BLK_STS_RESOURCE"?

Yes, it was a quick patch to get your thoughts.

Quoted 21 lines
Quoted 21 lines
include/linux/device-mapper.h +2 -1
index 9ba8453..da83f64 100644
@@ -550,6 +550,7 @@ struct dm_table *dm_swap_table(struct mapped_device *md,
 #define DM_ENDIO_DONE		0
 #define DM_ENDIO_INCOMPLETE	1
 #define DM_ENDIO_REQUEUE	2
+#define DM_ENDIO_DELAY_REQUEUE	3
 
 /*
  * Definitions of return values from target map function.
@@ -557,7 +558,7 @@ struct dm_table *dm_swap_table(struct mapped_device *md,
 #define DM_MAPIO_SUBMITTED	0
 #define DM_MAPIO_REMAPPED	1
 #define DM_MAPIO_REQUEUE	DM_ENDIO_REQUEUE
-#define DM_MAPIO_DELAY_REQUEUE	3
+#define DM_MAPIO_DELAY_REQUEUE	DM_ENDIO_DELAY_REQUEUE
 #define DM_MAPIO_KILL		4
 
Quoted 4 lines

include/linux/device-mapper.h struct dm_table *dm_swap_table(struct mapped_device *md, · line 564

Quoted 1 line
include/linux/device-mapper.h +0 -0
 #define dm_sector_div64(x, y)( \

Please consider to introduce enumeration types for the DM_ENDIO_* and the DM_MAPIO_* constants such that the compiler can catch what I reported above.

OK, point taken.

Quoted 1 line

Otherwise this patch looks fine to me.

Cool, thanks.

Mike

author
#37 lore raw
In reply to Bart Van Assche
Quoted 19 lines · Bart Van Assche
Quoted 2 lines · Mike Snitzer

OK, you have the stage: please give me a pointer to your best explaination of the several.

Since the previous discussion about this topic occurred more than a month ago it could take more time to look up an explanation than to explain it again. Anyway, here we go. As you know a block layer request queue needs to be rerun if one or more requests are waiting and a previous condition that prevented the request to be executed has been cleared. For the dm-mpath driver, examples of such conditions are no tags available, a path that is busy (see also pgpath_busy()), path initialization that is in progress (pg_init_in_progress) or a request completes with status, e.g. if the SCSI core calls __blk_mq_end_request(req, error) with error != 0. For some of these conditions, e.g. path initialization completes, a callback function in the dm-mpath driver is called and it is possible to explicitly rerun the queue. I agree that for such scenario's a delayed queue run should not be triggered. For other scenario's, e.g. if a SCSI initiator submits a SCSI request over a fabric and the SCSI target replies with "BUSY" then the SCSI core will end the I/O request with status BLK_STS_RESOURCE after the

Quoted 8 lines

maximum number of retries has been reached (see also scsi_io_completion()). In that last case, if a SCSI target sends a "BUSY" reply over the wire back to the initiator, there is no other approach for the SCSI initiator to figure out whether it can queue another request than to resubmit the request. The worst possible strategy is to resubmit a request immediately because that will cause a significant fraction of the fabric bandwidth to be used just for replying "BUSY" to requests that can't be processed immediately.

That isn't true, when BLK_STS_RESOURCE is returned to blk-mq, blk-mq will apply BLK_MQ_S_SCHED_RESTART to hold the queue until one in-flight request is completed, please see blk_mq_sched_restart() which is called from blk_mq_free_request().

Also now we have IO schedulers, when blk_get_request() in dm-mpath returns NULL, it doesn't provide underlying queue's BUSY accurately or in time, since at default size of scheduler tags is double size of driver tags. So it isn't good to depend blk_get_request() only to evaluate queue's busy status, this patchset provides underlying's dispatch result directly to blk-mq, and can deal with this case much better.

Quoted 6 lines

The intention of commit 6077c2d706097c0 was to address the last mentioned case. It may be possible to move the delayed queue rerun from the dm_queue_rq() into dm_requeue_original_request(). But I think it would be wrong to rerun the queue immediately in case a SCSI target system returns "BUSY".

Again, queue won't be rerun immediately after STS_RESOURCE is returned to blk-mq. And BLK_MQ_S_SCHED_RESTART should address your concern on continuous resubmission in case of running out of requests, right?

Thanks,
Ming