[pve-devel] [PATCH container 12/20] use CGroup::change_memory_limit

w.bumiller at proxmox.com w.bumiller at proxmox.com
Fri Apr 3 16:37:32 CEST 2020


From: Wolfgang Bumiller <w.bumiller at proxmox.com>

Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
---
 src/PVE/LXC/Config.pm | 31 +++++++------------------------
 1 file changed, 7 insertions(+), 24 deletions(-)

diff --git a/src/PVE/LXC/Config.pm b/src/PVE/LXC/Config.pm
index 6cc4e4a..fb05bba 100644
--- a/src/PVE/LXC/Config.pm
+++ b/src/PVE/LXC/Config.pm
@@ -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;
     };
 
-- 
2.20.1





More information about the pve-devel mailing list