all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [PATCH manager/qemu-server 0/2] fix memory usage reporting of VMs with an inflated balloon
@ 2026-11-30 10:20 Jonas Theisen
  2026-11-30 10:20 ` [PATCH qemu-server 1/2] vmstatus: do not count memory reclaimed by the balloon as used Jonas Theisen
  2026-11-30 10:20 ` [PATCH manager 2/2] ui: guest status: show memory reclaimed by the balloon device Jonas Theisen
  0 siblings, 2 replies; 3+ messages in thread
From: Jonas Theisen @ 2026-11-30 10:20 UTC (permalink / raw)
  To: pve-devel

The memory usage of a VM is calculated from the total and free memory
reported by the guest's balloon driver. The Windows driver keeps
reporting the full physical memory as total and accounts inflated
balloon pages as allocated, while the Linux driver removes them from
the total. With an inflated balloon, a Windows guest's reported usage
thus includes memory that the host already reclaimed, and the usage
graph can show more than the VM occupies on the host.

The qemu-server patch subtracts the part of the balloon that the guest
still includes in its total. It derives that from the reported values
rather than the OS type, so guests that already shrink their total are
not affected, and neither is auto-ballooning, which only uses the free
memory.

The pve-manager patch shows the reclaimed amount in the VM status
panel, so it is visible why the guest and host usage differ. It is
hidden while the balloon is not inflated. Showing the amount in the
memory graph as well would require a new RRD column, so this is left
out for now.

Tested on a Windows Server 2025 VM with 8 GiB of memory and a Debian
VM with 2 GiB, inflating the balloon to half of the memory each:

  VM       guest total  usage before  usage after  host usage
  Windows  8124 MiB     5406 MiB      1378 MiB     4129 MiB
  Debian    949 MiB      164 MiB       164 MiB      320 MiB

The patches do not depend on each other.


qemu-server:

Jonas Theisen (1):
  vmstatus: do not count memory reclaimed by the balloon as used

 src/PVE/QemuServer.pm | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)


manager:

Jonas Theisen (1):
  ui: guest status: show memory reclaimed by the balloon device

 www/manager6/panel/GuestStatusView.js | 15 +++++++++++++++
 1 file changed, 15 insertions(+)


Summary over all repositories:
  2 files changed, 26 insertions(+), 2 deletions(-)

-- 
Generated by murpp 0.12.1




^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH qemu-server 1/2] vmstatus: do not count memory reclaimed by the balloon as used
  2026-11-30 10:20 [PATCH manager/qemu-server 0/2] fix memory usage reporting of VMs with an inflated balloon Jonas Theisen
@ 2026-11-30 10:20 ` Jonas Theisen
  2026-11-30 10:20 ` [PATCH manager 2/2] ui: guest status: show memory reclaimed by the balloon device Jonas Theisen
  1 sibling, 0 replies; 3+ messages in thread
From: Jonas Theisen @ 2026-11-30 10:20 UTC (permalink / raw)
  To: pve-devel

The guest memory usage is calculated as the total minus the free memory
reported by the guest's balloon driver. The Linux driver removes
inflated pages from the guest's total memory, but the Windows driver
keeps reporting the full physical memory and accounts the balloon pages
as allocated. With an inflated balloon, a Windows guest's usage thus
includes memory that the host already reclaimed, and can exceed the
memory the VM actually occupies on the host.

Subtract the part of the balloon that the guest still includes in its
total memory, derived from how far the reported total exceeds the
current balloon size. This works independently of the guest OS and
leaves guests that already shrink their total unaffected. Firmware-
reserved memory is missing from the guest's total, so the usage can
be overestimated by that amount.

Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
 src/PVE/QemuServer.pm | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
