From a3d114d7b218d62f7b480dccf527fb7806d6c00a Mon Sep 17 00:00:00 2001 From: Fiona Ebner Date: Fri, 7 Oct 2022 14:41:44 +0200 Subject: [PATCH] use helper from common for cpu units/shares 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 Signed-off-by: Thomas Lamprecht --- 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 333286a..0d0141d 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::CGroup::clamp_cpu_shares($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::CGroup::clamp_cpu_shares($shares); $raw .= "lxc.cgroup2.cpu.weight = $shares\n"; } } diff --git a/src/PVE/LXC/Config.pm b/src/PVE/LXC/Config.pm index 4f62aef..2736fec 100644 --- a/src/PVE/LXC/Config.pm +++ b/src/PVE/LXC/Config.pm @@ -507,7 +507,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.39.2