All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kemeng Shi <shikemeng@huaweicloud.com>
To: hch@lst.de, axboe@kernel.dk, dwagner@suse.de, hare@suse.de,
	ming.lei@redhat.com, linux-block@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: john.garry@huawei.com, jack@suse.cz
Subject: [PATCH v3 07/14] blk-mq: make blk_mq_commit_rqs a general function for all commits
Date: Wed, 11 Jan 2023 21:01:52 +0800	[thread overview]
Message-ID: <20230111130159.3741753-8-shikemeng@huaweicloud.com> (raw)
In-Reply-To: <20230111130159.3741753-1-shikemeng@huaweicloud.com>

1. rename orignal blk_mq_commit_rqs to blk_mq_plug_commit_rqs as
trace_block_unplug is only needed when we dispatch request from plug list.
We need a commit_rqs wrapper for this case. Besides, this patch
adds queued check and only commits request if any request was queued
to keep commit behavior consistent and remove unnecessary commit.
2. add new blk_mq_commit_rqs for general commits. Current
blk_mq_commit_rqs will not clear queued as queued clearing is not
wanted generally.
3. document rule for unusual cases which need explicit commit_rqs.

Suggested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 block/blk-mq.c | 38 ++++++++++++++++++++++++++------------
 1 file changed, 26 insertions(+), 12 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index c6cc3feb3b84..98f6003474f2 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -2007,6 +2007,29 @@ static void blk_mq_release_budgets(struct request_queue *q,
 	}
 }
 
+/* blk_mq_commit_rqs and blk_mq_plug_commit_rqs notify driver using
+ * bd->last that there is no more requests. (See comment in struct
+ * blk_mq_ops for commit_rqs for details)
+ * Attention, we should explicitly call this in unusual cases:
+ *  1) did not queue everything initially scheduled to queue
+ *  2) the last attempt to queue a request failed
+ */
+static void blk_mq_commit_rqs(struct blk_mq_hw_ctx *hctx, int queued)
+{
+	if (hctx->queue->mq_ops->commit_rqs && queued) {
+		hctx->queue->mq_ops->commit_rqs(hctx);
+	}
+}
+
+static void blk_mq_plug_commit_rqs(struct blk_mq_hw_ctx *hctx, int *queued)
+{
+	if (hctx->queue->mq_ops->commit_rqs && *queued) {
+		trace_block_unplug(hctx->queue, *queued, true);
+		hctx->queue->mq_ops->commit_rqs(hctx);
+	}
+	*queued = 0;
+}
+
 /*
  * Returns true if we did some work AND can potentially do more.
  */
@@ -2555,15 +2578,6 @@ 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)
-{
-	if (hctx->queue->mq_ops->commit_rqs) {
-		trace_block_unplug(hctx->queue, *queued, true);
-		hctx->queue->mq_ops->commit_rqs(hctx);
-	}
-	*queued = 0;
-}
-
 static void blk_mq_bio_to_request(struct request *rq, struct bio *bio,
 		unsigned int nr_segs)
 {
@@ -2700,7 +2714,7 @@ static void blk_mq_plug_issue_direct(struct blk_plug *plug)
 
 		if (hctx != rq->mq_hctx) {
 			if (hctx)
-				blk_mq_commit_rqs(hctx, &queued);
+				blk_mq_plug_commit_rqs(hctx, &queued);
 			hctx = rq->mq_hctx;
 		}
 
@@ -2712,7 +2726,7 @@ static void blk_mq_plug_issue_direct(struct blk_plug *plug)
 		case BLK_STS_RESOURCE:
 		case BLK_STS_DEV_RESOURCE:
 			blk_mq_request_bypass_insert(rq, false, true);
-			blk_mq_commit_rqs(hctx, &queued);
+			blk_mq_plug_commit_rqs(hctx, &queued);
 			return;
 		default:
 			blk_mq_end_request(rq, ret);
@@ -2726,7 +2740,7 @@ static void blk_mq_plug_issue_direct(struct blk_plug *plug)
 	 * there was more coming, but that turned out to be a lie.
 	 */
 	if (errors)
-		blk_mq_commit_rqs(hctx, &queued);
+		blk_mq_plug_commit_rqs(hctx, &queued);
 }
 
 static void __blk_mq_flush_plug_list(struct request_queue *q,
-- 
2.30.0


  parent reply	other threads:[~2023-01-11  5:04 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-11 13:01 [PATCH v3 00/14] A few bugfix and cleanup patches for blk-mq Kemeng Shi
2023-01-11 13:01 ` [PATCH v3 01/14] blk-mq: avoid sleep in blk_mq_alloc_request_hctx Kemeng Shi
2023-01-11  5:05   ` Christoph Hellwig
2023-01-11 13:01 ` [PATCH v3 02/14] blk-mq: remove stale comment for blk_mq_sched_mark_restart_hctx Kemeng Shi
2023-01-11 13:01 ` [PATCH v3 03/14] blk-mq: wait on correct sbitmap_queue in blk_mq_mark_tag_wait Kemeng Shi
2023-01-11 13:01 ` [PATCH v3 04/14] blk-mq: Fix potential io hung for shared sbitmap per tagset Kemeng Shi
2023-01-11 13:01 ` [PATCH v3 05/14] blk-mq: remove unnecessary list_empty check in blk_mq_try_issue_list_directly Kemeng Shi
2023-01-11 13:01 ` [PATCH v3 06/14] blk-mq: remove unncessary from_schedule parameter in blk_mq_plug_issue_direct Kemeng Shi
2023-01-11 13:01 ` Kemeng Shi [this message]
2023-01-11  5:45   ` [PATCH v3 07/14] blk-mq: make blk_mq_commit_rqs a general function for all commits Christoph Hellwig
2023-01-11  6:30     ` Kemeng Shi
2023-01-16  1:07       ` Kemeng Shi
2023-01-16 16:09         ` Christoph Hellwig
2023-01-16 16:13           ` Jens Axboe
2023-01-17  1:01             ` Kemeng Shi
2023-01-11 13:01 ` [PATCH v3 08/14] blk-mq: remove unncessary error count and commit in blk_mq_plug_issue_direct Kemeng Shi
2023-01-11  5:06   ` Christoph Hellwig
2023-01-11 13:01 ` [PATCH v3 09/14] blk-mq: use blk_mq_commit_rqs helper in blk_mq_try_issue_list_directly Kemeng Shi
2023-01-11  5:19   ` Christoph Hellwig
2023-01-11 13:01 ` [PATCH v3 10/14] blk-mq: simplify flush check in blk_mq_dispatch_rq_list Kemeng Shi
2023-01-11  5:45   ` Christoph Hellwig
2023-01-11 13:01 ` [PATCH v3 11/14] blk-mq: remove unnecessary error count and " Kemeng Shi
2023-01-11 13:01 ` [PATCH v3 12/14] blk-mq: remove set of bd->last when get driver tag for next request fails Kemeng Shi
2023-01-11 13:01 ` [PATCH v3 13/14] blk-mq: use switch/case to improve readability in blk_mq_try_issue_list_directly Kemeng Shi
2023-01-11 13:01 ` [PATCH v3 14/14] blk-mq: correct stale comment of .get_budget Kemeng Shi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230111130159.3741753-8-shikemeng@huaweicloud.com \
    --to=shikemeng@huaweicloud.com \
    --cc=axboe@kernel.dk \
    --cc=dwagner@suse.de \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=jack@suse.cz \
    --cc=john.garry@huawei.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ming.lei@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.