Skip to contentSkip to conversation

Make legacy IO schedulers work with blk-mq

PATCHSET/RFC In review Jens Axboe 6 participants 32 messages Dec 3, 2016 – Dec 6, 2016

Subsystems (3)
lore
Share & tools
lore

Jens Axboe

author
#0 lore raw

This is by no means done, but it seems to work well enough that I thought I'd send it out for others to take a look at and play with.

Basically this allows blk-mq managed devices to run the legacy IO schedulers, unmodified. The only requirement is that the blk-mq device has to be single queue for now, though that limitation would be rather simple to lift.

Since this is a debug patch, the default scheduler is deadline. You can switch that to the other configured schedulers, as you would with non-mq devices. Here's an example of a scsi-mq device that is running deadline, and being switched to CFQ online:

root@leopard:~# cat /sys/block/sda/mq/0/tags 
nr_tags=31, reserved_tags=0, bits_per_word=4
nr_free=31, nr_reserved=0
active_queues=0
root@leopard:~# cat /sys/block/sda/queue/scheduler 
noop [deadline] cfq 
root@leopard:~# echo cfq > /sys/block/sda/queue/scheduler 
root@leopard:~# cat /sys/block/sda/queue/scheduler 
noop deadline [cfq] 

Testing welcome. There's certainly room for improvement here, so I'm mostly interested in grave performance issues or crashes, if any.

Can also be viewed/fetched via git:

git://git.kernel.dk/linux-block for-4.11/blk-mq-legacy-sched

Signature · 1 line
Jens Axboe
author
#1 lore raw

PATCH 1/7 block: use legacy path for flush requests for MQ with a scheduler

No functional changes with this patch, it's just in preparation for supporting legacy schedulers on blk-mq.

---
 block/blk-core.c  |  2 +-
 block/blk-exec.c  |  2 +-
 block/blk-flush.c | 26 ++++++++++++++------------
 block/blk.h       | 12 +++++++++++-
 4 files changed, 27 insertions(+), 15 deletions(-)
