]> git.proxmox.com Git - pve-container.git/commitdiff
fix growing of a running container's memory limit
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Mon, 8 Feb 2016 07:48:28 +0000 (08:48 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 8 Feb 2016 11:15:29 +0000 (12:15 +0100)
Since the memory cgroup has a memory and a "total" value
depending on whether you're increasing or decreasing the
values you have to set then in a working order. (Eg. you
can't reduce the total amount to less than the swap limit
or grow the swap limit to more than the total one.)

src/PVE/LXC.pm

index f761f33b564e28b822bfb6d861f9ee9478774aa7..6a3489ac14a35c4bfb1cf14a009473ab25db899a 100644 (file)
@@ -1308,13 +1308,22 @@ sub update_pct_config {
     my $wanted_swap =  PVE::Tools::extract_param($param, 'swap');
     if (defined($wanted_memory) || defined($wanted_swap)) {
 
-       $wanted_memory //= ($conf->{memory} || 512);
-       $wanted_swap //=  ($conf->{swap} || 0);
+       my $old_memory = ($conf->{memory} || 512);
+       my $old_swap = ($conf->{swap} || 0);
+
+       $wanted_memory //= $old_memory;
+       $wanted_swap //= $old_swap;
 
         my $total = $wanted_memory + $wanted_swap;
        if ($running) {
-           write_cgroup_value("memory", $vmid, "memory.limit_in_bytes", int($wanted_memory*1024*1024));
-           write_cgroup_value("memory", $vmid, "memory.memsw.limit_in_bytes", int($total*1024*1024));
+           my $old_total = $old_memory + $old_swap;
+           if ($total > $old_total) {
+               write_cgroup_value("memory", $vmid, "memory.memsw.limit_in_bytes", int($total*1024*1024));
+               write_cgroup_value("memory", $vmid, "memory.limit_in_bytes", int($wanted_memory*1024*1024));
+           } else {
+               write_cgroup_value("memory", $vmid, "memory.limit_in_bytes", int($wanted_memory*1024*1024));
+               write_cgroup_value("memory", $vmid, "memory.memsw.limit_in_bytes", int($total*1024*1024));
+           }
        }
        $conf->{memory} = $wanted_memory;
        $conf->{swap} = $wanted_swap;