Skip to content

Commit 94eddfb

Browse files
committed
blk-mq: ensure that we set REQ_IO_STAT so diskstats work
If disk stats are enabled on the queue, a request needs to be marked with REQ_IO_STAT for accounting to be active on that request. This fixes an issue with virtio-blk not showing up in /proc/diskstats after the conversion to blk-mq. Add QUEUE_FLAG_MQ_DEFAULT, setting stats and same cpu-group completion on by default. Reported-by: Dave Chinner <david@fromorbit.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 34f2fd8 commit 94eddfb

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

‎block/blk-mq.c‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,12 @@ bool blk_mq_can_queue(struct blk_mq_hw_ctx *hctx)
171171
}
172172
EXPORT_SYMBOL(blk_mq_can_queue);
173173

174-
static void blk_mq_rq_ctx_init(struct blk_mq_ctx *ctx, struct request *rq,
175-
unsigned int rw_flags)
174+
static void blk_mq_rq_ctx_init(struct request_queue *q, struct blk_mq_ctx *ctx,
175+
struct request *rq, unsigned int rw_flags)
176176
{
177+
if (blk_queue_io_stat(q))
178+
rw_flags |= REQ_IO_STAT;
179+
177180
rq->mq_ctx = ctx;
178181
rq->cmd_flags = rw_flags;
179182
ctx->rq_dispatched[rw_is_sync(rw_flags)]++;
@@ -197,7 +200,7 @@ static struct request *blk_mq_alloc_request_pinned(struct request_queue *q,
197200

198201
rq = __blk_mq_alloc_request(hctx, gfp & ~__GFP_WAIT, reserved);
199202
if (rq) {
200-
blk_mq_rq_ctx_init(ctx, rq, rw);
203+
blk_mq_rq_ctx_init(q, ctx, rq, rw);
201204
break;
202205
} else if (!(gfp & __GFP_WAIT))
203206
break;
@@ -921,7 +924,7 @@ static void blk_mq_make_request(struct request_queue *q, struct bio *bio)
921924
trace_block_getrq(q, bio, rw);
922925
rq = __blk_mq_alloc_request(hctx, GFP_ATOMIC, false);
923926
if (likely(rq))
924-
blk_mq_rq_ctx_init(ctx, rq, rw);
927+
blk_mq_rq_ctx_init(q, ctx, rq, rw);
925928
else {
926929
blk_mq_put_ctx(ctx);
927930
trace_block_sleeprq(q, bio, rw);
@@ -1377,6 +1380,7 @@ struct request_queue *blk_mq_init_queue(struct blk_mq_reg *reg,
13771380
q->queue_hw_ctx = hctxs;
13781381

13791382
q->mq_ops = reg->ops;
1383+
q->queue_flags |= QUEUE_FLAG_MQ_DEFAULT;
13801384

13811385
blk_queue_make_request(q, blk_mq_make_request);
13821386
blk_queue_rq_timed_out(q, reg->ops->timeout);

‎include/linux/blkdev.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,9 @@ struct request_queue {
505505
(1 << QUEUE_FLAG_SAME_COMP) | \
506506
(1 << QUEUE_FLAG_ADD_RANDOM))
507507

508+
#define QUEUE_FLAG_MQ_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \
509+
(1 << QUEUE_FLAG_SAME_COMP))
510+
508511
static inline void queue_lockdep_assert_held(struct request_queue *q)
509512
{
510513
if (q->queue_lock)

0 commit comments

Comments
 (0)