Skip to content

Commit fa0fcac

Browse files
bvanasschekawasaki
authored andcommitted
block: drop shared-tag fairness throttling
Original patch [1] by Bart Van Assche; this version is rebased onto the current tree. In testing it improves IOPS by roughly 16-18% by removing the fair-sharing throttle on shared tag queues. This patch removes the following code and structure members: - The function hctx_may_queue(). - blk_mq_hw_ctx.nr_active and request_queue.nr_active_requests_shared_tags and also all the code that modifies these two member variables. [1]: https://lore.kernel.org/linux-block/[email protected]/ Signed-off-by: Bart Van Assche <[email protected]> Signed-off-by: Sumit Saxena <[email protected]>
1 parent 4263042 commit fa0fcac

7 files changed

Lines changed: 22 additions & 131 deletions

File tree

block/blk-core.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,6 @@ struct request_queue *blk_alloc_queue(struct queue_limits *lim, int node_id)
421421

422422
q->node = node_id;
423423

424-
atomic_set(&q->nr_active_requests_shared_tags, 0);
425-
426424
timer_setup(&q->timeout, blk_rq_timed_out_timer, 0);
427425
INIT_WORK(&q->timeout_work, blk_timeout_work);
428426
INIT_LIST_HEAD(&q->icq_list);

block/blk-mq-debugfs.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,11 +468,31 @@ static int hctx_sched_tags_bitmap_show(void *data, struct seq_file *m)
468468
return 0;
469469
}
470470

471+
struct count_active_params {
472+
struct blk_mq_hw_ctx *hctx;
473+
int *active;
474+
};
475+
476+
static bool hctx_count_active(struct request *rq, void *data)
477+
{
478+
const struct count_active_params *params = data;
479+
480+
if (rq->mq_hctx == params->hctx)
481+
(*params->active)++;
482+
483+
return true;
484+
}
485+
471486
static int hctx_active_show(void *data, struct seq_file *m)
472487
{
473488
struct blk_mq_hw_ctx *hctx = data;
489+
int active = 0;
490+
struct count_active_params params = { .hctx = hctx, .active = &active };
491+
492+
blk_mq_all_tag_iter(hctx->sched_tags ?: hctx->tags, hctx_count_active,
493+
&params);
474494

475-
seq_printf(m, "%d\n", __blk_mq_active_requests(hctx));
495+
seq_printf(m, "%d\n", active);
476496
return 0;
477497
}
478498

block/blk-mq-tag.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,6 @@ void __blk_mq_tag_idle(struct blk_mq_hw_ctx *hctx)
109109
static int __blk_mq_get_tag(struct blk_mq_alloc_data *data,
110110
struct sbitmap_queue *bt)
111111
{
112-
if (!data->q->elevator && !(data->flags & BLK_MQ_REQ_RESERVED) &&
113-
!hctx_may_queue(data->hctx, bt))
114-
return BLK_MQ_NO_TAG;
115-
116112
if (data->shallow_depth)
117113
return sbitmap_queue_get_shallow(bt, data->shallow_depth);
118114
else

block/blk-mq.c

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,6 @@ __blk_mq_alloc_requests_batch(struct blk_mq_alloc_data *data)
489489
}
490490
} while (data->nr_tags > nr);
491491

492-
if (!(data->rq_flags & RQF_SCHED_TAGS))
493-
blk_mq_add_active_requests(data->hctx, nr);
494492
/* caller already holds a reference, add for remainder */
495493
percpu_ref_get_many(&data->q->q_usage_counter, nr - 1);
496494
data->nr_tags -= nr;
@@ -587,8 +585,6 @@ static struct request *__blk_mq_alloc_requests(struct blk_mq_alloc_data *data)
587585
goto retry;
588586
}
589587

590-
if (!(data->rq_flags & RQF_SCHED_TAGS))
591-
blk_mq_inc_active_requests(data->hctx);
592588
rq = blk_mq_rq_ctx_init(data, blk_mq_tags_from_data(data), tag);
593589
blk_mq_rq_time_init(rq, alloc_time_ns);
594590
return rq;
@@ -763,8 +759,6 @@ struct request *blk_mq_alloc_request_hctx(struct request_queue *q,
763759
tag = blk_mq_get_tag(&data);
764760
if (tag == BLK_MQ_NO_TAG)
765761
goto out_queue_exit;
766-
if (!(data.rq_flags & RQF_SCHED_TAGS))
767-
blk_mq_inc_active_requests(data.hctx);
768762
rq = blk_mq_rq_ctx_init(&data, blk_mq_tags_from_data(&data), tag);
769763
blk_mq_rq_time_init(rq, alloc_time_ns);
770764
rq->__data_len = 0;
@@ -807,10 +801,8 @@ static void __blk_mq_free_request(struct request *rq)
807801
blk_pm_mark_last_busy(rq);
808802
rq->mq_hctx = NULL;
809803

810-
if (rq->tag != BLK_MQ_NO_TAG) {
811-
blk_mq_dec_active_requests(hctx);
804+
if (rq->tag != BLK_MQ_NO_TAG)
812805
blk_mq_put_tag(hctx->tags, ctx, rq->tag);
813-
}
814806
if (sched_tag != BLK_MQ_NO_TAG)
815807
blk_mq_put_tag(hctx->sched_tags, ctx, sched_tag);
816808
blk_mq_sched_restart(hctx);
@@ -1188,8 +1180,6 @@ static inline void blk_mq_flush_tag_batch(struct blk_mq_hw_ctx *hctx,
11881180
{
11891181
struct request_queue *q = hctx->queue;
11901182

1191-
blk_mq_sub_active_requests(hctx, nr_tags);
1192-
11931183
blk_mq_put_tags(hctx->tags, tag_array, nr_tags);
11941184
percpu_ref_put_many(&q->q_usage_counter, nr_tags);
11951185
}
@@ -1875,17 +1865,13 @@ bool __blk_mq_alloc_driver_tag(struct request *rq)
18751865
if (blk_mq_tag_is_reserved(rq->mq_hctx->sched_tags, rq->internal_tag)) {
18761866
bt = &rq->mq_hctx->tags->breserved_tags;
18771867
tag_offset = 0;
1878-
} else {
1879-
if (!hctx_may_queue(rq->mq_hctx, bt))
1880-
return false;
18811868
}
18821869

18831870
tag = __sbitmap_queue_get(bt);
18841871
if (tag == BLK_MQ_NO_TAG)
18851872
return false;
18861873

18871874
rq->tag = tag + tag_offset;
1888-
blk_mq_inc_active_requests(rq->mq_hctx);
18891875
return true;
18901876
}
18911877

@@ -4058,7 +4044,6 @@ blk_mq_alloc_hctx(struct request_queue *q, struct blk_mq_tag_set *set,
40584044
if (!zalloc_cpumask_var_node(&hctx->cpumask, gfp, node))
40594045
goto free_hctx;
40604046

4061-
atomic_set(&hctx->nr_active, 0);
40624047
if (node == NUMA_NO_NODE)
40634048
node = set->numa_node;
40644049
hctx->numa_node = node;

block/blk-mq.h

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -291,70 +291,9 @@ static inline int blk_mq_get_rq_budget_token(struct request *rq)
291291
return -1;
292292
}
293293

294-
static inline void __blk_mq_add_active_requests(struct blk_mq_hw_ctx *hctx,
295-
int val)
296-
{
297-
if (blk_mq_is_shared_tags(hctx->flags))
298-
atomic_add(val, &hctx->queue->nr_active_requests_shared_tags);
299-
else
300-
atomic_add(val, &hctx->nr_active);
301-
}
302-
303-
static inline void __blk_mq_inc_active_requests(struct blk_mq_hw_ctx *hctx)
304-
{
305-
__blk_mq_add_active_requests(hctx, 1);
306-
}
307-
308-
static inline void __blk_mq_sub_active_requests(struct blk_mq_hw_ctx *hctx,
309-
int val)
310-
{
311-
if (blk_mq_is_shared_tags(hctx->flags))
312-
atomic_sub(val, &hctx->queue->nr_active_requests_shared_tags);
313-
else
314-
atomic_sub(val, &hctx->nr_active);
315-
}
316-
317-
static inline void __blk_mq_dec_active_requests(struct blk_mq_hw_ctx *hctx)
318-
{
319-
__blk_mq_sub_active_requests(hctx, 1);
320-
}
321-
322-
static inline void blk_mq_add_active_requests(struct blk_mq_hw_ctx *hctx,
323-
int val)
324-
{
325-
if (hctx->flags & BLK_MQ_F_TAG_QUEUE_SHARED)
326-
__blk_mq_add_active_requests(hctx, val);
327-
}
328-
329-
static inline void blk_mq_inc_active_requests(struct blk_mq_hw_ctx *hctx)
330-
{
331-
if (hctx->flags & BLK_MQ_F_TAG_QUEUE_SHARED)
332-
__blk_mq_inc_active_requests(hctx);
333-
}
334-
335-
static inline void blk_mq_sub_active_requests(struct blk_mq_hw_ctx *hctx,
336-
int val)
337-
{
338-
if (hctx->flags & BLK_MQ_F_TAG_QUEUE_SHARED)
339-
__blk_mq_sub_active_requests(hctx, val);
340-
}
341-
342-
static inline void blk_mq_dec_active_requests(struct blk_mq_hw_ctx *hctx)
343-
{
344-
if (hctx->flags & BLK_MQ_F_TAG_QUEUE_SHARED)
345-
__blk_mq_dec_active_requests(hctx);
346-
}
347-
348-
static inline int __blk_mq_active_requests(struct blk_mq_hw_ctx *hctx)
349-
{
350-
if (blk_mq_is_shared_tags(hctx->flags))
351-
return atomic_read(&hctx->queue->nr_active_requests_shared_tags);
352-
return atomic_read(&hctx->nr_active);
353-
}
354294
static inline void __blk_mq_put_driver_tag(struct blk_mq_hw_ctx *hctx,
355295
struct request *rq)
356296
{
357-
blk_mq_dec_active_requests(hctx);
358297
blk_mq_put_tag(hctx->tags, rq->mq_ctx, rq->tag);
359298
rq->tag = BLK_MQ_NO_TAG;
360299
}
@@ -396,45 +335,6 @@ static inline void blk_mq_free_requests(struct list_head *list)
396335
}
397336
}
398337