index 1d665877..7de7a939 100644
--- a/src/PVE/QemuServer.pm
+++ b/src/PVE/QemuServer.pm
@@ -2362,7 +2362,8 @@ our $vmstatus_return_properties = {
     },
     mem => {
         description => "Currently used memory in bytes. Does not take into account kernel"
-            . " same-page merging (KSM). Uses information from ballooning when available.",
+            . " same-page merging (KSM). Uses information from ballooning when available and"
+            . " excludes memory reclaimed by the balloon device.",
         type => 'integer',
         optional => 1,
         renderer => 'bytes',
@@ -2674,7 +2675,15 @@ sub vmstatus {
         $d->{balloon} = $info->{actual};
 
         if (defined($info->{total_mem}) && defined($info->{free_mem})) {
-            $d->{mem} = $info->{total_mem} - $info->{free_mem};
+            # Some guests, like Windows, keep ballooned pages in their total and report them as
+            # allocated. The host already reclaimed these pages, so do not count them as used.
+            my $ballooned = $info->{max_mem} - $info->{actual};
+            my $ballooned_in_total = $info->{total_mem} - $info->{actual};
+            $ballooned_in_total = 0 if $ballooned_in_total < 0;
+            $ballooned_in_total = $ballooned if $ballooned_in_total > $ballooned;
+
+            my $used = $info->{total_mem} - $info->{free_mem} - $ballooned_in_total;
+            $d->{mem} = $used > 0 ? $used : 0;
             $d->{freemem} = $info->{free_mem};
         }
 
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH manager 2/2] ui: guest status: show memory reclaimed by the balloon device
  2026-11-30 10:20 [PATCH manager/qemu-server 0/2] fix memory usage reporting of VMs with an inflated balloon Jonas Theisen
  2026-11-30 10:20 ` [PATCH qemu-server 1/2] vmstatus: do not count memory reclaimed by the balloon as used Jonas Theisen
@ 2026-11-30 10:20 ` Jonas Theisen
  1 sibling, 0 replies; 3+ messages in thread
From: Jonas Theisen @ 2026-11-30 10:20 UTC (permalink / raw)
  To: pve-devel

When the balloon is inflated, the memory usage of a VM is only
meaningful relative to the memory that is still left to the guest, and
the host memory usage drops accordingly. Neither the usage bar nor the
host memory usage show how much memory was reclaimed, which makes it
hard to tell whether ballooning is the reason for the difference.

Show the reclaimed amount as its own line in the status view, derived
from the balloon size and the maximum memory that the status API
already returns. Hide it while nothing is reclaimed, so VMs without an
active balloon look as before.

Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
 www/manager6/panel/GuestStatusView.js | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/www/manager6/panel/GuestStatusView.js b/www/manager6/panel/GuestStatusView.js
index 60d804a8..3f6bfb7e 100644
--- a/www/manager6/panel/GuestStatusView.js
+++ b/www/manager6/panel/GuestStatusView.js
@@ -136,6 +136,21 @@ Ext.define('PVE.panel.GuestStatusView', {
                 disabled: '{isLxc}',
             },
         },
+        {
+            itemId: 'memory-ballooned',
+            iconCls: 'fa fa-fw pmx-itype-icon-memory pmx-icon',
+            title: gettext('Ballooned memory'),
+            valueField: 'balloon',
+            maxField: 'maxmem',
+            printBar: false,
+            hidden: true,
+            // 'balloon' is the memory currently left to the guest, not the amount reclaimed
+            renderer: function (balloon, maxmem) {
+                let ballooned = Ext.isNumeric(balloon) && maxmem > balloon ? maxmem - balloon : 0;
+                this.setVisible(ballooned > 0);
+                return Proxmox.Utils.render_size(ballooned);
+            },
+        },
         {
             itemId: 'swap',
             iconCls: 'fa fa-refresh fa-fw',
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-30 10:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 10:20 [PATCH manager/qemu-server 0/2] fix memory usage reporting of VMs with an inflated balloon Jonas Theisen
2026-11-30 10:20 ` [PATCH qemu-server 1/2] vmstatus: do not count memory reclaimed by the balloon as used Jonas Theisen
2026-11-30 10:20 ` [PATCH manager 2/2] ui: guest status: show memory reclaimed by the balloon device Jonas Theisen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal