Skip to contentSkip to conversation

blk-mq: two improvemens on slow MQ devices

PATCH In review Ming Lei 6 participants 11 messages Sep 27, 2019 – Oct 24, 2019 Block layer

lore
Share & tools
lore

Ming Lei

author
#0 lore raw

cover blk-mq: two improvemens on slow MQ devices

Hi,

The 1st patch always applies io scheduler path if 'none' isn't used, so that sequential IO performance can be improved on slow MQ device. Also write order for zone device can be maintained becasue zone device requires mq-dealine to do that.

The 2nd patch applies normal plugging for MQ HDD.

Ming Lei (2):
blk-mq: respect io scheduler
blk-mq: apply normal plugging for HDD

 block/blk-mq.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
Cc Bart Van Assche <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Damien Le Moal <[email protected]>
Cc Dave Chinner <[email protected]>
Signature · 1 line
2.20.1
author
#1 lore raw

PATCH 1/2 blk-mq: respect io scheduler

Now in case of real MQ, io scheduler may be bypassed, and not only this way may hurt performance for some slow MQ device, but also break zoned device which depends on mq-deadline for respecting the write order in one zone.

So don't bypass io scheduler if we have one setup.

This patch can double sequential write performance basically on MQ scsi_debug when mq-deadline is applied.

Cc Bart Van Assche <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Damien Le Moal <[email protected]>
Cc Dave Chinner <[email protected]>
---
 block/blk-mq.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
block/blk-mq.c +4 -2
index 20a49be536b5..d7aed6518e62 100644
@@ -2003,6 +2003,8 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
 		}
 
 		blk_add_rq_to_plug(plug, rq);
