[libvirt] [PATCH] qemu: Parse current balloon value returned by query_balloon.

Qemu once supported following memory stats which will returned by "query_balloon": stat_put(dict, "actual", actual); stat_put(dict, "mem_swapped_in", dev->stats[VIRTIO_BALLOON_S_SWAP_IN]); stat_put(dict, "mem_swapped_out", dev->stats[VIRTIO_BALLOON_S_SWAP_OUT]); stat_put(dict, "major_page_faults", dev->stats[VIRTIO_BALLOON_S_MAJFLT]); stat_put(dict, "minor_page_faults", dev->stats[VIRTIO_BALLOON_S_MINFLT]); stat_put(dict, "free_mem", dev->stats[VIRTIO_BALLOON_S_MEMFREE]); stat_put(dict, "total_mem", dev->stats[VIRTIO_BALLOON_S_MEMTOT]); But it later disabled all the stats except "actual" by commit 07b0403dfc2b2ac179ae5b48105096cc2d03375a. libvirt doesn't parse "actual", so user will always see a empty result with "virsh dommemstat $domain". Even qemu haven't disabled the stats, we should support parsing "actual". --- include/libvirt/libvirt.h.in | 4 +++- src/libvirt.c | 2 ++ src/qemu/qemu_monitor_json.c | 12 ++++++++++++ tools/virsh.c | 2 ++ 4 files changed, 19 insertions(+), 1 deletions(-) diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index 8058229..864852b 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -456,11 +456,13 @@ typedef enum { */ VIR_DOMAIN_MEMORY_STAT_AVAILABLE = 5, + /* Current balloon value (in KB). */ + VIR_DOMAIN_MEMORY_STAT_ACTUAL = 6, /* * The number of statistics supported by this version of the interface. * To add new statistics, add them to the enum and increase this value. */ - VIR_DOMAIN_MEMORY_STAT_NR = 6, + VIR_DOMAIN_MEMORY_STAT_NR = 7, } virDomainMemoryStatTags; typedef struct _virDomainMemoryStat virDomainMemoryStatStruct; diff --git a/src/libvirt.c b/src/libvirt.c index eaae0ec..c635ff5 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -5802,6 +5802,8 @@ error: * The amount of memory which is not being used for any purpose (in kb). * VIR_DOMAIN_MEMORY_STAT_AVAILABLE: * The total amount of memory available to the domain's OS (in kb). + * VIR_DOMAIN_MEMORY_STAT_ACTUAL: + * Current balloon value (in kb). * * Returns: The number of stats provided or -1 in case of failure. */ diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 75adf66..9f16403 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -1119,6 +1119,18 @@ int qemuMonitorJSONGetMemoryStats(qemuMonitorPtr mon, goto cleanup; } + if (virJSONValueObjectHasKey(data, "actual") && (got < nr_stats)) { + if (virJSONValueObjectGetNumberUlong(data, "actual", &mem) < 0) { + qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("info balloon reply was missing balloon actual")); + ret = -1; + goto cleanup; + } + stats[got].tag = VIR_DOMAIN_MEMORY_STAT_ACTUAL; + stats[got].val = (mem/1024); + got++; + } + if (virJSONValueObjectHasKey(data, "mem_swapped_in") && (got < nr_stats)) { if (virJSONValueObjectGetNumberUlong(data, "mem_swapped_in", &mem) < 0) { qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s", diff --git a/tools/virsh.c b/tools/virsh.c index 5679a2d..a358b73 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -1147,6 +1147,8 @@ cmdDomMemStat(vshControl *ctl, const vshCmd *cmd) vshPrint (ctl, "unused %llu\n", stats[i].val); if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_AVAILABLE) vshPrint (ctl, "available %llu\n", stats[i].val); + if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_ACTUAL) + vshPrint (ctl, "actual %llu\n", stats[i].val); } virDomainFree(dom); -- 1.7.4

