[pve-devel] [PATCH qemu-server 4/6] fix #4295 : virtio-(blk|scsi): enable multiqueue by default

Alexandre Derumier aderumier at odiso.com
Thu Mar 9 09:52:15 CET 2023


set num_queues = maxcpus for qemu 8.0

redhat already done it in rhev since 2021
https://bugzilla.redhat.com/show_bug.cgi?id=1827722#c11

The -device virtio-blk,num-queues= and -device virtio-scsi,num_queues= parameters control how many virtqueues are available to the guest. Allocating one virtqueue per vCPU improves performance as follows:
Interrupts are handled on the vCPU that submitted the request, avoiding IPIs
The I/O scheduler is automatically set to “none” by the Linux block layer

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/QemuServer.pm | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index b49b59b..39d30e3 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -1505,7 +1505,14 @@ sub print_drivedevice_full {
 	my $pciaddr = print_pci_addr("$drive_id", $bridges, $arch, $machine_type);
 	$device = "virtio-blk-pci,drive=drive-$drive_id,id=${drive_id}${pciaddr}";
 	$device .= ",iothread=iothread-$drive_id" if $drive->{iothread};
+
+	my $machine_version = extract_version($machine_type, kvm_user_version());
+	if (min_version($machine_version, 8, 0)) {
+	    my ($sockets, $cores, $maxcpus) = get_cpu_topology($conf);
+	    $drive->{queues} = $maxcpus if !$drive->{queues};
+	}
 	$device .= ",num-queues=$drive->{queues}" if $drive->{queues};
+
     } elsif ($drive->{interface} eq 'scsi') {
 
 	my ($maxdev, $controller, $controller_prefix) = scsihw_infos($conf, $drive);
@@ -4043,6 +4050,12 @@ sub config_to_command {
 		);
 	    }
 
+	    if (min_version($machine_version, 8, 0)) {
+		my ($sockets, $cores, $maxcpus) = get_cpu_topology($conf);
+		$drive->{queues} = $maxcpus if !$drive->{queues};
+
+	    }
+
 	    my $queues = '';
 	    if($conf->{scsihw} && $conf->{scsihw} eq "virtio-scsi-single" && $drive->{queues}){
 		$queues = ",num_queues=$drive->{queues}";
@@ -4306,6 +4319,12 @@ sub vm_deviceplug {
 	    $devicefull .= ",iothread=iothread-$deviceid";
 	}
 
+	my $machine_version = PVE::QemuServer::Machine::extract_version($machine_type);
+	if (min_version($machine_version, 8, 0)) {
+	    my ($sockets, $cores, $maxcpus) = get_cpu_topology($conf);
+	    $device->{queues} = $maxcpus if !$device->{queues};
+	}
+
 	if($deviceid =~ m/^virtioscsi(\d+)$/ && $device->{queues}) {
 	    $devicefull .= ",num_queues=$device->{queues}";
 	}
-- 
2.30.2





More information about the pve-devel mailing list