]> git.proxmox.com Git - pve-qemu.git/blob - debian/patches/pve/0013-PVE-virtio-balloon-improve-query-balloon.patch
a52235f45d3363885a466c216d036be48307eca8
[pve-qemu.git] / debian / patches / pve / 0013-PVE-virtio-balloon-improve-query-balloon.patch
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Wolfgang Bumiller <w.bumiller@proxmox.com>
3 Date: Mon, 6 Apr 2020 12:16:43 +0200
4 Subject: [PATCH] PVE: virtio-balloon: improve query-balloon
5
6 Actually provide memory information via the query-balloon
7 command.
8
9 Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
10 ---
11 hw/virtio/virtio-balloon.c | 33 +++++++++++++++++++++++++++++++--
12 monitor/hmp-cmds.c | 30 +++++++++++++++++++++++++++++-
13 qapi/machine.json | 22 +++++++++++++++++++++-
14 3 files changed, 81 insertions(+), 4 deletions(-)
15
16 diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
17 index 163d244eb4..389907f1f8 100644
18 --- a/hw/virtio/virtio-balloon.c
19 +++ b/hw/virtio/virtio-balloon.c
20 @@ -813,8 +813,37 @@ static uint64_t virtio_balloon_get_features(VirtIODevice *vdev, uint64_t f,
21 static void virtio_balloon_stat(void *opaque, BalloonInfo *info)
22 {
23 VirtIOBalloon *dev = opaque;
24 - info->actual = get_current_ram_size() - ((uint64_t) dev->actual <<
25 - VIRTIO_BALLOON_PFN_SHIFT);
26 + ram_addr_t ram_size = get_current_ram_size();
27 + info->actual = ram_size - ((uint64_t) dev->actual <<
28 + VIRTIO_BALLOON_PFN_SHIFT);
29 +
30 + info->max_mem = ram_size;
31 +
32 + if (!(balloon_stats_enabled(dev) && balloon_stats_supported(dev) &&
33 + dev->stats_last_update)) {
34 + return;
35 + }
36 +
37 + info->last_update = dev->stats_last_update;
38 + info->has_last_update = true;
39 +
40 + info->mem_swapped_in = dev->stats[VIRTIO_BALLOON_S_SWAP_IN];
41 + info->has_mem_swapped_in = info->mem_swapped_in >= 0 ? true : false;
42 +
43 + info->mem_swapped_out = dev->stats[VIRTIO_BALLOON_S_SWAP_OUT];
44 + info->has_mem_swapped_out = info->mem_swapped_out >= 0 ? true : false;
45 +
46 + info->major_page_faults = dev->stats[VIRTIO_BALLOON_S_MAJFLT];
47 + info->has_major_page_faults = info->major_page_faults >= 0 ? true : false;
48 +
49 + info->minor_page_faults = dev->stats[VIRTIO_BALLOON_S_MINFLT];
50 + info->has_minor_page_faults = info->minor_page_faults >= 0 ? true : false;
51 +
52 + info->free_mem = dev->stats[VIRTIO_BALLOON_S_MEMFREE];
53 + info->has_free_mem = info->free_mem >= 0 ? true : false;
54 +
55 + info->total_mem = dev->stats[VIRTIO_BALLOON_S_MEMTOT];
56 + info->has_total_mem = info->total_mem >= 0 ? true : false;
57 }
58
59 static void virtio_balloon_to_target(void *opaque, ram_addr_t target)
60 diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
61 index 634968498b..5482dd0569 100644
62 --- a/monitor/hmp-cmds.c
63 +++ b/monitor/hmp-cmds.c
64 @@ -708,7 +708,35 @@ void hmp_info_balloon(Monitor *mon, const QDict *qdict)
65 return;
66 }
67
68 - monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
69 + monitor_printf(mon, "balloon: actual=%" PRId64, info->actual >> 20);
70 + monitor_printf(mon, " max_mem=%" PRId64, info->max_mem >> 20);
71 + if (info->has_total_mem) {
72 + monitor_printf(mon, " total_mem=%" PRId64, info->total_mem >> 20);
73 + }
74 + if (info->has_free_mem) {
75 + monitor_printf(mon, " free_mem=%" PRId64, info->free_mem >> 20);
76 + }
77 +
78 + if (info->has_mem_swapped_in) {
79 + monitor_printf(mon, " mem_swapped_in=%" PRId64, info->mem_swapped_in);
80 + }
81 + if (info->has_mem_swapped_out) {
82 + monitor_printf(mon, " mem_swapped_out=%" PRId64, info->mem_swapped_out);
83 + }
84 + if (info->has_major_page_faults) {
85 + monitor_printf(mon, " major_page_faults=%" PRId64,
86 + info->major_page_faults);
87 + }
88 + if (info->has_minor_page_faults) {
89 + monitor_printf(mon, " minor_page_faults=%" PRId64,
90 + info->minor_page_faults);
91 + }
92 + if (info->has_last_update) {
93 + monitor_printf(mon, " last_update=%" PRId64,
94 + info->last_update);
95 + }
96 +
97 + monitor_printf(mon, "\n");
98
99 qapi_free_BalloonInfo(info);
100 }
101 diff --git a/qapi/machine.json b/qapi/machine.json
102 index d25a481ce4..3627172aed 100644
103 --- a/qapi/machine.json
104 +++ b/qapi/machine.json
105 @@ -1018,10 +1018,30 @@
106 # @actual: the logical size of the VM in bytes
107 # Formula used: logical_vm_size = vm_ram_size - balloon_size
108 #
109 +# @last_update: time when stats got updated from guest
110 +#
111 +# @mem_swapped_in: number of pages swapped in within the guest
112 +#
113 +# @mem_swapped_out: number of pages swapped out within the guest
114 +#
115 +# @major_page_faults: number of major page faults within the guest
116 +#
117 +# @minor_page_faults: number of minor page faults within the guest
118 +#
119 +# @free_mem: amount of memory (in bytes) free in the guest
120 +#
121 +# @total_mem: amount of memory (in bytes) visible to the guest
122 +#
123 +# @max_mem: amount of memory (in bytes) assigned to the guest
124 +#
125 # Since: 0.14
126 #
127 ##
128 -{ 'struct': 'BalloonInfo', 'data': {'actual': 'int' } }
129 +{ 'struct': 'BalloonInfo',
130 + 'data': {'actual': 'int', '*last_update': 'int', '*mem_swapped_in': 'int',
131 + '*mem_swapped_out': 'int', '*major_page_faults': 'int',
132 + '*minor_page_faults': 'int', '*free_mem': 'int',
133 + '*total_mem': 'int', 'max_mem': 'int' } }
134
135 ##
136 # @query-balloon: