]> git.proxmox.com Git - pve-container.git/commitdiff
use helper from common for cpu units/shares
authorFiona Ebner <f.ebner@proxmox.com>
Fri, 7 Oct 2022 12:41:44 +0000 (14:41 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 8 Nov 2022 15:10:47 +0000 (16:10 +0100)
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@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PVE/LXC.pm
src/PVE/LXC/Config.pm

index 333286a25a7e58ac4d7aaaf66e56bca32a9c4ed2..0d0141dc483ee1ba430e410bc6fdbe1267bbfc9a 100644 (file)
@@ -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";
        }
     }
index 4f62aef963c9fd799c00c17539e1da2e06c77915..2736fec239390f6f074a171d55c0c39c70e973a6 100644 (file)
@@ -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',