Skip to content

Commit 37f4a24

Browse files
Ming Leiaxboe
authored andcommitted
blk-mq: centralise related handling into blk_mq_get_driver_tag
Move .nr_active update and request assignment into blk_mq_get_driver_tag(), all are good to do during getting driver tag. Meantime blk-flush related code is simplified and flush request needn't to update the request table manually any more. Signed-off-by: Ming Lei <[email protected]> Cc: Christoph Hellwig <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 723bf17 commit 37f4a24

File tree

4 files changed

+20
-44
lines changed

4 files changed

+20
-44
lines changed

block/blk-flush.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,10 @@ static void flush_end_io(struct request *flush_rq, blk_status_t error)
236236
error = fq->rq_status;
237237

238238
hctx = flush_rq->mq_hctx;
239-
if (!q->elevator) {
240-
blk_mq_tag_set_rq(hctx, flush_rq->tag, fq->orig_rq);
241-
flush_rq->tag = -1;
242-
} else {
243-
flush_rq->internal_tag = -1;
244-
}
239+
if (!q->elevator)
240+
flush_rq->tag = BLK_MQ_NO_TAG;
241+
else
242+
flush_rq->internal_tag = BLK_MQ_NO_TAG;
245243

246244
running = &fq->flush_queue[fq->flush_running_idx];
247245
BUG_ON(fq->flush_pending_idx == fq->flush_running_idx);
@@ -315,13 +313,10 @@ static void blk_kick_flush(struct request_queue *q, struct blk_flush_queue *fq,
315313
flush_rq->mq_ctx = first_rq->mq_ctx;
316314
flush_rq->mq_hctx = first_rq->mq_hctx;
317315

318-
if (!q->elevator) {
319-
fq->orig_rq = first_rq;
316+
if (!q->elevator)
320317
flush_rq->tag = first_rq->tag;
321-
blk_mq_tag_set_rq(flush_rq->mq_hctx, first_rq->tag, flush_rq);
322-
} else {
318+
else
323319
flush_rq->internal_tag = first_rq->internal_tag;
324-
}
325320

326321
flush_rq->cmd_flags = REQ_OP_FLUSH | REQ_PREFLUSH;
327322
flush_rq->cmd_flags |= (flags & REQ_DRV) | (flags & REQ_FAILFAST_MASK);

block/blk-mq-tag.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,6 @@ static inline bool hctx_may_queue(struct blk_mq_hw_ctx *hctx,
101101
return atomic_read(&hctx->nr_active) < depth;
102102
}
103103

104-
/*
105-
* This helper should only be used for flush request to share tag
106-
* with the request cloned from, and both the two requests can't be
107-
* in flight at the same time. The caller has to make sure the tag
108-
* can't be freed.
109-
*/
110-
static inline void blk_mq_tag_set_rq(struct blk_mq_hw_ctx *hctx,
111-
unsigned int tag, struct request *rq)
112-
{
113-
hctx->tags->rqs[tag] = rq;
114-
}
115-
116104
static inline bool blk_mq_tag_is_reserved(struct blk_mq_tags *tags,
117105
unsigned int tag)
118106
{

block/blk-mq.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -277,26 +277,20 @@ static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data,
277277
{
278278
struct blk_mq_tags *tags = blk_mq_tags_from_data(data);
279279
struct request *rq = tags->static_rqs[tag];
280-
req_flags_t rq_flags = 0;
281280

282281
if (data->q->elevator) {
283282
rq->tag = BLK_MQ_NO_TAG;
284283
rq->internal_tag = tag;
285284
} else {
286-
if (data->hctx->flags & BLK_MQ_F_TAG_SHARED) {
287-
rq_flags = RQF_MQ_INFLIGHT;
288-
atomic_inc(&data->hctx->nr_active);
289-
}
290285
rq->tag = tag;
291286
rq->internal_tag = BLK_MQ_NO_TAG;
292-
data->hctx->tags->rqs[rq->tag] = rq;
293287
}
294288

295289
/* csd/requeue_work/fifo_time is initialized before use */
296290
rq->q = data->q;
297291
rq->mq_ctx = data->ctx;
298292
rq->mq_hctx = data->hctx;
299-
rq->rq_flags = rq_flags;
293+
rq->rq_flags = 0;
300294
rq->cmd_flags = data->cmd_flags;
301295
if (data->flags & BLK_MQ_REQ_PREEMPT)
302296
rq->rq_flags |= RQF_PREEMPT;
@@ -1127,9 +1121,10 @@ static bool __blk_mq_get_driver_tag(struct request *rq)
11271121
{
11281122
struct sbitmap_queue *bt = &rq->mq_hctx->tags->bitmap_tags;
11291123
unsigned int tag_offset = rq->mq_hctx->tags->nr_reserved_tags;
1130-
bool shared = blk_mq_tag_busy(rq->mq_hctx);
11311124
int tag;
11321125

1126+
blk_mq_tag_busy(rq->mq_hctx);
1127+
11331128
if (blk_mq_tag_is_reserved(rq->mq_hctx->sched_tags, rq->internal_tag)) {
11341129
bt = &rq->mq_hctx->tags->breserved_tags;
11351130
tag_offset = 0;
@@ -1142,19 +1137,22 @@ static bool __blk_mq_get_driver_tag(struct request *rq)
11421137
return false;
11431138

11441139
rq->tag = tag + tag_offset;
1145-
if (shared) {
1146-
rq->rq_flags |= RQF_MQ_INFLIGHT;
1147-
atomic_inc(&rq->mq_hctx->nr_active);
1148-
}
1149-
rq->mq_hctx->tags->rqs[rq->tag] = rq;
11501140
return true;
11511141
}
11521142

11531143
static bool blk_mq_get_driver_tag(struct request *rq)
11541144
{
1155-
if (rq->tag != BLK_MQ_NO_TAG)
1156-
return true;
1157-
return __blk_mq_get_driver_tag(rq);
1145+
struct blk_mq_hw_ctx *hctx = rq->mq_hctx;
1146+
1147+
if (rq->tag == BLK_MQ_NO_TAG && !__blk_mq_get_driver_tag(rq))
1148+
return false;
1149+
1150+
if (hctx->flags & BLK_MQ_F_TAG_SHARED) {
1151+
rq->rq_flags |= RQF_MQ_INFLIGHT;
1152+
atomic_inc(&hctx->nr_active);
1153+
}
1154+
hctx->tags->rqs[rq->tag] = rq;
1155+
return true;
11581156
}
11591157

11601158
static int blk_mq_dispatch_wake(wait_queue_entry_t *wait, unsigned mode,

block/blk.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ struct blk_flush_queue {
2525
struct list_head flush_data_in_flight;
2626
struct request *flush_rq;
2727

28-
/*
29-
* flush_rq shares tag with this rq, both can't be active
30-
* at the same time
31-
*/
32-
struct request *orig_rq;
3328
struct lock_class_key key;
3429
spinlock_t mq_flush_lock;
3530
};

0 commit comments

Comments
 (0)