]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/5.0.15/virtio-blk-limit-number-of-hw-queues-by-nr_cpu_ids.patch
Linux 5.0.15
[thirdparty/kernel/stable-queue.git] / releases / 5.0.15 / virtio-blk-limit-number-of-hw-queues-by-nr_cpu_ids.patch
CommitLineData
64fefc3e
SL
1From d8cbe82796d5b7621095dbdf0cbbcd9a56c54808 Mon Sep 17 00:00:00 2001
2From: Dongli Zhang <dongli.zhang@oracle.com>
3Date: Wed, 27 Mar 2019 18:36:34 +0800
4Subject: virtio-blk: limit number of hw queues by nr_cpu_ids
5
6[ Upstream commit bf348f9b78d413e75bb079462751a1d86b6de36c ]
7
8When tag_set->nr_maps is 1, the block layer limits the number of hw queues
9by nr_cpu_ids. No matter how many hw queues are used by virtio-blk, as it
10has (tag_set->nr_maps == 1), it can use at most nr_cpu_ids hw queues.
11
12In addition, specifically for pci scenario, when the 'num-queues' specified
13by qemu is more than maxcpus, virtio-blk would not be able to allocate more
14than maxcpus vectors in order to have a vector for each queue. As a result,
15it falls back into MSI-X with one vector for config and one shared for
16queues.
17
18Considering above reasons, this patch limits the number of hw queues used
19by virtio-blk by nr_cpu_ids.
20
21Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
22Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
23Signed-off-by: Jens Axboe <axboe@kernel.dk>
24Signed-off-by: Sasha Levin <sashal@kernel.org>
25---
26 drivers/block/virtio_blk.c | 2 ++
27 1 file changed, 2 insertions(+)
28
29diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
30index 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--
432.20.1
44