From: Dietmar Maurer <dietmar@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH pve-common] common: procfs: use MemAvailable from kernel to compute memused
Date: Fri, 14 Mar 2025 10:33:19 +0100 [thread overview]
Message-ID: <20250314093319.106385-1-dietmar@proxmox.com> (raw)
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
reply other threads:[~2025-03-14 9:33 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250314093319.106385-1-dietmar@proxmox.com \
--to=dietmar@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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