399-
/*
400-
* For shared tag users, we track the number of currently active users
401-
* and attempt to provide a fair share of the tag depth for each of them.
402-
*/
403-
static inline bool hctx_may_queue(struct blk_mq_hw_ctx *hctx,
404-
struct sbitmap_queue *bt)
405-
{
406-
unsigned int depth, users;
407-
408-
if (!hctx || !(hctx->flags & BLK_MQ_F_TAG_QUEUE_SHARED))
409-
return true;
410-
411-
/*
412-
* Don't try dividing an ant
413-
*/
414-
if (bt->sb.depth == 1)
415-
return true;
416-
417-
if (blk_mq_is_shared_tags(hctx->flags)) {
418-
struct request_queue *q = hctx->queue;
419-
420-
if (!test_bit(QUEUE_FLAG_HCTX_ACTIVE, &q->queue_flags))
421-
return true;
422-
} else {
423-
if (!test_bit(BLK_MQ_S_TAG_ACTIVE, &hctx->state))
424-
return true;
425-
}
426-
427-
users = READ_ONCE(hctx->tags->active_queues);
428-
if (!users)
429-
return true;
430-
431-
/*
432-
* Allow at least some tags
433-
*/
434-
depth = max((bt->sb.depth + users - 1) / users, 4U);
435-
return __blk_mq_active_requests(hctx) < depth;
436-
}
437-
438338
/* run the code block in @dispatch_ops with rcu/srcu read lock held */
439339
#define __blk_mq_run_dispatch_ops(q, check_sleep, dispatch_ops) \
440340
do { \

include/linux/blk-mq.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -432,12 +432,6 @@ struct blk_mq_hw_ctx {
432432
/** @queue_num: Index of this hardware queue. */
433433
unsigned int queue_num;
434434

435-
/**
436-
* @nr_active: Number of active requests. Only used when a tag set is
437-
* shared across request queues.
438-
*/
439-
atomic_t nr_active;
440-
441435
/** @cpuhp_online: List to store request if CPU is going to die */
442436
struct hlist_node cpuhp_online;
443437
/** @cpuhp_dead: List to store request if some CPU die. */

include/linux/blkdev.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,8 +567,6 @@ struct request_queue {
567567
struct timer_list timeout;
568568
struct work_struct timeout_work;
569569

570-
atomic_t nr_active_requests_shared_tags;
571-
572570
struct blk_mq_tags *sched_shared_tags;
573571

574572
struct list_head icq_list;

0 commit comments

Comments
 (0)