+	} else if (q->elevator) {
+		blk_mq_sched_insert_request(rq, false, true, true);
 	} else if (plug && !blk_queue_nomerges(q)) {
 		/*
 		 * We do limited plugging. If the bio can be merged, do that.
@@ -2026,8 +2028,8 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
 			blk_mq_try_issue_directly(data.hctx, same_queue_rq,
 					&cookie);
 		}
-	} else if ((q->nr_hw_queues > 1 && is_sync) || (!q->elevator &&
-			!data.hctx->dispatch_busy)) {
+	} else if ((q->nr_hw_queues > 1 && is_sync) ||
+			!data.hctx->dispatch_busy) {
 		blk_mq_try_issue_directly(data.hctx, rq, &cookie);
 	} else {
 		blk_mq_sched_insert_request(rq, false, true, true);
Signature · 1 line
2.20.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] blk-mq: respect io scheduler

Quoted 46 lines · Ming Lei

Now in case of real MQ, io scheduler may be bypassed, and not only this way may hurt performance for some slow MQ device, but also break zoned device which depends on mq-deadline for respecting the write order in one zone.

So don't bypass io scheduler if we have one setup.

This patch can double sequential write performance basically on MQ scsi_debug when mq-deadline is applied.

Cc Bart Van Assche <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Damien Le Moal <[email protected]>
Cc Dave Chinner <[email protected]>

---
block/blk-mq.c | 6 ++++--

1 file changed, 4 insertions(+), 2 deletions(-)
block/blk-mq.c +4 -3
index 20a49be536b5..d7aed6518e62 100644
@@ -2003,6 +2003,8 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
 		}
 
 		blk_add_rq_to_plug(plug, rq);
+	} else if (q->elevator) {
+		blk_mq_sched_insert_request(rq, false, true, true);
 	} else if (plug && !blk_queue_nomerges(q)) {
 		/*
 		 * We do limited plugging. If the bio can be merged, do that.
@@ -2026,8 +2028,8 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
 			blk_mq_try_issue_directly(data.hctx, same_queue_rq,
 					&cookie);
 		}
-	} else if ((q->nr_hw_queues > 1 && is_sync) || (!q->elevator &&
-			!data.hctx->dispatch_busy)) {
+	} else if ((q->nr_hw_queues > 1 && is_sync) ||
+			!data.hctx->dispatch_busy) {
 		blk_mq_try_issue_directly(data.hctx, rq, &cookie);
 	} else {
 		blk_mq_sched_insert_request(rq, false, true, true);
--
Quoted 1 line

2.20.1

Looks good to me. Fixes a couple issues we have seen with zoned devices too.

#3 lore raw

Re: [PATCH 1/2] blk-mq: respect io scheduler

In reply to Ming Lei
Quoted 45 lines · Ming Lei

Now in case of real MQ, io scheduler may be bypassed, and not only this way may hurt performance for some slow MQ device, but also break zoned device which depends on mq-deadline for respecting the write order in one zone.

So don't bypass io scheduler if we have one setup.

This patch can double sequential write performance basically on MQ scsi_debug when mq-deadline is applied.

Cc Bart Van Assche <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Damien Le Moal <[email protected]>
Cc Dave Chinner <[email protected]>
---
 block/blk-mq.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
block/blk-mq.c +4 -3
index 20a49be536b5..d7aed6518e62 100644
@@ -2003,6 +2003,8 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
                }
 
                blk_add_rq_to_plug(plug, rq);
+       } else if (q->elevator) {
+               blk_mq_sched_insert_request(rq, false, true, true);
        } else if (plug && !blk_queue_nomerges(q)) {
                /*
                 * We do limited plugging. If the bio can be merged, do that.
@@ -2026,8 +2028,8 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
                        blk_mq_try_issue_directly(data.hctx, same_queue_rq,
                                        &cookie);
                }
-       } else if ((q->nr_hw_queues > 1 && is_sync) || (!q->elevator &&
-                       !data.hctx->dispatch_busy)) {
+       } else if ((q->nr_hw_queues > 1 && is_sync) ||
+                       !data.hctx->dispatch_busy) {
                blk_mq_try_issue_directly(data.hctx, rq, &cookie);
        } else {
                blk_mq_sched_insert_request(rq, false, true, true);
--
Quoted 2 lines

2.20.1

I've verified that the issue I saw with zone locking being skipped due to scheduler bypass is resolved with this patch.

Thanks,
Hans

Reviewed-by on v1 1/2
#4 lore raw

Re: [PATCH 1/2] blk-mq: respect io scheduler

In reply to Ming Lei
Quoted 33 lines · Ming Lei

Now in case of real MQ, io scheduler may be bypassed, and not only this way may hurt performance for some slow MQ device, but also break zoned device which depends on mq-deadline for respecting the write order in one zone.

So don't bypass io scheduler if we have one setup.

This patch can double sequential write performance basically on MQ scsi_debug when mq-deadline is applied.

Cc Bart Van Assche <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Damien Le Moal <[email protected]>
Cc Dave Chinner <[email protected]>
---
 block/blk-mq.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
block/blk-mq.c +2 -0
index 20a49be536b5..d7aed6518e62 100644
@@ -2003,6 +2003,8 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
 		}
 
 		blk_add_rq_to_plug(plug, rq);
+	} else if (q->elevator) {
+		blk_mq_sched_insert_request(rq, false, true, true);>  	} else if (plug && !blk_queue_nomerges(q)) {
 		/*
 		 * We do limited plugging. If the bio can be merged, do that.

block/blk-mq.c static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio) · line 2035

Quoted 10 lines
block/blk-mq.c +2 -2
@@ -2026,8 +2028,8 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
 			blk_mq_try_issue_directly(data.hctx, same_queue_rq,
 					&cookie);
 		}
-	} else if ((q->nr_hw_queues > 1 && is_sync) || (!q->elevator &&
-			!data.hctx->dispatch_busy)) {
+	} else if ((q->nr_hw_queues > 1 && is_sync) ||
+			!data.hctx->dispatch_busy) {
 		blk_mq_try_issue_directly(data.hctx, rq, &cookie);
 	} else {
 		blk_mq_sched_insert_request(rq, false, true, true);

I think this patch should have a Cc: [email protected]
This fixes a problem existing since we added deadline zone write-locking with commit 5700f69178e9 ("mq-deadline: Introduce zone locking support").

Otherwise:

Signature · 2 lines
Damien Le Moal
Western Digital Research
maintainer
#5 lore raw

Re: [PATCH 1/2] blk-mq: respect io scheduler

Quoted 40 lines · Damien Le Moal
Quoted 39 lines · Ming Lei

Now in case of real MQ, io scheduler may be bypassed, and not only this way may hurt performance for some slow MQ device, but also break zoned device which depends on mq-deadline for respecting the write order in one zone.

So don't bypass io scheduler if we have one setup.

This patch can double sequential write performance basically on MQ scsi_debug when mq-deadline is applied.

Cc Bart Van Assche <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Damien Le Moal <[email protected]>
Cc Dave Chinner <[email protected]>
---
  block/blk-mq.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
block/blk-mq.c +4 -2
index 20a49be536b5..d7aed6518e62 100644
@@ -2003,6 +2003,8 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
  		}
 
  		blk_add_rq_to_plug(plug, rq);
+	} else if (q->elevator) {
+		blk_mq_sched_insert_request(rq, false, true, true);>  	} else if (plug && !blk_queue_nomerges(q)) {
  		/*
  		 * We do limited plugging. If the bio can be merged, do that.
@@ -2026,8 +2028,8 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
  			blk_mq_try_issue_directly(data.hctx, same_queue_rq,
  					&cookie);
  		}
-	} else if ((q->nr_hw_queues > 1 && is_sync) || (!q->elevator &&
-			!data.hctx->dispatch_busy)) {
+	} else if ((q->nr_hw_queues > 1 && is_sync) ||
+			!data.hctx->dispatch_busy) {
Quoted 8 lines

block/blk-mq.c static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio) · line 2035

Quoted 4 lines
block/blk-mq.c +0 -0
  		blk_mq_try_issue_directly(data.hctx, rq, &cookie);
  	} else {
  		blk_mq_sched_insert_request(rq, false, true, true);

I think this patch should have a Cc: [email protected]
This fixes a problem existing since we added deadline zone write-locking with commit 5700f69178e9 ("mq-deadline: Introduce zone locking support").

I'd rather not mark it for stable until it's been in the kernel for some weeks at least, since we are potentially dealing with behavioral change for everyone. We've been burnt by stuff like this in the past.

That said, this patch could be a candidate. Let's revisit in a few weeks.

Signature · 1 line
Jens Axboe
#6 lore raw

Re: [PATCH 1/2] blk-mq: respect io scheduler

Quoted 50 lines · Jens Axboe
Quoted 40 lines · Damien Le Moal
Quoted 39 lines · Ming Lei

Now in case of real MQ, io scheduler may be bypassed, and not only this way may hurt performance for some slow MQ device, but also break zoned device which depends on mq-deadline for respecting the write order in one zone.

So don't bypass io scheduler if we have one setup.

This patch can double sequential write performance basically on MQ scsi_debug when mq-deadline is applied.

Cc Bart Van Assche <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Damien Le Moal <[email protected]>
Cc Dave Chinner <[email protected]>
---
  block/blk-mq.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
block/blk-mq.c +4 -2
index 20a49be536b5..d7aed6518e62 100644
@@ -2003,6 +2003,8 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
  		}
 
  		blk_add_rq_to_plug(plug, rq);
+	} else if (q->elevator) {
+		blk_mq_sched_insert_request(rq, false, true, true);>  	} else if (plug && !blk_queue_nomerges(q)) {
  		/*
  		 * We do limited plugging. If the bio can be merged, do that.
@@ -2026,8 +2028,8 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
  			blk_mq_try_issue_directly(data.hctx, same_queue_rq,
  					&cookie);
  		}
-	} else if ((q->nr_hw_queues > 1 && is_sync) || (!q->elevator &&
-			!data.hctx->dispatch_busy)) {
+	} else if ((q->nr_hw_queues > 1 && is_sync) ||
+			!data.hctx->dispatch_busy) {
Quoted 8 lines

block/blk-mq.c static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio) · line 2035

Quoted 4 lines
block/blk-mq.c +0 -0
  		blk_mq_try_issue_directly(data.hctx, rq, &cookie);
  	} else {
  		blk_mq_sched_insert_request(rq, false, true, true);

I think this patch should have a Cc: [email protected]
This fixes a problem existing since we added deadline zone write-locking with commit 5700f69178e9 ("mq-deadline: Introduce zone locking support").

Quoted 6 lines

I'd rather not mark it for stable until it's been in the kernel for some weeks at least, since we are potentially dealing with behavioral change for everyone. We've been burnt by stuff like this in the past.

That said, this patch could be a candidate. Let's revisit in a few weeks.

OK. Thanks !

Signature · 2 lines
Damien Le Moal
Western Digital Research
#7 lore raw

Re: [PATCH 1/2] blk-mq: respect io scheduler

In reply to Ming Lei

Hello Ming Lei,

Quoted 34 lines · Ming Lei

Now in case of real MQ, io scheduler may be bypassed, and not only this way may hurt performance for some slow MQ device, but also break zoned device which depends on mq-deadline for respecting the write order in one zone.

So don't bypass io scheduler if we have one setup.

This patch can double sequential write performance basically on MQ scsi_debug when mq-deadline is applied.

Cc Bart Van Assche <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Damien Le Moal <[email protected]>
Cc Dave Chinner <[email protected]>
---
 block/blk-mq.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
block/blk-mq.c +2 -0
index 20a49be536b5..d7aed6518e62 100644
@@ -2003,6 +2003,8 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
 		}
 
 		blk_add_rq_to_plug(plug, rq);
+	} else if (q->elevator) {
+		blk_mq_sched_insert_request(rq, false, true, true);
 	} else if (plug && !blk_queue_nomerges(q)) {
 		/*
 		 * We do limited plugging. If the bio can be merged, do that.

block/blk-mq.c static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio) · line 2035

Quoted 10 lines
block/blk-mq.c +2 -2
@@ -2026,8 +2028,8 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
 			blk_mq_try_issue_directly(data.hctx, same_queue_rq,
 					&cookie);
 		}
-	} else if ((q->nr_hw_queues > 1 && is_sync) || (!q->elevator &&
-			!data.hctx->dispatch_busy)) {
+	} else if ((q->nr_hw_queues > 1 && is_sync) ||
+			!data.hctx->dispatch_busy) {
 		blk_mq_try_issue_directly(data.hctx, rq, &cookie);
 	} else {
 		blk_mq_sched_insert_request(rq, false, true, true);

This patch introduces identical branches, both "else if (q->elevator)" and "else" do the same thing. Wouldn't be enough to just remove the condition "!q->elevator" without adding a new if?

Thanks,
André

author
#8 lore raw

PATCH 2/2 blk-mq: apply normal plugging for HDD

In reply to Ming Lei

Some HDD drive may expose multiple hw queue, such as MegraRaid, so still apply the normal plugging for such devices because sequential IO may benefit a lot from plug merging.

Cc Bart Van Assche <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Damien Le Moal <[email protected]>
Cc Dave Chinner <[email protected]>
---
 block/blk-mq.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
block/blk-mq.c +5 -1
index d7aed6518e62..969dfe02fa7c 100644
@@ -1983,10 +1983,14 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
 		/* bypass scheduler for flush rq */
 		blk_insert_flush(rq);
 		blk_mq_run_hw_queue(data.hctx, true);
-	} else if (plug && (q->nr_hw_queues == 1 || q->mq_ops->commit_rqs)) {
+	} else if (plug && (q->nr_hw_queues == 1 || q->mq_ops->commit_rqs ||
+				!blk_queue_nonrot(q))) {
 		/*
 		 * Use plugging if we have a ->commit_rqs() hook as well, as
 		 * we know the driver uses bd->last in a smart fashion.
+		 *
+		 * Use normal plugging if this disk is slow HDD, as sequential
+		 * IO may benefit a lot from plug merging.
 		 */
 		unsigned int request_count = plug->rq_count;
 		struct request *last = NULL;
Signature · 1 line
2.20.1
Reviewed-by on v1 2/2
#9 lore raw

Re: [PATCH 2/2] blk-mq: apply normal plugging for HDD

Quoted 24 lines · Ming Lei

Some HDD drive may expose multiple hw queue, such as MegraRaid, so still apply the normal plugging for such devices because sequential IO may benefit a lot from plug merging.

Cc Bart Van Assche <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Damien Le Moal <[email protected]>
Cc Dave Chinner <[email protected]>
---
 block/blk-mq.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
block/blk-mq.c +1 -1
index d7aed6518e62..969dfe02fa7c 100644
@@ -1983,10 +1983,14 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
 		/* bypass scheduler for flush rq */
 		blk_insert_flush(rq);
 		blk_mq_run_hw_queue(data.hctx, true);
-	} else if (plug && (q->nr_hw_queues == 1 || q->mq_ops->commit_rqs)) {
+	} else if (plug && (q->nr_hw_queues == 1 || q->mq_ops->commit_rqs ||

block/blk-mq.c static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio) · line 1996

Quoted 10 lines
block/blk-mq.c +4 -0
+				!blk_queue_nonrot(q))) {
 		/*
 		 * Use plugging if we have a ->commit_rqs() hook as well, as
 		 * we know the driver uses bd->last in a smart fashion.
+		 *
+		 * Use normal plugging if this disk is slow HDD, as sequential
+		 * IO may benefit a lot from plug merging.
 		 */
 		unsigned int request_count = plug->rq_count;
 		struct request *last = NULL;

Cc stable needed ?

Signature · 2 lines
Damien Le Moal
Western Digital Research
maintainer
#10 lore raw
In reply to Ming Lei
Quoted 8 lines · Ming Lei

Hi,

The 1st patch always applies io scheduler path if 'none' isn't used, so that sequential IO performance can be improved on slow MQ device. Also write order for zone device can be maintained becasue zone device requires mq-dealine to do that.

The 2nd patch applies normal plugging for MQ HDD.

Both look clean and fine to me. I will wait with queueing them up until I've done some testing.

Signature · 1 line
Jens Axboe