mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: luferry <luferry@163.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: Dongli Zhang <dongli.zhang@oracle.com>,
	Ming Lei <ming.lei@redhat.com>, Christoph Hellwig <hch@lst.de>,
	xuyun <luferry@163.com>,
	linux-block@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] make blk_mq_map_queues more friendly for cpu topology
Date: Mon, 25 Mar 2019 23:26:40 +0800	[thread overview]
Message-ID: <20190325152640.48120-1-luferry@163.com> (raw)

under virtual machine environment, cpu topology may differ
from normal physical server.

for example (machine with 4 cores, 2 threads per core):

normal physical server:
core-id   thread-0-id  thread-1-id
0         0            4
1         1            5
2         2            6
3         3            7

virtual machine:
core-id   thread-0-id  thread-1-id
0         0            1
1         2            3
2         4            5
3         6            7

If we attach disk with multi queues to virtual machine,
blk_mq_map_queues can cause serious imbalance.this will lead to
performance impact on system IO.

Here is the qemu cmdline:
"-smp 8,sockets=1,cores=8,threads=2"
"-device virtio-blk-pci,drive=drive0,id=device0,num-queues=4,vectors=2"

when vectors less than num-queues, virtio-blk will fallback to
blk_mq_map_queues

Before this patch:
[root@blk-mq ~]# cat /sys/block/vd*/mq/*/cpu_list
0, 4, 5, 8, 9, 12, 13
1
2, 6, 7, 10, 11, 14, 15
3

After this patch:
[root@blk-mq ~]# cat /sys/block/vd*/mq/*/cpu_list
0, 1, 8, 9
2, 3, 10, 11
4, 5, 12, 13
6, 7, 14, 15

Signed-off-by: luferry <luferry@163.com>
---
 block/blk-mq-cpumap.c | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/block/blk-mq-cpumap.c b/block/blk-mq-cpumap.c
index 03a534820271..2eb78ad4a49b 100644
--- a/block/blk-mq-cpumap.c
+++ b/block/blk-mq-cpumap.c
@@ -35,22 +35,37 @@ int blk_mq_map_queues(struct blk_mq_queue_map *qmap)
 {
 	unsigned int *map = qmap->mq_map;
 	unsigned int nr_queues = qmap->nr_queues;
-	unsigned int cpu, first_sibling;
+	unsigned int cpu, first_sibling, core = 0;
+	bool core_map = false;
 
+	/*
+	 * If core num is euqal or over nr_queues,
+	 * there be sure at least per core per queue
+	 */
+	for_each_possible_cpu(cpu) {
+		if (get_first_sibling(cpu) == cpu)
+			core++;
+	}
+	if (core >= nr_queues)
+		core_map = true;
+
+	core = 0;
 	for_each_possible_cpu(cpu) {
 		/*
-		 * First do sequential mapping between CPUs and queues.
-		 * In case we still have CPUs to map, and we have some number of
-		 * threads per cores then map sibling threads to the same queue for
+		 * If cores is enough, just do map between cores and queues
+		 * else will do sequential mapping between CPUs and queues first.
+		 * For other cpus, we have some number of threads per cores
+		 * then map sibling threads to the same queue for
 		 * performace optimizations.
 		 */
-		if (cpu < nr_queues) {
+		if (!core_map && cpu < nr_queues) {
 			map[cpu] = cpu_to_queue_index(qmap, nr_queues, cpu);
 		} else {
 			first_sibling = get_first_sibling(cpu);
-			if (first_sibling == cpu)
-				map[cpu] = cpu_to_queue_index(qmap, nr_queues, cpu);
-			else
+			if (first_sibling == cpu) {
+				map[cpu] = cpu_to_queue_index(qmap, nr_queues, core);
+				core++;
+			} else
 				map[cpu] = map[first_sibling];
 		}
 	}
-- 
2.14.1.40.g8e62ba1


             reply	other threads:[~2019-03-25 15:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-25 15:26 luferry [this message]
2019-03-26  7:39 ` Christoph Hellwig
2019-03-26  7:55   ` luferry
2019-03-27  8:16     ` Christoph Hellwig
2019-03-27  9:17       ` luferry
2019-03-27  9:39         ` Dongli Zhang
2019-03-27  9:53           ` luferry

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190325152640.48120-1-luferry@163.com \
    --to=luferry@163.com \
    --cc=axboe@kernel.dk \
    --cc=dongli.zhang@oracle.com \
    --cc=hch@lst.de \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ming.lei@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®