2018-02-19 12:38:54 +03:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2017-04-05 11:49:19 +03:00
|
|
|
From: Wolfgang Bumiller <w.bumiller@proxmox.com>
|
2020-04-07 17:53:19 +03:00
|
|
|
Date: Mon, 6 Apr 2020 12:16:43 +0200
|
|
|
|
Subject: [PATCH] PVE: virtio-balloon: improve query-balloon
|
2017-04-05 11:49:19 +03:00
|
|
|
|
|
|
|
Actually provide memory information via the query-balloon
|
|
|
|
command.
|
2019-06-06 13:58:15 +03:00
|
|
|
|
|
|
|
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
|
2023-01-10 11:40:57 +03:00
|
|
|
[FE: add BalloonInfo to member name exceptions list]
|
|
|
|
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
|
2017-04-05 11:49:19 +03:00
|
|
|
---
|
|
|
|
hw/virtio/virtio-balloon.c | 33 +++++++++++++++++++++++++++++++--
|
2019-11-20 17:45:35 +03:00
|
|
|
monitor/hmp-cmds.c | 30 +++++++++++++++++++++++++++++-
|
2021-02-11 19:11:11 +03:00
|
|
|
qapi/machine.json | 22 +++++++++++++++++++++-
|
2023-01-10 11:40:57 +03:00
|
|
|
qapi/pragma.json | 1 +
|
|
|
|
4 files changed, 82 insertions(+), 4 deletions(-)
|
2017-04-05 11:49:19 +03:00
|
|
|
|
|
|
|
diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
|
update submodule and patches to 7.1.0
Notable changes:
* The only big change is the switch to using a custom QIOChannel for
savevm-async, because the previously used QEMUFileOps was dropped.
Changes to the current implementation:
* Switch to vector based methods as required for an IO channel. For
short reads the passed-in IO vector is stuffed with zeroes at the
end, just to be sure.
* For reading: The documentation in include/io/channel.h states that
at least one byte should be read, so also error out when whe are
at the very end instead of returning 0.
* For reading: Fix off-by-one error when request goes beyond end.
The wrong code piece was:
if ((pos + size) > maxlen) {
size = maxlen - pos - 1;
}
Previously, the last byte would not be read. It's actually
possible to get a snapshot .raw file that has content all the way
up the final 512 byte (= BDRV_SECTOR_SIZE) boundary without any
trailing zero bytes (I wrote a script to do it).
Luckily, it didn't cause a real issue, because qemu_loadvm_state()
is not interested in the final (i.e. QEMU_VM_VMDESCRIPTION)
section. The buffer for reading it is simply freed up afterwards
and the function will assume that it read the whole section, even
if that's not the case.
* For writing: Make use of the generated blk_pwritev() wrapper
instead of manually wrapping the coroutine to simplify and save a
few lines.
* Adapt to changed interfaces for blk_{pread,pwrite}:
* a9262f551e ("block: Change blk_{pread,pwrite}() param order")
* 3b35d4542c ("block: Add a 'flags' param to blk_pread()")
* bf5b16fa40 ("block: Make blk_{pread,pwrite}() return 0 on success")
Those changes especially affected the qemu-img dd patches, because
the context also changed, but also some of our block drivers used
the functions.
* Drop qemu-common.h include: it got renamed after essentially
everything was moved to other headers. The only remaining user I
could find for things dropped from the header between 7.0 and 7.1
was qemu_get_vm_name() in the iscsi-initiatorname patch, but it
already includes the header to which the function was moved.
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2022-10-14 15:07:13 +03:00
|
|
|
index 73ac5eb675..bbfe7eca62 100644
|
2017-04-05 11:49:19 +03:00
|
|
|
--- a/hw/virtio/virtio-balloon.c
|
|
|
|
+++ b/hw/virtio/virtio-balloon.c
|
update submodule and patches to 7.1.0
Notable changes:
* The only big change is the switch to using a custom QIOChannel for
savevm-async, because the previously used QEMUFileOps was dropped.
Changes to the current implementation:
* Switch to vector based methods as required for an IO channel. For
short reads the passed-in IO vector is stuffed with zeroes at the
end, just to be sure.
* For reading: The documentation in include/io/channel.h states that
at least one byte should be read, so also error out when whe are
at the very end instead of returning 0.
* For reading: Fix off-by-one error when request goes beyond end.
The wrong code piece was:
if ((pos + size) > maxlen) {
size = maxlen - pos - 1;
}
Previously, the last byte would not be read. It's actually
possible to get a snapshot .raw file that has content all the way
up the final 512 byte (= BDRV_SECTOR_SIZE) boundary without any
trailing zero bytes (I wrote a script to do it).
Luckily, it didn't cause a real issue, because qemu_loadvm_state()
is not interested in the final (i.e. QEMU_VM_VMDESCRIPTION)
section. The buffer for reading it is simply freed up afterwards
and the function will assume that it read the whole section, even
if that's not the case.
* For writing: Make use of the generated blk_pwritev() wrapper
instead of manually wrapping the coroutine to simplify and save a
few lines.
* Adapt to changed interfaces for blk_{pread,pwrite}:
* a9262f551e ("block: Change blk_{pread,pwrite}() param order")
* 3b35d4542c ("block: Add a 'flags' param to blk_pread()")
* bf5b16fa40 ("block: Make blk_{pread,pwrite}() return 0 on success")
Those changes especially affected the qemu-img dd patches, because
the context also changed, but also some of our block drivers used
the functions.
* Drop qemu-common.h include: it got renamed after essentially
everything was moved to other headers. The only remaining user I
could find for things dropped from the header between 7.0 and 7.1
was qemu_get_vm_name() in the iscsi-initiatorname patch, but it
already includes the header to which the function was moved.
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2022-10-14 15:07:13 +03:00
|
|
|
@@ -806,8 +806,37 @@ static uint64_t virtio_balloon_get_features(VirtIODevice *vdev, uint64_t f,
|
2017-04-05 11:49:19 +03:00
|
|
|
static void virtio_balloon_stat(void *opaque, BalloonInfo *info)
|
|
|
|
{
|
|
|
|
VirtIOBalloon *dev = opaque;
|
|
|
|
- info->actual = get_current_ram_size() - ((uint64_t) dev->actual <<
|
|
|
|
- VIRTIO_BALLOON_PFN_SHIFT);
|
|
|
|
+ ram_addr_t ram_size = get_current_ram_size();
|
|
|
|
+ info->actual = ram_size - ((uint64_t) dev->actual <<
|
|
|
|
+ VIRTIO_BALLOON_PFN_SHIFT);
|
|
|
|
+
|
|
|
|
+ info->max_mem = ram_size;
|
|
|
|
+
|
|
|
|
+ if (!(balloon_stats_enabled(dev) && balloon_stats_supported(dev) &&
|
|
|
|
+ dev->stats_last_update)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ info->last_update = dev->stats_last_update;
|
|
|
|
+ info->has_last_update = true;
|
|
|
|
+
|
|
|
|
+ info->mem_swapped_in = dev->stats[VIRTIO_BALLOON_S_SWAP_IN];
|
|
|
|
+ info->has_mem_swapped_in = info->mem_swapped_in >= 0 ? true : false;
|
|
|
|
+
|
|
|
|
+ info->mem_swapped_out = dev->stats[VIRTIO_BALLOON_S_SWAP_OUT];
|
|
|
|
+ info->has_mem_swapped_out = info->mem_swapped_out >= 0 ? true : false;
|
|
|
|
+
|
|
|
|
+ info->major_page_faults = dev->stats[VIRTIO_BALLOON_S_MAJFLT];
|
|
|
|
+ info->has_major_page_faults = info->major_page_faults >= 0 ? true : false;
|
|
|
|
+
|
|
|
|
+ info->minor_page_faults = dev->stats[VIRTIO_BALLOON_S_MINFLT];
|
|
|
|
+ info->has_minor_page_faults = info->minor_page_faults >= 0 ? true : false;
|
|
|
|
+
|
|
|
|
+ info->free_mem = dev->stats[VIRTIO_BALLOON_S_MEMFREE];
|
|
|
|
+ info->has_free_mem = info->free_mem >= 0 ? true : false;
|
|
|
|
+
|
|
|
|
+ info->total_mem = dev->stats[VIRTIO_BALLOON_S_MEMTOT];
|
|
|
|
+ info->has_total_mem = info->total_mem >= 0 ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void virtio_balloon_to_target(void *opaque, ram_addr_t target)
|
2019-11-20 17:45:35 +03:00
|
|
|
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
|
2022-12-14 17:16:32 +03:00
|
|
|
index 01b789a79e..480b798963 100644
|
2019-11-20 17:45:35 +03:00
|
|
|
--- a/monitor/hmp-cmds.c
|
|
|
|
+++ b/monitor/hmp-cmds.c
|
2022-12-14 17:16:32 +03:00
|
|
|
@@ -696,7 +696,35 @@ void hmp_info_balloon(Monitor *mon, const QDict *qdict)
|
2019-11-20 17:45:35 +03:00
|
|
|
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);
|
|
|
|
}
|
2021-02-11 19:11:11 +03:00
|
|
|
diff --git a/qapi/machine.json b/qapi/machine.json
|
2022-12-14 17:16:32 +03:00
|
|
|
index b9228a5e46..10e77a9af3 100644
|
2021-02-11 19:11:11 +03:00
|
|
|
--- a/qapi/machine.json
|
|
|
|
+++ b/qapi/machine.json
|
update submodule and patches to 7.1.0
Notable changes:
* The only big change is the switch to using a custom QIOChannel for
savevm-async, because the previously used QEMUFileOps was dropped.
Changes to the current implementation:
* Switch to vector based methods as required for an IO channel. For
short reads the passed-in IO vector is stuffed with zeroes at the
end, just to be sure.
* For reading: The documentation in include/io/channel.h states that
at least one byte should be read, so also error out when whe are
at the very end instead of returning 0.
* For reading: Fix off-by-one error when request goes beyond end.
The wrong code piece was:
if ((pos + size) > maxlen) {
size = maxlen - pos - 1;
}
Previously, the last byte would not be read. It's actually
possible to get a snapshot .raw file that has content all the way
up the final 512 byte (= BDRV_SECTOR_SIZE) boundary without any
trailing zero bytes (I wrote a script to do it).
Luckily, it didn't cause a real issue, because qemu_loadvm_state()
is not interested in the final (i.e. QEMU_VM_VMDESCRIPTION)
section. The buffer for reading it is simply freed up afterwards
and the function will assume that it read the whole section, even
if that's not the case.
* For writing: Make use of the generated blk_pwritev() wrapper
instead of manually wrapping the coroutine to simplify and save a
few lines.
* Adapt to changed interfaces for blk_{pread,pwrite}:
* a9262f551e ("block: Change blk_{pread,pwrite}() param order")
* 3b35d4542c ("block: Add a 'flags' param to blk_pread()")
* bf5b16fa40 ("block: Make blk_{pread,pwrite}() return 0 on success")
Those changes especially affected the qemu-img dd patches, because
the context also changed, but also some of our block drivers used
the functions.
* Drop qemu-common.h include: it got renamed after essentially
everything was moved to other headers. The only remaining user I
could find for things dropped from the header between 7.0 and 7.1
was qemu_get_vm_name() in the iscsi-initiatorname patch, but it
already includes the header to which the function was moved.
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2022-10-14 15:07:13 +03:00
|
|
|
@@ -1054,9 +1054,29 @@
|
2021-02-11 19:11:11 +03:00
|
|
|
# @actual: the logical size of the VM in bytes
|
|
|
|
# Formula used: logical_vm_size = vm_ram_size - balloon_size
|
2017-04-05 11:49:19 +03:00
|
|
|
#
|
2017-04-05 12:38:26 +03:00
|
|
|
+# @last_update: time when stats got updated from guest
|
2017-04-05 11:49:19 +03:00
|
|
|
+#
|
2017-04-05 12:38:26 +03:00
|
|
|
+# @mem_swapped_in: number of pages swapped in within the guest
|
2017-04-05 11:49:19 +03:00
|
|
|
+#
|
2017-04-05 12:38:26 +03:00
|
|
|
+# @mem_swapped_out: number of pages swapped out within the guest
|
2017-04-05 11:49:19 +03:00
|
|
|
+#
|
2017-04-05 12:38:26 +03:00
|
|
|
+# @major_page_faults: number of major page faults within the guest
|
2018-02-22 14:34:57 +03:00
|
|
|
+#
|
2017-04-05 12:38:26 +03:00
|
|
|
+# @minor_page_faults: number of minor page faults within the guest
|
2017-04-05 11:49:19 +03:00
|
|
|
+#
|
2017-04-05 12:38:26 +03:00
|
|
|
+# @free_mem: amount of memory (in bytes) free in the guest
|
2017-04-05 11:49:19 +03:00
|
|
|
+#
|
2017-04-05 12:38:26 +03:00
|
|
|
+# @total_mem: amount of memory (in bytes) visible to the guest
|
2017-04-05 11:49:19 +03:00
|
|
|
+#
|
|
|
|
+# @max_mem: amount of memory (in bytes) assigned to the guest
|
2018-02-22 14:34:57 +03:00
|
|
|
+#
|
2021-05-27 13:43:32 +03:00
|
|
|
# Since: 0.14
|
2017-04-05 11:49:19 +03:00
|
|
|
##
|
|
|
|
-{ 'struct': 'BalloonInfo', 'data': {'actual': 'int' } }
|
|
|
|
+{ 'struct': 'BalloonInfo',
|
|
|
|
+ 'data': {'actual': 'int', '*last_update': 'int', '*mem_swapped_in': 'int',
|
|
|
|
+ '*mem_swapped_out': 'int', '*major_page_faults': 'int',
|
|
|
|
+ '*minor_page_faults': 'int', '*free_mem': 'int',
|
|
|
|
+ '*total_mem': 'int', 'max_mem': 'int' } }
|
|
|
|
|
|
|
|
##
|
|
|
|
# @query-balloon:
|
2023-01-10 11:40:57 +03:00
|
|
|
diff --git a/qapi/pragma.json b/qapi/pragma.json
|
|
|
|
index 29233db825..f2097b9020 100644
|
|
|
|
--- a/qapi/pragma.json
|
|
|
|
+++ b/qapi/pragma.json
|
|
|
|
@@ -37,6 +37,7 @@
|
|
|
|
'member-name-exceptions': [ # visible in:
|
|
|
|
'ACPISlotType', # query-acpi-ospm-status
|
|
|
|
'AcpiTableOptions', # -acpitable
|
|
|
|
+ 'BalloonInfo', # query-balloon
|
|
|
|
'BlkdebugEvent', # blockdev-add, -blockdev
|
|
|
|
'BlkdebugSetStateOptions', # blockdev-add, -blockdev
|
|
|
|
'BlockDeviceInfo', # query-block
|