block/blk-core.c +1 -1
index 3f2eb8d80189..0e23589ab3bf 100644
@@ -1310,7 +1310,7 @@ static struct request *blk_old_get_request(struct request_queue *q, int rw,
 
 struct request *blk_get_request(struct request_queue *q, int rw, gfp_t gfp_mask)
 {
-	if (q->mq_ops)
+	if (blk_use_mq_path(q))
 		return blk_mq_alloc_request(q, rw,
 			(gfp_mask & __GFP_DIRECT_RECLAIM) ?
 				0 : BLK_MQ_REQ_NOWAIT);
block/blk-exec.c +1 -1
index 3ecb00a6cf45..73b8a701ae6d 100644
@@ -64,7 +64,7 @@ void blk_execute_rq_nowait(struct request_queue *q, struct gendisk *bd_disk,
 	 * don't check dying flag for MQ because the request won't
 	 * be reused after dying flag is set
 	 */
-	if (q->mq_ops) {
+	if (blk_use_mq_path(q)) {
 		blk_mq_insert_request(rq, at_head, true, false);
 		return;
 	}
block/blk-flush.c +14 -12
index 1bdbb3d3e5f5..0b68a1258bdd 100644
@@ -133,14 +133,16 @@ static void blk_flush_restore_request(struct request *rq)
 
 static bool blk_flush_queue_rq(struct request *rq, bool add_front)
 {
-	if (rq->q->mq_ops) {
+	struct request_queue *q = rq->q;
+
+	if (blk_use_mq_path(q)) {
 		blk_mq_add_to_requeue_list(rq, add_front, true);
 		return false;
 	} else {
 		if (add_front)
-			list_add(&rq->queuelist, &rq->q->queue_head);
+			list_add(&rq->queuelist, &q->queue_head);
 		else
-			list_add_tail(&rq->queuelist, &rq->q->queue_head);
+			list_add_tail(&rq->queuelist, &q->queue_head);
 		return true;
 	}
 }
@@ -201,7 +203,7 @@ static bool blk_flush_complete_seq(struct request *rq,
 		BUG_ON(!list_empty(&rq->queuelist));
 		list_del_init(&rq->flush.list);
 		blk_flush_restore_request(rq);
-		if (q->mq_ops)
+		if (blk_use_mq_path(q))
 			blk_mq_end_request(rq, error);
 		else
 			__blk_end_request_all(rq, error);
@@ -224,7 +226,7 @@ static void flush_end_io(struct request *flush_rq, int error)
 	unsigned long flags = 0;
 	struct blk_flush_queue *fq = blk_get_flush_queue(q, flush_rq->mq_ctx);
 
-	if (q->mq_ops) {
+	if (blk_use_mq_path(q)) {
 		struct blk_mq_hw_ctx *hctx;
 
 		/* release the tag's ownership to the req cloned from */
@@ -240,7 +242,7 @@ static void flush_end_io(struct request *flush_rq, int error)
 	/* account completion of the flush request */
 	fq->flush_running_idx ^= 1;
 
-	if (!q->mq_ops)
+	if (!blk_use_mq_path(q))
 		elv_completed_request(q, flush_rq);
 
 	/* and push the waiting requests to the next stage */
@@ -267,7 +269,7 @@ static void flush_end_io(struct request *flush_rq, int error)
 		blk_run_queue_async(q);
 	}
 	fq->flush_queue_delayed = 0;
-	if (q->mq_ops)
+	if (blk_use_mq_path(q))
 		spin_unlock_irqrestore(&fq->mq_flush_lock, flags);
 }
 
@@ -315,7 +317,7 @@ static bool blk_kick_flush(struct request_queue *q, struct blk_flush_queue *fq)
 	 * be in flight at the same time. And acquire the tag's
 	 * ownership for flush req.
 	 */
-	if (q->mq_ops) {
+	if (blk_use_mq_path(q)) {
 		struct blk_mq_hw_ctx *hctx;
 
 		flush_rq->mq_ctx = first_rq->mq_ctx;
@@ -409,7 +411,7 @@ void blk_insert_flush(struct request *rq)
 	 * complete the request.
 	 */
 	if (!policy) {
-		if (q->mq_ops)
+		if (blk_use_mq_path(q))
 			blk_mq_end_request(rq, 0);
 		else
 			__blk_end_bidi_request(rq, 0, 0, 0);
@@ -425,9 +427,9 @@ void blk_insert_flush(struct request *rq)
 	 */
 	if ((policy & REQ_FSEQ_DATA) &&
 	    !(policy & (REQ_FSEQ_PREFLUSH | REQ_FSEQ_POSTFLUSH))) {
-		if (q->mq_ops) {
+		if (blk_use_mq_path(q))
 			blk_mq_insert_request(rq, false, false, true);
-		} else
+		else
 			list_add_tail(&rq->queuelist, &q->queue_head);
 		return;
 	}
@@ -440,7 +442,7 @@ void blk_insert_flush(struct request *rq)
 	INIT_LIST_HEAD(&rq->flush.list);
 	rq->rq_flags |= RQF_FLUSH_SEQ;
 	rq->flush.saved_end_io = rq->end_io; /* Usually NULL */
-	if (q->mq_ops) {
+	if (blk_use_mq_path(q)) {
 		rq->end_io = mq_flush_data_end_io;
 
 		spin_lock_irq(&fq->mq_flush_lock);
block/blk.h +11 -1
index 041185e5f129..094fc10429c3 100644
@@ -36,10 +36,20 @@ extern struct kmem_cache *request_cachep;
 extern struct kobj_type blk_queue_ktype;
 extern struct ida blk_queue_ida;
 
+/*
+ * Use the MQ path if we have mq_ops, but not if we are using an IO
+ * scheduler. For the scheduler, we should use the legacy path. Only
+ * for internal use in the block layer.
+ */
+static inline bool blk_use_mq_path(struct request_queue *q)
+{
+	return q->mq_ops && !q->elevator;
+}
+
 static inline struct blk_flush_queue *blk_get_flush_queue(
 		struct request_queue *q, struct blk_mq_ctx *ctx)
 {
-	if (q->mq_ops)
+	if (blk_use_mq_path(q))
 		return blk_mq_map_queue(q, ctx->cpu)->fq;
 	return q->fq;
 }
Signature · 1 line
2.7.4
#2 lore raw

Re: [PATCH 1/7] block: use legacy path for flush requests for MQ with a scheduler

Quoted 2 lines · Jens Axboe

No functional changes with this patch, it's just in preparation for supporting legacy schedulers on blk-mq.

Ewww. I think without refactoring to clear what 'use_mq_path' means here and better naming this is a total non-started. Even with that we'll now have yet another code path to worry about. Is there any chance to instead consolidate into a single path?

block/blk-core.c static struct request *blk_old_get_request(struct request_queue *q, int rw, · line 1316

Quoted 7 lines

struct request *blk_get_request(struct request_queue *q, int rw, gfp_t gfp_mask) {

block/blk-core.c +1 -1
-	if (q->mq_ops)
+	if (blk_use_mq_path(q))
 		return blk_mq_alloc_request(q, rw,
 			(gfp_mask & __GFP_DIRECT_RECLAIM) ?
 				0 : BLK_MQ_REQ_NOWAIT);

So now with blk-mq and an elevator set we go into blk_old_get_request, hich will simply allocate new requests. How does this not break every existing driver?

author
#3 lore raw

Re: [PATCH 1/7] block: use legacy path for flush requests for MQ with a scheduler

Quoted 8 lines · Christoph Hellwig
Quoted 2 lines · Jens Axboe

No functional changes with this patch, it's just in preparation for supporting legacy schedulers on blk-mq.

Ewww. I think without refactoring to clear what 'use_mq_path' means here and better naming this is a total non-started. Even with that we'll now have yet another code path to worry about. Is there any chance to instead consolidate into a single path?

It's not pretty at all. I should have prefaced this patchset with saying that it's an experiment in seeing what it would take to simply use the old IO schedulers, as a temporary measure, on blk/scsi-mq. I did clean it up a bit after posting:

http://git.kernel.dk/cgit/linux-block/log/?h=blk-mq-legacy-sched

but I'm not going to claim this is anywhere near merge read, nor clean.

Quoted 11 lines

block/blk-core.c static struct request *blk_old_get_request(struct request_queue *q, int rw, · line 1316

Quoted 7 lines

struct request *blk_get_request(struct request_queue *q, int rw, gfp_t gfp_mask) {

block/blk-core.c +1 -1
-	if (q->mq_ops)
+	if (blk_use_mq_path(q))
 		return blk_mq_alloc_request(q, rw,
 			(gfp_mask & __GFP_DIRECT_RECLAIM) ?
 				0 : BLK_MQ_REQ_NOWAIT);

So now with blk-mq and an elevator set we go into blk_old_get_request, hich will simply allocate new requests. How does this not break every existing driver?

Since Johannes found that confusion, maybe I should explain how it all works.

Basically, if we are blk-mq (q->mq_ops) and now have an IO scheduler attached (q->elevator), then the path from bio to request is essentially the old one. We allocate a request through get_request() and friends, and insert it with the elevator interface. When the queue is later run, our blk_mq_sched_dispatch() asks the IO scheduler for a request, and if successful, we allocate a real MQ request and dispatch that. So all the driver ever sees is MQ requests, and it uses the MQ interface. Only the internal bits now look at blk_use_mq_path() to tell whether they should alloc+insert with that.

The above will break if we have drivers manually allocating a request through blk_get_request(), and then using MQ functions to insert/run it. I didn't audit all of that, and I think most (all?) of them just use the MQ interfaces. That would also currently be broken, we either/or the logic to run software queues or run through the elevator.

Signature · 1 line
Jens Axboe
#4 lore raw

Re: [PATCH 1/7] block: use legacy path for flush requests for MQ with a scheduler

Quoted 31 lines · Jens Axboe
Quoted 8 lines · Christoph Hellwig
Quoted 2 lines · Jens Axboe

No functional changes with this patch, it's just in preparation for supporting legacy schedulers on blk-mq.

Ewww. I think without refactoring to clear what 'use_mq_path' means here and better naming this is a total non-started. Even with that we'll now have yet another code path to worry about. Is there any chance to instead consolidate into a single path?

It's not pretty at all. I should have prefaced this patchset with saying that it's an experiment in seeing what it would take to simply use the old IO schedulers, as a temporary measure, on blk/scsi-mq. I did clean it up a bit after posting:

http://git.kernel.dk/cgit/linux-block/log/?h=blk-mq-legacy-sched

but I'm not going to claim this is anywhere near merge read, nor clean.

Quoted 11 lines

block/blk-core.c static struct request *blk_old_get_request(struct request_queue *q, int rw, · line 1316

Quoted 7 lines

struct request *blk_get_request(struct request_queue *q, int rw, gfp_t gfp_mask) {

block/blk-core.c +1 -1
-	if (q->mq_ops)
+	if (blk_use_mq_path(q))
 		return blk_mq_alloc_request(q, rw,
 			(gfp_mask & __GFP_DIRECT_RECLAIM) ?
 				0 : BLK_MQ_REQ_NOWAIT);

So now with blk-mq and an elevator set we go into blk_old_get_request, hich will simply allocate new requests. How does this not break every existing driver?

Quoted 2 lines

Since Johannes found that confusion, maybe I should explain how it all works.

To clarify the naming, how about sth. like blk_mq_use_sched() (to align with blk_mq_sched_dispatch())?

Signature · 6 lines
Johannes Thumshirn                                          Storage
[email protected]                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg
GF: Felix Imend�rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N�rnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
author
#5 lore raw

Re: [PATCH 1/7] block: use legacy path for flush requests for MQ with a scheduler

Quoted 32 lines · Johannes Thumshirn
Quoted 31 lines · Jens Axboe
Quoted 8 lines · Christoph Hellwig
Quoted 2 lines · Jens Axboe

No functional changes with this patch, it's just in preparation for supporting legacy schedulers on blk-mq.

Ewww. I think without refactoring to clear what 'use_mq_path' means here and better naming this is a total non-started. Even with that we'll now have yet another code path to worry about. Is there any chance to instead consolidate into a single path?

It's not pretty at all. I should have prefaced this patchset with saying that it's an experiment in seeing what it would take to simply use the old IO schedulers, as a temporary measure, on blk/scsi-mq. I did clean it up a bit after posting:

http://git.kernel.dk/cgit/linux-block/log/?h=blk-mq-legacy-sched

but I'm not going to claim this is anywhere near merge read, nor clean.

Quoted 11 lines

block/blk-core.c static struct request *blk_old_get_request(struct request_queue *q, int rw, · line 1316

Quoted 7 lines

struct request *blk_get_request(struct request_queue *q, int rw, gfp_t gfp_mask) {

block/blk-core.c +1 -1
-	if (q->mq_ops)
+	if (blk_use_mq_path(q))
 		return blk_mq_alloc_request(q, rw,
 			(gfp_mask & __GFP_DIRECT_RECLAIM) ?
 				0 : BLK_MQ_REQ_NOWAIT);

So now with blk-mq and an elevator set we go into blk_old_get_request, hich will simply allocate new requests. How does this not break every existing driver?

Quoted 5 lines
Quoted 2 lines

Since Johannes found that confusion, maybe I should explain how it all works.

To clarify the naming, how about sth. like blk_mq_use_sched() (to align with blk_mq_sched_dispatch())?

Yeah, that is a much better name indeed. I'll make that change.

Signature · 1 line
Jens Axboe
#6 lore raw

Re: [PATCH 1/7] block: use legacy path for flush requests for MQ with a scheduler

In reply to Jens Axboe
Quoted 11 lines · Jens Axboe
Quoted 8 lines · Christoph Hellwig
Quoted 2 lines · Jens Axboe

No functional changes with this patch, it's just in preparation for supporting legacy schedulers on blk-mq.

Ewww. I think without refactoring to clear what 'use_mq_path' means here and better naming this is a total non-started. Even with that we'll now have yet another code path to worry about. Is there any chance to instead consolidate into a single path?

Quoted 8 lines

It's not pretty at all. I should have prefaced this patchset with saying that it's an experiment in seeing what it would take to simply use the old IO schedulers, as a temporary measure, on blk/scsi-mq. I did clean it up a bit after posting:

http://git.kernel.dk/cgit/linux-block/log/?h=blk-mq-legacy-sched

but I'm not going to claim this is anywhere near merge read, nor clean.

Nice to see you've lowered your standards...

Maybe now we can revisit this line of work? ;)
http://git.kernel.org/cgit/linux/kernel/git/snitzer/linux.git/log/?h=wip

To fix: https://bugzilla.kernel.org/show_bug.cgi?id=119841

Quoted 25 lines
Quoted 11 lines

block/blk-core.c static struct request *blk_old_get_request(struct request_queue *q, int rw, · line 1316

Quoted 7 lines

struct request *blk_get_request(struct request_queue *q, int rw, gfp_t gfp_mask) {

block/blk-core.c +1 -1
-    if (q->mq_ops)
+    if (blk_use_mq_path(q))
             return blk_mq_alloc_request(q, rw,
                     (gfp_mask & __GFP_DIRECT_RECLAIM) ?
                             0 : BLK_MQ_REQ_NOWAIT);

So now with blk-mq and an elevator set we go into blk_old_get_request, hich will simply allocate new requests. How does this not break every existing driver?

Since Johannes found that confusion, maybe I should explain how it all works.

Basically, if we are blk-mq (q->mq_ops) and now have an IO scheduler attached (q->elevator), then the path from bio to request is essentially the old one. We allocate a request through get_request() and friends, and insert it with the elevator interface. When the queue is later run, our blk_mq_sched_dispatch() asks the IO scheduler for a request, and if successful, we allocate a real MQ request and dispatch that. So all the driver ever sees is MQ requests, and it uses the MQ interface. Only the internal bits now look at blk_use_mq_path() to tell whether they should alloc+insert with that.

Quoted 5 lines

The above will break if we have drivers manually allocating a request through blk_get_request(), and then using MQ functions to insert/run it. I didn't audit all of that, and I think most (all?) of them just use the MQ interfaces. That would also currently be broken, we either/or the logic to run software queues or run through the elevator.

I'm not seeing anything in elevator_switch() that would prevent an elevator from attempting to be used on an mq device with > 1 hw queue. But I could easily be missing it.

That aside, this patchset has all the makings of a _serious_ problem for dm-mq multipath (e.g. if dm_mod.use_blk_mq=Y and dm_mod.dm_mq_nr_hw_queues=1). There is a bunch of code in drivers/dm/dm-rq.c that looks at q->mq_ops vs not to determine if mq is used vs old .request_fn.

I think we really need a way to force an allocated mq request_queue (with a single hw_queue) to not support this technological terror you've constructed. (*cough*
http://es.memegenerator.net/instance/58341711 )

In fact I'd prefer there be a mechanism to only allow this if some opt-in interface is used... or the inverse: dm-mq can allocate a blk-mq request_requeue that will _never_ support this.

I could be super dense on this line of work. But what is the point of all this? Seems like a really unfortunate distraction that makes the block code all the more encumbered with fiddley old vs new logic. So now we're opening old .request_fn users up to blk-mq-with-scheduler vs non-blk-mq bugs.

Color me skeptical. In time, maybe I'll warm to all this but for now we need a big "OFF!" switch (aside from DEFAULT_MQ_SCHED_NONE, in request_queue allocation interface).

FWIW, dm-multipath has supported a top-level .request_fn requeue_queue, legacy elevator and all, stacked on blk-mq queue(s) for quite a while. If people _really_ want this you could easily give it to them by forcing the use of the DM "multipath" target with multipath's "queue_mode" feature set to "rq".

author
#7 lore raw

Re: [PATCH 1/7] block: use legacy path for flush requests for MQ with a scheduler

Quoted 17 lines · Mike Snitzer
Quoted 16 lines · Jens Axboe
Quoted 8 lines · Christoph Hellwig
Quoted 2 lines · Jens Axboe

No functional changes with this patch, it's just in preparation for supporting legacy schedulers on blk-mq.

Ewww. I think without refactoring to clear what 'use_mq_path' means here and better naming this is a total non-started. Even with that we'll now have yet another code path to worry about. Is there any chance to instead consolidate into a single path?

It's not pretty at all. I should have prefaced this patchset with saying that it's an experiment in seeing what it would take to simply use the old IO schedulers, as a temporary measure, on blk/scsi-mq. I did clean it up a bit after posting:

Quoted 8 lines
Quoted 3 lines

http://git.kernel.dk/cgit/linux-block/log/?h=blk-mq-legacy-sched

but I'm not going to claim this is anywhere near merge read, nor clean.

Nice to see you've lowered your standards...

Maybe now we can revisit this line of work? ;)
http://git.kernel.org/cgit/linux/kernel/git/snitzer/linux.git/log/?h=wip

I haven't lowered my standards. I thought this posting was pretty clear
- it's an experiment in what supporting legacy schedulers would look like. As you quote me above, this is NOT proposed for merging, nor do I consider it anywhere near clean.

Quoted 3 lines

I'm not seeing anything in elevator_switch() that would prevent an elevator from attempting to be used on an mq device with > 1 hw queue. But I could easily be missing it.

You missed it, it's in blk_mq_sched_init(), called from elv_iosched_store() when trying to switch (or setup a new) schedulers.

Quoted 9 lines

That aside, this patchset has all the makings of a _serious_ problem for dm-mq multipath (e.g. if dm_mod.use_blk_mq=Y and dm_mod.dm_mq_nr_hw_queues=1). There is a bunch of code in drivers/dm/dm-rq.c that looks at q->mq_ops vs not to determine if mq is used vs old .request_fn.

I think we really need a way to force an allocated mq request_queue (with a single hw_queue) to not support this technological terror you've constructed. (*cough*

See BLK_MQ_F_NO_SCHED.

Quoted 5 lines

I could be super dense on this line of work. But what is the point of all this? Seems like a really unfortunate distraction that makes the block code all the more encumbered with fiddley old vs new logic. So now we're opening old .request_fn users up to blk-mq-with-scheduler vs non-blk-mq bugs.

See above, it's just an experiment in seeing what this would look like, how transparent (or not) we could make that.

Don't overthink any of this, and don't start making plans or coming up with problems on why X or Y would not work with whatever interface variant of dm. That's jumping the gun.

Signature · 1 line
Jens Axboe
#8 lore raw

Re: [PATCH 1/7] block: use legacy path for flush requests for MQ with a scheduler

Quoted 24 lines · Jens Axboe
Quoted 23 lines · Mike Snitzer
Quoted 11 lines · Jens Axboe
Quoted 8 lines · Christoph Hellwig
Quoted 2 lines · Jens Axboe

No functional changes with this patch, it's just in preparation for supporting legacy schedulers on blk-mq.

Ewww. I think without refactoring to clear what 'use_mq_path' means here and better naming this is a total non-started. Even with that we'll now have yet another code path to worry about. Is there any chance to instead consolidate into a single path?

Quoted 8 lines

It's not pretty at all. I should have prefaced this patchset with saying that it's an experiment in seeing what it would take to simply use the old IO schedulers, as a temporary measure, on blk/scsi-mq. I did clean it up a bit after posting:

http://git.kernel.dk/cgit/linux-block/log/?h=blk-mq-legacy-sched

but I'm not going to claim this is anywhere near merge read, nor clean.

Nice to see you've lowered your standards...

Quoted 7 lines
Quoted 2 lines

Maybe now we can revisit this line of work? ;)
http://git.kernel.org/cgit/linux/kernel/git/snitzer/linux.git/log/?h=wip

I haven't lowered my standards. I thought this posting was pretty clear
- it's an experiment in what supporting legacy schedulers would look like. As you quote me above, this is NOT proposed for merging, nor do I consider it anywhere near clean.

Where'd your sense of humor go?

Quoted 13 lines
Quoted 3 lines

I'm not seeing anything in elevator_switch() that would prevent an elevator from attempting to be used on an mq device with > 1 hw queue. But I could easily be missing it.

You missed it, it's in blk_mq_sched_init(), called from elv_iosched_store() when trying to switch (or setup a new) schedulers.

Quoted 6 lines

That aside, this patchset has all the makings of a _serious_ problem for dm-mq multipath (e.g. if dm_mod.use_blk_mq=Y and dm_mod.dm_mq_nr_hw_queues=1). There is a bunch of code in drivers/dm/dm-rq.c that looks at q->mq_ops vs not to determine if mq is used vs old .request_fn.

Quoted 5 lines
Quoted 3 lines

I think we really need a way to force an allocated mq request_queue (with a single hw_queue) to not support this technological terror you've constructed. (*cough*

See BLK_MQ_F_NO_SCHED.

Yeap, missed it, thanks. Reviewing patches via gmail _sucks_ I should've just looked at your git branch(es) from the start.

Quoted 8 lines
Quoted 5 lines

I could be super dense on this line of work. But what is the point of all this? Seems like a really unfortunate distraction that makes the block code all the more encumbered with fiddley old vs new logic. So now we're opening old .request_fn users up to blk-mq-with-scheduler vs non-blk-mq bugs.

See above, it's just an experiment in seeing what this would look like, how transparent (or not) we could make that.

OK, seems not very transparent so far. But that aside, I'm more curious on what the goal(s) and/or benefit(s) might be? I know that before you were hopeful to eventually eliminate the old .request_fn path in block core (in favor of blk-mq, once it grew IO scheduling capabilties).

But by tieing blk-mq through to the old request path (and associated IO schedulers) it certainly complicates getting rid of all the legacy code.

Selfishly, I'm looking forward to eliminating the old .request_fn request-based code in DM core. This advance to supporting the old IO schedulers make that less likely.

Quoted 3 lines

Don't overthink any of this, and don't start making plans or coming up with problems on why X or Y would not work with whatever interface variant of dm. That's jumping the gun.

Not overthinking.. just thinking ;) But if this does happen then maybe I should look to invert the request-based DM core cleanup: remove all the old .request_fn support and impose the same (namely IO scheduler enabled DM multipath) via dm_mod.use_blk_mq=Y and dm_mod.dm_mod.dm_mq_nr_hw_queues=1

Mike

#9 lore raw

Re: [PATCH 1/7] block: use legacy path for flush requests for MQ with a scheduler

In reply to Jens Axboe
Quoted 16 lines · Jens Axboe

No functional changes with this patch, it's just in preparation for supporting legacy schedulers on blk-mq.

---
 block/blk-core.c  |  2 +-
 block/blk-exec.c  |  2 +-
 block/blk-flush.c | 26 ++++++++++++++------------
 block/blk.h       | 12 +++++++++++-
 4 files changed, 27 insertions(+), 15 deletions(-)
block/blk-core.c +0 -0
index 3f2eb8d80189..0e23589ab3bf 100644

block/blk-core.c static struct request *blk_old_get_request(struct request_queue *q, int rw, · line 1316

Quoted 8 lines
block/blk-core.c +1 -1
@@ -1310,7 +1310,7 @@ static struct request *blk_old_get_request(struct request_queue *q, int rw,
 
 struct request *blk_get_request(struct request_queue *q, int rw, gfp_t gfp_mask)
 {
-       if (q->mq_ops)
+       if (blk_use_mq_path(q))
                return blk_mq_alloc_request(q, rw,
                        (gfp_mask & __GFP_DIRECT_RECLAIM) ?
                                0 : BLK_MQ_REQ_NOWAIT);

Another way might be to use mq allocator to allocate rq in case of mq_sched, such as: just replace mempool_alloc in __get_request() with blk_mq_alloc_request(), in this way, it should be possible to avoid one extra rq allocation in blk_mq_sched_dispatch(), and keep mq's benefit of rq preallocation, which can avoid to hold queue_lock during the allocation too.

Quoted 145 lines
block/blk-exec.c +1 -1
index 3ecb00a6cf45..73b8a701ae6d 100644
@@ -64,7 +64,7 @@ void blk_execute_rq_nowait(struct request_queue *q, struct gendisk *bd_disk,
         * don't check dying flag for MQ because the request won't
         * be reused after dying flag is set
         */
-       if (q->mq_ops) {
+       if (blk_use_mq_path(q)) {
                blk_mq_insert_request(rq, at_head, true, false);
                return;
        }
block/blk-flush.c +14 -12
index 1bdbb3d3e5f5..0b68a1258bdd 100644
@@ -133,14 +133,16 @@ static void blk_flush_restore_request(struct request *rq)
 
 static bool blk_flush_queue_rq(struct request *rq, bool add_front)
 {
-       if (rq->q->mq_ops) {
+       struct request_queue *q = rq->q;
+
+       if (blk_use_mq_path(q)) {
                blk_mq_add_to_requeue_list(rq, add_front, true);
                return false;
        } else {
                if (add_front)
-                       list_add(&rq->queuelist, &rq->q->queue_head);
+                       list_add(&rq->queuelist, &q->queue_head);
                else
-                       list_add_tail(&rq->queuelist, &rq->q->queue_head);
+                       list_add_tail(&rq->queuelist, &q->queue_head);
                return true;
        }
 }
@@ -201,7 +203,7 @@ static bool blk_flush_complete_seq(struct request *rq,
                BUG_ON(!list_empty(&rq->queuelist));
                list_del_init(&rq->flush.list);
                blk_flush_restore_request(rq);
-               if (q->mq_ops)
+               if (blk_use_mq_path(q))
                        blk_mq_end_request(rq, error);
                else
                        __blk_end_request_all(rq, error);
@@ -224,7 +226,7 @@ static void flush_end_io(struct request *flush_rq, int error)
        unsigned long flags = 0;
        struct blk_flush_queue *fq = blk_get_flush_queue(q, flush_rq->mq_ctx);
 
-       if (q->mq_ops) {
+       if (blk_use_mq_path(q)) {
                struct blk_mq_hw_ctx *hctx;
 
                /* release the tag's ownership to the req cloned from */
@@ -240,7 +242,7 @@ static void flush_end_io(struct request *flush_rq, int error)
        /* account completion of the flush request */
        fq->flush_running_idx ^= 1;
 
-       if (!q->mq_ops)
+       if (!blk_use_mq_path(q))
                elv_completed_request(q, flush_rq);
 
        /* and push the waiting requests to the next stage */
@@ -267,7 +269,7 @@ static void flush_end_io(struct request *flush_rq, int error)
                blk_run_queue_async(q);
        }
        fq->flush_queue_delayed = 0;
-       if (q->mq_ops)
+       if (blk_use_mq_path(q))
                spin_unlock_irqrestore(&fq->mq_flush_lock, flags);
 }
 
@@ -315,7 +317,7 @@ static bool blk_kick_flush(struct request_queue *q, struct blk_flush_queue *fq)
         * be in flight at the same time. And acquire the tag's
         * ownership for flush req.
         */
-       if (q->mq_ops) {
+       if (blk_use_mq_path(q)) {
                struct blk_mq_hw_ctx *hctx;
 
                flush_rq->mq_ctx = first_rq->mq_ctx;
@@ -409,7 +411,7 @@ void blk_insert_flush(struct request *rq)
         * complete the request.
         */
        if (!policy) {
-               if (q->mq_ops)
+               if (blk_use_mq_path(q))
                        blk_mq_end_request(rq, 0);
                else
                        __blk_end_bidi_request(rq, 0, 0, 0);
@@ -425,9 +427,9 @@ void blk_insert_flush(struct request *rq)
         */
        if ((policy & REQ_FSEQ_DATA) &&
            !(policy & (REQ_FSEQ_PREFLUSH | REQ_FSEQ_POSTFLUSH))) {
-               if (q->mq_ops) {
+               if (blk_use_mq_path(q))
                        blk_mq_insert_request(rq, false, false, true);
-               } else
+               else
                        list_add_tail(&rq->queuelist, &q->queue_head);
                return;
        }
@@ -440,7 +442,7 @@ void blk_insert_flush(struct request *rq)
        INIT_LIST_HEAD(&rq->flush.list);
        rq->rq_flags |= RQF_FLUSH_SEQ;
        rq->flush.saved_end_io = rq->end_io; /* Usually NULL */
-       if (q->mq_ops) {
+       if (blk_use_mq_path(q)) {
                rq->end_io = mq_flush_data_end_io;
 
                spin_lock_irq(&fq->mq_flush_lock);
block/blk.h +11 -2
index 041185e5f129..094fc10429c3 100644
@@ -36,10 +36,20 @@ extern struct kmem_cache *request_cachep;
 extern struct kobj_type blk_queue_ktype;
 extern struct ida blk_queue_ida;
 
+/*
+ * Use the MQ path if we have mq_ops, but not if we are using an IO
+ * scheduler. For the scheduler, we should use the legacy path. Only
+ * for internal use in the block layer.
+ */
+static inline bool blk_use_mq_path(struct request_queue *q)
+{
+       return q->mq_ops && !q->elevator;
+}
+
 static inline struct blk_flush_queue *blk_get_flush_queue(
                struct request_queue *q, struct blk_mq_ctx *ctx)
 {
-       if (q->mq_ops)
+       if (blk_use_mq_path(q))
                return blk_mq_map_queue(q, ctx->cpu)->fq;
        return q->fq;
 }
--

2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-block" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#10 lore raw

Re: [PATCH 1/7] block: use legacy path for flush requests for MQ with a scheduler

Quoted 18 lines · Ming Lei
Quoted 17 lines · Jens Axboe

No functional changes with this patch, it's just in preparation for supporting legacy schedulers on blk-mq.

---
 block/blk-core.c  |  2 +-
 block/blk-exec.c  |  2 +-
 block/blk-flush.c | 26 ++++++++++++++------------
 block/blk.h       | 12 +++++++++++-
 4 files changed, 27 insertions(+), 15 deletions(-)
block/blk-core.c +0 -0
index 3f2eb8d80189..0e23589ab3bf 100644
@@ -1310,7 +1310,7 @@ static struct request *blk_old_get_request(struct request_queue *q, int rw,
 
Quoted 14 lines

block/blk-core.c static struct request *blk_old_get_request(struct request_queue *q, int rw, · line 1316

Quoted 7 lines
block/blk-core.c +1 -1
 struct request *blk_get_request(struct request_queue *q, int rw, gfp_t gfp_mask)
 {
-       if (q->mq_ops)
+       if (blk_use_mq_path(q))
                return blk_mq_alloc_request(q, rw,
                        (gfp_mask & __GFP_DIRECT_RECLAIM) ?
                                0 : BLK_MQ_REQ_NOWAIT);

Another way might be to use mq allocator to allocate rq in case of mq_sched, such as: just replace mempool_alloc in __get_request() with blk_mq_alloc_request(), in this way, it should be possible to avoid one extra rq allocation in blk_mq_sched_dispatch(), and keep mq's benefit of rq preallocation, which can avoid to hold queue_lock during the allocation too.

One problem with the MQ rq allocation is that it's tied to the device queue depth. This is a problem for scheduling, since we want to have a larger pool of requests that the IO scheduler can use, so that we actually have something that we can schedule with. This is a non-starter on QD=1 devices, but it's also a problem for SATA with 31 effectively usable tags.

That's why I split it in two, so we have the "old" requests that we hand to the scheduler. I know the 'rq' field copy isn't super pretty, though.

Signature · 1 line
Jens Axboe
#11 lore raw

Re: [PATCH 1/7] block: use legacy path for flush requests for MQ with a scheduler

Quoted 41 lines · Jens Axboe
Quoted 18 lines · Ming Lei
Quoted 17 lines · Jens Axboe

No functional changes with this patch, it's just in preparation for supporting legacy schedulers on blk-mq.

---
 block/blk-core.c  |  2 +-
 block/blk-exec.c  |  2 +-
 block/blk-flush.c | 26 ++++++++++++++------------
 block/blk.h       | 12 +++++++++++-
 4 files changed, 27 insertions(+), 15 deletions(-)
block/blk-core.c +0 -0
index 3f2eb8d80189..0e23589ab3bf 100644
@@ -1310,7 +1310,7 @@ static struct request *blk_old_get_request(struct request_queue *q, int rw,
 
Quoted 14 lines

block/blk-core.c static struct request *blk_old_get_request(struct request_queue *q, int rw, · line 1316

Quoted 7 lines
block/blk-core.c +1 -1
 struct request *blk_get_request(struct request_queue *q, int rw, gfp_t gfp_mask)
 {
-       if (q->mq_ops)
+       if (blk_use_mq_path(q))
                return blk_mq_alloc_request(q, rw,
                        (gfp_mask & __GFP_DIRECT_RECLAIM) ?
                                0 : BLK_MQ_REQ_NOWAIT);

Another way might be to use mq allocator to allocate rq in case of mq_sched, such as: just replace mempool_alloc in __get_request() with blk_mq_alloc_request(), in this way, it should be possible to avoid one extra rq allocation in blk_mq_sched_dispatch(), and keep mq's benefit of rq preallocation, which can avoid to hold queue_lock during the allocation too.

One problem with the MQ rq allocation is that it's tied to the device queue depth. This is a problem for scheduling, since we want to have a larger pool of requests that the IO scheduler can use, so that we actually have something that we can schedule with. This is a non-starter on QD=1 devices, but it's also a problem for SATA with 31 effectively usable tags.

Quoted 2 lines

That's why I split it in two, so we have the "old" requests that we hand to the scheduler. I know the 'rq' field copy isn't super pretty, though.

OK, got it, thanks for your explanation.

So could we fall back to mempool_alloc() for allocating rq with mq size if MQ rq allocator fails? Then in this way the extra rq allocation in blk_mq_alloc_request() may be killed.

Thanks,
Ming

author
#12 lore raw

Re: [PATCH 1/7] block: use legacy path for flush requests for MQ with a scheduler

Quoted 42 lines · Ming Lei
Quoted 41 lines · Jens Axboe
Quoted 18 lines · Ming Lei
Quoted 17 lines · Jens Axboe

No functional changes with this patch, it's just in preparation for supporting legacy schedulers on blk-mq.

---
 block/blk-core.c  |  2 +-
 block/blk-exec.c  |  2 +-
 block/blk-flush.c | 26 ++++++++++++++------------
 block/blk.h       | 12 +++++++++++-
 4 files changed, 27 insertions(+), 15 deletions(-)
block/blk-core.c +0 -0
index 3f2eb8d80189..0e23589ab3bf 100644
@@ -1310,7 +1310,7 @@ static struct request *blk_old_get_request(struct request_queue *q, int rw,
 
Quoted 14 lines

block/blk-core.c static struct request *blk_old_get_request(struct request_queue *q, int rw, · line 1316

Quoted 7 lines
block/blk-core.c +1 -1
 struct request *blk_get_request(struct request_queue *q, int rw, gfp_t gfp_mask)
 {
-       if (q->mq_ops)
+       if (blk_use_mq_path(q))
                return blk_mq_alloc_request(q, rw,
                        (gfp_mask & __GFP_DIRECT_RECLAIM) ?
                                0 : BLK_MQ_REQ_NOWAIT);

Another way might be to use mq allocator to allocate rq in case of mq_sched, such as: just replace mempool_alloc in __get_request() with blk_mq_alloc_request(), in this way, it should be possible to avoid one extra rq allocation in blk_mq_sched_dispatch(), and keep mq's benefit of rq preallocation, which can avoid to hold queue_lock during the allocation too.

One problem with the MQ rq allocation is that it's tied to the device queue depth. This is a problem for scheduling, since we want to have a larger pool of requests that the IO scheduler can use, so that we actually have something that we can schedule with. This is a non-starter on QD=1 devices, but it's also a problem for SATA with 31 effectively usable tags.

Quoted 8 lines
Quoted 2 lines

That's why I split it in two, so we have the "old" requests that we hand to the scheduler. I know the 'rq' field copy isn't super pretty, though.

OK, got it, thanks for your explanation.

So could we fall back to mempool_alloc() for allocating rq with mq size if MQ rq allocator fails? Then in this way the extra rq allocation in blk_mq_alloc_request() may be killed.

We could, yes, though I'm not sure it's worth special casing that. The copy is pretty damn cheap compared to the high costs of going through the legacy path. And given that, I'd probably prefer to keep it all the same, regardless or the depth of the device. I don't think the change would be noticable.

Signature · 1 line
Jens Axboe
author
#13 lore raw

PATCH 2/7 cfq-iosched: use appropriate run queue function

In reply to Jens Axboe

For MQ devices, we have to use other functions to run the queue. No functional changes in this patch, just a prep patch for support legacy schedulers on blk-mq.

---
 block/cfq-iosched.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)
block/cfq-iosched.c +19 -3
index c73a6fcaeb9d..d6d454a72bd4 100644
@@ -919,8 +919,14 @@ static inline struct cfq_data *cic_to_cfqd(struct cfq_io_cq *cic)
 static inline void cfq_schedule_dispatch(struct cfq_data *cfqd)
 {
 	if (cfqd->busy_queues) {
+		struct request_queue *q = cfqd->queue;
+
 		cfq_log(cfqd, "schedule dispatch");
-		kblockd_schedule_work(&cfqd->unplug_work);
+
+		if (q->mq_ops)
+			blk_mq_run_hw_queues(q, true);
+		else
+			kblockd_schedule_work(&cfqd->unplug_work);
 	}
 }
 
@@ -4086,6 +4092,16 @@ static void cfq_preempt_queue(struct cfq_data *cfqd, struct cfq_queue *cfqq)
 	cfq_mark_cfqq_slice_new(cfqq);
 }
 
+static void cfq_run_queue(struct cfq_data *cfqd)
+{
+	struct request_queue *q = cfqd->queue;
+
+	if (q->mq_ops)
+		blk_mq_run_hw_queues(q, true);
+	else
+		__blk_run_queue(q);
+}
+
 /*
  * Called when a new fs request (rq) is added (to cfqq). Check if there's
  * something we should do about it
@@ -4122,7 +4138,7 @@ cfq_rq_enqueued(struct cfq_data *cfqd, struct cfq_queue *cfqq,
 			    cfqd->busy_queues > 1) {
 				cfq_del_timer(cfqd, cfqq);
 				cfq_clear_cfqq_wait_request(cfqq);
-				__blk_run_queue(cfqd->queue);
+				cfq_run_queue(cfqd);
 			} else {
 				cfqg_stats_update_idle_time(cfqq->cfqg);
 				cfq_mark_cfqq_must_dispatch(cfqq);
@@ -4136,7 +4152,7 @@ cfq_rq_enqueued(struct cfq_data *cfqd, struct cfq_queue *cfqq,
 		 * this new queue is RT and the current one is BE
 		 */
 		cfq_preempt_queue(cfqd, cfqq);
-		__blk_run_queue(cfqd->queue);
+		cfq_run_queue(cfqd);
 	}
 }
 
Signature · 1 line
2.7.4
#14 lore raw

Re: [PATCH 2/7] cfq-iosched: use appropriate run queue function

Quoted 14 lines · Jens Axboe

For MQ devices, we have to use other functions to run the queue. No functional changes in this patch, just a prep patch for support legacy schedulers on blk-mq.

---
 block/cfq-iosched.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)
block/cfq-iosched.c +0 -0
index c73a6fcaeb9d..d6d454a72bd4 100644

block/cfq-iosched.c static inline struct cfq_data *cic_to_cfqd(struct cfq_io_cq *cic) · line 926

Quoted 9 lines
block/cfq-iosched.c +4 -1
@@ -919,8 +919,14 @@ static inline struct cfq_data *cic_to_cfqd(struct cfq_io_cq *cic)
 static inline void cfq_schedule_dispatch(struct cfq_data *cfqd)
 {
 	if (cfqd->busy_queues) {
+		struct request_queue *q = cfqd->queue;
+
 		cfq_log(cfqd, "schedule dispatch");
-		kblockd_schedule_work(&cfqd->unplug_work);
+
+		if (q->mq_ops)

You've introduced blk_use_mq_path() in patch 1, so why don't you use it here as well?

Quoted 7 lines
block/cfq-iosched.c +3 -0
+			blk_mq_run_hw_queues(q, true);
+		else
+			kblockd_schedule_work(&cfqd->unplug_work);
 	}
 }
 

block/cfq-iosched.c static void cfq_preempt_queue(struct cfq_data *cfqd, struct cfq_queue *cfqq) · line 4099

Quoted 8 lines
block/cfq-iosched.c +5 -0
@@ -4086,6 +4092,16 @@ static void cfq_preempt_queue(struct cfq_data *cfqd, struct cfq_queue *cfqq)
 	cfq_mark_cfqq_slice_new(cfqq);
 }
 
+static void cfq_run_queue(struct cfq_data *cfqd)
+{
+	struct request_queue *q = cfqd->queue;
+
+	if (q->mq_ops)

Ditto.

Quoted 33 lines
block/cfq-iosched.c +7 -2
+		blk_mq_run_hw_queues(q, true);
+	else
+		__blk_run_queue(q);
+}
+
 /*
  * Called when a new fs request (rq) is added (to cfqq). Check if there's
  * something we should do about it
@@ -4122,7 +4138,7 @@ cfq_rq_enqueued(struct cfq_data *cfqd, struct cfq_queue *cfqq,
 			    cfqd->busy_queues > 1) {
 				cfq_del_timer(cfqd, cfqq);
 				cfq_clear_cfqq_wait_request(cfqq);
-				__blk_run_queue(cfqd->queue);
+				cfq_run_queue(cfqd);
 			} else {
 				cfqg_stats_update_idle_time(cfqq->cfqg);
 				cfq_mark_cfqq_must_dispatch(cfqq);
@@ -4136,7 +4152,7 @@ cfq_rq_enqueued(struct cfq_data *cfqd, struct cfq_queue *cfqq,
 		 * this new queue is RT and the current one is BE
 		 */
 		cfq_preempt_queue(cfqd, cfqq);
-		__blk_run_queue(cfqd->queue);
+		cfq_run_queue(cfqd);
 	}
 }
 
Signature · 6 lines
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-block" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 6 lines
Johannes Thumshirn                                          Storage
[email protected]                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg
GF: Felix Imend�rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N�rnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
author
#15 lore raw

Re: [PATCH 2/7] cfq-iosched: use appropriate run queue function

Quoted 19 lines · Johannes Thumshirn
Quoted 18 lines · Jens Axboe

For MQ devices, we have to use other functions to run the queue. No functional changes in this patch, just a prep patch for support legacy schedulers on blk-mq.

---
 block/cfq-iosched.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)
block/cfq-iosched.c +1 -0
index c73a6fcaeb9d..d6d454a72bd4 100644
@@ -919,8 +919,14 @@ static inline struct cfq_data *cic_to_cfqd(struct cfq_io_cq *cic)
 static inline void cfq_schedule_dispatch(struct cfq_data *cfqd)
 {
 	if (cfqd->busy_queues) {
+		struct request_queue *q = cfqd->queue;
Quoted 8 lines

block/cfq-iosched.c static inline struct cfq_data *cic_to_cfqd(struct cfq_io_cq *cic) · line 926

Quoted 5 lines
block/cfq-iosched.c +3 -1
+
 		cfq_log(cfqd, "schedule dispatch");
-		kblockd_schedule_work(&cfqd->unplug_work);
+
+		if (q->mq_ops)

You've introduced blk_use_mq_path() in patch 1, so why don't you use it here as well?

There's a difference. q->mq_ops means "this driver is blk-mq", blk_use_mq_path() checks for ->elevator as well, which means "for this driver, allocate and insert requests via the legacy IO scheduler path".

Signature · 1 line
Jens Axboe
#16 lore raw

Re: [PATCH 2/7] cfq-iosched: use appropriate run queue function

Quoted 29 lines · Jens Axboe
Quoted 19 lines · Johannes Thumshirn
Quoted 18 lines · Jens Axboe

For MQ devices, we have to use other functions to run the queue. No functional changes in this patch, just a prep patch for support legacy schedulers on blk-mq.

---
 block/cfq-iosched.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)
block/cfq-iosched.c +1 -0
index c73a6fcaeb9d..d6d454a72bd4 100644
@@ -919,8 +919,14 @@ static inline struct cfq_data *cic_to_cfqd(struct cfq_io_cq *cic)
 static inline void cfq_schedule_dispatch(struct cfq_data *cfqd)
 {
 	if (cfqd->busy_queues) {
+		struct request_queue *q = cfqd->queue;
Quoted 8 lines

block/cfq-iosched.c static inline struct cfq_data *cic_to_cfqd(struct cfq_io_cq *cic) · line 926

Quoted 5 lines
block/cfq-iosched.c +3 -1
+
 		cfq_log(cfqd, "schedule dispatch");
-		kblockd_schedule_work(&cfqd->unplug_work);
+
+		if (q->mq_ops)

You've introduced blk_use_mq_path() in patch 1, so why don't you use it here as well?

Quoted 3 lines

There's a difference. q->mq_ops means "this driver is blk-mq", blk_use_mq_path() checks for ->elevator as well, which means "for this driver, allocate and insert requests via the legacy IO scheduler path".

Ah OK, that clarifies it. thanks

Signature · 6 lines
Johannes Thumshirn                                          Storage
[email protected]                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg
GF: Felix Imend�rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N�rnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
#17 lore raw

Re: [PATCH 2/7] cfq-iosched: use appropriate run queue function

In reply to Jens Axboe
Quoted 3 lines · Jens Axboe

For MQ devices, we have to use other functions to run the queue. No functional changes in this patch, just a prep patch for support legacy schedulers on blk-mq.

I don't think supporting CFQ on blk-mq makes any sense. Even if we for some reason reuse existing scheduler (something I'm not in favour except as bringup vehicle) we should limit it to deadline and in the (hopefully near) future BFQ.

author
#18 lore raw

Re: [PATCH 2/7] cfq-iosched: use appropriate run queue function

Quoted 9 lines · Christoph Hellwig
Quoted 3 lines · Jens Axboe

For MQ devices, we have to use other functions to run the queue. No functional changes in this patch, just a prep patch for support legacy schedulers on blk-mq.

I don't think supporting CFQ on blk-mq makes any sense. Even if we for some reason reuse existing scheduler (something I'm not in favour except as bringup vehicle) we should limit it to deadline and in the (hopefully near) future BFQ.

Not disagreeing with that. It'd be synthetically limiting it, though, as there's really nothing preventing CFQ from running under it, with the slight queue run change here.

Signature · 1 line
Jens Axboe
author
#19 lore raw

PATCH 3/7 block: use appropriate queue running functions

In reply to Jens Axboe

Use MQ variants for MQ, legacy ones for legacy.

---
 block/blk-core.c  |  5 ++++-
 block/blk-exec.c  | 10 ++++++++--
 block/blk-flush.c | 14 ++++++++++----
 block/elevator.c  |  5 ++++-
 4 files changed, 26 insertions(+), 8 deletions(-)
block/blk-core.c +4 -1
index 0e23589ab3bf..3591f5419509 100644
@@ -340,7 +340,10 @@ void __blk_run_queue(struct request_queue *q)
 	if (unlikely(blk_queue_stopped(q)))
 		return;
 
-	__blk_run_queue_uncond(q);
+	if (WARN_ON_ONCE(q->mq_ops))
+		blk_mq_run_hw_queues(q, true);
+	else
+		__blk_run_queue_uncond(q);
 }
 EXPORT_SYMBOL(__blk_run_queue);
 
block/blk-exec.c +8 -2
index 73b8a701ae6d..27e4d82564ed 100644
@@ -80,8 +80,14 @@ void blk_execute_rq_nowait(struct request_queue *q, struct gendisk *bd_disk,
 	}
 
 	__elv_add_request(q, rq, where);
-	__blk_run_queue(q);
-	spin_unlock_irq(q->queue_lock);
+
+	if (q->mq_ops) {
+		spin_unlock_irq(q->queue_lock);
+		blk_mq_run_hw_queues(q, false);
+	} else {
+		__blk_run_queue(q);
+		spin_unlock_irq(q->queue_lock);
+	}
 }
 EXPORT_SYMBOL_GPL(blk_execute_rq_nowait);
 
block/blk-flush.c +10 -4
index 0b68a1258bdd..620d69909b8d 100644
@@ -265,8 +265,10 @@ static void flush_end_io(struct request *flush_rq, int error)
 	 * kblockd.
 	 */
 	if (queued || fq->flush_queue_delayed) {
-		WARN_ON(q->mq_ops);
-		blk_run_queue_async(q);
+		if (q->mq_ops)
+			blk_mq_run_hw_queues(q, true);
+		else
+			blk_run_queue_async(q);
 	}
 	fq->flush_queue_delayed = 0;
 	if (blk_use_mq_path(q))
@@ -346,8 +348,12 @@ static void flush_data_end_io(struct request *rq, int error)
 	 * After populating an empty queue, kick it to avoid stall.  Read
 	 * the comment in flush_end_io().
 	 */
-	if (blk_flush_complete_seq(rq, fq, REQ_FSEQ_DATA, error))
-		blk_run_queue_async(q);
+	if (blk_flush_complete_seq(rq, fq, REQ_FSEQ_DATA, error)) {
+		if (q->mq_ops)
+			blk_mq_run_hw_queues(q, true);
+		else
+			blk_run_queue_async(q);
+	}
 }
 
 static void mq_flush_data_end_io(struct request *rq, int error)
block/elevator.c +4 -1
index a18a5db274e4..11d2cfee2bc1 100644
@@ -627,7 +627,10 @@ void __elv_add_request(struct request_queue *q, struct request *rq, int where)
 		 *   with anything.  There's no point in delaying queue
 		 *   processing.
 		 */
-		__blk_run_queue(q);
+		if (q->mq_ops)
+			blk_mq_run_hw_queues(q, true);
+		else
+			__blk_run_queue(q);
 		break;
 
 	case ELEVATOR_INSERT_SORT_MERGE:
Signature · 1 line
2.7.4
#20 lore raw

Re: [PATCH 3/7] block: use appropriate queue running functions

Quoted 15 lines · Jens Axboe

Use MQ variants for MQ, legacy ones for legacy.

---
 block/blk-core.c  |  5 ++++-
 block/blk-exec.c  | 10 ++++++++--
 block/blk-flush.c | 14 ++++++++++----
 block/elevator.c  |  5 ++++-
 4 files changed, 26 insertions(+), 8 deletions(-)
block/blk-core.c +0 -0
index 0e23589ab3bf..3591f5419509 100644

block/blk-core.c void __blk_run_queue(struct request_queue *q) · line 343

Quoted 4 lines
block/blk-core.c +0 -1
@@ -340,7 +340,10 @@ void __blk_run_queue(struct request_queue *q)
 	if (unlikely(blk_queue_stopped(q)))
 		return;
 
-	__blk_run_queue_uncond(q);

I don't quite get the WARN_ON_ONCE() is it for debug purposes? And similarly blk_use_mq_path() + the other occurences below as well?

Signature · 6 lines
Johannes Thumshirn                                          Storage
[email protected]                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg
GF: Felix Imend�rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N�rnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
#21 lore raw

Re: [PATCH 3/7] block: use appropriate queue running functions

In reply to Jens Axboe
Quoted 15 lines · Jens Axboe

Use MQ variants for MQ, legacy ones for legacy.

---
 block/blk-core.c  |  5 ++++-
 block/blk-exec.c  | 10 ++++++++--
 block/blk-flush.c | 14 ++++++++++----
 block/elevator.c  |  5 ++++-
 4 files changed, 26 insertions(+), 8 deletions(-)
block/blk-core.c +0 -0
index 0e23589ab3bf..3591f5419509 100644

block/blk-core.c void __blk_run_queue(struct request_queue *q) · line 345

Quoted 7 lines
block/blk-core.c +3 -1
@@ -340,7 +340,10 @@ void __blk_run_queue(struct request_queue *q)
 	if (unlikely(blk_queue_stopped(q)))
 		return;
 
-	__blk_run_queue_uncond(q);
+	if (WARN_ON_ONCE(q->mq_ops))
+		blk_mq_run_hw_queues(q, true);
+	else

This looks odd with the WARN_ON..

Quoted 5 lines
block/blk-core.c +1 -0
+++ b/block/blk-exec.c
@@ -80,8 +80,14 @@ void blk_execute_rq_nowait(struct request_queue *q, struct gendisk *bd_disk,
 	}
 
 	__elv_add_request(q, rq, where);

block/blk-core.c void blk_execute_rq_nowait(struct request_queue *q, struct gendisk *bd_disk, · line 90

Quoted 10 lines
block/blk-core.c +8 -2
-	__blk_run_queue(q);
-	spin_unlock_irq(q->queue_lock);
+
+	if (q->mq_ops) {
+		spin_unlock_irq(q->queue_lock);
+		blk_mq_run_hw_queues(q, false);
+	} else {
+		__blk_run_queue(q);
+		spin_unlock_irq(q->queue_lock);
+	}

We already branch out to the blk-mq path earlier in the function.

author
#22 lore raw

Re: [PATCH 3/7] block: use appropriate queue running functions

Quoted 19 lines · Christoph Hellwig
Quoted 18 lines · Jens Axboe

Use MQ variants for MQ, legacy ones for legacy.

---
 block/blk-core.c  |  5 ++++-
 block/blk-exec.c  | 10 ++++++++--
 block/blk-flush.c | 14 ++++++++++----
 block/elevator.c  |  5 ++++-
 4 files changed, 26 insertions(+), 8 deletions(-)
block/blk-core.c +0 -0
index 0e23589ab3bf..3591f5419509 100644
@@ -340,7 +340,10 @@ void __blk_run_queue(struct request_queue *q)
 	if (unlikely(blk_queue_stopped(q)))
 		return;
 
Quoted 6 lines

block/blk-core.c void __blk_run_queue(struct request_queue *q) · line 345

Quoted 4 lines
block/blk-core.c +3 -1
-	__blk_run_queue_uncond(q);
+	if (WARN_ON_ONCE(q->mq_ops))
+		blk_mq_run_hw_queues(q, true);
+	else

This looks odd with the WARN_ON..

It's just a debug thing, should go away.

Quoted 4 lines
Quoted 4 lines
block/blk-core.c +1 -0
+++ b/block/blk-exec.c
@@ -80,8 +80,14 @@ void blk_execute_rq_nowait(struct request_queue *q, struct gendisk *bd_disk,
 	}
 
Quoted 13 lines

block/blk-core.c void blk_execute_rq_nowait(struct request_queue *q, struct gendisk *bd_disk, · line 90

Quoted 11 lines
block/blk-core.c +8 -2
 	__elv_add_request(q, rq, where);
-	__blk_run_queue(q);
-	spin_unlock_irq(q->queue_lock);
+
+	if (q->mq_ops) {
+		spin_unlock_irq(q->queue_lock);
+		blk_mq_run_hw_queues(q, false);
+	} else {
+		__blk_run_queue(q);
+		spin_unlock_irq(q->queue_lock);
+	}

We already branch out to the blk-mq path earlier in the function.

Ah good point, this is a subset of an earlier branch that also checks q->elevator.

Signature · 1 line
Jens Axboe
maintainer
#23 lore raw

Re: [PATCH 3/7] block: use appropriate queue running functions

Quoted 47 lines · Jens Axboe
Quoted 19 lines · Christoph Hellwig
Quoted 18 lines · Jens Axboe

Use MQ variants for MQ, legacy ones for legacy.

---
 block/blk-core.c  |  5 ++++-
 block/blk-exec.c  | 10 ++++++++--
 block/blk-flush.c | 14 ++++++++++----
 block/elevator.c  |  5 ++++-
 4 files changed, 26 insertions(+), 8 deletions(-)
block/blk-core.c +0 -0
index 0e23589ab3bf..3591f5419509 100644
@@ -340,7 +340,10 @@ void __blk_run_queue(struct request_queue *q)
 	if (unlikely(blk_queue_stopped(q)))
 		return;
 
Quoted 6 lines

block/blk-core.c void __blk_run_queue(struct request_queue *q) · line 345

Quoted 4 lines
block/blk-core.c +3 -1
-	__blk_run_queue_uncond(q);
+	if (WARN_ON_ONCE(q->mq_ops))
+		blk_mq_run_hw_queues(q, true);
+	else

This looks odd with the WARN_ON..

It's just a debug thing, should go away.

Quoted 4 lines
Quoted 4 lines
block/blk-core.c +1 -0
+++ b/block/blk-exec.c
@@ -80,8 +80,14 @@ void blk_execute_rq_nowait(struct request_queue *q, struct gendisk *bd_disk,
 	}
 
Quoted 13 lines

block/blk-core.c void blk_execute_rq_nowait(struct request_queue *q, struct gendisk *bd_disk, · line 90

Quoted 11 lines
block/blk-core.c +8 -2
 	__elv_add_request(q, rq, where);
-	__blk_run_queue(q);
-	spin_unlock_irq(q->queue_lock);
+
+	if (q->mq_ops) {
+		spin_unlock_irq(q->queue_lock);
+		blk_mq_run_hw_queues(q, false);
+	} else {
+		__blk_run_queue(q);
+		spin_unlock_irq(q->queue_lock);
+	}

We already branch out to the blk-mq path earlier in the function.

Quoted 2 lines

Ah good point, this is a subset of an earlier branch that also checks q->elevator.

Actually, I take that back - if q->mq_ops && q->elevator, we still get here, and we should run the queue with the MQ variant. The code was correct as-is.

Signature · 1 line
Jens Axboe
author
#24 lore raw

PATCH 4/7 blk-mq: blk_account_io_start() takes a bool

In reply to Jens Axboe
---
 block/blk-mq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/blk-mq.c +1 -1
index bac12caece06..90db5b490df9 100644
@@ -1237,7 +1237,7 @@ static void blk_mq_bio_to_request(struct request *rq, struct bio *bio)
 {
 	init_request_from_bio(rq, bio);
 
-	blk_account_io_start(rq, 1);
+	blk_account_io_start(rq, true);
 }
 
 static inline bool hctx_allow_merges(struct blk_mq_hw_ctx *hctx)
Signature · 1 line
2.7.4
Reviewed-by on v1 4/7
#25 lore raw

Re: [PATCH 4/7] blk-mq: blk_account_io_start() takes a bool

Quoted 2 lines · Jens Axboe

---

Easy enough,

Signature · 6 lines
Johannes Thumshirn                                          Storage
[email protected]                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg
GF: Felix Imend�rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N�rnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
author
#27 lore raw

PATCH 5/7 blk-mq: test patch to get legacy IO schedulers working

In reply to Jens Axboe

With this applied, a single queue blk-mq manage device can use any of the legacy IO schedulers. The driver has to set BLK_MQ_F_SQ_SCHED for now, and we default to 'deadline'.

The scheduler defaults to deadline for now. Can be runtime switched, like the non-mq devices, by echoing something else into /sys/block/</dev>/queue/scheduler

---
 block/blk-core.c       |  38 ++++---
 block/blk-merge.c      |   5 +
 block/blk-mq.c         | 290 ++++++++++++++++++++++++++++++++++++++++++++++---
 block/blk-sysfs.c      |   2 +-
 block/blk.h            |   4 +
 block/elevator.c       |  11 +-
 include/linux/blk-mq.h |   1 +
 include/linux/blkdev.h |   2 +
 8 files changed, 316 insertions(+), 37 deletions(-)
block/blk-core.c +24 -14
index 3591f5419509..6c1063aab1a0 100644
@@ -1159,6 +1159,8 @@ static struct request *__get_request(struct request_list *rl, unsigned int op,
 	blk_rq_set_rl(rq, rl);
 	rq->cmd_flags = op;
 	rq->rq_flags = rq_flags;
+	if (q->mq_ops)
+		rq->rq_flags |= RQF_MQ_RL;
 
 	/* init elvpriv */
 	if (rq_flags & RQF_ELVPRIV) {
@@ -1246,8 +1248,8 @@ static struct request *__get_request(struct request_list *rl, unsigned int op,
  * Returns ERR_PTR on failure, with @q->queue_lock held.
  * Returns request pointer on success, with @q->queue_lock *not held*.
  */
-static struct request *get_request(struct request_queue *q, unsigned int op,
-		struct bio *bio, gfp_t gfp_mask)
+struct request *get_request(struct request_queue *q, unsigned int op,
+			    struct bio *bio, gfp_t gfp_mask)
 {
 	const bool is_sync = op_is_sync(op);
 	DEFINE_WAIT(wait);
@@ -1430,7 +1432,7 @@ void __blk_put_request(struct request_queue *q, struct request *req)
 	if (unlikely(!q))
 		return;
 
-	if (q->mq_ops) {
+	if (q->mq_ops && !(req->rq_flags & RQF_MQ_RL)) {
 		blk_mq_free_request(req);
 		return;
 	}
@@ -1466,7 +1468,7 @@ void blk_put_request(struct request *req)
 {
 	struct request_queue *q = req->q;
 
-	if (q->mq_ops)
+	if (q->mq_ops && !(req->rq_flags & RQF_MQ_RL))
 		blk_mq_free_request(req);
 	else {
 		unsigned long flags;
@@ -1556,6 +1558,15 @@ bool bio_attempt_front_merge(struct request_queue *q, struct request *req,
 	return true;
 }
 
+struct list_head *blk_get_plug_list(struct request_queue *q,
+				    struct blk_plug *plug)
+{
+	if (!q->mq_ops || q->elevator)
+		return &plug->list;
+
+	return &plug->mq_list;
+}
+
 /**
  * blk_attempt_plug_merge - try to merge with %current's plugged list
  * @q: request_queue new bio is being queued at
@@ -1592,10 +1603,7 @@ bool blk_attempt_plug_merge(struct request_queue *q, struct bio *bio,
 		goto out;
 	*request_count = 0;
 
-	if (q->mq_ops)
-		plug_list = &plug->mq_list;
-	else
-		plug_list = &plug->list;
+	plug_list = blk_get_plug_list(q, plug);
 
 	list_for_each_entry_reverse(rq, plug_list, queuelist) {
 		int el_ret;
@@ -1640,10 +1648,7 @@ unsigned int blk_plug_queued_count(struct request_queue *q)
 	if (!plug)
 		goto out;
 
-	if (q->mq_ops)
-		plug_list = &plug->mq_list;
-	else
-		plug_list = &plug->list;
+	plug_list = blk_get_plug_list(q, plug);
 
 	list_for_each_entry(rq, plug_list, queuelist) {
 		if (rq->q == q)
@@ -3197,7 +3202,9 @@ static void queue_unplugged(struct request_queue *q, unsigned int depth,
 {
 	trace_block_unplug(q, depth, !from_schedule);
 
-	if (from_schedule)
+	if (q->mq_ops)
+		blk_mq_run_hw_queues(q, true);
+	else if (from_schedule)
 		blk_run_queue_async(q);
 	else
 		__blk_run_queue(q);
@@ -3293,7 +3300,10 @@ void blk_flush_plug_list(struct blk_plug *plug, bool from_schedule)
 		 * Short-circuit if @q is dead
 		 */
 		if (unlikely(blk_queue_dying(q))) {
-			__blk_end_request_all(rq, -ENODEV);
+			if (q->mq_ops)
+				blk_mq_end_request(rq, -ENODEV);
+			else
+				__blk_end_request_all(rq, -ENODEV);
 			continue;
 		}
 
block/blk-merge.c +5 -0
index 1002afdfee99..0952e0503aa4 100644
@@ -754,6 +754,11 @@ static int attempt_merge(struct request_queue *q, struct request *req,
 	/* owner-ship of bio passed from next to req */
 	next->bio = NULL;
 	__blk_put_request(q, next);
+
+	/* FIXME: MQ+sched holds a reference */
+	if (q->mq_ops && q->elevator)
+		blk_queue_exit(q);
+
 	return 1;
 }
 
block/blk-mq.c +272 -18

388 lines not on this page · raw message

block/blk-sysfs.c +1 -1
index 706b27bd73a1..f3a11d4de4e6 100644
@@ -896,7 +896,7 @@ int blk_register_queue(struct gendisk *disk)
 
 	blk_wb_init(q);
 
-	if (!q->request_fn)
+	if (!q->elevator)
 		return 0;
 
 	ret = elv_register_queue(q);
block/blk.h +4 -0
index 094fc10429c3..3137ff09725e 100644
@@ -77,6 +77,9 @@ bool __blk_end_bidi_request(struct request *rq, int error,
 			    unsigned int nr_bytes, unsigned int bidi_bytes);
 void blk_freeze_queue(struct request_queue *q);
 
+struct request *get_request(struct request_queue *, unsigned int, struct bio *,
+				gfp_t);
+
 static inline void blk_queue_enter_live(struct request_queue *q)
 {
 	/*
@@ -110,6 +113,7 @@ bool blk_attempt_plug_merge(struct request_queue *q, struct bio *bio,
 			    unsigned int *request_count,
 			    struct request **same_queue_rq);
 unsigned int blk_plug_queued_count(struct request_queue *q);
+struct list_head *blk_get_plug_list(struct request_queue *, struct blk_plug *);
 
 void blk_account_io_start(struct request *req, bool new_io);
 void blk_account_io_completion(struct request *req, unsigned int bytes);
block/elevator.c +7 -4
index 11d2cfee2bc1..c62974ef1052 100644
@@ -1002,18 +1002,21 @@ ssize_t elv_iosched_store(struct request_queue *q, const char *name,
 ssize_t elv_iosched_show(struct request_queue *q, char *name)
 {
 	struct elevator_queue *e = q->elevator;
-	struct elevator_type *elv;
+	struct elevator_type *elv = NULL;
 	struct elevator_type *__e;
 	int len = 0;
 
-	if (!q->elevator || !blk_queue_stackable(q))
+	if (!blk_queue_stackable(q))
 		return sprintf(name, "none\n");
 
-	elv = e->type;
+	if (!q->elevator)
+		len += sprintf(name+len, "[none] ");
+	else
+		elv = e->type;
 
 	spin_lock(&elv_list_lock);
 	list_for_each_entry(__e, &elv_list, list) {
-		if (!strcmp(elv->elevator_name, __e->elevator_name))
+		if (elv && !strcmp(elv->elevator_name, __e->elevator_name))
 			len += sprintf(name+len, "[%s] ", elv->elevator_name);
 		else
 			len += sprintf(name+len, "%s ", __e->elevator_name);
include/linux/blk-mq.h +1 -0
index 35a0af5ede6d..485d922b3fe6 100644
@@ -151,6 +151,7 @@ enum {
 	BLK_MQ_F_SG_MERGE	= 1 << 2,
 	BLK_MQ_F_DEFER_ISSUE	= 1 << 4,
 	BLK_MQ_F_BLOCKING	= 1 << 5,
+	BLK_MQ_F_SQ_SCHED	= 1 << 6,
 	BLK_MQ_F_ALLOC_POLICY_START_BIT = 8,
 	BLK_MQ_F_ALLOC_POLICY_BITS = 1,
 
include/linux/blkdev.h +2 -0
index ebeef2b79c5a..a8c580f806cc 100644
@@ -120,6 +120,8 @@ typedef __u32 __bitwise req_flags_t;
 #define RQF_HASHED		((__force req_flags_t)(1 << 16))
 /* IO stats tracking on */
 #define RQF_STATS		((__force req_flags_t)(1 << 17))
+/* rl based request on MQ queue */
+#define RQF_MQ_RL		((__force req_flags_t)(1 << 18))
 
 /* flags that prevent us from merging requests: */
 #define RQF_NOMERGE_FLAGS \
Signature · 1 line
2.7.4
author
#28 lore raw

PATCH 6/7 block: drop irq+lock when flushing queue plugs

In reply to Jens Axboe

Not convinced this is a faster approach, and it does look IRQs off longer than otherwise. With mq+scheduling, it's a problem since it forces us to offload the queue running. If we get rid of it, we can run the queue without the queue lock held.

---
 block/blk-core.c | 32 ++++++++++++++------------------
 1 file changed, 14 insertions(+), 18 deletions(-)
block/blk-core.c +14 -18
index 6c1063aab1a0..80b5259080a9 100644
@@ -3197,18 +3197,21 @@ static int plug_rq_cmp(void *priv, struct list_head *a, struct list_head *b)
  * plugger did not intend it.
  */
 static void queue_unplugged(struct request_queue *q, unsigned int depth,
-			    bool from_schedule)
+			    bool from_schedule, unsigned long flags)
 	__releases(q->queue_lock)
 {
 	trace_block_unplug(q, depth, !from_schedule);
 
-	if (q->mq_ops)
-		blk_mq_run_hw_queues(q, true);
-	else if (from_schedule)
-		blk_run_queue_async(q);
-	else
-		__blk_run_queue(q);
-	spin_unlock(q->queue_lock);
+	if (q->mq_ops) {
+		spin_unlock_irqrestore(q->queue_lock, flags);
+		blk_mq_run_hw_queues(q, from_schedule);
+	} else {
+		if (from_schedule)
+			blk_run_queue_async(q);
+		else
+			__blk_run_queue(q);
+		spin_unlock_irqrestore(q->queue_lock, flags);
+	}
 }
 
 static void flush_plug_callbacks(struct blk_plug *plug, bool from_schedule)
@@ -3276,11 +3279,6 @@ void blk_flush_plug_list(struct blk_plug *plug, bool from_schedule)
 	q = NULL;
 	depth = 0;
 
-	/*
-	 * Save and disable interrupts here, to avoid doing it for every
-	 * queue lock we have to take.
-	 */
-	local_irq_save(flags);
 	while (!list_empty(&list)) {
 		rq = list_entry_rq(list.next);
 		list_del_init(&rq->queuelist);
@@ -3290,10 +3288,10 @@ void blk_flush_plug_list(struct blk_plug *plug, bool from_schedule)
 			 * This drops the queue lock
 			 */
 			if (q)
-				queue_unplugged(q, depth, from_schedule);
+				queue_unplugged(q, depth, from_schedule, flags);
 			q = rq->q;
 			depth = 0;
-			spin_lock(q->queue_lock);
+			spin_lock_irqsave(q->queue_lock, flags);
 		}
 
 		/*
@@ -3322,9 +3320,7 @@ void blk_flush_plug_list(struct blk_plug *plug, bool from_schedule)
 	 * This drops the queue lock
 	 */
 	if (q)
-		queue_unplugged(q, depth, from_schedule);
-
-	local_irq_restore(flags);
+		queue_unplugged(q, depth, from_schedule, flags);
 }
 
 void blk_finish_plug(struct blk_plug *plug)
Signature · 1 line
2.7.4
author
#29 lore raw

PATCH 7/7 null_blk: add parameters to ask for mq-sched and write cache

In reply to Jens Axboe
---
 drivers/block/null_blk.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/block/null_blk.c +14 -0
index 4943ee22716e..f2726936cd1a 100644
@@ -117,6 +117,14 @@ static bool use_lightnvm;
 module_param(use_lightnvm, bool, S_IRUGO);
 MODULE_PARM_DESC(use_lightnvm, "Register as a LightNVM device");
 
+static bool use_sched;
+module_param(use_sched, bool, S_IRUGO);
+MODULE_PARM_DESC(use_sched, "Ask for blk-mq scheduling");
+
+static bool wc;
+module_param(wc, bool, S_IRUGO);
+MODULE_PARM_DESC(use_sched, "Claim volatile write cache");
+
 static int irqmode = NULL_IRQ_SOFTIRQ;
 
 static int null_set_irqmode(const char *str, const struct kernel_param *kp)
@@ -724,6 +732,9 @@ static int null_add_dev(void)
 		nullb->tag_set.flags = BLK_MQ_F_SHOULD_MERGE;
 		nullb->tag_set.driver_data = nullb;
 
+		if (use_sched)
+			nullb->tag_set.flags |= BLK_MQ_F_SQ_SCHED;
+
 		rv = blk_mq_alloc_tag_set(&nullb->tag_set);
 		if (rv)
 			goto out_cleanup_queues;
@@ -760,6 +771,9 @@ static int null_add_dev(void)
 	queue_flag_set_unlocked(QUEUE_FLAG_NONROT, nullb->q);
 	queue_flag_clear_unlocked(QUEUE_FLAG_ADD_RANDOM, nullb->q);
 
+	if (wc)
+		blk_queue_write_cache(nullb->q, true, false);
+
 	mutex_lock(&lock);
 	nullb->index = nullb_indexes++;
 	mutex_unlock(&lock);
Signature · 1 line
2.7.4
author
#30 lore raw
In reply to Jens Axboe
Quoted 26 lines · Jens Axboe

This is by no means done, but it seems to work well enough that I thought I'd send it out for others to take a look at and play with.

Basically this allows blk-mq managed devices to run the legacy IO schedulers, unmodified. The only requirement is that the blk-mq device has to be single queue for now, though that limitation would be rather simple to lift.

Since this is a debug patch, the default scheduler is deadline. You can switch that to the other configured schedulers, as you would with non-mq devices. Here's an example of a scsi-mq device that is running deadline, and being switched to CFQ online:

root@leopard:~# cat /sys/block/sda/mq/0/tags 
nr_tags=31, reserved_tags=0, bits_per_word=4
nr_free=31, nr_reserved=0
active_queues=0
root@leopard:~# cat /sys/block/sda/queue/scheduler 
noop [deadline] cfq 
root@leopard:~# echo cfq > /sys/block/sda/queue/scheduler 
root@leopard:~# cat /sys/block/sda/queue/scheduler 
noop deadline [cfq] 
Quoted 6 lines

Testing welcome. There's certainly room for improvement here, so I'm mostly interested in grave performance issues or crashes, if any.

Can also be viewed/fetched via git:

git://git.kernel.dk/linux-block for-4.11/blk-mq-legacy-sched

BTW, didn't include the patch for SCSI. You need the below to enable scheduling on SCSI devices.

drivers/scsi/scsi_lib.c +1 -1
index aedcec3..47a5c87 100644
@@ -2121,7 +2121,7 @@ int scsi_mq_setup_tags(struct Scsi_Host *shost)
 	shost->tag_set.queue_depth = shost->can_queue;
 	shost->tag_set.cmd_size = cmd_size;
 	shost->tag_set.numa_node = NUMA_NO_NODE;
-	shost->tag_set.flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_SG_MERGE | BLK_MQ_F_SQ_SCHED;
+	shost->tag_set.flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_SG_MERGE;
 	shost->tag_set.flags |=
 		BLK_ALLOC_POLICY_TO_MQ_FLAG(shost->hostt->tag_alloc_policy);
 	shost->tag_set.driver_data = shost;
Signature · 1 line
Jens Axboe
maintainer
#31 lore raw
Quoted 30 lines · Jens Axboe
Quoted 29 lines · Jens Axboe

This is by no means done, but it seems to work well enough that I thought I'd send it out for others to take a look at and play with.

Basically this allows blk-mq managed devices to run the legacy IO schedulers, unmodified. The only requirement is that the blk-mq device has to be single queue for now, though that limitation would be rather simple to lift.

Since this is a debug patch, the default scheduler is deadline. You can switch that to the other configured schedulers, as you would with non-mq devices. Here's an example of a scsi-mq device that is running deadline, and being switched to CFQ online:

root@leopard:~# cat /sys/block/sda/mq/0/tags 
nr_tags=31, reserved_tags=0, bits_per_word=4
nr_free=31, nr_reserved=0
active_queues=0
root@leopard:~# cat /sys/block/sda/queue/scheduler 
noop [deadline] cfq 
root@leopard:~# echo cfq > /sys/block/sda/queue/scheduler 
root@leopard:~# cat /sys/block/sda/queue/scheduler 
noop deadline [cfq] 

Testing welcome. There's certainly room for improvement here, so I'm mostly interested in grave performance issues or crashes, if any.

Quoted 6 lines
Quoted 3 lines

Can also be viewed/fetched via git:

git://git.kernel.dk/linux-block for-4.11/blk-mq-legacy-sched

BTW, didn't include the patch for SCSI. You need the below to enable scheduling on SCSI devices.

Gah, that was reversed, time to put the computer away for the night. Below is correct.

commit 8eea81e0903fcde1c28044ea66acc4c5c578f553

Author: Jens Axboe <[email protected]>
Date:   Fri Dec 2 21:03:43 2016 -0700

scsi: enable IO scheduling for scsi-mq

drivers/scsi/scsi_lib.c +1 -1
index 47a5c8783b89..aedcec30ee5f 100644
@@ -2121,7 +2121,7 @@ int scsi_mq_setup_tags(struct Scsi_Host *shost)
 	shost->tag_set.queue_depth = shost->can_queue;
 	shost->tag_set.cmd_size = cmd_size;
 	shost->tag_set.numa_node = NUMA_NO_NODE;
-	shost->tag_set.flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_SG_MERGE;
+	shost->tag_set.flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_SG_MERGE | BLK_MQ_F_SQ_SCHED;
 	shost->tag_set.flags |=
 		BLK_ALLOC_POLICY_TO_MQ_FLAG(shost->hostt->tag_alloc_policy);
 	shost->tag_set.driver_data = shost;
Signature · 1 line
Jens Axboe