Skip to content

Commit f98afe4

Browse files
hailan94axboe
authored andcommitted
blk-mq: add a new queue sysfs attribute async_depth
Add a new field async_depth to request_queue and related APIs, this is currently not used, following patches will convert elevators to use this instead of internal async_depth. Signed-off-by: Yu Kuai <yukuai@fnnas.com> Reviewed-by: Nilay Shroff <nilay@linux.ibm.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent cf02d7d commit f98afe4

5 files changed

Lines changed: 51 additions & 0 deletions

File tree

block/blk-core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ struct request_queue *blk_alloc_queue(struct queue_limits *lim, int node_id)
463463
fs_reclaim_release(GFP_KERNEL);
464464

465465
q->nr_requests = BLKDEV_DEFAULT_RQ;
466+
q->async_depth = BLKDEV_DEFAULT_RQ;
466467

467468
return q;
468469

block/blk-mq.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4662,6 +4662,7 @@ int blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,
46624662
spin_lock_init(&q->requeue_lock);
46634663

46644664
q->nr_requests = set->queue_depth;
4665+
q->async_depth = set->queue_depth;
46654666

46664667
blk_mq_init_cpu_queues(q, set->nr_hw_queues);
46674668
blk_mq_map_swqueue(q);
@@ -5028,6 +5029,11 @@ struct elevator_tags *blk_mq_update_nr_requests(struct request_queue *q,
50285029
q->elevator->et = et;
50295030
}
50305031

5032+
/*
5033+
* Preserve relative value, both nr and async_depth are at most 16 bit
5034+
* value, no need to worry about overflow.
5035+
*/
5036+
q->async_depth = max(q->async_depth * nr / q->nr_requests, 1);
50315037
q->nr_requests = nr;
50325038
if (q->elevator && q->elevator->type->ops.depth_updated)
50335039
q->elevator->type->ops.depth_updated(q);

block/blk-sysfs.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,46 @@ queue_requests_store(struct gendisk *disk, const char *page, size_t count)
127127
return ret;
128128
}
129129

130+
static ssize_t queue_async_depth_show(struct gendisk *disk, char *page)
131+
{
132+
guard(mutex)(&disk->queue->elevator_lock);
133+
134+
return queue_var_show(disk->queue->async_depth, page);
135+
}
136+
137+
static ssize_t
138+
queue_async_depth_store(struct gendisk *disk, const char *page, size_t count)
139+
{
140+
struct request_queue *q = disk->queue;
141+
unsigned int memflags;
142+
unsigned long nr;
143+
int ret;
144+
145+
if (!queue_is_mq(q))
146+
return -EINVAL;
147+
148+
ret = queue_var_store(&nr, page, count);
149+
if (ret < 0)
150+
return ret;
151+
152+
if (nr == 0)
153+
return -EINVAL;
154+
155+
memflags = blk_mq_freeze_queue(q);
156+
scoped_guard(mutex, &q->elevator_lock) {
157+
if (q->elevator) {
158+
q->async_depth = min(q->nr_requests, nr);
159+
if (q->elevator->type->ops.depth_updated)
160+
q->elevator->type->ops.depth_updated(q);
161+
} else {
162+
ret = -EINVAL;
163+
}
164+
}
165+
blk_mq_unfreeze_queue(q, memflags);
166+
167+
return ret;
168+
}
169+
130170
static ssize_t queue_ra_show(struct gendisk *disk, char *page)
131171
{
132172
ssize_t ret;
@@ -532,6 +572,7 @@ static struct queue_sysfs_entry _prefix##_entry = { \
532572
}
533573

534574
QUEUE_RW_ENTRY(queue_requests, "nr_requests");
575+
QUEUE_RW_ENTRY(queue_async_depth, "async_depth");
535576
QUEUE_RW_ENTRY(queue_ra, "read_ahead_kb");
536577
QUEUE_LIM_RW_ENTRY(queue_max_sectors, "max_sectors_kb");
537578
QUEUE_LIM_RO_ENTRY(queue_max_hw_sectors, "max_hw_sectors_kb");
@@ -719,6 +760,7 @@ static struct attribute *blk_mq_queue_attrs[] = {
719760
*/
720761
&elv_iosched_entry.attr,
721762
&queue_requests_entry.attr,
763+
&queue_async_depth_entry.attr,
722764
#ifdef CONFIG_BLK_WBT
723765
&queue_wb_lat_entry.attr,
724766
#endif

block/elevator.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ static int elevator_switch(struct request_queue *q, struct elv_change_ctx *ctx)
589589
blk_queue_flag_clear(QUEUE_FLAG_SQ_SCHED, q);
590590
q->elevator = NULL;
591591
q->nr_requests = q->tag_set->queue_depth;
592+
q->async_depth = q->tag_set->queue_depth;
592593
}
593594
blk_add_trace_msg(q, "elv switch: %s", ctx->name);
594595

include/linux/blkdev.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ struct request_queue {
551551
* queue settings
552552
*/
553553
unsigned int nr_requests; /* Max # of requests */
554+
unsigned int async_depth; /* Max # of async requests */
554555

555556
#ifdef CONFIG_BLK_INLINE_ENCRYPTION
556557
struct blk_crypto_profile *crypto_profile;

0 commit comments

Comments
 (0)