]>
Commit | Line | Data |
---|---|---|
64fefc3e SL |
1 | From d8cbe82796d5b7621095dbdf0cbbcd9a56c54808 Mon Sep 17 00:00:00 2001 |
2 | From: Dongli Zhang <dongli.zhang@oracle.com> | |
3 | Date: Wed, 27 Mar 2019 18:36:34 +0800 | |
4 | Subject: virtio-blk: limit number of hw queues by nr_cpu_ids | |
5 | ||
6 | [ Upstream commit bf348f9b78d413e75bb079462751a1d86b6de36c ] | |
7 | ||
8 | When tag_set->nr_maps is 1, the block layer limits the number of hw queues | |
9 | by nr_cpu_ids. No matter how many hw queues are used by virtio-blk, as it | |
10 | has (tag_set->nr_maps == 1), it can use at most nr_cpu_ids hw queues. | |
11 | ||
12 | In addition, specifically for pci scenario, when the 'num-queues' specified | |
13 | by qemu is more than maxcpus, virtio-blk would not be able to allocate more | |
14 | than maxcpus vectors in order to have a vector for each queue. As a result, | |
15 | it falls back into MSI-X with one vector for config and one shared for | |
16 | queues. | |
17 | ||
18 | Considering above reasons, this patch limits the number of hw queues used | |
19 | by virtio-blk by nr_cpu_ids. | |
20 | ||
21 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> | |
22 | Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com> | |
23 | Signed-off-by: Jens Axboe <axboe@kernel.dk> | |
24 | Signed-off-by: Sasha Levin <sashal@kernel.org> | |
25 | --- | |
26 | drivers/block/virtio_blk.c | 2 ++ | |
27 | 1 file changed, 2 insertions(+) | |
28 | ||
29 | diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c | |
30 | index b16a887bbd02a..29bede887237f 100644 | |
31 | --- a/drivers/block/virtio_blk.c | |
32 | +++ b/drivers/block/virtio_blk.c | |
33 | @@ -513,6 +513,8 @@ static int init_vq(struct virtio_blk *vblk) | |
34 | if (err) | |
35 | num_vqs = 1; | |
36 | ||
37 | + num_vqs = min_t(unsigned int, nr_cpu_ids, num_vqs); | |
38 | + | |
39 | vblk->vqs = kmalloc_array(num_vqs, sizeof(*vblk->vqs), GFP_KERNEL); | |
40 | if (!vblk->vqs) | |
41 | return -ENOMEM; | |
42 | -- | |
43 | 2.20.1 | |
44 |