public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH pve-common] common: procfs: use MemAvailable from kernel to compute memused
@ 2025-03-14  9:33 Dietmar Maurer
  0 siblings, 0 replies; only message in thread
From: Dietmar Maurer @ 2025-03-14  9:33 UTC (permalink / raw)
  To: pve-devel

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 <dietmar@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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-03-14  9:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-14  9:33 [pve-devel] [PATCH pve-common] common: procfs: use MemAvailable from kernel to compute memused Dietmar Maurer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal