Skip to content

Commit 7746564

Browse files
isilenceaxboe
authored andcommitted
block: fix hctx checks for batch allocation
When there are no read queues read requests will be assigned a default queue on allocation. However, blk_mq_get_cached_request() is not prepared for that and will fail all attempts to grab read requests from the cache. Worst case it doubles the number of requests allocated, roughly half of which will be returned by blk_mq_free_plug_rqs(). It only affects batched allocations and so is io_uring specific. For reference, QD8 t/io_uring benchmark improves by 20-35%. Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/80d4511011d7d4751b4cf6375c4e38f237d935e3.1673955390.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent 9d6033e commit 7746564

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

block/blk-mq.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2890,6 +2890,7 @@ static inline struct request *blk_mq_get_cached_request(struct request_queue *q,
28902890
struct blk_plug *plug, struct bio **bio, unsigned int nsegs)
28912891
{
28922892
struct request *rq;
2893+
enum hctx_type type, hctx_type;
28932894

28942895
if (!plug)
28952896
return NULL;
@@ -2902,7 +2903,10 @@ static inline struct request *blk_mq_get_cached_request(struct request_queue *q,
29022903
return NULL;
29032904
}
29042905

2905-
if (blk_mq_get_hctx_type((*bio)->bi_opf) != rq->mq_hctx->type)
2906+
type = blk_mq_get_hctx_type((*bio)->bi_opf);
2907+
hctx_type = rq->mq_hctx->type;
2908+
if (type != hctx_type &&
2909+
!(type == HCTX_TYPE_READ && hctx_type == HCTX_TYPE_DEFAULT))
29062910
return NULL;
29072911
if (op_is_flush(rq->cmd_flags) != op_is_flush((*bio)->bi_opf))
29082912
return NULL;

0 commit comments

Comments
 (0)