The current code does not consider "SReclaimable" as cached memory,
which can lead to totally wrong values for memfree/memused.

This fix uses MemAvailable to compute memused, and returns MemFree
without adding buffers and caches. This corrensponds to the
values displayed by the "free" command line tool (total, used, free, avilable),
where used+available=total.

The value for buffers+cache can be estimated with: available - free

Signed-off-by: Dietmar Maurer <diet...@proxmox.com>
---
 src/PVE/ProcFSTools.pm | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/PVE/ProcFSTools.pm b/src/PVE/ProcFSTools.pm
index 3826fcc..04b0a0a 100644
--- a/src/PVE/ProcFSTools.pm
+++ b/src/PVE/ProcFSTools.pm
@@ -299,8 +299,8 @@ sub read_meminfo {
     close($fh);
 
     $res->{memtotal} = $d->{memtotal};
-    $res->{memfree} =  $d->{memfree} + $d->{buffers} + $d->{cached};
-    $res->{memused} = $res->{memtotal} - $res->{memfree};
+    $res->{memfree} =  $d->{memfree};
+    $res->{memused} = $res->{memtotal} - $d->{memavailable};
 
     $res->{swaptotal} = $d->{swaptotal};
     $res->{swapfree} = $d->{swapfree};
-- 
2.39.5


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to