Skip to content

Limit number of hw queues by nr_cpu_ids for virtio-blk and virtio-scsi

Dongli Zhang linux-block linux-scsi lkml virtualization 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 7 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2virtio-blk: limit number of hw queues by nr_cpu_idsdrivers/block/virtio_blk.c+2 -02 replies
1/2virtio-blk: limit number of hw queues by nr_cpu_idsdrivers/block/virtio_blk.c+2 -00 replies
2/2scsi: virtio_scsi: limit number of hw queues by nr_cpu_idsdrivers/scsi/virtio_scsi.c+1 -02 replies
2/2scsi: virtio_scsi: limit number of hw queues by nr_cpu_idsdrivers/scsi/virtio_scsi.c+1 -00 replies

Reviews trailers per patch

All 4 patches have a Reviewed-by or Acked-by.

PatchStefan Hajnoczi
1/2R-b R-b
1/2R-b R-b
2/2R-b R-b
2/2R-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 0/2] Limit number of hw queues by nr_cpu_ids for virtio-blk and virtio-scsi

When tag_set->nr_maps is 1, the block layer limits the number of hw queues by nr_cpu_ids. No matter how many hw queues are use by virtio-blk/virtio-scsi, as they both have (tag_set->nr_maps == 1), they can use at most nr_cpu_ids hw queues.

In addition, specifically for pci scenario, when the 'num-queues' specified by qemu is more than maxcpus, virtio-blk/virtio-scsi would not be able to allocate more than maxcpus vectors in order to have a vector for each queue. As a result, they fall back into MSI-X with one vector for config and one shared for queues.

Considering above reasons, this patch set limits the number of hw queues used by nr_cpu_ids for both virtio-blk and virtio-scsi.

-------------------------------------------------------------

Here is test result of virtio-scsi:

qemu cmdline:

-smp 2,maxcpus=4, \
-device virtio-scsi-pci,id=scsi0,num_queues=8, \
-device scsi-hd,drive=drive0,bus=scsi0.0,channel=0,scsi-id=0,lun=0, \
-drive file=test.img,if=none,id=drive0

Although maxcpus=4 and num_queues=8, 4 queues are used while 2 interrupts are allocated.

# cat /proc/interrupts
... ...
 24:          0          0   PCI-MSI 65536-edge      virtio0-config
 25:          0        369   PCI-MSI 65537-edge      virtio0-virtqueues
... ...
# /sys/block/sda/mq/
0  1  2  3   ------> 4 queues although qemu sets num_queues=8

With the patch set, there is per-queue interrupt.

# cat /proc/interrupts
 24:          0          0   PCI-MSI 65536-edge      virtio0-config
 25:          0          0   PCI-MSI 65537-edge      virtio0-control
 26:          0          0   PCI-MSI 65538-edge      virtio0-event
 27:        296          0   PCI-MSI 65539-edge      virtio0-request
 28:          0        139   PCI-MSI 65540-edge      virtio0-request
 29:          0          0   PCI-MSI 65541-edge      virtio0-request
 30:          0          0   PCI-MSI 65542-edge      virtio0-request
# ls /sys/block/sda/mq
0  1  2  3

-------------------------------------------------------------

Here is test result of virtio-blk:

qemu cmdline:

-smp 2,maxcpus=4,
-device virtio-blk-pci,drive=drive-virtio-disk0,id=virtio-disk0,num-queues=8 -drive test.img,format=raw,if=none,id=drive-virtio-disk0

Although maxcpus=4 and num-queues=8, 4 queues are used while 2 interrupts are allocated.

# cat /proc/interrupts
... ...
 24:          0          0   PCI-MSI 65536-edge      virtio0-config
 25:          0         65   PCI-MSI 65537-edge      virtio0-virtqueues
... ...
# ls /sys/block/vda/mq
0  1  2  3    -------> 4 queues although qemu sets num_queues=8

With the patch set, there is per-queue interrupt.

# cat /proc/interrupts
 24:          0          0   PCI-MSI 65536-edge      virtio0-config
 25:         64          0   PCI-MSI 65537-edge      virtio0-req.0
 26:          0      10290   PCI-MSI 65538-edge      virtio0-req.1
 27:          0          0   PCI-MSI 65539-edge      virtio0-req.2
 28:          0          0   PCI-MSI 65540-edge      virtio0-req.3
# ls /sys/block/vda/mq/
0  1  2  3

Reference: https://lore.kernel.org/lkml/e4afe4c5-0262-4500-aeec-60f30734b4fc@default/

Thank you very much!

Dongli Zhang