[PATCH 1/3] blk-mq: add an API to estimate hardware queue node

From: Shaohua Li
Date: Fri Mar 25 2016 - 17:36:57 EST


we allocate most data structure in device's node, but some data
structures are not for DMA and mostly used by specific cpus/node which
could diff from device's node. Allocating such hot data in device's
node doesn't make sense. Add an API to estimate hardware queue node.
This can be used before blk-mq actually establishes the mapping. This
API runs slow, but it only used in initialization time.

Signed-off-by: Shaohua Li <shli@xxxxxx>
---
block/blk-mq.c | 21 +++++++++++++++++++++
include/linux/blk-mq.h | 2 ++
2 files changed, 23 insertions(+)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 050f7a1..ec214d3 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -2330,6 +2330,27 @@ void blk_mq_free_tag_set(struct blk_mq_tag_set *set)
}
EXPORT_SYMBOL(blk_mq_free_tag_set);

+int blk_mq_estimate_hw_queue_node(unsigned int total_queues,
+ unsigned int index)
+{
+ unsigned int *map;
+ int node;
+
+ if (total_queues == 1)
+ return NUMA_NO_NODE;
+ map = kzalloc(sizeof(*map) * nr_cpu_ids, GFP_KERNEL);
+ if (!map)
+ return NUMA_NO_NODE;
+ if (blk_mq_update_queue_map(map, total_queues, cpu_online_mask)) {
+ kfree(map);
+ return NUMA_NO_NODE;
+ }
+ node = blk_mq_hw_queue_to_node(map, index);
+ kfree(map);
+ return node;
+}
+EXPORT_SYMBOL(blk_mq_estimate_hw_queue_node);
+
int blk_mq_update_nr_requests(struct request_queue *q, unsigned int nr)
{
struct blk_mq_tag_set *set = q->tag_set;
diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h
index 15a73d4..892b41b 100644
--- a/include/linux/blk-mq.h
+++ b/include/linux/blk-mq.h
@@ -188,6 +188,8 @@ void blk_mq_insert_request(struct request *, bool, bool, bool);
void blk_mq_free_request(struct request *rq);
void blk_mq_free_hctx_request(struct blk_mq_hw_ctx *, struct request *rq);
bool blk_mq_can_queue(struct blk_mq_hw_ctx *);
+int blk_mq_estimate_hw_queue_node(unsigned int total_queues,
+ unsigned int index);

enum {
BLK_MQ_REQ_NOWAIT = (1 << 0), /* return when out of requests */
--
2.8.0.rc2