From: Aaron Lauterer <a.lauterer@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH qemu-server v2 2/4] vmstatus: add memhost for host view of vm mem consumption
Date: Wed, 9 Jul 2025 18:36:59 +0200 [thread overview]
Message-ID: <20250709163703.2540012-20-a.lauterer@proxmox.com> (raw)
In-Reply-To: <20250709163703.2540012-1-a.lauterer@proxmox.com>
The mem field itself will switch from the outside view to the "inside"
view if the VM is reporting detailed memory usage informatio via the
ballooning device.
Since sometime other processes belong to a VM too, vor example swtpm,
we collect all PIDs belonging to the VM cgroup and fetch their PSS data
to account for shared libraries used.
Signed-off-by: Aaron Lauterer <a.lauterer@proxmox.com>
---
Notes:
changes since:
RFC:
* collect memory info for all processes in cgroup directly without too
generic helper function
src/PVE/QemuServer.pm | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
index 01f7a4f..4dd30c4 100644
--- a/src/PVE/QemuServer.pm
+++ b/src/PVE/QemuServer.pm
@@ -2586,6 +2586,7 @@ sub vmstatus {
$d->{uptime} = 0;
$d->{cpu} = 0;
$d->{mem} = 0;
+ $d->{memhost} = 0;
$d->{netout} = 0;
$d->{netin} = 0;
@@ -2670,6 +2671,24 @@ sub vmstatus {
$d->{pressureiofull} = $pressures->{io}->{full}->{avg10};
$d->{pressurememorysome} = $pressures->{memory}->{some}->{avg10};
$d->{pressurememoryfull} = $pressures->{memory}->{full}->{avg10};
+
+ my $fh = IO::File->new("/sys/fs/cgroup/qemu.slice/${vmid}.scope/cgroup.procs", "r");
+ if ($fh) {
+ while (my $childPid = <$fh>) {
+ chomp($childPid);
+ open(my $SMAPS_FH, '<', "/proc/$childPid/smaps_rollup")
+ or die "failed to open PSS memory-stat from process - $!\n";
+
+ while (my $line = <$SMAPS_FH>) {
+ if ($line =~ m/^Pss:\s+([0-9]+) kB$/) {
+ $d->{memhost} = $d->{memhost} + int($1) * 1024;
+ last;
+ }
+ }
+ close $SMAPS_FH;
+ }
+ }
+ close($fh);
}
return $res if !$full;
--
2.39.5
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next prev parent reply other threads:[~2025-07-09 16:43 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-09 16:36 [pve-devel] [PATCH many v2 00/23] Expand and migrate RRD data (excluding GUI) Aaron Lauterer
2025-07-09 16:36 ` [pve-devel] [PATCH cluster-pve8 v2 1/2] cfs status.c: drop old pve2-vm rrd schema support Aaron Lauterer
2025-07-09 16:36 ` [pve-devel] [PATCH cluster-pve8 v2 2/2] status: handle new metrics update data Aaron Lauterer
2025-07-09 16:36 ` [pve-devel] [PATCH manager-pve8 v2 1/2] api2tools: drop old VM rrd schema Aaron Lauterer
2025-07-09 16:36 ` [pve-devel] [PATCH manager-pve8 v2 2/2] api2tools: extract stats: handle existence of new pve-{type}-9.0 data Aaron Lauterer
2025-07-09 16:36 ` [pve-devel] [PATCH pve9-rrd-migration-tool v2 1/1] introduce rrd migration tool for pve8 -> pve9 Aaron Lauterer
2025-07-09 16:36 ` [pve-devel] [PATCH cluster v2 1/4] cfs status.c: drop old pve2-vm rrd schema support Aaron Lauterer
2025-07-09 16:36 ` [pve-devel] [PATCH cluster v2 2/4] status: handle new metrics update data Aaron Lauterer
2025-07-09 16:36 ` [pve-devel] [PATCH cluster v2 3/4] status: introduce new pve-{type}- rrd and metric format Aaron Lauterer
2025-07-09 16:36 ` [pve-devel] [PATCH cluster v2 4/4] rrd: adapt to new RRD format with different aggregation windows Aaron Lauterer
2025-07-09 16:36 ` [pve-devel] [PATCH common v2 1/2] fix error in pressure parsing Aaron Lauterer
2025-07-09 16:36 ` [pve-devel] [PATCH common v2 2/2] add functions to retrieve pressures for vm/ct Aaron Lauterer
2025-07-09 16:36 ` [pve-devel] [PATCH manager v2 1/5] api2tools: drop old VM rrd schema Aaron Lauterer
2025-07-09 16:36 ` [pve-devel] [PATCH manager v2 2/5] api2tools: extract stats: handle existence of new pve-{type}-9.0 data Aaron Lauterer
2025-07-09 16:36 ` [pve-devel] [PATCH manager v2 3/5] pvestatd: collect and distribute new pve-{type}-9.0 metrics Aaron Lauterer
2025-07-09 16:36 ` [pve-devel] [PATCH manager v2 4/5] api: nodes: rrd and rrddata add decade option and use new pve-node-9.0 rrd files Aaron Lauterer
2025-07-09 16:36 ` [pve-devel] [PATCH manager v2 5/5] api2tools: extract_vm_status add new vm memhost column Aaron Lauterer
2025-07-09 16:36 ` [pve-devel] [PATCH storage v2 1/1] status: rrddata: use new pve-storage-9.0 rrd location if file is present Aaron Lauterer
2025-07-09 16:36 ` [pve-devel] [PATCH qemu-server v2 1/4] metrics: add pressure to metrics Aaron Lauterer
2025-07-09 16:36 ` Aaron Lauterer [this message]
2025-07-09 16:37 ` [pve-devel] [PATCH qemu-server v2 3/4] vmstatus: switch mem stat to PSS of VM cgroup Aaron Lauterer
2025-07-09 16:37 ` [pve-devel] [PATCH qemu-server v2 4/4] rrddata: use new pve-vm-9.0 rrd location if file is present Aaron Lauterer
2025-07-09 16:37 ` [pve-devel] [PATCH container v2 1/2] metrics: add pressures to metrics Aaron Lauterer
2025-07-09 16:37 ` [pve-devel] [PATCH container v2 2/2] rrddata: use new pve-vm-9.0 rrd location if file is present Aaron Lauterer
2025-07-15 14:33 ` [pve-devel] SUPERSEEDED Re: [PATCH many v2 00/23] Expand and migrate RRD data (excluding GUI) Aaron Lauterer
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=20250709163703.2540012-20-a.lauterer@proxmox.com \
--to=a.lauterer@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