From: Thomas Lamprecht Date: Tue, 18 Oct 2016 13:35:14 +0000 (+0200) Subject: vmstatus: fix memory usage value including cache sizes X-Git-Url: https://git.proxmox.com/?p=pve-container.git;a=commitdiff_plain;h=b3059d3569616523039c4e65b6bc2079f0734771 vmstatus: fix memory usage value including cache sizes The cgroup value memory.usage_in_bytes includes the memory used by file buffers and other caches, resolve this by getting the cache value from the memory.stat file and substract it from memory.usage_in_bytes when calculating the current memory usage of the CT. This results in the same value as a `free` call from the container does (when not including the buffered data), at least with a free version which uses data from /proc and not the sysinfo() syscall. Addresses partly the bug #1139 Signed-off-by: Thomas Lamprecht CC: Wolfgang Bumiller --- diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm index 35ce796..535147f 100644 --- a/src/PVE/LXC.pm +++ b/src/PVE/LXC.pm @@ -192,8 +192,11 @@ sub vmstatus { my $ctime = (stat("/proc/$pid"))[10]; # 10 = ctime $d->{uptime} = time - $ctime; # the method lxcfs uses - $d->{mem} = read_cgroup_value('memory', $vmid, 'memory.usage_in_bytes'); - $d->{swap} = read_cgroup_value('memory', $vmid, 'memory.memsw.usage_in_bytes') - $d->{mem}; + my $memory_stat = read_cgroup_list('memory', $vmid, 'memory.stat'); + my $mem_usage_in_bytes = read_cgroup_value('memory', $vmid, 'memory.usage_in_bytes'); + + $d->{mem} = $mem_usage_in_bytes - $memory_stat->{cache}; + $d->{swap} = read_cgroup_value('memory', $vmid, 'memory.memsw.usage_in_bytes') - $mem_usage_in_bytes; my $blkio_bytes = read_cgroup_value('blkio', $vmid, 'blkio.throttle.io_service_bytes', 1); my @bytes = split(/\n/, $blkio_bytes); @@ -251,6 +254,14 @@ sub vmstatus { return $list; } +sub read_cgroup_list { + my ($group, $vmid, $name) = @_; + + my $content = read_cgroup_value($group, $vmid, $name, 1); + + return { split(/\s+/, $content) }; +} + sub read_cgroup_value { my ($group, $vmid, $name, $full) = @_;