Allow drivers to tap into tags initialization
cover Allow drivers to tap into tags initialization
Patches based upon Axboe's blk-mq/core branch
git://git.kernel.dk/linux-block.git
These two patches enable a driver to control if tags are initialized by blk-mq or itself. This allows a driver to map multiple struct blk_mq_tags to multiple hardware and share tags.
This is for example used by the NVMe, that has a limited number of queues, shared by multiple request queues.
v1->v2
* Changed blk_mq_init_tags_shared to blk_mq_tags_get.
* Moved from EXPORT_SYMBOL_GPL to EXPORT_SYMBOL
* Moved to using a flag for defining when driver handles tags initialization.
Matias Bjorling (2):
blk-mq: allow request queues to share tags map
blk-mq: add maps_tags fn and add usage
block/blk-mq-tag.c | 22 +++++++++++++++++++++- block/blk-mq.c | 18 ++++++++++-------- include/linux/blk-mq.h | 6 ++++++ 3 files changed, 37 insertions(+), 9 deletions(-)
Signature · 1 line
1.8.3.2
PATCH 1/2 blk-mq: allow request queues to share tags map
Some devices, such as NVMe, initializes a limited number of queues. These are shared by all the block devices. Allow a driver to tap into the tags structure and decide if an existing tag structure should be used.
--- block/blk-mq-tag.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
block/blk-mq-tag.c +21 -1
@@ -1,4 +1,5 @@#include <linux/kernel.h> +#include <linux/kref.h> #include <linux/module.h> #include <linux/percpu_ida.h>
@@ -18,6 +19,8 @@ struct blk_mq_tags {struct percpu_ida free_tags;struct percpu_ida reserved_tags; + +struct kref ref_count; };void blk_mq_wait_for_tags (struct blk_mq_tags *tags)
@@ -116,6 +119,12 @@ void blk_mq_tag_busy_iter(struct blk_mq_tags *tags,kfree (tag_map); } +void blk_mq_get_tags (struct blk_mq_tags *tags) +{ +kref_get (&tags->ref_count); +} +EXPORT_SYMBOL (blk_mq_get_tags); +struct blk_mq_tags *blk_mq_init_tags (unsigned int total_tags,unsigned int reserved_tags,int node) {
@@ -145,6 +154,8 @@ struct blk_mq_tags *blk_mq_init_tags(unsigned int total_tags, tags->nr_max_cache = nr_cache; tags->nr_batch_move =max (1u , nr_cache /2 ); +kref_init (&tags->ref_count); + ret = __percpu_ida_init(&tags->free_tags, tags->nr_tags - tags->nr_reserved_tags, tags->nr_max_cache,
@@ -171,14 +182,23 @@ err_free_tags:kfree (tags);return NULL ; } +EXPORT_SYMBOL (blk_mq_init_tags); -void blk_mq_free_tags (struct blk_mq_tags *tags) +static void __blk_mq_free_tags (struct kref *kref) { + struct blk_mq_tags *tags = container_of(kref, struct blk_mq_tags, + ref_count); +percpu_ida_destroy (&tags->free_tags);percpu_ida_destroy (&tags->reserved_tags);kfree (tags); } +void blk_mq_free_tags (struct blk_mq_tags *tags) +{ +kref_put (&tags->ref_count, __blk_mq_free_tags); +} +ssize_t blk_mq_tag_sysfs_show (struct blk_mq_tags *tags,char *page) {char *orig_page = page;
Signature · 1 line
1.8.3.2
PATCH 2/2 blk-mq: add maps_tags fn and add usage
In reply to Matias BjorlingNow that the tags mapping allows shared mapping, update blk-mq to allow the driver to control initialization of the tags structure.
--- block/blk-mq.c | 19 +++++++++++-------- include/linux/blk-mq.h | 6 ++++++ 2 files changed, 17 insertions(+), 8 deletions(-)
block/blk-mq.c +11 -8
@@ -1093,7 +1093,7 @@ static size_t order_to_size(unsigned int order) }static int blk_mq_init_rq_map (struct blk_mq_hw_ctx *hctx, -unsigned int reserved_tags,int node) +struct blk_mq_reg *reg,int node) {unsigned int i, j, entries_per_page, max_order =4 ;size_t rq_size, left;
@@ -1150,7 +1150,7 @@ static int blk_mq_init_rq_map(struct blk_mq_hw_ctx *hctx, } } -if (i < (reserved_tags +BLK_MQ_TAG_MIN )) +if (i < (reg->reserved_tags +BLK_MQ_TAG_MIN )) goto err_rq_map;else if (i != hctx->queue_depth) { hctx->queue_depth = i;
@@ -1158,14 +1158,17 @@ static int blk_mq_init_rq_map(struct blk_mq_hw_ctx *hctx, __func__, i); } - hctx->tags =blk_mq_init_tags (hctx->queue_depth, reserved_tags, node); -if (!hctx->tags) { +if (reg->flags & ~(BLK_MQ_F_DRV_INIT_TAGS )) { + hctx->tags =blk_mq_init_tags (hctx->queue_depth, + reg->reserved_tags, node); +if (!hctx->tags) + goto err_rq_map; + } + +return 0 ; err_rq_map:blk_mq_free_rq_map (hctx);return -ENOMEM ; - } - -return 0 ; } static int blk_mq_init_hw_queues(struct request_queue *q,
@@ -1198,7 +1201,7 @@ static int blk_mq_init_hw_queues(struct request_queue *q, blk_mq_hctx_notify, hctx);blk_mq_register_cpu_notifier (&hctx->cpu_notifier); -if (blk_mq_init_rq_map (hctx, reg->reserved_tags, node)) +if (blk_mq_init_rq_map (hctx, reg, node))break ;/*
include/linux/blk-mq.h +6 -0
@@ -107,6 +107,8 @@ enum {BLK_MQ_F_SHOULD_SORT =1 <<1 ,BLK_MQ_F_SHOULD_IPI =1 <<2 , +BLK_MQ_F_DRV_INIT_TAGS =1 <<3 , +BLK_MQ_S_STOPPED =1 <<0 , BLK_MQ_MAX_DEPTH = 2048,
@@ -138,6 +140,10 @@ void blk_mq_stop_hw_queue(struct blk_mq_hw_ctx *hctx);void blk_mq_start_hw_queue (struct blk_mq_hw_ctx *hctx);void blk_mq_start_stopped_hw_queues (struct request_queue *q); +struct blk_mq_tags *blk_mq_init_tags (unsigned int total_tags, +unsigned int reserved_tags,int node); +void blk_mq_get_tags (struct blk_mq_tags *tags); +/* * Driver command data is immediately after the request. So subtract request * size to get back to the original request.
Signature · 1 line
1.8.3.2