Skip to contentSkip to conversation

blk-mq: use hctx->nr_ctx to compute size of percpu tag cache

RFC PATCH New Ming Lei 1 participant 1 message Apr 23, 2014 Block layer

lore
Share & tools
lore

Ming Lei

author
#0 lore raw

RFC PATCH 1/1 blk-mq: use hctx->nr_ctx to compute size of percpu tag cache

The idea behind the patch is simple: if there are only part of CPUs mapped to one hw queue, set the size of percpu tag cache as total tags divided by count of these CPUs, instead of all CPUs, then percpu tag allocation will become more efficient than before.

The change is a bit complicated, because:

- Christoph introduces tag set, so the tags can be shared by more than one request queue, and the patch delays tags' allocation until request queue's initialization

- hctx->nr_ctx's computing need to take account of cpu hotplug

With the patch, the below test on one quad core SMP VM:

#modprobe null_blk irqmode=2 hw_queue_depth=16 submit_queues=4

shows percpu tag allocation is much more efficient than before,
- for boot CPU, allocation from local CPU increases from ~5% to ~50%
- for non-boot CPUs, allocation from local CPU increases from ~30% to ~90%

---
 block/blk-mq-tag.c     |    9 ++--
 block/blk-mq-tag.h     |    4 +-
 block/blk-mq.c         |  124 +++++++++++++++++++++++++++++++++---------------
 include/linux/blk-mq.h |    1 +
 include/linux/blkdev.h |    1 +
 5 files changed, 98 insertions(+), 41 deletions(-)
block/blk-mq-tag.c +6 -3
index 7a799c4..117d3cc 100644
@@ -104,10 +104,11 @@ void blk_mq_tag_busy_iter(struct blk_mq_tags *tags,
 	kfree(tag_map);
 }
 
-struct blk_mq_tags *blk_mq_init_tags(unsigned int total_tags,
+struct blk_mq_tags *blk_mq_init_tags(struct blk_mq_hw_ctx *hctx,
+				     unsigned int total_tags,
 				     unsigned int reserved_tags, int node)
 {
-	unsigned int nr_tags, nr_cache;
+	unsigned int nr_tags, nr_cache, nr_cnt;
 	struct blk_mq_tags *tags;
 	int ret;
 
@@ -121,7 +122,9 @@ struct blk_mq_tags *blk_mq_init_tags(unsigned int total_tags,
 		return NULL;
 
 	nr_tags = total_tags - reserved_tags;
-	nr_cache = nr_tags / num_possible_cpus();
+
+	nr_cnt = hctx->nr_ctx ? hctx->nr_ctx : 1;
+	nr_cache = nr_tags / nr_cnt;
 
 	if (nr_cache < BLK_MQ_TAG_CACHE_MIN)
 		nr_cache = BLK_MQ_TAG_CACHE_MIN;
block/blk-mq-tag.h +3 -1
index b602e3f..2796a8d 100644
@@ -20,7 +20,9 @@ struct blk_mq_tags {
 };
 
 
-extern struct blk_mq_tags *blk_mq_init_tags(unsigned int nr_tags, unsigned int reserved_tags, int node);
+extern struct blk_mq_tags *blk_mq_init_tags(struct blk_mq_hw_ctx *hctx,
+				     unsigned int total_tags,
+				     unsigned int reserved_tags, int node);
 extern void blk_mq_free_tags(struct blk_mq_tags *tags);
 
 extern unsigned int blk_mq_get_tag(struct blk_mq_tags *tags, gfp_t gfp, bool reserved);
block/blk-mq.c +87 -37

206 lines not on this page · raw message

include/linux/blk-mq.h +1 -0
index ab469d5..7fb0b15 100644
@@ -123,6 +123,7 @@ enum {
 	BLK_MQ_F_SHOULD_MERGE	= 1 << 0,
 	BLK_MQ_F_SHOULD_SORT	= 1 << 1,
 	BLK_MQ_F_SHOULD_IPI	= 1 << 2,
+	BLK_MQ_F_TAG_ALLOCATED	= 1 << 3,
 
 	BLK_MQ_S_STOPPED	= 0,
 
include/linux/blkdev.h +1 -0
index 74ee55f..b6278f2 100644
@@ -330,6 +330,7 @@ struct request_queue {
 	dma_drain_needed_fn	*dma_drain_needed;
 	lld_busy_fn		*lld_busy_fn;
 
+	struct blk_mq_tag_set	*set;
 	struct blk_mq_ops	*mq_ops;
 
 	unsigned int		*mq_map;
Signature · 1 line
1.7.9.5