blk-mq-sched: use q->queue_depth as hint for q->nr_requests
cover blk-mq-sched: use q->queue_depth as hint for q->nr_requests
This two patches improves computation of default queue depth of scheduler queue by using q->queue_depth.
Ming Lei (2):
blk-mq-sched: introduce blk_mq_sched_queue_depth()
blk-mq-sched: use q->queue_depth as hint for q->nr_requests
block/blk-mq-sched.c | 8 +------- block/blk-mq-sched.h | 23 +++++++++++++++++++++++ block/blk-mq.c | 27 +++++++++++++++++++++++++-- block/blk-mq.h | 1 + block/blk-settings.c | 2 ++ 5 files changed, 52 insertions(+), 9 deletions(-)
Signature · 1 line
2.9.4
PATCH 1/2 blk-mq-sched: introduce blk_mq_sched_queue_depth()
The following patch will propose some hints to figure out default queue depth for scheduler queue, so introduce helper of blk_mq_sched_queue_depth() for this purpose.
--- block/blk-mq-sched.c | 8 +------- block/blk-mq-sched.h | 11 +++++++++++ 2 files changed, 12 insertions(+), 7 deletions(-)
block/blk-mq-sched.c +1 -7
@@ -514,13 +514,7 @@ int blk_mq_init_sched(struct request_queue *q, struct elevator_type *e)return 0 ; } -/* -* Default to double of smaller one between hw queue_depth and 128, -* since we don't split into sync/async like the old code did. -* Additionally, this is a per-hw queue depth. -*/ - q->nr_requests = 2 * min_t(unsigned int, q->tag_set->queue_depth, -BLKDEV_MAX_RQ ); + q->nr_requests =blk_mq_sched_queue_depth (q);queue_for_each_hw_ctx (q, hctx, i) { ret =blk_mq_sched_alloc_tags (q, hctx, i);
block/blk-mq-sched.h +11 -0
@@ -96,4 +96,15 @@ static inline bool blk_mq_sched_needs_restart(struct blk_mq_hw_ctx *hctx)return test_bit (BLK_MQ_S_SCHED_RESTART , &hctx->state); } +static inline unsigned blk_mq_sched_queue_depth (struct request_queue *q) +{ +/* +* Default to double of smaller one between hw queue_depth and 128, +* since we don't split into sync/async like the old code did. +* Additionally, this is a per-hw queue depth. +*/ + return 2 * min_t(unsigned int, q->tag_set->queue_depth, +BLKDEV_MAX_RQ ); +} +#endif
Signature · 1 line
2.9.4
Re: [PATCH 1/2] blk-mq-sched: introduce blk_mq_sched_queue_depth()
Looks fine,
PATCH 2/2 blk-mq-sched: use q->queue_depth as hint for q->nr_requests
In reply to Ming LeiSCSI sets q->queue_depth from shost->cmd_per_lun, and q->queue_depth is per request_queue and more related to scheduler queue compared with hw queue depth, which can be shared by queues, such as TAG_SHARED.
This patch trys to use q->queue_depth as hint for computing q->nr_requests, which should be more effective than current way.
--- block/blk-mq-sched.h | 18 +++++++++++++++--- block/blk-mq.c | 27 +++++++++++++++++++++++++-- block/blk-mq.h | 1 + block/blk-settings.c | 2 ++ 4 files changed, 43 insertions(+), 5 deletions(-)
block/blk-mq-sched.h +15 -3
@@ -99,12 +99,24 @@ static inline bool blk_mq_sched_needs_restart(struct blk_mq_hw_ctx *hctx)static inline unsigned blk_mq_sched_queue_depth (struct request_queue *q) {/* -* Default to double of smaller one between hw queue_depth and 128, +* q->queue_depth is more close to scheduler queue, so use it +* as hint for computing scheduler queue depth if it is valid +*/ +unsigned q_depth = q->queue_depth ?: q->tag_set->queue_depth; + +/* +* Default to double of smaller one between queue depth and 128, * since we don't split into sync/async like the old code did. * Additionally, this is a per-hw queue depth. */ - return 2 * min_t(unsigned int, q->tag_set->queue_depth, -BLKDEV_MAX_RQ ); + q_depth = 2 * min_t(unsigned int, q_depth, BLKDEV_MAX_RQ); + +/* +* when queue depth of driver is too small, we set queue depth +* of scheduler queue as 32 so that small queue device still +* can benefit from IO merging. +*/ +return max_t (unsigned, q_depth,32 ); }#endif
block/blk-mq.c +25 -2
@@ -2558,7 +2558,9 @@ void blk_mq_free_tag_set(struct blk_mq_tag_set *set) }EXPORT_SYMBOL (blk_mq_free_tag_set); -int blk_mq_update_nr_requests (struct request_queue *q,unsigned int nr) +static int __blk_mq_update_nr_requests (struct request_queue *q, +bool sched_only, +unsigned int nr) {struct blk_mq_tag_set *set = q->tag_set;struct blk_mq_hw_ctx *hctx;
@@ -2577,7 +2579,7 @@ int blk_mq_update_nr_requests(struct request_queue *q, unsigned int nr)* If we're using an MQ scheduler, just update the scheduler * queue depth. This is similar to what the old code would do. */ -if (!hctx->sched_tags) { +if (!sched_only && !hctx->sched_tags) { ret =blk_mq_tag_update_depth (hctx, &hctx->tags,min (nr, set->queue_depth), false);
@@ -2597,6 +2599,27 @@ int blk_mq_update_nr_requests(struct request_queue *q, unsigned int nr)return ret; } +int blk_mq_update_nr_requests (struct request_queue *q,unsigned int nr) +{ +return __blk_mq_update_nr_requests (q, false, nr); +} + +/* +* When drivers update q->queue_depth, this API is called so that +* we can use this queue depth as hint for adjusting scheduler +* queue depth. +*/ +int blk_mq_update_sched_queue_depth (struct request_queue *q) +{ +unsigned nr; + +if (!q->mq_ops || !q->elevator) +return 0 ; + + nr =blk_mq_sched_queue_depth (q); +return __blk_mq_update_nr_requests (q, true, nr); +} +static void __blk_mq_update_nr_hw_queues (struct blk_mq_tag_set *set,int nr_hw_queues) {
block/blk-mq.h +1 -0
@@ -35,6 +35,7 @@ void blk_mq_flush_busy_ctxs(struct blk_mq_hw_ctx *hctx, struct list_head *list);bool blk_mq_hctx_has_pending (struct blk_mq_hw_ctx *hctx);bool blk_mq_get_driver_tag (struct request *rq,struct blk_mq_hw_ctx **hctx,bool wait); +int blk_mq_update_sched_queue_depth (struct request_queue *q);/* * Internal helpers for allocating/freeing the request map
block/blk-settings.c +2 -0
@@ -877,6 +877,8 @@ void blk_set_queue_depth(struct request_queue *q, unsigned int depth) { q->queue_depth = depth;wbt_set_queue_depth (q->rq_wb, depth); + +WARN_ON (blk_mq_update_sched_queue_depth (q)); }EXPORT_SYMBOL (blk_set_queue_depth);
Signature · 1 line
2.9.4
This looks pretty reasonable: