summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@fb.com>2014-04-30 13:43:56 -0600
committerJens Axboe <axboe@fb.com>2014-04-30 13:43:56 -0600
commitc6d600c65ebfa10a2a10d3e9183a24527ebe2aa4 (patch)
tree37fb918771c5048284da88170ecae051a221d94e
parent98bc1f272aba620d4222120853011d0ef026cf56 (diff)
blk-mq: refactor request insertion/merging
Refactor the logic around adding a new bio to a software queue, so we nest the ctx->lock where we really need it (merge and insertion) and don't hold it when we don't (init and IO start accounting). Signed-off-by: Jens Axboe <axboe@fb.com>
-rw-r--r--block/blk-mq.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/block/blk-mq.c b/block/blk-mq.c
index 77308a84dfb2..ca51ee4aa485 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -1037,17 +1037,25 @@ static void blk_mq_make_request(struct request_queue *q, struct bio *bio)
}
}
- spin_lock(&ctx->lock);
+ if (!(hctx->flags & BLK_MQ_F_SHOULD_MERGE)) {
+ init_request_from_bio(rq, bio);
- if ((hctx->flags & BLK_MQ_F_SHOULD_MERGE) &&
- blk_mq_attempt_merge(q, ctx, bio))
- __blk_mq_free_request(hctx, ctx, rq);
- else {
- blk_mq_bio_to_request(rq, bio);
+ spin_lock(&ctx->lock);
+insert_rq:
__blk_mq_insert_request(hctx, rq, false);
+ spin_unlock(&ctx->lock);
+ blk_account_io_start(rq, 1);
+ } else {
+ spin_lock(&ctx->lock);
+ if (!blk_mq_attempt_merge(q, ctx, bio)) {
+ init_request_from_bio(rq, bio);
+ goto insert_rq;
+ }
+
+ spin_unlock(&ctx->lock);
+ __blk_mq_free_request(hctx, ctx, rq);
}
- spin_unlock(&ctx->lock);
/*
* For a SYNC request, send it to the hardware immediately. For an