From f43d7f67bff37c87024b812cda62fb5f20a8e256 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Fri, 11 Feb 2022 09:28:26 +0100 Subject: [PATCH] cpu units: handle clamping more centrally preparation for also clamping on hotplug and lower the minimum in the schema so that the full v2 range can be used. Signed-off-by: Thomas Lamprecht --- PVE/QemuServer.pm | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index a4d6487f..6b04e20c 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -3393,7 +3393,15 @@ sub query_understood_cpu_flags { my sub get_cpuunits { my ($conf) = @_; - return $conf->{cpuunits} // (PVE::CGroup::cgroup_mode() == 2 ? 100 : 1024); + my $is_cgroupv2 = PVE::CGroup::cgroup_mode() == 2; + + my $cpuunits = $conf->{cpuunits}; + return $is_cgroupv2 ? 100 : 1024 if !defined($cpuunits); + + if ($is_cgroupv2) { + $cpuunits = 10000 if $cpuunits >= 10000; # v1 can be higher, so clamp v2 there + } + return $cpuunits; } # Since commit 277d33454f77ec1d1e0bc04e37621e4dd2424b67 in pve-qemu, smm is not off by default @@ -5567,7 +5575,6 @@ sub vm_start_nolock { ); if (PVE::CGroup::cgroup_mode() == 2) { - $cpuunits = 10000 if $cpuunits >= 10000; # else we get an error $systemd_properties{CPUWeight} = $cpuunits; } else { $systemd_properties{CPUShares} = $cpuunits;