From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Wolfgang Bumiller <w.bumiller@proxmox.com>
-Date: Wed, 9 Dec 2015 14:27:49 +0100
+Date: Mon, 6 Apr 2020 12:16:43 +0200
Subject: [PATCH] PVE: virtio-balloon: improve query-balloon
Actually provide memory information via the query-balloon
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---
- hmp.c | 30 +++++++++++++++++++++++++++++-
hw/virtio/virtio-balloon.c | 33 +++++++++++++++++++++++++++++++--
- qapi/misc.json | 22 +++++++++++++++++++++-
+ monitor/hmp-cmds.c | 30 +++++++++++++++++++++++++++++-
+ qapi/machine.json | 22 +++++++++++++++++++++-
3 files changed, 81 insertions(+), 4 deletions(-)
-diff --git a/hmp.c b/hmp.c
-index 8eec768088..25fe18cbcf 100644
---- a/hmp.c
-+++ b/hmp.c
-@@ -863,7 +863,35 @@ void hmp_info_balloon(Monitor *mon, const QDict *qdict)
- return;
- }
-
-- monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
-+ monitor_printf(mon, "balloon: actual=%" PRId64, info->actual >> 20);
-+ monitor_printf(mon, " max_mem=%" PRId64, info->max_mem >> 20);
-+ if (info->has_total_mem) {
-+ monitor_printf(mon, " total_mem=%" PRId64, info->total_mem >> 20);
-+ }
-+ if (info->has_free_mem) {
-+ monitor_printf(mon, " free_mem=%" PRId64, info->free_mem >> 20);
-+ }
-+
-+ if (info->has_mem_swapped_in) {
-+ monitor_printf(mon, " mem_swapped_in=%" PRId64, info->mem_swapped_in);
-+ }
-+ if (info->has_mem_swapped_out) {
-+ monitor_printf(mon, " mem_swapped_out=%" PRId64, info->mem_swapped_out);
-+ }
-+ if (info->has_major_page_faults) {
-+ monitor_printf(mon, " major_page_faults=%" PRId64,
-+ info->major_page_faults);
-+ }
-+ if (info->has_minor_page_faults) {
-+ monitor_printf(mon, " minor_page_faults=%" PRId64,
-+ info->minor_page_faults);
-+ }
-+ if (info->has_last_update) {
-+ monitor_printf(mon, " last_update=%" PRId64,
-+ info->last_update);
-+ }
-+
-+ monitor_printf(mon, "\n");
-
- qapi_free_BalloonInfo(info);
- }
diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
-index adde97fe4b..e7f91a3cec 100644
+index b22b5beda3..6e581439bf 100644
--- a/hw/virtio/virtio-balloon.c
+++ b/hw/virtio/virtio-balloon.c
-@@ -712,8 +712,37 @@ static uint64_t virtio_balloon_get_features(VirtIODevice *vdev, uint64_t f,
+@@ -805,8 +805,37 @@ static uint64_t virtio_balloon_get_features(VirtIODevice *vdev, uint64_t f,
static void virtio_balloon_stat(void *opaque, BalloonInfo *info)
{
VirtIOBalloon *dev = opaque;
}
static void virtio_balloon_to_target(void *opaque, ram_addr_t target)
-diff --git a/qapi/misc.json b/qapi/misc.json
-index 8b3ca4fdd3..c98bb4b559 100644
---- a/qapi/misc.json
-+++ b/qapi/misc.json
-@@ -682,10 +682,30 @@
- #
- # @actual: the number of bytes the balloon currently contains
+diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
+index 65d8ff4849..705f08a8f1 100644
+--- a/monitor/hmp-cmds.c
++++ b/monitor/hmp-cmds.c
+@@ -695,7 +695,35 @@ void hmp_info_balloon(Monitor *mon, const QDict *qdict)
+ return;
+ }
+
+- monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
++ monitor_printf(mon, "balloon: actual=%" PRId64, info->actual >> 20);
++ monitor_printf(mon, " max_mem=%" PRId64, info->max_mem >> 20);
++ if (info->has_total_mem) {
++ monitor_printf(mon, " total_mem=%" PRId64, info->total_mem >> 20);
++ }
++ if (info->has_free_mem) {
++ monitor_printf(mon, " free_mem=%" PRId64, info->free_mem >> 20);
++ }
++
++ if (info->has_mem_swapped_in) {
++ monitor_printf(mon, " mem_swapped_in=%" PRId64, info->mem_swapped_in);
++ }
++ if (info->has_mem_swapped_out) {
++ monitor_printf(mon, " mem_swapped_out=%" PRId64, info->mem_swapped_out);
++ }
++ if (info->has_major_page_faults) {
++ monitor_printf(mon, " major_page_faults=%" PRId64,
++ info->major_page_faults);
++ }
++ if (info->has_minor_page_faults) {
++ monitor_printf(mon, " minor_page_faults=%" PRId64,
++ info->minor_page_faults);
++ }
++ if (info->has_last_update) {
++ monitor_printf(mon, " last_update=%" PRId64,
++ info->last_update);
++ }
++
++ monitor_printf(mon, "\n");
+
+ qapi_free_BalloonInfo(info);
+ }
+diff --git a/qapi/machine.json b/qapi/machine.json
+index 7c9a263778..3e59199280 100644
+--- a/qapi/machine.json
++++ b/qapi/machine.json
+@@ -1205,10 +1205,30 @@
+ # @actual: the logical size of the VM in bytes
+ # Formula used: logical_vm_size = vm_ram_size - balloon_size
#
+# @last_update: time when stats got updated from guest
+#