linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH 01/13] blk-mq: avoid sleep in blk_mq_alloc_request_hctx
  2022-12-23 12:52 ` [PATCH 01/13] blk-mq: avoid sleep in blk_mq_alloc_request_hctx Kemeng Shi
@ 2022-12-23  5:37   ` Christoph Hellwig
  2022-12-23  6:38     ` Kemeng Shi
  0 siblings, 1 reply; 18+ messages in thread
From: Christoph Hellwig @ 2022-12-23  5:37 UTC (permalink / raw)
  To: Kemeng Shi
  Cc: axboe, dwagner, hare, ming.lei, linux-block, linux-kernel, hch,
	john.garry

On Fri, Dec 23, 2022 at 08:52:11PM +0800, Kemeng Shi wrote:
> +	if (WARN_ON_ONCE(((!flags) & (BLK_MQ_REQ_NOWAIT | BLK_MQ_REQ_RESERVED))))

This check does not make any sense.  I think what you want is

	if (WARN_ON_ONCE(!(flags & BLK_MQ_REQ_NOWAIT) ||
	    WARN_ON_ONCE(!(flags & BLK_MQ_REQ_RESERVED))))

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 12/13] blk-mq: use switch/case to improve readability in blk_mq_try_issue_list_directly
  2022-12-23 12:52 ` [PATCH 12/13] blk-mq: use switch/case to improve readability in blk_mq_try_issue_list_directly Kemeng Shi
@ 2022-12-23  5:53   ` Christoph Hellwig
  2022-12-23  6:57     ` Kemeng Shi
  0 siblings, 1 reply; 18+ messages in thread
From: Christoph Hellwig @ 2022-12-23  5:53 UTC (permalink / raw)
  To: Kemeng Shi
  Cc: axboe, dwagner, hare, ming.lei, linux-block, linux-kernel, hch,
	john.garry

On Fri, Dec 23, 2022 at 08:52:22PM +0800, Kemeng Shi wrote:
> +			blk_mq_request_bypass_insert(rq, false, list_empty(list));

Please try to avoid the overly long line here.

That beng said blk_mq_request_bypass_insert is simply a horrible
API.  I think we should do something like this:


diff --git a/block/blk-flush.c b/block/blk-flush.c
index 53202eff545efb..b6157ae11df651 100644
--- a/block/blk-flush.c
+++ b/block/blk-flush.c
@@ -432,7 +432,8 @@ void blk_insert_flush(struct request *rq)
 	 */
 	if ((policy & REQ_FSEQ_DATA) &&
 	    !(policy & (REQ_FSEQ_PREFLUSH | REQ_FSEQ_POSTFLUSH))) {
-		blk_mq_request_bypass_insert(rq, false, true);
+		blk_mq_request_bypass_insert(rq);
+		blk_mq_run_hw_queue(rq->mq_hctx, false);
 		return;
 	}
 
diff --git a/block/blk-mq-sched.c b/block/blk-mq-sched.c
index 23d1a90fec4271..d49fe4503b09d7 100644
--- a/block/blk-mq-sched.c
+++ b/block/blk-mq-sched.c
@@ -437,12 +437,13 @@ void blk_mq_sched_insert_request(struct request *rq, bool at_head,
 		 * Simply queue flush rq to the front of hctx->dispatch so that
 		 * intensive flush workloads can benefit in case of NCQ HW.
 		 */
-		at_head = (rq->rq_flags & RQF_FLUSH_SEQ) ? true : at_head;
-		blk_mq_request_bypass_insert(rq, at_head, false);
-		goto run;
-	}
-
-	if (e) {
+		spin_lock(&hctx->lock);
+		if ((rq->rq_flags & RQF_FLUSH_SEQ) || at_head)
+			list_add(&rq->queuelist, &hctx->dispatch);
+		else
+			list_add_tail(&rq->queuelist, &hctx->dispatch);
+		spin_unlock(&hctx->lock);
+	} else if (e) {
 		LIST_HEAD(list);
 
 		list_add(&rq->queuelist, &list);
@@ -453,7 +454,6 @@ void blk_mq_sched_insert_request(struct request *rq, bool at_head,
 		spin_unlock(&ctx->lock);
 	}
 
-run:
 	if (run_queue)
 		blk_mq_run_hw_queue(hctx, async);
 }
diff --git a/block/blk-mq.c b/block/blk-mq.c
index c5cf0dbca1db8d..43bb9b36c90da7 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -1467,7 +1467,7 @@ static void blk_mq_requeue_work(struct work_struct *work)
 		 * merge.
 		 */
 		if (rq->rq_flags & RQF_DONTPREP)
-			blk_mq_request_bypass_insert(rq, false, false);
+			blk_mq_request_bypass_insert(rq);
 		else
 			blk_mq_sched_insert_request(rq, true, false, false);
 	}
@@ -2504,26 +2504,17 @@ void __blk_mq_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
 /**
  * blk_mq_request_bypass_insert - Insert a request at dispatch list.
  * @rq: Pointer to request to be inserted.
- * @at_head: true if the request should be inserted at the head of the list.
- * @run_queue: If we should run the hardware queue after inserting the request.
  *
  * Should only be used carefully, when the caller knows we want to
  * bypass a potential IO scheduler on the target device.
  */
-void blk_mq_request_bypass_insert(struct request *rq, bool at_head,
-				  bool run_queue)
+void blk_mq_request_bypass_insert(struct request *rq)
 {
 	struct blk_mq_hw_ctx *hctx = rq->mq_hctx;
 
 	spin_lock(&hctx->lock);
-	if (at_head)
-		list_add(&rq->queuelist, &hctx->dispatch);
-	else
-		list_add_tail(&rq->queuelist, &hctx->dispatch);
+	list_add_tail(&rq->queuelist, &hctx->dispatch);
 	spin_unlock(&hctx->lock);
-
-	if (run_queue)
-		blk_mq_run_hw_queue(hctx, false);
 }
 
 void blk_mq_insert_requests(struct blk_mq_hw_ctx *hctx, struct blk_mq_ctx *ctx,
@@ -2670,10 +2661,17 @@ static void blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx,
 	blk_status_t ret =
 		__blk_mq_try_issue_directly(hctx, rq, false, true);
 
-	if (ret == BLK_STS_RESOURCE || ret == BLK_STS_DEV_RESOURCE)
-		blk_mq_request_bypass_insert(rq, false, true);
-	else if (ret != BLK_STS_OK)
+	switch (ret) {
+	case BLK_STS_OK:
+		break;
+	case BLK_STS_RESOURCE:
+	case BLK_STS_DEV_RESOURCE:
+		blk_mq_request_bypass_insert(rq);
+		blk_mq_run_hw_queue(rq->mq_hctx, false);
+		break;
+	default:
 		blk_mq_end_request(rq, ret);
+	}
 }
 
 static blk_status_t blk_mq_request_issue_directly(struct request *rq, bool last)
