]>
Commit | Line | Data |
---|---|---|
1a91ab45 | 1 | From 5921bc0360f6964a5bb5355c2707c806425f4734 Mon Sep 17 00:00:00 2001 |
ca0fe5f5 WB |
2 | From: Wolfgang Bumiller <w.bumiller@proxmox.com> |
3 | Date: Wed, 9 Dec 2015 14:27:49 +0100 | |
adeb0c7a | 4 | Subject: [PATCH 06/48] virtio-balloon: fix query |
ca0fe5f5 WB |
5 | |
6 | Actually provide memory information via the query-balloon | |
7 | command. | |
8 | --- | |
9 | hmp.c | 30 +++++++++++++++++++++++++++++- | |
10 | hw/virtio/virtio-balloon.c | 33 +++++++++++++++++++++++++++++++-- | |
11 | qapi-schema.json | 23 +++++++++++++++++++++-- | |
1a91ab45 | 12 | 3 files changed, 81 insertions(+), 5 deletions(-) |
ca0fe5f5 WB |
13 | |
14 | diff --git a/hmp.c b/hmp.c | |
1a91ab45 | 15 | index edb8970..904542d 100644 |
ca0fe5f5 WB |
16 | --- a/hmp.c |
17 | +++ b/hmp.c | |
1a91ab45 | 18 | @@ -723,7 +723,35 @@ void hmp_info_balloon(Monitor *mon, const QDict *qdict) |
ca0fe5f5 WB |
19 | return; |
20 | } | |
21 | ||
22 | - monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20); | |
23 | + monitor_printf(mon, "balloon: actual=%" PRId64, info->actual >> 20); | |
24 | + monitor_printf(mon, " max_mem=%" PRId64, info->max_mem >> 20); | |
25 | + if (info->has_total_mem) { | |
26 | + monitor_printf(mon, " total_mem=%" PRId64, info->total_mem >> 20); | |
27 | + } | |
28 | + if (info->has_free_mem) { | |
29 | + monitor_printf(mon, " free_mem=%" PRId64, info->free_mem >> 20); | |
30 | + } | |
31 | + | |
32 | + if (info->has_mem_swapped_in) { | |
33 | + monitor_printf(mon, " mem_swapped_in=%" PRId64, info->mem_swapped_in); | |
34 | + } | |
35 | + if (info->has_mem_swapped_out) { | |
36 | + monitor_printf(mon, " mem_swapped_out=%" PRId64, info->mem_swapped_out); | |
37 | + } | |
38 | + if (info->has_major_page_faults) { | |
39 | + monitor_printf(mon, " major_page_faults=%" PRId64, | |
40 | + info->major_page_faults); | |
41 | + } | |
42 | + if (info->has_minor_page_faults) { | |
43 | + monitor_printf(mon, " minor_page_faults=%" PRId64, | |
44 | + info->minor_page_faults); | |
45 | + } | |
46 | + if (info->has_last_update) { | |
47 | + monitor_printf(mon, " last_update=%" PRId64, | |
48 | + info->last_update); | |
49 | + } | |
50 | + | |
51 | + monitor_printf(mon, "\n"); | |
52 | ||
53 | qapi_free_BalloonInfo(info); | |
54 | } | |
55 | diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c | |
1a91ab45 | 56 | index a705e0e..158e13e 100644 |
ca0fe5f5 WB |
57 | --- a/hw/virtio/virtio-balloon.c |
58 | +++ b/hw/virtio/virtio-balloon.c | |
1a91ab45 | 59 | @@ -379,8 +379,37 @@ static uint64_t virtio_balloon_get_features(VirtIODevice *vdev, uint64_t f, |
ca0fe5f5 WB |
60 | static void virtio_balloon_stat(void *opaque, BalloonInfo *info) |
61 | { | |
62 | VirtIOBalloon *dev = opaque; | |
63 | - info->actual = get_current_ram_size() - ((uint64_t) dev->actual << | |
64 | - VIRTIO_BALLOON_PFN_SHIFT); | |
65 | + ram_addr_t ram_size = get_current_ram_size(); | |
66 | + info->actual = ram_size - ((uint64_t) dev->actual << | |
67 | + VIRTIO_BALLOON_PFN_SHIFT); | |
68 | + | |
69 | + info->max_mem = ram_size; | |
70 | + | |
71 | + if (!(balloon_stats_enabled(dev) && balloon_stats_supported(dev) && | |
72 | + dev->stats_last_update)) { | |
73 | + return; | |
74 | + } | |
75 | + | |
76 | + info->last_update = dev->stats_last_update; | |
77 | + info->has_last_update = true; | |
78 | + | |
79 | + info->mem_swapped_in = dev->stats[VIRTIO_BALLOON_S_SWAP_IN]; | |
80 | + info->has_mem_swapped_in = info->mem_swapped_in >= 0 ? true : false; | |
81 | + | |
82 | + info->mem_swapped_out = dev->stats[VIRTIO_BALLOON_S_SWAP_OUT]; | |
83 | + info->has_mem_swapped_out = info->mem_swapped_out >= 0 ? true : false; | |
84 | + | |
85 | + info->major_page_faults = dev->stats[VIRTIO_BALLOON_S_MAJFLT]; | |
86 | + info->has_major_page_faults = info->major_page_faults >= 0 ? true : false; | |
87 | + | |
88 | + info->minor_page_faults = dev->stats[VIRTIO_BALLOON_S_MINFLT]; | |
89 | + info->has_minor_page_faults = info->minor_page_faults >= 0 ? true : false; | |
90 | + | |
91 | + info->free_mem = dev->stats[VIRTIO_BALLOON_S_MEMFREE]; | |
92 | + info->has_free_mem = info->free_mem >= 0 ? true : false; | |
93 | + | |
94 | + info->total_mem = dev->stats[VIRTIO_BALLOON_S_MEMTOT]; | |
95 | + info->has_total_mem = info->total_mem >= 0 ? true : false; | |
96 | } | |
97 | ||
98 | static void virtio_balloon_to_target(void *opaque, ram_addr_t target) | |
99 | diff --git a/qapi-schema.json b/qapi-schema.json | |
1a91ab45 | 100 | index b921994..e7a8117 100644 |
ca0fe5f5 WB |
101 | --- a/qapi-schema.json |
102 | +++ b/qapi-schema.json | |
1a91ab45 | 103 | @@ -1900,10 +1900,29 @@ |
ca0fe5f5 WB |
104 | # |
105 | # @actual: the number of bytes the balloon currently contains | |
106 | # | |
107 | -# Since: 0.14.0 | |
1a91ab45 | 108 | +# @last_update: time when stats got updated from guest |
ca0fe5f5 | 109 | +# |
1a91ab45 | 110 | +# @mem_swapped_in: number of pages swapped in within the guest |
ca0fe5f5 | 111 | +# |
1a91ab45 | 112 | +# @mem_swapped_out: number of pages swapped out within the guest |
ca0fe5f5 | 113 | +# |
1a91ab45 | 114 | +# @major_page_faults: number of major page faults within the guest |
ca0fe5f5 | 115 | # |
1a91ab45 | 116 | +# @minor_page_faults: number of minor page faults within the guest |
ca0fe5f5 | 117 | +# |
1a91ab45 | 118 | +# @free_mem: amount of memory (in bytes) free in the guest |
ca0fe5f5 | 119 | +# |
1a91ab45 | 120 | +# @total_mem: amount of memory (in bytes) visible to the guest |
ca0fe5f5 WB |
121 | +# |
122 | +# @max_mem: amount of memory (in bytes) assigned to the guest | |
123 | +# | |
124 | +# Since: 0.14.0 | |
125 | ## | |
126 | -{ 'struct': 'BalloonInfo', 'data': {'actual': 'int' } } | |
127 | +{ 'struct': 'BalloonInfo', | |
128 | + 'data': {'actual': 'int', '*last_update': 'int', '*mem_swapped_in': 'int', | |
129 | + '*mem_swapped_out': 'int', '*major_page_faults': 'int', | |
130 | + '*minor_page_faults': 'int', '*free_mem': 'int', | |
131 | + '*total_mem': 'int', 'max_mem': 'int' } } | |
132 | ||
133 | ## | |
134 | # @query-balloon: | |
ca0fe5f5 WB |
135 | -- |
136 | 2.1.4 | |
137 |