]> git.proxmox.com Git - pve-container.git/commitdiff
use CGroup::change_memory_limit
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 3 Apr 2020 14:37:32 +0000 (16:37 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Sat, 4 Apr 2020 17:39:02 +0000 (19:39 +0200)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/PVE/LXC/Config.pm

index 6cc4e4a76a7d73308c8edd31b9f3e82f393b9762..fb05bba320cee8696db0b0a3cfdd71a9268a596d 100644 (file)
@@ -1178,35 +1178,18 @@ sub vmconfig_hotplug_pending {
        $class->write_config($vmid, $conf);
     }
 
+    my $cgroup = PVE::LXC::CGroup->new($vmid);
+
     # There's no separate swap size to configure, there's memory and "total"
     # memory (iow. memory+swap). This means we have to change them together.
     my $hotplug_memory_done;
     my $hotplug_memory = sub {
        my ($wanted_memory, $wanted_swap) = @_;
-       my $old_memory = ($conf->{memory} || $confdesc->{memory}->{default});
-       my $old_swap = ($conf->{swap} || $confdesc->{swap}->{default});
-
-       $wanted_memory //= $old_memory;
-       $wanted_swap //= $old_swap;
-
-       my $total = $wanted_memory + $wanted_swap;
-       my $old_total = $old_memory + $old_swap;
-
-       if ($total > $old_total) {
-           PVE::LXC::write_cgroup_value("memory", $vmid,
-                                        "memory.memsw.limit_in_bytes",
-                                        int($total*1024*1024));
-           PVE::LXC::write_cgroup_value("memory", $vmid,
-                                        "memory.limit_in_bytes",
-                                        int($wanted_memory*1024*1024));
-       } else {
-           PVE::LXC::write_cgroup_value("memory", $vmid,
-                                        "memory.limit_in_bytes",
-                                        int($wanted_memory*1024*1024));
-           PVE::LXC::write_cgroup_value("memory", $vmid,
-                                        "memory.memsw.limit_in_bytes",
-                                        int($total*1024*1024));
-       }
+
+       $wanted_memory = int($wanted_memory * 1024 * 1024) if defined($wanted_memory);
+       $wanted_swap = int($wanted_swap * 1024 * 1024) if defined($wanted_swap);
+       $cgroup->change_memory_limit($wanted_memory, $wanted_swap);
+
        $hotplug_memory_done = 1;
     };