@@ -2705,7 +2703,8 @@ static void blk_mq_plug_issue_direct(struct blk_plug *plug, bool from_schedule)
 			break;
 		case BLK_STS_RESOURCE:
 		case BLK_STS_DEV_RESOURCE:
-			blk_mq_request_bypass_insert(rq, false, true);
+			blk_mq_request_bypass_insert(rq);
+			blk_mq_run_hw_queue(rq->mq_hctx, false);
 			blk_mq_commit_rqs(hctx, &queued, from_schedule);
 			return;
 		default:
@@ -2818,8 +2817,9 @@ void blk_mq_try_issue_list_directly(struct blk_mq_hw_ctx *hctx,
 			errors++;
 			if (ret == BLK_STS_RESOURCE ||
 					ret == BLK_STS_DEV_RESOURCE) {
-				blk_mq_request_bypass_insert(rq, false,
-							list_empty(list));
+				blk_mq_request_bypass_insert(rq);
+				if (list_empty(list))
+					blk_mq_run_hw_queue(rq->mq_hctx, false);
 				break;
 			}
 			blk_mq_end_request(rq, ret);
diff --git a/block/blk-mq.h b/block/blk-mq.h
index ef59fee62780d3..3733429561e1eb 100644
--- a/block/blk-mq.h
+++ b/block/blk-mq.h
@@ -61,8 +61,7 @@ void blk_mq_free_map_and_rqs(struct blk_mq_tag_set *set,
  */
 void __blk_mq_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
 				bool at_head);
-void blk_mq_request_bypass_insert(struct request *rq, bool at_head,
-				  bool run_queue);
+void blk_mq_request_bypass_insert(struct request *rq);
 void blk_mq_insert_requests(struct blk_mq_hw_ctx *hctx, struct blk_mq_ctx *ctx,
 				struct list_head *list);
 void blk_mq_try_issue_list_directly(struct blk_mq_hw_ctx *hctx,

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH 01/13] blk-mq: avoid sleep in blk_mq_alloc_request_hctx
  2022-12-23  5:37   ` Christoph Hellwig
@ 2022-12-23  6:38     ` Kemeng Shi
  0 siblings, 0 replies; 18+ messages in thread
From: Kemeng Shi @ 2022-12-23  6:38 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: axboe, dwagner, hare, ming.lei, linux-block, linux-kernel,
	john.garry

Hi, Christoph.
on 12/23/2022 1:37 PM, Christoph Hellwig wrote:
> On Fri, Dec 23, 2022 at 08:52:11PM +0800, Kemeng Shi wrote:
>> +	if (WARN_ON_ONCE(((!flags) & (BLK_MQ_REQ_NOWAIT | BLK_MQ_REQ_RESERVED))))
> 
> This check does not make any sense.  I think what you want is
> 
> 	if (WARN_ON_ONCE(!(flags & BLK_MQ_REQ_NOWAIT) ||
> 	    WARN_ON_ONCE(!(flags & BLK_MQ_REQ_RESERVED))))
This is exactly what I want and I will fix this in next version. Thanks.

-- 
Best wishes
Kemeng Shi


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 12/13] blk-mq: use switch/case to improve readability in blk_mq_try_issue_list_directly
  2022-12-23  5:53   ` Christoph Hellwig
@ 2022-12-23  6:57     ` Kemeng Shi
  0 siblings, 0 replies; 18+ messages in thread
From: Kemeng Shi @ 2022-12-23  6:57 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: axboe, dwagner, hare, ming.lei, linux-block, linux-kernel,
	john.garry


on 12/23/2022 1:53 PM, Christoph Hellwig wrote:
> On Fri, Dec 23, 2022 at 08:52:22PM +0800, Kemeng Shi wrote:
>> +			blk_mq_request_bypass_insert(rq, false, list_empty(list));
> 
> Please try to avoid the overly long line here.
Get it and I will fix this in next version. Thanks!
> That beng said blk_mq_request_bypass_insert is simply a horrible
> API.  I think we should do something like this:
I am not quite follow this. I guess this API is horrible for two possbile reasons:
1. It accepts two bool parameters which may be confusing betwwen them.
2. It adds additional checks for if we need to insert at head and if we need to run
queue which is already checked by caller.

Anyway, it seems another patch is needed for this, but I don't know proper way to
send this patch. Add your patch to this patchset or you want to send a single one
after this patchset.

-- 
Best wishes
Kemeng Shi


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH 00/13] A few bugfix and cleanup patches for blk-mq
@ 2022-12-23 12:52 Kemeng Shi
  2022-12-23 12:52 ` [PATCH 01/13] blk-mq: avoid sleep in blk_mq_alloc_request_hctx Kemeng Shi
                   ` (12 more replies)
  0 siblings, 13 replies; 18+ messages in thread
From: Kemeng Shi @ 2022-12-23 12:52 UTC (permalink / raw)
  To: axboe, dwagner, hare, ming.lei, linux-block, linux-kernel
  Cc: hch, john.garry, shikemeng

Hi, this series contain several bugfix patches to fix potential io
hung and a few cleanup patches to remove stale codes and unnecessary
check. Most changes are in request issue and dispatch path. Thanks.

Kemeng Shi (13):
  blk-mq: avoid sleep in blk_mq_alloc_request_hctx
  blk-mq: remove stale comment for blk_mq_sched_mark_restart_hctx
  blk-mq: wait on correct sbitmap_queue in blk_mq_mark_tag_wait
  blk-mq: Fix potential io hung for shared sbitmap per tagset
  blk-mq: remove unnecessary list_empty check in
    blk_mq_try_issue_list_directly
  blk-mq: remove unncessary error count and flush in
    blk_mq_plug_issue_direct
  blk-mq: remove error count and unncessary flush in
    blk_mq_try_issue_list_directly
  blk-mq: simplify flush check in blk_mq_dispatch_rq_list
  blk-mq: remove unnecessary error count and check in
    blk_mq_dispatch_rq_list
  blk-mq: remove set bd->last when get driver tag for next request fails
  blk-mq: remove unncessary from_schedule parameter in
    blk_mq_plug_issue_direct
  blk-mq: use switch/case to improve readability in
    blk_mq_try_issue_list_directly
  blk-mq: correct stale comment of .get_budget

 block/blk-mq-sched.c |   7 ++-
 block/blk-mq.c       | 103 ++++++++++++++++++-------------------------
 2 files changed, 46 insertions(+), 64 deletions(-)

