From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@fb.com>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 2/5] blk-mq: initialize request in __blk_mq_alloc_request
Date: Tue, 27 May 2014 20:59:47 +0200 [thread overview]
Message-ID: <1401217190-32453-3-git-send-email-hch@lst.de> (raw)
In-Reply-To: <1401217190-32453-1-git-send-email-hch@lst.de>
Both callers if __blk_mq_alloc_request want to initialize the request, so
lift it into the common path.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/blk-mq.c | 62 +++++++++++++++++++++++++++-----------------------------
1 file changed, 30 insertions(+), 32 deletions(-)
diff --git a/block/blk-mq.c b/block/blk-mq.c
index f8f84e2..848b3b6 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -92,30 +92,6 @@ static void blk_mq_hctx_clear_pending(struct blk_mq_hw_ctx *hctx,
clear_bit(CTX_TO_BIT(hctx, ctx), &bm->word);
}
-static struct request *__blk_mq_alloc_request(struct blk_mq_hw_ctx *hctx,
- struct blk_mq_ctx *ctx,
- gfp_t gfp, bool reserved)
-{
- struct request *rq;
- unsigned int tag;
-
- tag = blk_mq_get_tag(hctx, &ctx->last_tag, gfp, reserved);
- if (tag != BLK_MQ_TAG_FAIL) {
- rq = hctx->tags->rqs[tag];
-
- rq->cmd_flags = 0;
- if (blk_mq_tag_busy(hctx)) {
- rq->cmd_flags = REQ_MQ_INFLIGHT;
- atomic_inc(&hctx->nr_active);
- }
-
- rq->tag = tag;
- return rq;
- }
-
- return NULL;
-}
-
static int blk_mq_queue_enter(struct request_queue *q)
{
int ret;
@@ -263,6 +239,32 @@ static void blk_mq_rq_ctx_init(struct request_queue *q, struct blk_mq_ctx *ctx,
ctx->rq_dispatched[rw_is_sync(rw_flags)]++;
}
+static struct request *
+__blk_mq_alloc_request(struct request_queue *q, struct blk_mq_hw_ctx *hctx,
+ struct blk_mq_ctx *ctx, int rw, gfp_t gfp, bool reserved)
+{
+ struct request *rq;
+ unsigned int tag;
+
+ tag = blk_mq_get_tag(hctx, &ctx->last_tag, gfp, reserved);
+ if (tag != BLK_MQ_TAG_FAIL) {
+ rq = hctx->tags->rqs[tag];
+
+ rq->cmd_flags = 0;
+ if (blk_mq_tag_busy(hctx)) {
+ rq->cmd_flags = REQ_MQ_INFLIGHT;
+ atomic_inc(&hctx->nr_active);
+ }
+
+ rq->tag = tag;
+ blk_mq_rq_ctx_init(q, ctx, rq, rw);
+ return rq;
+ }
+
+ return NULL;
+}
+
+
static struct request *blk_mq_alloc_request_pinned(struct request_queue *q,
int rw, gfp_t gfp,
bool reserved)
@@ -273,12 +275,10 @@ static struct request *blk_mq_alloc_request_pinned(struct request_queue *q,
struct blk_mq_ctx *ctx = blk_mq_get_ctx(q);
struct blk_mq_hw_ctx *hctx = q->mq_ops->map_queue(q, ctx->cpu);
- rq = __blk_mq_alloc_request(hctx, ctx, gfp & ~__GFP_WAIT,
+ rq = __blk_mq_alloc_request(q, hctx, ctx, rw, gfp & ~__GFP_WAIT,
reserved);
- if (rq) {
- blk_mq_rq_ctx_init(q, ctx, rq, rw);
+ if (rq)
break;
- }
if (gfp & __GFP_WAIT) {
__blk_mq_run_hw_queue(hctx);
@@ -1114,10 +1114,8 @@ static struct request *blk_mq_map_request(struct request_queue *q,
rw |= REQ_SYNC;
trace_block_getrq(q, bio, rw);
- rq = __blk_mq_alloc_request(hctx, ctx, GFP_ATOMIC, false);
- if (likely(rq))
- blk_mq_rq_ctx_init(q, ctx, rq, rw);
- else {
+ rq = __blk_mq_alloc_request(q, hctx, ctx, rw, GFP_ATOMIC, false);
+ if (unlikely(!rq)) {
blk_mq_put_ctx(ctx);
trace_block_sleeprq(q, bio, rw);
rq = blk_mq_alloc_request_pinned(q, rw, __GFP_WAIT|GFP_ATOMIC,
--
1.7.10.4
next prev parent reply other threads:[~2014-05-27 18:58 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-27 18:59 blk-mq: refactor request allocation Christoph Hellwig
2014-05-27 18:59 ` [PATCH 1/5] blk-mq: merge blk_mq_alloc_reserved_request into blk_mq_alloc_request Christoph Hellwig
2014-05-27 18:59 ` Christoph Hellwig [this message]
2014-05-27 18:59 ` [PATCH 3/5] blk-mq: remove blk_mq_wait_for_tags Christoph Hellwig
2014-05-27 18:59 ` [PATCH 4/5] blk-mq: do not use blk_mq_alloc_request_pinned in blk_mq_map_request Christoph Hellwig
2014-05-27 18:59 ` [PATCH 5/5] blk-mq: remove blk_mq_alloc_request_pinned Christoph Hellwig
2014-05-27 20:58 ` blk-mq: refactor request allocation Jens Axboe
2014-05-28 5:19 ` Christoph Hellwig
2014-05-28 14:20 ` Jens Axboe
2014-05-28 15:47 ` Jens Axboe
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=1401217190-32453-3-git-send-email-hch@lst.de \
--to=hch@lst.de \
--cc=axboe@fb.com \
--cc=linux-kernel@vger.kernel.org \
/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 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).