* [PATCH 1/2] blk-mq: allocate blk_mq_tags and requests in correct node
@ 2017-02-01 4:25 Shaohua Li
2017-02-01 4:25 ` [PATCH 2/2] nvme: allocate nvme_queue " Shaohua Li
2017-02-01 9:32 ` [PATCH 1/2] blk-mq: allocate blk_mq_tags and requests " Christoph Hellwig
0 siblings, 2 replies; 4+ messages in thread
From: Shaohua Li @ 2017-02-01 4:25 UTC (permalink / raw)
To: linux-kernel, linux-block; +Cc: hch, axboe
blk_mq_tags/requests of specific hardware queue are mostly used in
specific cpus, which might not be in the same numa node as disk. For
example, a nvme card is in node 0. half hardware queue will be used by
node 0, the other node 1.
Signed-off-by: Shaohua Li <shli@fb.com>
---
block/blk-mq.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/block/blk-mq.c b/block/blk-mq.c
index c3400b5..90a37ba 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -1594,9 +1594,13 @@ static struct blk_mq_tags *blk_mq_init_rq_map(struct blk_mq_tag_set *set,
struct blk_mq_tags *tags;
unsigned int i, j, entries_per_page, max_order = 4;
size_t rq_size, left;
+ int node;
+
+ node = blk_mq_hw_queue_to_node(set->mq_map, hctx_idx);
+ if (node == NUMA_NO_NODE)
+ node = set->numa_node;
- tags = blk_mq_init_tags(set->queue_depth, set->reserved_tags,
- set->numa_node,
+ tags = blk_mq_init_tags(set->queue_depth, set->reserved_tags, node,
BLK_MQ_FLAG_TO_ALLOC_POLICY(set->flags));
if (!tags)
return NULL;
@@ -1605,7 +1609,7 @@ static struct blk_mq_tags *blk_mq_init_rq_map(struct blk_mq_tag_set *set,
tags->rqs = kzalloc_node(set->queue_depth * sizeof(struct request *),
GFP_NOIO | __GFP_NOWARN | __GFP_NORETRY,
- set->numa_node);
+ node);
if (!tags->rqs) {
blk_mq_free_tags(tags);
return NULL;
@@ -1629,7 +1633,7 @@ static struct blk_mq_tags *blk_mq_init_rq_map(struct blk_mq_tag_set *set,
this_order--;
do {
- page = alloc_pages_node(set->numa_node,
+ page = alloc_pages_node(node,
GFP_NOIO | __GFP_NOWARN | __GFP_NORETRY | __GFP_ZERO,
this_order);
if (page)
@@ -1660,7 +1664,7 @@ static struct blk_mq_tags *blk_mq_init_rq_map(struct blk_mq_tag_set *set,
if (set->ops->init_request) {
if (set->ops->init_request(set->driver_data,
tags->rqs[i], hctx_idx, i,
- set->numa_node)) {
+ node)) {
tags->rqs[i] = NULL;
goto fail;
}
--
2.9.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] nvme: allocate nvme_queue in correct node
2017-02-01 4:25 [PATCH 1/2] blk-mq: allocate blk_mq_tags and requests in correct node Shaohua Li
@ 2017-02-01 4:25 ` Shaohua Li
2017-02-01 9:34 ` Christoph Hellwig
2017-02-01 9:32 ` [PATCH 1/2] blk-mq: allocate blk_mq_tags and requests " Christoph Hellwig
1 sibling, 1 reply; 4+ messages in thread
From: Shaohua Li @ 2017-02-01 4:25 UTC (permalink / raw)
To: linux-kernel, linux-block; +Cc: hch, axboe
nvme_queue is per-cpu queue (mostly). Allocating it in node where blk-mq
will use it.
Signed-off-by: Shaohua Li <shli@fb.com>
---
drivers/nvme/host/pci.c | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 3faefab..f81c0ed 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -1041,9 +1041,10 @@ static int nvme_alloc_sq_cmds(struct nvme_dev *dev, struct nvme_queue *nvmeq,
}
static struct nvme_queue *nvme_alloc_queue(struct nvme_dev *dev, int qid,
- int depth)
+ int depth, int node)
{
- struct nvme_queue *nvmeq = kzalloc(sizeof(*nvmeq), GFP_KERNEL);
+ struct nvme_queue *nvmeq = kzalloc_node(sizeof(*nvmeq), GFP_KERNEL,
+ node);
if (!nvmeq)
return NULL;
@@ -1219,7 +1220,8 @@ static int nvme_configure_admin_queue(struct nvme_dev *dev)
nvmeq = dev->queues[0];
if (!nvmeq) {
- nvmeq = nvme_alloc_queue(dev, 0, NVME_AQ_DEPTH);
+ nvmeq = nvme_alloc_queue(dev, 0, NVME_AQ_DEPTH,
+ dev_to_node(dev->dev));
if (!nvmeq)
return -ENOMEM;
}
@@ -1309,9 +1311,18 @@ static int nvme_create_io_queues(struct nvme_dev *dev)
{
unsigned i, max;
int ret = 0;
+ const struct cpumask *mask;
for (i = dev->queue_count; i <= dev->max_qid; i++) {
- if (!nvme_alloc_queue(dev, i, dev->q_depth)) {
+ int node = dev_to_node(dev->dev);
+
+ mask = pci_irq_get_affinity(to_pci_dev(dev->dev), i);
+ if (mask) {
+ node = cpu_to_node(cpumask_first(mask));
+ node = local_memory_node(node);
+ }
+
+ if (!nvme_alloc_queue(dev, i, dev->q_depth, node)) {
ret = -ENOMEM;
break;
}
--
2.9.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] blk-mq: allocate blk_mq_tags and requests in correct node
2017-02-01 4:25 [PATCH 1/2] blk-mq: allocate blk_mq_tags and requests in correct node Shaohua Li
2017-02-01 4:25 ` [PATCH 2/2] nvme: allocate nvme_queue " Shaohua Li
@ 2017-02-01 9:32 ` Christoph Hellwig
1 sibling, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2017-02-01 9:32 UTC (permalink / raw)
To: Shaohua Li; +Cc: linux-kernel, linux-block, hch, axboe
Hi Shaohua,
the code your patching has changed a lot in Jens' tree, so I think
you'll have to respin it. But the idea looks fine.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] nvme: allocate nvme_queue in correct node
2017-02-01 4:25 ` [PATCH 2/2] nvme: allocate nvme_queue " Shaohua Li
@ 2017-02-01 9:34 ` Christoph Hellwig
0 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2017-02-01 9:34 UTC (permalink / raw)
To: Shaohua Li; +Cc: linux-kernel, linux-block, hch, axboe
> + mask = pci_irq_get_affinity(to_pci_dev(dev->dev), i);
> + if (mask) {
> + node = cpu_to_node(cpumask_first(mask));
> + node = local_memory_node(node);
> + }
Can you move this to a PCI-layer helper, e.g. something like:
int pci_irq_get_node(struct pci_dev *dev, unsigned vec)
{
const struct cpumask *mask = pci_irq_get_affinity(dev), i);
if (mask)
return local_memory_node(cpu_to_node(cpumask_first(mask)));
return dev_to_node(&dev->dev);
}
Otherwise this looks fine.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-02-01 9:34 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-01 4:25 [PATCH 1/2] blk-mq: allocate blk_mq_tags and requests in correct node Shaohua Li
2017-02-01 4:25 ` [PATCH 2/2] nvme: allocate nvme_queue " Shaohua Li
2017-02-01 9:34 ` Christoph Hellwig
2017-02-01 9:32 ` [PATCH 1/2] blk-mq: allocate blk_mq_tags and requests " Christoph Hellwig
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).