-- 
2.30.0


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH 01/13] blk-mq: avoid sleep in blk_mq_alloc_request_hctx
  2022-12-23 12:52 [PATCH 00/13] A few bugfix and cleanup patches for blk-mq Kemeng Shi
@ 2022-12-23 12:52 ` Kemeng Shi
  2022-12-23  5:37   ` Christoph Hellwig
  2022-12-23 12:52 ` [PATCH 02/13] blk-mq: remove stale comment for blk_mq_sched_mark_restart_hctx Kemeng Shi
                   ` (11 subsequent siblings)
  12 siblings, 1 reply; 18+ messages in thread
From: Kemeng Shi @ 2022-12-23 12:52 UTC (permalink / raw)
  To: axboe, dwagner, hare, ming.lei, linux-block, linux-kernel
  Cc: hch, john.garry, shikemeng

Commit 1f5bd336b9150 ("blk-mq: add blk_mq_alloc_request_hctx") add
blk_mq_alloc_request_hctx to send commands to a specific queue. If
BLK_MQ_REQ_NOWAIT is not set in tag allocation, we may change to different
hctx after sleep and get tag from unexpected hctx. So BLK_MQ_REQ_NOWAIT
must be set in flags for blk_mq_alloc_request_hctx.
After commit 600c3b0cea784 ("blk-mq: open code __blk_mq_alloc_request in
blk_mq_alloc_request_hctx"), blk_mq_alloc_request_hctx return -EINVAL
if both BLK_MQ_REQ_NOWAIT and BLK_MQ_REQ_RESERVED are not set instead of
if BLK_MQ_REQ_NOWAIT is not set. So if BLK_MQ_REQ_NOWAIT is not set and
BLK_MQ_REQ_RESERVED is set, blk_mq_alloc_request_hctx could alloc tag
from unexpected hctx. I guess what we need here is that return -EINVAL
if either BLK_MQ_REQ_NOWAIT or BLK_MQ_REQ_RESERVED is not set.

Currently both BLK_MQ_REQ_NOWAIT and BLK_MQ_REQ_RESERVED will be set if
specific hctx is needed in nvme_auth_submit, nvmf_connect_io_queue
and nvmf_connect_admin_queue. Fix the potential BLK_MQ_REQ_NOWAIT missed
case in future.

Fixes: 600c3b0cea78 ("blk-mq: open code __blk_mq_alloc_request in blk_mq_alloc_request_hctx")
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 block/blk-mq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 4e6b3ccd4989..988812811db9 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -657,7 +657,7 @@ struct request *blk_mq_alloc_request_hctx(struct request_queue *q,
 	 * allocator for this for the rare use case of a command tied to
 	 * a specific queue.
 	 */
-	if (WARN_ON_ONCE(!(flags & (BLK_MQ_REQ_NOWAIT | BLK_MQ_REQ_RESERVED))))
+	if (WARN_ON_ONCE(((!flags) & (BLK_MQ_REQ_NOWAIT | BLK_MQ_REQ_RESERVED))))
 		return ERR_PTR(-EINVAL);
 
 	if (hctx_idx >= q->nr_hw_queues)
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 02/13] blk-mq: remove stale comment for blk_mq_sched_mark_restart_hctx
  2022-12-23 12:52 [PATCH 00/13] A few bugfix and cleanup patches for blk-mq Kemeng Shi
  2022-12-23 12:52 ` [PATCH 01/13] blk-mq: avoid sleep in blk_mq_alloc_request_hctx Kemeng Shi
@ 2022-12-23 12:52 ` Kemeng Shi
  2022-12-23 12:52 ` [PATCH 03/13] blk-mq: wait on correct sbitmap_queue in blk_mq_mark_tag_wait Kemeng Shi
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 18+ messages in thread
From: Kemeng Shi @ 2022-12-23 12:52 UTC (permalink / raw)
  To: axboe, dwagner, hare, ming.lei, linux-block, linux-kernel
  Cc: hch, john.garry, shikemeng

Commit 97889f9ac24f8 ("blk-mq: remove synchronize_rcu() from
blk_mq_del_queue_tag_set()") remove handle of TAG_SHARED in restart,
then shared_hctx_restart counted for how many hardware queues are marked
for restart is removed too.
Remove the stale comment that we still count hardware queues need restart.

Fixes: 97889f9ac24f ("blk-mq: remove synchronize_rcu() from blk_mq_del_queue_tag_set()")
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 block/blk-mq-sched.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/block/blk-mq-sched.c b/block/blk-mq-sched.c
index 23d1a90fec42..ae40cdb7a383 100644
--- a/block/blk-mq-sched.c
+++ b/block/blk-mq-sched.c
@@ -19,8 +19,7 @@
 #include "blk-wbt.h"
 
 /*
- * Mark a hardware queue as needing a restart. For shared queues, maintain
- * a count of how many hardware queues are marked for restart.
+ * Mark a hardware queue as needing a restart.
  */
 void blk_mq_sched_mark_restart_hctx(struct blk_mq_hw_ctx *hctx)
 {
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 03/13] blk-mq: wait on correct sbitmap_queue in blk_mq_mark_tag_wait
  2022-12-23 12:52 [PATCH 00/13] A few bugfix and cleanup patches for blk-mq Kemeng Shi
  2022-12-23 12:52 ` [PATCH 01/13] blk-mq: avoid sleep in blk_mq_alloc_request_hctx Kemeng Shi
  2022-12-23 12:52 ` [PATCH 02/13] blk-mq: remove stale comment for blk_mq_sched_mark_restart_hctx Kemeng Shi
@ 2022-12-23 12:52 ` Kemeng Shi
  2022-12-23 12:52 ` [PATCH 04/13] blk-mq: Fix potential io hung for shared sbitmap per tagset Kemeng Shi
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 18+ messages in thread
From: Kemeng Shi @ 2022-12-23 12:52 UTC (permalink / raw)
  To: axboe, dwagner, hare, ming.lei, linux-block, linux-kernel
  Cc: hch, john.garry, shikemeng

For shared queues case, we will only wait on bitmap_tags if we fail to get
driver tag. However, rq could be from breserved_tags, then two problems
will occur:
1. io hung if no tag is currently allocated from bitmap_tags.
2. unnecessary wakeup when tag is freed to bitmap_tags while no tag is
freed to breserved_tags.
Wait on the bitmap from which rq from to fix this.

Fixes: f906a6a0f426 ("blk-mq: improve tag waiting setup for non-shared tags")
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 block/blk-mq.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 988812811db9..202975f4d357 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -1819,7 +1819,7 @@ static int blk_mq_dispatch_wake(wait_queue_entry_t *wait, unsigned mode,
 static bool blk_mq_mark_tag_wait(struct blk_mq_hw_ctx *hctx,
 				 struct request *rq)
 {
-	struct sbitmap_queue *sbq = &hctx->tags->bitmap_tags;
+	struct sbitmap_queue *sbq;
 	struct wait_queue_head *wq;
 	wait_queue_entry_t *wait;
 	bool ret;
@@ -1842,6 +1842,10 @@ static bool blk_mq_mark_tag_wait(struct blk_mq_hw_ctx *hctx,
 	if (!list_empty_careful(&wait->entry))
 		return false;
 
+	if (blk_mq_tag_is_reserved(rq->mq_hctx->sched_tags, rq->internal_tag))
+		sbq = &hctx->tags->breserved_tags;
+	else
+		sbq = &hctx->tags->bitmap_tags;
 	wq = &bt_wait_ptr(sbq, hctx)->wait;
 
 	spin_lock_irq(&wq->lock);
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 04/13] blk-mq: Fix potential io hung for shared sbitmap per tagset
  2022-12-23 12:52 [PATCH 00/13] A few bugfix and cleanup patches for blk-mq Kemeng Shi
                   ` (2 preceding siblings ...)
  2022-12-23 12:52 ` [PATCH 03/13] blk-mq: wait on correct sbitmap_queue in blk_mq_mark_tag_wait Kemeng Shi
@ 2022-12-23 12:52 ` Kemeng Shi
  2022-12-23 12:52 ` [PATCH 05/13] blk-mq: remove unnecessary list_empty check in blk_mq_try_issue_list_directly Kemeng Shi
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 18+ messages in thread
From: Kemeng Shi @ 2022-12-23 12:52 UTC (permalink / raw)
  To: axboe, dwagner, hare, ming.lei, linux-block, linux-kernel
  Cc: hch, john.garry, shikemeng

Commit f906a6a0f4268 ("blk-mq: improve tag waiting setup for non-shared
tags") mark restart for unshared tags for improvement. At that time,
tags is only shared betweens queues and we can check if tags is shared
by test BLK_MQ_F_TAG_SHARED.
Afterwards, commit 32bc15afed04b ("blk-mq: Facilitate a shared sbitmap per
tagset") enabled tags share betweens hctxs inside a queue. We only
mark restart for shared hctxs inside a queue and may cause io hung if
there is no tag currently allocated by hctxs going to be marked restart.
Wait on sbitmap_queue instead of mark restart for shared hctxs case to
fix this.

Fixes: 32bc15afed04 ("blk-mq: Facilitate a shared sbitmap per tagset")
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 block/blk-mq.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 202975f4d357..bfba0e151733 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -1824,7 +1824,8 @@ static bool blk_mq_mark_tag_wait(struct blk_mq_hw_ctx *hctx,
 	wait_queue_entry_t *wait;
 	bool ret;
 
-	if (!(hctx->flags & BLK_MQ_F_TAG_QUEUE_SHARED)) {
+	if (!(hctx->flags & BLK_MQ_F_TAG_QUEUE_SHARED) &&
+	    !(blk_mq_is_shared_tags(hctx->flags))) {
 		blk_mq_sched_mark_restart_hctx(hctx);
 
 		/*
@@ -2094,7 +2095,8 @@ bool blk_mq_dispatch_rq_list(struct blk_mq_hw_ctx *hctx, struct list_head *list,
 		bool needs_restart;
 		/* For non-shared tags, the RESTART check will suffice */
 		bool no_tag = prep == PREP_DISPATCH_NO_TAG &&
-			(hctx->flags & BLK_MQ_F_TAG_QUEUE_SHARED);
+			((hctx->flags & BLK_MQ_F_TAG_QUEUE_SHARED) ||
+			blk_mq_is_shared_tags(hctx->flags));
 
 		if (nr_budgets)
 			blk_mq_release_budgets(q, list);
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 05/13] blk-mq: remove unnecessary list_empty check in blk_mq_try_issue_list_directly
  2022-12-23 12:52 [PATCH 00/13] A few bugfix and cleanup patches for blk-mq Kemeng Shi
                   ` (3 preceding siblings ...)
  2022-12-23 12:52 ` [PATCH 04/13] blk-mq: Fix potential io hung for shared sbitmap per tagset Kemeng Shi
@ 2022-12-23 12:52 ` Kemeng Shi
  2022-12-23 12:52 ` [PATCH 06/13] blk-mq: remove unncessary error count and flush in blk_mq_plug_issue_direct Kemeng Shi
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 18+ messages in thread
From: Kemeng Shi @ 2022-12-23 12:52 UTC (permalink / raw)
  To: axboe, dwagner, hare, ming.lei, linux-block, linux-kernel
  Cc: hch, john.garry, shikemeng

We only break the list walk if we get 'BLK_STS_*RESOURCE'. We also
count errors for 'BLK_STS_*RESOURCE' error. If list is not empty,
errors will always be non-zero. So we can remove unnecessary list_empty
check. This will remove redundant list_empty check for case that
error happened at sending last request in list.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 block/blk-mq.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index bfba0e151733..a447a7586032 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -2832,8 +2832,7 @@ void blk_mq_try_issue_list_directly(struct blk_mq_hw_ctx *hctx,
 	 * the driver there was more coming, but that turned out to
 	 * be a lie.
 	 */
-	if ((!list_empty(list) || errors) &&
-	     hctx->queue->mq_ops->commit_rqs && queued)
+	if (errors && hctx->queue->mq_ops->commit_rqs && queued)
 		hctx->queue->mq_ops->commit_rqs(hctx);
 }
 
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 06/13] blk-mq: remove unncessary error count and flush in blk_mq_plug_issue_direct
  2022-12-23 12:52 [PATCH 00/13] A few bugfix and cleanup patches for blk-mq Kemeng Shi
                   ` (4 preceding siblings ...)
  2022-12-23 12:52 ` [PATCH 05/13] blk-mq: remove unnecessary list_empty check in blk_mq_try_issue_list_directly Kemeng Shi
@ 2022-12-23 12:52 ` Kemeng Shi
  2022-12-23 12:52 ` [PATCH 07/13] blk-mq: remove error count and unncessary flush in blk_mq_try_issue_list_directly Kemeng Shi
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 18+ messages in thread
From: Kemeng Shi @ 2022-12-23 12:52 UTC (permalink / raw)
  To: axboe, dwagner, hare, ming.lei, linux-block, linux-kernel
  Cc: hch, john.garry, shikemeng

blk_mq_plug_issue_direct try to send a list of requests which belong to
different hctxs. Normally, we will send flush when hctx changes as there
maybe no more request for the same hctx. Besides we will send flush along
with last request in the list by set last parameter of
blk_mq_request_issue_directly.

Extra flush is needed for two cases:
1. We stop sending at middle of list, then normal flush sent after last
request of current hctx is miss.
2. Error happens at sending last request and normal flush may be lost.

In blk_mq_plug_issue_direct, we only break the list walk if we get
BLK_STS_RESOURCE or BLK_STS_DEV_RESOURCE error. We will send extra flush
for this case already.
We count error number and send extra flush if error number is non-zero
after sending all requests in list. This could cover case 2 described
above, but there are two things to improve:
1. If last request is sent successfully, error of request at middle of list
will trigger an unnecessary flush.
2. We only need error of last request instead of error number and error of
last request can be simply retrieved from ret.

Cover case 2 above by simply check ret of last request and remove
unnecessary error count and flush to improve blk_mq_plug_issue_direct.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 block/blk-mq.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index a447a7586032..01f48a73eacd 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -2686,11 +2686,10 @@ static void blk_mq_plug_issue_direct(struct blk_plug *plug, bool from_schedule)
 	struct blk_mq_hw_ctx *hctx = NULL;
 	struct request *rq;
 	int queued = 0;
-	int errors = 0;
+	blk_status_t ret;
 
 	while ((rq = rq_list_pop(&plug->mq_list))) {
 		bool last = rq_list_empty(plug->mq_list);
-		blk_status_t ret;
 
 		if (hctx != rq->mq_hctx) {
 			if (hctx)
@@ -2710,7 +2709,6 @@ static void blk_mq_plug_issue_direct(struct blk_plug *plug, bool from_schedule)
 			return;
 		default:
 			blk_mq_end_request(rq, ret);
-			errors++;
 			break;
 		}
 	}
@@ -2719,7 +2717,7 @@ static void blk_mq_plug_issue_direct(struct blk_plug *plug, bool from_schedule)
 	 * If we didn't flush the entire list, we could have told the driver
 	 * there was more coming, but that turned out to be a lie.
 	 */
-	if (errors)
+	if (ret != BLK_STS_OK)
 		blk_mq_commit_rqs(hctx, &queued, from_schedule);
 }
 
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 07/13] blk-mq: remove error count and unncessary flush in blk_mq_try_issue_list_directly
  2022-12-23 12:52 [PATCH 00/13] A few bugfix and cleanup patches for blk-mq Kemeng Shi
                   ` (5 preceding siblings ...)
  2022-12-23 12:52 ` [PATCH 06/13] blk-mq: remove unncessary error count and flush in blk_mq_plug_issue_direct Kemeng Shi
@ 2022-12-23 12:52 ` Kemeng Shi
  2022-12-23 12:52 ` [PATCH 08/13] blk-mq: simplify flush check in blk_mq_dispatch_rq_list Kemeng Shi
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 18+ messages in thread
From: Kemeng Shi @ 2022-12-23 12:52 UTC (permalink / raw)
  To: axboe, dwagner, hare, ming.lei, linux-block, linux-kernel
  Cc: hch, john.garry, shikemeng

blk_mq_try_issue_list_directly try to send a list requests belong to the
same hctx to driver. Normally, we will send flush along with last request
in the list by set last parameter in blk_mq_request_issue_directly.
Extra flush is needed for two cases:
1. We stop sending at middle of list and normal flush along with last
request will not be sent.
2. Error happens at sending last request and normal flush may be lost.

We will only break list walk if we get BLK_STS_RESOURCE or
BLK_STS_DEV_RESOURCE which will be stored in ret. So for case 1, we can
simply check ret and send a extra flush if ret is not BLK_STS_OK.
For case 2, the error of last request in the list is also stored in ret, we
can simply check ret and send a extra flush if ret is not BLK_STS_OK too.

Then error count is not needed and error in middle of list will not trigger
unnecessary extra flush anymore.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 block/blk-mq.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 01f48a73eacd..f67acd78a9c2 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -2803,17 +2803,15 @@ void blk_mq_try_issue_list_directly(struct blk_mq_hw_ctx *hctx,
 		struct list_head *list)
 {
 	int queued = 0;
-	int errors = 0;
+	blk_status_t ret;
 
 	while (!list_empty(list)) {
-		blk_status_t ret;
 		struct request *rq = list_first_entry(list, struct request,
 				queuelist);
 
 		list_del_init(&rq->queuelist);
 		ret = blk_mq_request_issue_directly(rq, list_empty(list));
 		if (ret != BLK_STS_OK) {
-			errors++;
 			if (ret == BLK_STS_RESOURCE ||
 					ret == BLK_STS_DEV_RESOURCE) {
 				blk_mq_request_bypass_insert(rq, false,
@@ -2830,7 +2828,7 @@ void blk_mq_try_issue_list_directly(struct blk_mq_hw_ctx *hctx,
 	 * the driver there was more coming, but that turned out to
 	 * be a lie.
 	 */
-	if (errors && hctx->queue->mq_ops->commit_rqs && queued)
+	if (ret != BLK_STS_OK && hctx->queue->mq_ops->commit_rqs && queued)
 		hctx->queue->mq_ops->commit_rqs(hctx);
 }
 
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 08/13] blk-mq: simplify flush check in blk_mq_dispatch_rq_list
  2022-12-23 12:52 [PATCH 00/13] A few bugfix and cleanup patches for blk-mq Kemeng Shi
                   ` (6 preceding siblings ...)
  2022-12-23 12:52 ` [PATCH 07/13] blk-mq: remove error count and unncessary flush in blk_mq_try_issue_list_directly Kemeng Shi
@ 2022-12-23 12:52 ` Kemeng Shi
  2022-12-23 12:52 ` [PATCH 09/13] blk-mq: remove unnecessary error count and " Kemeng Shi
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 18+ messages in thread
From: Kemeng Shi @ 2022-12-23 12:52 UTC (permalink / raw)
  To: axboe, dwagner, hare, ming.lei, linux-block, linux-kernel
  Cc: hch, john.garry, shikemeng

For busy error BLK_STS*_RESOURCE, request will always be added
back to list, so need_resource will not be true and ret will
not be == BLK_STS_DEV_RESOURCE if list is empty. We could remove
these dead check.
If list is empty, we only need to send extra flush
if error happens at last request in the list which is stored in
ret. So send a extra flush if ret is not BLK_STS_OK instead of
errors is non-zero to avoid unnecessary flush for error at middle
request in list.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 block/blk-mq.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index f67acd78a9c2..9c5971b04adc 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -2084,8 +2084,8 @@ bool blk_mq_dispatch_rq_list(struct blk_mq_hw_ctx *hctx, struct list_head *list,
 	/* If we didn't flush the entire list, we could have told the driver
 	 * there was more coming, but that turned out to be a lie.
 	 */
-	if ((!list_empty(list) || errors || needs_resource ||
-	     ret == BLK_STS_DEV_RESOURCE) && q->mq_ops->commit_rqs && queued)
+	if ((!list_empty(list) || ret != BLK_STS_OK) &&
+	     q->mq_ops->commit_rqs && queued)
 		q->mq_ops->commit_rqs(hctx);
 	/*
 	 * Any items that need requeuing? Stuff them into hctx->dispatch,
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 09/13] blk-mq: remove unnecessary error count and check in blk_mq_dispatch_rq_list
  2022-12-23 12:52 [PATCH 00/13] A few bugfix and cleanup patches for blk-mq Kemeng Shi
                   ` (7 preceding siblings ...)
  2022-12-23 12:52 ` [PATCH 08/13] blk-mq: simplify flush check in blk_mq_dispatch_rq_list Kemeng Shi
@ 2022-12-23 12:52 ` Kemeng Shi
  2022-12-23 12:52 ` [PATCH 10/13] blk-mq: remove set of bd->last when get driver tag for next request fails Kemeng Shi
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 18+ messages in thread
From: Kemeng Shi @ 2022-12-23 12:52 UTC (permalink / raw)
  To: axboe, dwagner, hare, ming.lei, linux-block, linux-kernel
  Cc: hch, john.garry, shikemeng

blk_mq_dispatch_rq_list will notify if hctx is busy in return bool. It will
return true if we are not busy and can handle more and return false on the
opposite. Inside blk_mq_dispatch_rq_list, we will return true if list is
empty and (errors + queued) != 0.

For busy error BLK_STS*_RESOURCE, the failed request will be added back
to list and list will not be empty. We count queued for BLK_STS_OK and
errors for rest error except busy error.
So if list is empty, (errors + queued) will be total requests in the list
which is checked not empty at beginning of blk_mq_dispatch_rq_list. So
(errors + queued) != 0 is always met if all requests are handled. Then the
(errors + queued) != 0 check and errors number count is not needed.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 block/blk-mq.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 9c5971b04adc..97e2a07062de 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -2009,7 +2009,7 @@ bool blk_mq_dispatch_rq_list(struct blk_mq_hw_ctx *hctx, struct list_head *list,
 	enum prep_dispatch prep;
 	struct request_queue *q = hctx->queue;
 	struct request *rq, *nxt;
-	int errors, queued;
+	int queued;
 	blk_status_t ret = BLK_STS_OK;
 	LIST_HEAD(zone_list);
 	bool needs_resource = false;
@@ -2020,7 +2020,7 @@ bool blk_mq_dispatch_rq_list(struct blk_mq_hw_ctx *hctx, struct list_head *list,
 	/*
 	 * Now process all the entries, sending them to the driver.
 	 */
-	errors = queued = 0;
+	queued = 0;
 	do {
 		struct blk_mq_queue_data bd;
 
@@ -2073,7 +2073,6 @@ bool blk_mq_dispatch_rq_list(struct blk_mq_hw_ctx *hctx, struct list_head *list,
 			needs_resource = true;
 			break;
 		default:
-			errors++;
 			blk_mq_end_request(rq, ret);
 		}
 	} while (!list_empty(list));
@@ -2151,10 +2150,10 @@ bool blk_mq_dispatch_rq_list(struct blk_mq_hw_ctx *hctx, struct list_head *list,
 
 		blk_mq_update_dispatch_busy(hctx, true);
 		return false;
-	} else
-		blk_mq_update_dispatch_busy(hctx, false);
+	}
 
-	return (queued + errors) != 0;
+	blk_mq_update_dispatch_busy(hctx, false);
+	return true;
 }
 
 /**
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 10/13] blk-mq: remove set of bd->last when get driver tag for next request fails
  2022-12-23 12:52 [PATCH 00/13] A few bugfix and cleanup patches for blk-mq Kemeng Shi
                   ` (8 preceding siblings ...)
  2022-12-23 12:52 ` [PATCH 09/13] blk-mq: remove unnecessary error count and " Kemeng Shi
@ 2022-12-23 12:52 ` Kemeng Shi
  2022-12-23 12:52 ` [PATCH 11/13] blk-mq: remove unncessary from_schedule parameter in blk_mq_plug_issue_direct Kemeng Shi
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 18+ messages in thread
From: Kemeng Shi @ 2022-12-23 12:52 UTC (permalink / raw)
  To: axboe, dwagner, hare, ming.lei, linux-block, linux-kernel
  Cc: hch, john.garry, shikemeng

Commit 113285b473824 ("blk-mq: ensure that bd->last is always set
correctly") will set last if we failed to get driver tag for next
request to avoid flush miss as we break the list walk and will not
send the last request in the list which will be sent with last set
normally.
This code seems stale now becase the flush introduced is always
redundant as:
For case tag is really out, we will send a extra flush if we find
list is not empty after list walk.
For case some tag is freed before retry in blk_mq_prep_dispatch_rq for
next, then we can get a tag for next request in retry and flush notified
already is not necessary.

Just remove these stale codes.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 block/blk-mq.c | 24 ++----------------------
 1 file changed, 2 insertions(+), 22 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 97e2a07062de..452f2e0fba05 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -1916,16 +1916,6 @@ static void blk_mq_update_dispatch_busy(struct blk_mq_hw_ctx *hctx, bool busy)
 static void blk_mq_handle_dev_resource(struct request *rq,
 				       struct list_head *list)
 {
-	struct request *next =
-		list_first_entry_or_null(list, struct request, queuelist);
-
-	/*
-	 * If an I/O scheduler has been configured and we got a driver tag for
-	 * the next request already, free it.
-	 */
-	if (next)
-		blk_mq_put_driver_tag(next);
-
 	list_add(&rq->queuelist, list);
 	__blk_mq_requeue_request(rq);
 }
@@ -2008,7 +1998,7 @@ bool blk_mq_dispatch_rq_list(struct blk_mq_hw_ctx *hctx, struct list_head *list,
 {
 	enum prep_dispatch prep;
 	struct request_queue *q = hctx->queue;
-	struct request *rq, *nxt;
+	struct request *rq;
 	int queued;
 	blk_status_t ret = BLK_STS_OK;
 	LIST_HEAD(zone_list);
@@ -2034,17 +2024,7 @@ bool blk_mq_dispatch_rq_list(struct blk_mq_hw_ctx *hctx, struct list_head *list,
 		list_del_init(&rq->queuelist);
 
 		bd.rq = rq;
-
-		/*
-		 * Flag last if we have no more requests, or if we have more
-		 * but can't assign a driver tag to it.
-		 */
-		if (list_empty(list))
-			bd.last = true;
-		else {
-			nxt = list_first_entry(list, struct request, queuelist);
-			bd.last = !blk_mq_get_driver_tag(nxt);
-		}
+		bd.last = list_empty(list);
 
 		/*
 		 * once the request is queued to lld, no need to cover the
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 11/13] blk-mq: remove unncessary from_schedule parameter in blk_mq_plug_issue_direct
  2022-12-23 12:52 [PATCH 00/13] A few bugfix and cleanup patches for blk-mq Kemeng Shi
                   ` (9 preceding siblings ...)
  2022-12-23 12:52 ` [PATCH 10/13] blk-mq: remove set of bd->last when get driver tag for next request fails Kemeng Shi
@ 2022-12-23 12:52 ` Kemeng Shi
  2022-12-23 12:52 ` [PATCH 12/13] blk-mq: use switch/case to improve readability in blk_mq_try_issue_list_directly Kemeng Shi
  2022-12-23 12:52 ` [PATCH 13/13] blk-mq: correct stale comment of .get_budget Kemeng Shi
  12 siblings, 0 replies; 18+ messages in thread
From: Kemeng Shi @ 2022-12-23 12:52 UTC (permalink / raw)
  To: axboe, dwagner, hare, ming.lei, linux-block, linux-kernel
  Cc: hch, john.garry, shikemeng

Function blk_mq_plug_issue_direct tries to issue batch requests in plug
list to driver directly. We will only issue plug request to driver if we
are not from scheduler, so from_scheduler parameter of
blk_mq_plug_issue_direct is always false, so as the blk_mq_commit_rqs
which is only called in blk_mq_plug_issue_direct.
Remove unncessary from_scheduler of blk_mq_plug_issue_direct and
blk_mq_commit_rqs.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 block/blk-mq.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 452f2e0fba05..a48f2a913295 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -2527,11 +2527,10 @@ void blk_mq_insert_requests(struct blk_mq_hw_ctx *hctx, struct blk_mq_ctx *ctx,
 	spin_unlock(&ctx->lock);
 }
 
-static void blk_mq_commit_rqs(struct blk_mq_hw_ctx *hctx, int *queued,
-			      bool from_schedule)
+static void blk_mq_commit_rqs(struct blk_mq_hw_ctx *hctx, int *queued)
 {
 	if (hctx->queue->mq_ops->commit_rqs) {
-		trace_block_unplug(hctx->queue, *queued, !from_schedule);
+		trace_block_unplug(hctx->queue, *queued, true);
 		hctx->queue->mq_ops->commit_rqs(hctx);
 	}
 	*queued = 0;
@@ -2660,7 +2659,7 @@ static blk_status_t blk_mq_request_issue_directly(struct request *rq, bool last)
 	return __blk_mq_try_issue_directly(rq->mq_hctx, rq, true, last);
 }
 
-static void blk_mq_plug_issue_direct(struct blk_plug *plug, bool from_schedule)
+static void blk_mq_plug_issue_direct(struct blk_plug *plug)
 {
 	struct blk_mq_hw_ctx *hctx = NULL;
 	struct request *rq;
@@ -2672,7 +2671,7 @@ static void blk_mq_plug_issue_direct(struct blk_plug *plug, bool from_schedule)
 
 		if (hctx != rq->mq_hctx) {
 			if (hctx)
-				blk_mq_commit_rqs(hctx, &queued, from_schedule);
+				blk_mq_commit_rqs(hctx, &queued);
 			hctx = rq->mq_hctx;
 		}
 
@@ -2684,7 +2683,7 @@ static void blk_mq_plug_issue_direct(struct blk_plug *plug, bool from_schedule)
 		case BLK_STS_RESOURCE:
 		case BLK_STS_DEV_RESOURCE:
 			blk_mq_request_bypass_insert(rq, false, true);
-			blk_mq_commit_rqs(hctx, &queued, from_schedule);
+			blk_mq_commit_rqs(hctx, &queued);
 			return;
 		default:
 			blk_mq_end_request(rq, ret);
@@ -2697,7 +2696,7 @@ static void blk_mq_plug_issue_direct(struct blk_plug *plug, bool from_schedule)
 	 * there was more coming, but that turned out to be a lie.
 	 */
 	if (ret != BLK_STS_OK)
-		blk_mq_commit_rqs(hctx, &queued, from_schedule);
+		blk_mq_commit_rqs(hctx, &queued);
 }
 
 static void __blk_mq_flush_plug_list(struct request_queue *q,
@@ -2768,7 +2767,7 @@ void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule)
 		}
 
 		blk_mq_run_dispatch_ops(q,
-				blk_mq_plug_issue_direct(plug, false));
+				blk_mq_plug_issue_direct(plug));
 		if (rq_list_empty(plug->mq_list))
 			return;
 	}
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 12/13] blk-mq: use switch/case to improve readability in blk_mq_try_issue_list_directly
  2022-12-23 12:52 [PATCH 00/13] A few bugfix and cleanup patches for blk-mq Kemeng Shi
                   ` (10 preceding siblings ...)
  2022-12-23 12:52 ` [PATCH 11/13] blk-mq: remove unncessary from_schedule parameter in blk_mq_plug_issue_direct Kemeng Shi
