Skip to content

Commit 9d74e25

Browse files
Christoph Hellwigaxboe
authored andcommitted
blk-mq: do not initialize req->special
Drivers can reach their private data easily using the blk_mq_rq_to_pdu helper and don't need req->special. By not initializing it code can be simplified nicely, and we also shave off a few more instructions from the I/O path. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@fb.com>
1 parent 742ee69 commit 9d74e25

5 files changed

Lines changed: 9 additions & 27 deletions

File tree

‎block/blk-flush.c‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -306,22 +306,16 @@ static bool blk_kick_flush(struct request_queue *q)
306306
*/
307307
q->flush_pending_idx ^= 1;
308308

309+
blk_rq_init(q, q->flush_rq);
309310
if (q->mq_ops) {
310-
struct blk_mq_ctx *ctx = first_rq->mq_ctx;
311-
struct blk_mq_hw_ctx *hctx = q->mq_ops->map_queue(q, ctx->cpu);
312-
313-
blk_mq_rq_init(hctx, q->flush_rq);
314-
q->flush_rq->mq_ctx = ctx;
315-
316311
/*
317312
* Reuse the tag value from the fist waiting request,
318313
* with blk-mq the tag is generated during request
319314
* allocation and drivers can rely on it being inside
320315
* the range they asked for.
321316
*/
317+
q->flush_rq->mq_ctx = first_rq->mq_ctx;
322318
q->flush_rq->tag = first_rq->tag;
323-
} else {
324-
blk_rq_init(q, q->flush_rq);
325319
}
326320

327321
q->flush_rq->cmd_type = REQ_TYPE_FS;

‎block/blk-mq.c‎

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -251,24 +251,13 @@ struct request *blk_mq_alloc_reserved_request(struct request_queue *q, int rw,
251251
}
252252
EXPORT_SYMBOL(blk_mq_alloc_reserved_request);
253253

254-
/*
255-
* Re-init and set pdu, if we have it
256-
*/
257-
void blk_mq_rq_init(struct blk_mq_hw_ctx *hctx, struct request *rq)
258-
{
259-
blk_rq_init(hctx->queue, rq);
260-
261-
if (hctx->cmd_size)
262-
rq->special = blk_mq_rq_to_pdu(rq);
263-
}
264-
265254
static void __blk_mq_free_request(struct blk_mq_hw_ctx *hctx,
266255
struct blk_mq_ctx *ctx, struct request *rq)
267256
{
268257
const int tag = rq->tag;
269258
struct request_queue *q = rq->q;
270259

271-
blk_mq_rq_init(hctx, rq);
260+
blk_rq_init(hctx->queue, rq);
272261
blk_mq_put_tag(hctx->tags, tag);
273262

274263
blk_mq_queue_exit(q);
@@ -1165,7 +1154,7 @@ static int blk_mq_init_rq_map(struct blk_mq_hw_ctx *hctx,
11651154
left -= to_do * rq_size;
11661155
for (j = 0; j < to_do; j++) {
11671156
hctx->rqs[i] = p;
1168-
blk_mq_rq_init(hctx, hctx->rqs[i]);
1157+
blk_rq_init(hctx->queue, hctx->rqs[i]);
11691158
p += rq_size;
11701159
i++;
11711160
}

‎block/blk-mq.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ void blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async);
2727
void blk_mq_init_flush(struct request_queue *q);
2828
void blk_mq_drain_queue(struct request_queue *q);
2929
void blk_mq_free_queue(struct request_queue *q);
30-
void blk_mq_rq_init(struct blk_mq_hw_ctx *hctx, struct request *rq);
3130

3231
/*
3332
* CPU hotplug helpers

‎drivers/block/null_blk.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ static void null_cmd_end_timer(struct nullb_cmd *cmd)
226226

227227
static void null_softirq_done_fn(struct request *rq)
228228
{
229-
end_cmd(rq->special);
229+
end_cmd(blk_mq_rq_to_pdu(rq));
230230
}
231231

232232
static inline void null_handle_cmd(struct nullb_cmd *cmd)
@@ -311,7 +311,7 @@ static void null_request_fn(struct request_queue *q)
311311

312312
static int null_queue_rq(struct blk_mq_hw_ctx *hctx, struct request *rq)
313313
{
314-
struct nullb_cmd *cmd = rq->special;
314+
struct nullb_cmd *cmd = blk_mq_rq_to_pdu(rq);
315315

316316
cmd->rq = rq;
317317
cmd->nq = hctx->driver_data;

‎drivers/block/virtio_blk.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ static int __virtblk_add_req(struct virtqueue *vq,
112112

113113
static inline void virtblk_request_done(struct request *req)
114114
{
115-
struct virtblk_req *vbr = req->special;
115+
struct virtblk_req *vbr = blk_mq_rq_to_pdu(req);
116116
int error = virtblk_result(vbr);
117117

118118
if (req->cmd_type == REQ_TYPE_BLOCK_PC) {
@@ -154,7 +154,7 @@ static void virtblk_done(struct virtqueue *vq)
154154
static int virtio_queue_rq(struct blk_mq_hw_ctx *hctx, struct request *req)
155155
{
156156
struct virtio_blk *vblk = hctx->queue->queuedata;
157-
struct virtblk_req *vbr = req->special;
157+
struct virtblk_req *vbr = blk_mq_rq_to_pdu(req);
158158
unsigned long flags;
159159
unsigned int num;
160160
const bool last = (req->cmd_flags & REQ_END) != 0;
@@ -501,7 +501,7 @@ static int virtblk_init_vbr(void *data, struct blk_mq_hw_ctx *hctx,
501501
struct request *rq, unsigned int nr)
502502
{
503503
struct virtio_blk *vblk = data;
504-
struct virtblk_req *vbr = rq->special;
504+
struct virtblk_req *vbr = blk_mq_rq_to_pdu(rq);
505505

506506
sg_init_table(vbr->sg, vblk->sg_elems);
507507
return 0;

0 commit comments

Comments
 (0)