Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

blk-mq: map all HWQ also in hyperthreaded system

This patch performs sequential mapping between CPUs and queues.
In case the system has more CPUs than HWQs then there are still
CPUs to map to HWQs. In hyperthreaded system, map the unmapped CPUs
and their siblings to the same HWQ.
This actually fixes a bug that found unmapped HWQs in a system with
2 sockets, 18 cores per socket, 2 threads per core (total 72 CPUs)
running NVMEoF (opens upto maximum of 64 HWQs).

Performance results running fio (72 jobs, 128 iodepth)
using null_blk (w/w.o patch):

bs IOPS(read submit_queues=72) IOPS(write submit_queues=72) IOPS(read submit_queues=24) IOPS(write submit_queues=24)
----- ---------------------------- ------------------------------ ---------------------------- -----------------------------
512 4890.4K/4723.5K 4524.7K/4324.2K 4280.2K/4264.3K 3902.4K/3909.5K
1k 4910.1K/4715.2K 4535.8K/4309.6K 4296.7K/4269.1K 3906.8K/3914.9K
2k 4906.3K/4739.7K 4526.7K/4330.6K 4301.1K/4262.4K 3890.8K/3900.1K
4k 4918.6K/4730.7K 4556.1K/4343.6K 4297.6K/4264.5K 3886.9K/3893.9K
8k 4906.4K/4748.9K 4550.9K/4346.7K 4283.2K/4268.8K 3863.4K/3858.2K
16k 4903.8K/4782.6K 4501.5K/4233.9K 4292.3K/4282.3K 3773.1K/3773.5K
32k 4885.8K/4782.4K 4365.9K/4184.2K 4307.5K/4289.4K 3780.3K/3687.3K
64k 4822.5K/4762.7K 2752.8K/2675.1K 4308.8K/4312.3K 2651.5K/2655.7K
128k 2388.5K/2313.8K 1391.9K/1375.7K 2142.8K/2152.2K 1395.5K/1374.2K

Signed-off-by: Max Gurtovoy <maxg@mellanox.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Max Gurtovoy and committed by
Jens Axboe
fe631457 f1d4ef7d

+25 -49
+25 -49
block/blk-mq-cpumap.c
··· 14 14 #include "blk.h" 15 15 #include "blk-mq.h" 16 16 17 - static int cpu_to_queue_index(unsigned int nr_cpus, unsigned int nr_queues, 18 - const int cpu) 17 + static int cpu_to_queue_index(unsigned int nr_queues, const int cpu, 18 + const struct cpumask *online_mask) 19 19 { 20 - return cpu * nr_queues / nr_cpus; 20 + /* 21 + * Non online CPU will be mapped to queue index 0. 22 + */ 23 + if (!cpumask_test_cpu(cpu, online_mask)) 24 + return 0; 25 + return cpu % nr_queues; 21 26 } 22 27 23 28 static int get_first_sibling(unsigned int cpu) ··· 41 36 unsigned int *map = set->mq_map; 42 37 unsigned int nr_queues = set->nr_hw_queues; 43 38 const struct cpumask *online_mask = cpu_online_mask; 44 - unsigned int i, nr_cpus, nr_uniq_cpus, queue, first_sibling; 45 - cpumask_var_t cpus; 39 + unsigned int cpu, first_sibling; 46 40 47 - if (!alloc_cpumask_var(&cpus, GFP_ATOMIC)) 48 - return -ENOMEM; 49 - 50 - cpumask_clear(cpus); 51 - nr_cpus = nr_uniq_cpus = 0; 52 - for_each_cpu(i, online_mask) { 53 - nr_cpus++; 54 - first_sibling = get_first_sibling(i); 55 - if (!cpumask_test_cpu(first_sibling, cpus)) 56 - nr_uniq_cpus++; 57 - cpumask_set_cpu(i, cpus); 41 + for_each_possible_cpu(cpu) { 42 + /* 43 + * First do sequential mapping between CPUs and queues. 44 + * In case we still have CPUs to map, and we have some number of 45 + * threads per cores then map sibling threads to the same queue for 46 + * performace optimizations. 47 + */ 48 + if (cpu < nr_queues) { 49 + map[cpu] = cpu_to_queue_index(nr_queues, cpu, online_mask); 50 + } else { 51 + first_sibling = get_first_sibling(cpu); 52 + if (first_sibling == cpu) 53 + map[cpu] = cpu_to_queue_index(nr_queues, cpu, online_mask); 54 + else 55 + map[cpu] = map[first_sibling]; 56 + } 58 57 } 59 58 60 - queue = 0; 61 - for_each_possible_cpu(i) { 62 - if (!cpumask_test_cpu(i, online_mask)) { 63 - map[i] = 0; 64 - continue; 65 - } 66 - 67 - /* 68 - * Easy case - we have equal or more hardware queues. Or 69 - * there are no thread siblings to take into account. Do 70 - * 1:1 if enough, or sequential mapping if less. 71 - */ 72 - if (nr_queues >= nr_cpus || nr_cpus == nr_uniq_cpus) { 73 - map[i] = cpu_to_queue_index(nr_cpus, nr_queues, queue); 74 - queue++; 75 - continue; 76 - } 77 - 78 - /* 79 - * Less then nr_cpus queues, and we have some number of 80 - * threads per cores. Map sibling threads to the same 81 - * queue. 82 - */ 83 - first_sibling = get_first_sibling(i); 84 - if (first_sibling == i) { 85 - map[i] = cpu_to_queue_index(nr_uniq_cpus, nr_queues, 86 - queue); 87 - queue++; 88 - } else 89 - map[i] = map[first_sibling]; 90 - } 91 - 92 - free_cpumask_var(cpus); 93 59 return 0; 94 60 } 95 61 EXPORT_SYMBOL_GPL(blk_mq_map_queues);