[pve-devel] [PATCH container 4/7] use helper from guest-common for cpuunits

Fiona Ebner f.ebner at proxmox.com
Fri Oct 7 14:41:44 CEST 2022


to make behavior more consistent with what we do for VMs. The helper
will clamp the value as needed, rather than dying.

Allows starting existing containers with an out-of-range (for the
relevant cgroup version) value. It's also possible to end up with
out-of-range values via update/create API.

Signed-off-by: Fiona Ebner <f.ebner at proxmox.com>
---

Dependency bump for guest-common needed.

 src/PVE/LXC.pm        | 5 ++---
 src/PVE/LXC/Config.pm | 5 ++++-
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index fe63087..e143855 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -699,7 +699,7 @@ sub update_lxc_config {
 	    $raw .= "lxc.cgroup.cpu.cfs_quota_us = $value\n";
 	}
 
-	my $shares = $conf->{cpuunits} || 1024;
+	my $shares = PVE::GuestHelpers::get_cpuunits($conf->{cpuunits});
 	$raw .= "lxc.cgroup.cpu.shares = $shares\n";
     } elsif ($cgv2->{cpu}) {
 	# See PVE::CGroup
@@ -709,8 +709,7 @@ sub update_lxc_config {
 	}
 
 	if (defined(my $shares = $conf->{cpuunits})) {
-	    die "cpu weight (shares) must be in range [1, 10000]\n"
-		if $shares < 1 || $shares > 10000;
+	    $shares = PVE::GuestHelpers::get_cpuunits($shares);
 	    $raw .= "lxc.cgroup2.cpu.weight = $shares\n";
 	}
     }
diff --git a/src/PVE/LXC/Config.pm b/src/PVE/LXC/Config.pm
index b32eff6..7be6be1 100644
--- a/src/PVE/LXC/Config.pm
+++ b/src/PVE/LXC/Config.pm
@@ -504,7 +504,10 @@ my $confdesc = {
     cpuunits => {
 	optional => 1,
 	type => 'integer',
-	description => "CPU weight for a VM. Argument is used in the kernel fair scheduler. The larger the number is, the more CPU time this VM gets. Number is relative to the weights of all the other running VMs.",
+	description => "CPU weight for a container, will be clamped to [1, 10000] in cgroup v2.",
+	verbose_description => "CPU weight for a container. Argument is used in the kernel fair "
+	    ."scheduler. The larger the number is, the more CPU time this container gets. Number "
+	    ."is relative to the weights of all the other running guests.",
 	minimum => 0,
 	maximum => 500000,
 	default => 'cgroup v1: 1024, cgroup v2: 100',
-- 
2.30.2






More information about the pve-devel mailing list