@ 2022-12-23 12:52 ` Kemeng Shi
  2022-12-23  5:53   ` Christoph Hellwig
  2022-12-23 12:52 ` [PATCH 13/13] blk-mq: correct stale comment of .get_budget Kemeng Shi
  12 siblings, 1 reply; 18+ messages in thread
From: Kemeng Shi @ 2022-12-23 12:52 UTC (permalink / raw)
  To: axboe, dwagner, hare, ming.lei, linux-block, linux-kernel
  Cc: hch, john.garry, shikemeng

Use switch/case handle error as other function do to improve
readability in blk_mq_try_issue_list_directly.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 block/blk-mq.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index a48f2a913295..2a3db9524974 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -2789,16 +2789,20 @@ void blk_mq_try_issue_list_directly(struct blk_mq_hw_ctx *hctx,
 
 		list_del_init(&rq->queuelist);
 		ret = blk_mq_request_issue_directly(rq, list_empty(list));
-		if (ret != BLK_STS_OK) {
-			if (ret == BLK_STS_RESOURCE ||
-					ret == BLK_STS_DEV_RESOURCE) {
-				blk_mq_request_bypass_insert(rq, false,
-							list_empty(list));
-				break;
-			}
-			blk_mq_end_request(rq, ret);
-		} else
+		switch (ret) {
+		case BLK_STS_OK:
 			queued++;
+			break;
+		case BLK_STS_RESOURCE:
+		case BLK_STS_DEV_RESOURCE:
+			blk_mq_request_bypass_insert(rq, false, list_empty(list));
+			if (hctx->queue->mq_ops->commit_rqs && queued)
+				hctx->queue->mq_ops->commit_rqs(hctx);
+			return;
+		default:
+			blk_mq_end_request(rq, ret);
+			break;
+		}
 	}
 
 	/*
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 13/13] blk-mq: correct stale comment of .get_budget
  2022-12-23 12:52 [PATCH 00/13] A few bugfix and cleanup patches for blk-mq Kemeng Shi
                   ` (11 preceding siblings ...)
  2022-12-23 12:52 ` [PATCH 12/13] blk-mq: use switch/case to improve readability in blk_mq_try_issue_list_directly Kemeng Shi
@ 2022-12-23 12:52 ` Kemeng Shi
  12 siblings, 0 replies; 18+ messages in thread
