]>
Commit | Line | Data |
---|---|---|
23102ed6 | 1 | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
95259824 | 2 | From: Wolfgang Bumiller <w.bumiller@proxmox.com> |
83faa3fe TL |
3 | Date: Mon, 6 Apr 2020 12:16:43 +0200 |
4 | Subject: [PATCH] PVE: virtio-balloon: improve query-balloon | |
95259824 WB |
5 | |
6 | Actually provide memory information via the query-balloon | |
7 | command. | |
b855dce7 TL |
8 | |
9 | Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com> | |
95259824 | 10 | --- |
95259824 | 11 | hw/virtio/virtio-balloon.c | 33 +++++++++++++++++++++++++++++++-- |
be901f66 | 12 | monitor/hmp-cmds.c | 30 +++++++++++++++++++++++++++++- |
817b7667 | 13 | qapi/machine.json | 22 +++++++++++++++++++++- |
6838f038 | 14 | 3 files changed, 81 insertions(+), 4 deletions(-) |
95259824 | 15 | |
95259824 | 16 | diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c |
dc9827a6 | 17 | index 163d244eb4..389907f1f8 100644 |
95259824 WB |
18 | --- a/hw/virtio/virtio-balloon.c |
19 | +++ b/hw/virtio/virtio-balloon.c | |
dc9827a6 | 20 | @@ -813,8 +813,37 @@ static uint64_t virtio_balloon_get_features(VirtIODevice *vdev, uint64_t f, |
95259824 WB |
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) | |
be901f66 | 60 | diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c |
dc9827a6 | 61 | index 634968498b..5482dd0569 100644 |
be901f66 SR |
62 | --- a/monitor/hmp-cmds.c |
63 | +++ b/monitor/hmp-cmds.c | |
dc9827a6 | 64 | @@ -708,7 +708,35 @@ void hmp_info_balloon(Monitor *mon, const QDict *qdict) |
be901f66 SR |
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 | } | |
817b7667 | 101 | diff --git a/qapi/machine.json b/qapi/machine.json |
dc9827a6 | 102 | index d25a481ce4..3627172aed 100644 |
817b7667 SR |
103 | --- a/qapi/machine.json |
104 | +++ b/qapi/machine.json | |
f376b2b9 | 105 | @@ -1018,10 +1018,30 @@ |
817b7667 SR |
106 | # @actual: the logical size of the VM in bytes |
107 | # Formula used: logical_vm_size = vm_ram_size - balloon_size | |
95259824 | 108 | # |
a544966d | 109 | +# @last_update: time when stats got updated from guest |
95259824 | 110 | +# |
a544966d | 111 | +# @mem_swapped_in: number of pages swapped in within the guest |
95259824 | 112 | +# |
a544966d | 113 | +# @mem_swapped_out: number of pages swapped out within the guest |
95259824 | 114 | +# |
a544966d | 115 | +# @major_page_faults: number of major page faults within the guest |
6838f038 | 116 | +# |
a544966d | 117 | +# @minor_page_faults: number of minor page faults within the guest |
95259824 | 118 | +# |
a544966d | 119 | +# @free_mem: amount of memory (in bytes) free in the guest |
95259824 | 120 | +# |
a544966d | 121 | +# @total_mem: amount of memory (in bytes) visible to the guest |
95259824 WB |
122 | +# |
123 | +# @max_mem: amount of memory (in bytes) assigned to the guest | |
6838f038 | 124 | +# |
8dca018b | 125 | # Since: 0.14 |
6838f038 | 126 | # |
95259824 WB |
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: |