mirror of https://gitee.com/openkylin/linux.git
blk-mq: Some tag allocation code refactoring
The tag allocation code to alloc the sbitmap pairs is common for regular bitmaps tags and shared sbitmap, so refactor into a common function. Also remove superfluous "flags" argument from blk_mq_init_shared_sbitmap(). Signed-off-by: John Garry <john.garry@huawei.com> Reviewed-by: Ming Lei <ming.lei@redhat.com> Link: https://lore.kernel.org/r/1620907258-30910-2-git-send-email-john.garry@huawei.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
364b61818f
commit
56b68085e5
|
@ -471,39 +471,54 @@ static int bt_alloc(struct sbitmap_queue *bt, unsigned int depth,
|
||||||
node);
|
node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int blk_mq_init_bitmaps(struct sbitmap_queue *bitmap_tags,
|
||||||
|
struct sbitmap_queue *breserved_tags,
|
||||||
|
unsigned int queue_depth, unsigned int reserved,
|
||||||
|
int node, int alloc_policy)
|
||||||
|
{
|
||||||
|
unsigned int depth = queue_depth - reserved;
|
||||||
|
bool round_robin = alloc_policy == BLK_TAG_ALLOC_RR;
|
||||||
|
|
||||||
|
if (bt_alloc(bitmap_tags, depth, round_robin, node))
|
||||||
|
return -ENOMEM;
|
||||||
|
if (bt_alloc(breserved_tags, reserved, round_robin, node))
|
||||||
|
goto free_bitmap_tags;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
free_bitmap_tags:
|
||||||
|
sbitmap_queue_free(bitmap_tags);
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
static int blk_mq_init_bitmap_tags(struct blk_mq_tags *tags,
|
static int blk_mq_init_bitmap_tags(struct blk_mq_tags *tags,
|
||||||
int node, int alloc_policy)
|
int node, int alloc_policy)
|
||||||
{
|
{
|
||||||
unsigned int depth = tags->nr_tags - tags->nr_reserved_tags;
|
int ret;
|
||||||
bool round_robin = alloc_policy == BLK_TAG_ALLOC_RR;
|
|
||||||
|
|
||||||
if (bt_alloc(&tags->__bitmap_tags, depth, round_robin, node))
|
ret = blk_mq_init_bitmaps(&tags->__bitmap_tags,
|
||||||
return -ENOMEM;
|
&tags->__breserved_tags,
|
||||||
if (bt_alloc(&tags->__breserved_tags, tags->nr_reserved_tags,
|
tags->nr_tags, tags->nr_reserved_tags,
|
||||||
round_robin, node))
|
node, alloc_policy);
|
||||||
goto free_bitmap_tags;
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
tags->bitmap_tags = &tags->__bitmap_tags;
|
tags->bitmap_tags = &tags->__bitmap_tags;
|
||||||
tags->breserved_tags = &tags->__breserved_tags;
|
tags->breserved_tags = &tags->__breserved_tags;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
free_bitmap_tags:
|
|
||||||
sbitmap_queue_free(&tags->__bitmap_tags);
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int blk_mq_init_shared_sbitmap(struct blk_mq_tag_set *set, unsigned int flags)
|
int blk_mq_init_shared_sbitmap(struct blk_mq_tag_set *set)
|
||||||
{
|
{
|
||||||
unsigned int depth = set->queue_depth - set->reserved_tags;
|
|
||||||
int alloc_policy = BLK_MQ_FLAG_TO_ALLOC_POLICY(set->flags);
|
int alloc_policy = BLK_MQ_FLAG_TO_ALLOC_POLICY(set->flags);
|
||||||
bool round_robin = alloc_policy == BLK_TAG_ALLOC_RR;
|
int i, ret;
|
||||||
int i, node = set->numa_node;
|
|
||||||
|
|
||||||
if (bt_alloc(&set->__bitmap_tags, depth, round_robin, node))
|
ret = blk_mq_init_bitmaps(&set->__bitmap_tags, &set->__breserved_tags,
|
||||||
return -ENOMEM;
|
set->queue_depth, set->reserved_tags,
|
||||||
if (bt_alloc(&set->__breserved_tags, set->reserved_tags,
|
set->numa_node, alloc_policy);
|
||||||
round_robin, node))
|
if (ret)
|
||||||
goto free_bitmap_tags;
|
return ret;
|
||||||
|
|
||||||
for (i = 0; i < set->nr_hw_queues; i++) {
|
for (i = 0; i < set->nr_hw_queues; i++) {
|
||||||
struct blk_mq_tags *tags = set->tags[i];
|
struct blk_mq_tags *tags = set->tags[i];
|
||||||
|
@ -513,9 +528,6 @@ int blk_mq_init_shared_sbitmap(struct blk_mq_tag_set *set, unsigned int flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
free_bitmap_tags:
|
|
||||||
sbitmap_queue_free(&set->__bitmap_tags);
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void blk_mq_exit_shared_sbitmap(struct blk_mq_tag_set *set)
|
void blk_mq_exit_shared_sbitmap(struct blk_mq_tag_set *set)
|
||||||
|
|
|
@ -32,11 +32,14 @@ extern struct blk_mq_tags *blk_mq_init_tags(unsigned int nr_tags,
|
||||||
unsigned int reserved_tags,
|
unsigned int reserved_tags,
|
||||||
int node, unsigned int flags);
|
int node, unsigned int flags);
|
||||||
extern void blk_mq_free_tags(struct blk_mq_tags *tags, unsigned int flags);
|
extern void blk_mq_free_tags(struct blk_mq_tags *tags, unsigned int flags);
|
||||||
|
extern int blk_mq_init_bitmaps(struct sbitmap_queue *bitmap_tags,
|
||||||
|
struct sbitmap_queue *breserved_tags,
|
||||||
|
unsigned int queue_depth,
|
||||||
|
unsigned int reserved,
|
||||||
|
int node, int alloc_policy);
|
||||||
|
|
||||||
extern int blk_mq_init_shared_sbitmap(struct blk_mq_tag_set *set,
|
extern int blk_mq_init_shared_sbitmap(struct blk_mq_tag_set *set);
|
||||||
unsigned int flags);
|
|
||||||
extern void blk_mq_exit_shared_sbitmap(struct blk_mq_tag_set *set);
|
extern void blk_mq_exit_shared_sbitmap(struct blk_mq_tag_set *set);
|
||||||
|
|
||||||
extern unsigned int blk_mq_get_tag(struct blk_mq_alloc_data *data);
|
extern unsigned int blk_mq_get_tag(struct blk_mq_alloc_data *data);
|
||||||
extern void blk_mq_put_tag(struct blk_mq_tags *tags, struct blk_mq_ctx *ctx,
|
extern void blk_mq_put_tag(struct blk_mq_tags *tags, struct blk_mq_ctx *ctx,
|
||||||
unsigned int tag);
|
unsigned int tag);
|
||||||
|
|
|
@ -3564,7 +3564,7 @@ int blk_mq_alloc_tag_set(struct blk_mq_tag_set *set)
|
||||||
if (blk_mq_is_sbitmap_shared(set->flags)) {
|
if (blk_mq_is_sbitmap_shared(set->flags)) {
|
||||||
atomic_set(&set->active_queues_shared_sbitmap, 0);
|
atomic_set(&set->active_queues_shared_sbitmap, 0);
|
||||||
|
|
||||||
if (blk_mq_init_shared_sbitmap(set, set->flags)) {
|
if (blk_mq_init_shared_sbitmap(set)) {
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto out_free_mq_rq_maps;
|
goto out_free_mq_rq_maps;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue