Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754802AbcCYVg4 (ORCPT ); Fri, 25 Mar 2016 17:36:56 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:11505 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754706AbcCYVgf (ORCPT ); Fri, 25 Mar 2016 17:36:35 -0400 From: Shaohua Li To: , CC: , , Subject: [PATCH 1/3] blk-mq: add an API to estimate hardware queue node Date: Fri, 25 Mar 2016 14:36:30 -0700 Message-ID: <68fed570910230ce847f8f3b685eeea399640a7f.1458941500.git.shli@fb.com> X-Mailer: git-send-email 2.8.0.rc2 X-FB-Internal: Safe MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-03-25_06:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1997 Lines: 60 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 --- 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