From: Kemeng Shi @ 2022-12-23 12:52 UTC (permalink / raw)
  To: axboe, dwagner, hare, ming.lei, linux-block, linux-kernel
  Cc: hch, john.garry, shikemeng

Commit 88022d7201e96 ("blk-mq: don't handle failure in .get_budget")
remove BLK_STS_RESOURCE return value and we only check if we can get
the budget from .get_budget() now.
Correct stale comment that ".get_budget() returns BLK_STS_NO_RESOURCE"
to ".get_budget() fails to get the budget".

Fixes: 88022d7201e9 ("blk-mq: don't handle failure in .get_budget")
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 block/blk-mq-sched.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/block/blk-mq-sched.c b/block/blk-mq-sched.c
index ae40cdb7a383..06b312c69114 100644
--- a/block/blk-mq-sched.c
+++ b/block/blk-mq-sched.c
@@ -81,7 +81,7 @@ static bool blk_mq_dispatch_hctx_list(struct list_head *rq_list)
 /*
  * Only SCSI implements .get_budget and .put_budget, and SCSI restarts
  * its queue by itself in its completion handler, so we don't need to
- * restart queue if .get_budget() returns BLK_STS_NO_RESOURCE.
+ * restart queue if .get_budget() fails to get the budget.
  *
  * Returns -EAGAIN if hctx->dispatch was found non-empty and run_work has to
  * be run again.  This is necessary to avoid starving flushes.
@@ -209,7 +209,7 @@ static struct blk_mq_ctx *blk_mq_next_ctx(struct blk_mq_hw_ctx *hctx,
 /*
  * Only SCSI implements .get_budget and .put_budget, and SCSI restarts
  * its queue by itself in its completion handler, so we don't need to
- * restart queue if .get_budget() returns BLK_STS_NO_RESOURCE.
+ * restart queue if .get_budget() fails to get the budget.
  *
  * Returns -EAGAIN if hctx->dispatch was found non-empty and run_work has to
  * be run again.  This is necessary to avoid starving flushes.
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2022-12-23  6:58 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-23 12:52 [PATCH 00/13] A few bugfix and cleanup patches for blk-mq Kemeng Shi
2022-12-23 12:52 ` [PATCH 01/13] blk-mq: avoid sleep in blk_mq_alloc_request_hctx Kemeng Shi
2022-12-23  5:37   ` Christoph Hellwig
2022-12-23  6:38     ` Kemeng Shi
2022-12-23 12:52 ` [PATCH 02/13] blk-mq: remove stale comment for blk_mq_sched_mark_restart_hctx Kemeng Shi
2022-12-23 12:52 ` [PATCH 03/13] blk-mq: wait on correct sbitmap_queue in blk_mq_mark_tag_wait Kemeng Shi
2022-12-23 12:52 ` [PATCH 04/13] blk-mq: Fix potential io hung for shared sbitmap per tagset Kemeng Shi
2022-12-23 12:52 ` [PATCH 05/13] blk-mq: remove unnecessary list_empty check in blk_mq_try_issue_list_directly Kemeng Shi
2022-12-23 12:52 ` [PATCH 06/13] blk-mq: remove unncessary error count and flush in blk_mq_plug_issue_direct Kemeng Shi
2022-12-23 12:52 ` [PATCH 07/13] blk-mq: remove error count and unncessary flush in blk_mq_try_issue_list_directly Kemeng Shi
2022-12-23 12:52 ` [PATCH 08/13] blk-mq: simplify flush check in blk_mq_dispatch_rq_list Kemeng Shi
2022-12-23 12:52 ` [PATCH 09/13] blk-mq: remove unnecessary error count and " Kemeng Shi
2022-12-23 12:52 ` [PATCH 10/13] blk-mq: remove set of bd->last when get driver tag for next request fails Kemeng Shi
2022-12-23 12:52 ` [PATCH 11/13] blk-mq: remove unncessary from_schedule parameter in blk_mq_plug_issue_direct Kemeng Shi
2022-12-23 12:52 ` [PATCH 12/13] blk-mq: use switch/case to improve readability in blk_mq_try_issue_list_directly Kemeng Shi
2022-12-23  5:53   ` Christoph Hellwig
2022-12-23  6:57     ` Kemeng Shi
2022-12-23 12:52 ` [PATCH 13/13] blk-mq: correct stale comment of .get_budget Kemeng Shi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).