2011/6/3 Osier Yang <jyang@redhat.com>:
Qemu once supported following memory stats which will returned by "query_balloon":
stat_put(dict, "actual", actual); stat_put(dict, "mem_swapped_in", dev->stats[VIRTIO_BALLOON_S_SWAP_IN]); stat_put(dict, "mem_swapped_out", dev->stats[VIRTIO_BALLOON_S_SWAP_OUT]); stat_put(dict, "major_page_faults", dev->stats[VIRTIO_BALLOON_S_MAJFLT]); stat_put(dict, "minor_page_faults", dev->stats[VIRTIO_BALLOON_S_MINFLT]); stat_put(dict, "free_mem", dev->stats[VIRTIO_BALLOON_S_MEMFREE]); stat_put(dict, "total_mem", dev->stats[VIRTIO_BALLOON_S_MEMTOT]);
But it later disabled all the stats except "actual" by commit 07b0403dfc2b2ac179ae5b48105096cc2d03375a.
libvirt doesn't parse "actual", so user will always see a empty result with "virsh dommemstat $domain". Even qemu haven't disabled the stats, we should support parsing "actual". --- include/libvirt/libvirt.h.in | 4 +++- src/libvirt.c | 2 ++ src/qemu/qemu_monitor_json.c | 12 ++++++++++++ tools/virsh.c | 2 ++ 4 files changed, 19 insertions(+), 1 deletions(-)
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index 8058229..864852b 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -456,11 +456,13 @@ typedef enum { */ VIR_DOMAIN_MEMORY_STAT_AVAILABLE = 5,
+ /* Current balloon value (in KB). */ + VIR_DOMAIN_MEMORY_STAT_ACTUAL = 6,
Is this the memory size occupied by the balloon? Then I suggest we call this VIR_DOMAIN_MEMORY_STAT_BALLOON instead or VIR_DOMAIN_MEMORY_STAT_ACTUAL_BALLOON if you want to keep the 'actual' in there. Matthias

On 06/03/2011 02:24 AM, Osier Yang wrote:
Qemu once supported following memory stats which will returned by "query_balloon":
stat_put(dict, "actual", actual); stat_put(dict, "mem_swapped_in", dev->stats[VIRTIO_BALLOON_S_SWAP_IN]); stat_put(dict, "mem_swapped_out", dev->stats[VIRTIO_BALLOON_S_SWAP_OUT]); stat_put(dict, "major_page_faults", dev->stats[VIRTIO_BALLOON_S_MAJFLT]); stat_put(dict, "minor_page_faults", dev->stats[VIRTIO_BALLOON_S_MINFLT]); stat_put(dict, "free_mem", dev->stats[VIRTIO_BALLOON_S_MEMFREE]); stat_put(dict, "total_mem", dev->stats[VIRTIO_BALLOON_S_MEMTOT]);
include/libvirt/libvirt.h.in | 4 +++- src/libvirt.c | 2 ++ src/qemu/qemu_monitor_json.c | 12 ++++++++++++ tools/virsh.c | 2 ++ 4 files changed, 19 insertions(+), 1 deletions(-)
In addition to Matthias' review, does qemu_monitor_text.c also need to support this? I think we need a v2. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

On 06/03/2011 10:22 PM, Eric Blake wrote:
On 06/03/2011 02:24 AM, Osier Yang wrote:
Qemu once supported following memory stats which will returned by "query_balloon":
stat_put(dict, "actual", actual); stat_put(dict, "mem_swapped_in", dev->stats[VIRTIO_BALLOON_S_SWAP_IN]); stat_put(dict, "mem_swapped_out", dev->stats[VIRTIO_BALLOON_S_SWAP_OUT]); stat_put(dict, "major_page_faults", dev->stats[VIRTIO_BALLOON_S_MAJFLT]); stat_put(dict, "minor_page_faults", dev->stats[VIRTIO_BALLOON_S_MINFLT]); stat_put(dict, "free_mem", dev->stats[VIRTIO_BALLOON_S_MEMFREE]); stat_put(dict, "total_mem", dev->stats[VIRTIO_BALLOON_S_MEMTOT]);
include/libvirt/libvirt.h.in | 4 +++- src/libvirt.c | 2 ++ src/qemu/qemu_monitor_json.c | 12 ++++++++++++ tools/virsh.c | 2 ++ 4 files changed, 19 insertions(+), 1 deletions(-)
In addition to Matthias' review, does qemu_monitor_text.c also need to support this? I think we need a v2.
Yes, will update, thanks for the reviewing. Regards Osier
participants (3)
-
Eric Blake
-
Matthias Bolte
-
Osier Yang