]> git.proxmox.com Git - pve-qemu-kvm.git/blame - debian/patches/pve/0006-virtio-balloon-fix-query.patch
update to 2.7
[pve-qemu-kvm.git] / debian / patches / pve / 0006-virtio-balloon-fix-query.patch
CommitLineData
68a30562 1From ff496e015b9b53c2d49a0110d247223872d5a582 Mon Sep 17 00:00:00 2001
ca0fe5f5
WB
2From: Wolfgang Bumiller <w.bumiller@proxmox.com>
3Date: Wed, 9 Dec 2015 14:27:49 +0100
68a30562 4Subject: [PATCH 06/41] virtio-balloon: fix query
ca0fe5f5
WB
5
6Actually provide memory information via the query-balloon
7command.
8---
9 hmp.c | 30 +++++++++++++++++++++++++++++-
10 hw/virtio/virtio-balloon.c | 33 +++++++++++++++++++++++++++++++--
11 qapi-schema.json | 23 +++++++++++++++++++++--
12 qmp-commands.hx | 13 +++++++++++++
13 4 files changed, 94 insertions(+), 5 deletions(-)
14
15diff --git a/hmp.c b/hmp.c
68a30562 16index cc2056e..aa1395d 100644
ca0fe5f5
WB
17--- a/hmp.c
18+++ b/hmp.c
68a30562 19@@ -704,7 +704,35 @@ void hmp_info_balloon(Monitor *mon, const QDict *qdict)
ca0fe5f5
WB
20 return;
21 }
22
23- monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
24+ monitor_printf(mon, "balloon: actual=%" PRId64, info->actual >> 20);
25+ monitor_printf(mon, " max_mem=%" PRId64, info->max_mem >> 20);
26+ if (info->has_total_mem) {
27+ monitor_printf(mon, " total_mem=%" PRId64, info->total_mem >> 20);
28+ }
29+ if (info->has_free_mem) {
30+ monitor_printf(mon, " free_mem=%" PRId64, info->free_mem >> 20);
31+ }
32+
33+ if (info->has_mem_swapped_in) {
34+ monitor_printf(mon, " mem_swapped_in=%" PRId64, info->mem_swapped_in);
35+ }
36+ if (info->has_mem_swapped_out) {
37+ monitor_printf(mon, " mem_swapped_out=%" PRId64, info->mem_swapped_out);
38+ }
39+ if (info->has_major_page_faults) {
40+ monitor_printf(mon, " major_page_faults=%" PRId64,
41+ info->major_page_faults);
42+ }
43+ if (info->has_minor_page_faults) {
44+ monitor_printf(mon, " minor_page_faults=%" PRId64,
45+ info->minor_page_faults);
46+ }
47+ if (info->has_last_update) {
48+ monitor_printf(mon, " last_update=%" PRId64,
49+ info->last_update);
50+ }
51+
52+ monitor_printf(mon, "\n");
53
54 qapi_free_BalloonInfo(info);
55 }
56diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
68a30562 57index 5af429a..d87b971 100644
ca0fe5f5
WB
58--- a/hw/virtio/virtio-balloon.c
59+++ b/hw/virtio/virtio-balloon.c
68a30562 60@@ -376,8 +376,37 @@ static uint64_t virtio_balloon_get_features(VirtIODevice *vdev, uint64_t f,
ca0fe5f5
WB
61 static void virtio_balloon_stat(void *opaque, BalloonInfo *info)
62 {
63 VirtIOBalloon *dev = opaque;
64- info->actual = get_current_ram_size() - ((uint64_t) dev->actual <<
65- VIRTIO_BALLOON_PFN_SHIFT);
66+ ram_addr_t ram_size = get_current_ram_size();
67+ info->actual = ram_size - ((uint64_t) dev->actual <<
68+ VIRTIO_BALLOON_PFN_SHIFT);
69+
70+ info->max_mem = ram_size;
71+
72+ if (!(balloon_stats_enabled(dev) && balloon_stats_supported(dev) &&
73+ dev->stats_last_update)) {
74+ return;
75+ }
76+
77+ info->last_update = dev->stats_last_update;
78+ info->has_last_update = true;
79+
80+ info->mem_swapped_in = dev->stats[VIRTIO_BALLOON_S_SWAP_IN];
81+ info->has_mem_swapped_in = info->mem_swapped_in >= 0 ? true : false;
82+
83+ info->mem_swapped_out = dev->stats[VIRTIO_BALLOON_S_SWAP_OUT];
84+ info->has_mem_swapped_out = info->mem_swapped_out >= 0 ? true : false;
85+
86+ info->major_page_faults = dev->stats[VIRTIO_BALLOON_S_MAJFLT];
87+ info->has_major_page_faults = info->major_page_faults >= 0 ? true : false;
88+
89+ info->minor_page_faults = dev->stats[VIRTIO_BALLOON_S_MINFLT];
90+ info->has_minor_page_faults = info->minor_page_faults >= 0 ? true : false;
91+
92+ info->free_mem = dev->stats[VIRTIO_BALLOON_S_MEMFREE];
93+ info->has_free_mem = info->free_mem >= 0 ? true : false;
94+
95+ info->total_mem = dev->stats[VIRTIO_BALLOON_S_MEMTOT];
96+ info->has_total_mem = info->total_mem >= 0 ? true : false;
97 }
98
99 static void virtio_balloon_to_target(void *opaque, ram_addr_t target)
100diff --git a/qapi-schema.json b/qapi-schema.json
68a30562 101index 5658723..4bf7222 100644
ca0fe5f5
WB
102--- a/qapi-schema.json
103+++ b/qapi-schema.json
68a30562 104@@ -1278,10 +1278,29 @@
ca0fe5f5
WB
105 #
106 # @actual: the number of bytes the balloon currently contains
107 #
108-# Since: 0.14.0
109+# @last_update: #optional time when stats got updated from guest
110+#
111+# @mem_swapped_in: #optional number of pages swapped in within the guest
112+#
113+# @mem_swapped_out: #optional number of pages swapped out within the guest
114+#
115+# @major_page_faults: #optional number of major page faults within the guest
116 #
117+# @minor_page_faults: #optional number of minor page faults within the guest
118+#
119+# @free_mem: #optional amount of memory (in bytes) free in the guest
120+#
121+# @total_mem: #optional 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.0
126 ##
127-{ 'struct': 'BalloonInfo', 'data': {'actual': 'int' } }
128+{ 'struct': 'BalloonInfo',
129+ 'data': {'actual': 'int', '*last_update': 'int', '*mem_swapped_in': 'int',
130+ '*mem_swapped_out': 'int', '*major_page_faults': 'int',
131+ '*minor_page_faults': 'int', '*free_mem': 'int',
132+ '*total_mem': 'int', 'max_mem': 'int' } }
133
134 ##
135 # @query-balloon:
136diff --git a/qmp-commands.hx b/qmp-commands.hx
68a30562 137index 6866264..6de28d4 100644
ca0fe5f5
WB
138--- a/qmp-commands.hx
139+++ b/qmp-commands.hx
68a30562 140@@ -3854,6 +3854,13 @@ Make an asynchronous request for balloon info. When the request completes a
ca0fe5f5
WB
141 json-object will be returned containing the following data:
142
143 - "actual": current balloon value in bytes (json-int)
144+- "mem_swapped_in": Amount of memory swapped in bytes (json-int, optional)
145+- "mem_swapped_out": Amount of memory swapped out in bytes (json-int, optional)
146+- "major_page_faults": Number of major faults (json-int, optional)
147+- "minor_page_faults": Number of minor faults (json-int, optional)
148+- "free_mem": Total amount of free and unused memory in
149+ bytes (json-int, optional)
150+- "total_mem": Total amount of available memory in bytes (json-int, optional)
151
152 Example:
153
68a30562 154@@ -3861,6 +3868,12 @@ Example:
ca0fe5f5
WB
155 <- {
156 "return":{
157 "actual":1073741824,
158+ "mem_swapped_in":0,
159+ "mem_swapped_out":0,
160+ "major_page_faults":142,
161+ "minor_page_faults":239245,
162+ "free_mem":1014185984,
163+ "total_mem":1044668416
164 }
165 }
166
167--
1682.1.4
169