diff options
author | Adam Litke <agl@us.ibm.com> | 2010-01-26 14:17:35 -0600 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2010-01-26 17:08:03 -0600 |
commit | 625a5befc2e3200b396594f002218d235e375da5 (patch) | |
tree | 89b9362c879d319b5061424035e3dbead9555e70 /monitor.c | |
parent | 940cc30d0d456781adcc48bf9f8c5582026d7983 (diff) | |
download | qemu-625a5befc2e3200b396594f002218d235e375da5.tar.gz qemu-625a5befc2e3200b396594f002218d235e375da5.tar.bz2 qemu-625a5befc2e3200b396594f002218d235e375da5.zip |
virtio: Add memory statistics reporting to the balloon driver
When using ballooning to manage overcommitted memory on a host, a system for
guests to communicate their memory usage to the host can provide information
that will minimize the impact of ballooning on the guests. The current method
employs a daemon running in each guest that communicates memory statistics to a
host daemon at a specified time interval. The host daemon aggregates this
information and inflates and/or deflates balloons according to the level of
host memory pressure. This approach is effective but overly complex since a
daemon must be installed inside each guest and coordinated to communicate with
the host. A simpler approach is to collect memory statistics in the virtio
balloon driver and communicate them directly to the hypervisor.
Signed-off-by: Adam Litke <agl@us.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'monitor.c')
-rw-r--r-- | monitor.c | 98 |
1 files changed, 61 insertions, 37 deletions
@@ -2152,33 +2152,13 @@ static void do_info_status(Monitor *mon, QObject **ret_data) vm_running, singlestep); } -static ram_addr_t balloon_get_value(void) +static void print_balloon_stat(const char *key, QObject *obj, void *opaque) { - ram_addr_t actual; - - if (kvm_enabled() && !kvm_has_sync_mmu()) { - qemu_error_new(QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon"); - return 0; - } - - actual = qemu_balloon_status(); - if (actual == 0) { - qemu_error_new(QERR_DEVICE_NOT_ACTIVE, "balloon"); - return 0; - } - - return actual; -} + Monitor *mon = opaque; -/** - * do_balloon(): Request VM to change its memory allocation - */ -static void do_balloon(Monitor *mon, const QDict *qdict, QObject **ret_data) -{ - if (balloon_get_value()) { - /* ballooning is active */ - qemu_balloon(qdict_get_int(qdict, "value")); - } + if (strcmp(key, "actual")) + monitor_printf(mon, ",%s=%" PRId64, key, + qint_get_int(qobject_to_qint(obj))); } static void monitor_print_balloon(Monitor *mon, const QObject *data) @@ -2186,31 +2166,74 @@ static void monitor_print_balloon(Monitor *mon, const QObject *data) QDict *qdict; qdict = qobject_to_qdict(data); + if (!qdict_haskey(qdict, "actual")) + return; - monitor_printf(mon, "balloon: actual=%" PRId64 "\n", - qdict_get_int(qdict, "balloon") >> 20); + monitor_printf(mon, "balloon: actual=%" PRId64, + qdict_get_int(qdict, "actual") >> 20); + qdict_iter(qdict, print_balloon_stat, mon); + monitor_printf(mon, "\n"); } /** * do_info_balloon(): Balloon information * - * Return a QDict with the following information: + * Make an asynchronous request for balloon info. When the request completes + * a QDict will be returned according to the following specification: * - * - "balloon": current balloon value in bytes + * - "actual": current balloon value in bytes + * The following fields may or may not be present: + * - "mem_swapped_in": Amount of memory swapped in (bytes) + * - "mem_swapped_out": Amount of memory swapped out (bytes) + * - "major_page_faults": Number of major faults + * - "minor_page_faults": Number of minor faults + * - "free_mem": Total amount of free and unused memory (bytes) + * - "total_mem": Total amount of available memory (bytes) * * Example: * - * { "balloon": 1073741824 } + * { "actual": 1073741824, "mem_swapped_in": 0, "mem_swapped_out": 0, + * "major_page_faults": 142, "minor_page_faults": 239245, + * "free_mem": 1014185984, "total_mem": 1044668416 } + */ +static int do_info_balloon(Monitor *mon, MonitorCompletion cb, void *opaque) +{ + int ret; + + if (kvm_enabled() && !kvm_has_sync_mmu()) { + qemu_error_new(QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon"); + return -1; + } + + ret = qemu_balloon_status(cb, opaque); + if (!ret) { + qemu_error_new(QERR_DEVICE_NOT_ACTIVE, "balloon"); + return -1; + } + + return 0; +} + +/** + * do_balloon(): Request VM to change its memory allocation */ -static void do_info_balloon(Monitor *mon, QObject **ret_data) +static int do_balloon(Monitor *mon, const QDict *params, + MonitorCompletion cb, void *opaque) { - ram_addr_t actual; + int ret; + + if (kvm_enabled() && !kvm_has_sync_mmu()) { + qemu_error_new(QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon"); + return -1; + } - actual = balloon_get_value(); - if (actual != 0) { - *ret_data = qobject_from_jsonf("{ 'balloon': %" PRId64 "}", - (int64_t) actual); + ret = qemu_balloon(qdict_get_int(params, "value"), cb, opaque); + if (ret == 0) { + qemu_error_new(QERR_DEVICE_NOT_ACTIVE, "balloon"); + return -1; } + + return 0; } static qemu_acl *find_acl(Monitor *mon, const char *name) @@ -2696,7 +2719,8 @@ static const mon_cmd_t info_cmds[] = { .params = "", .help = "show balloon information", .user_print = monitor_print_balloon, - .mhandler.info_new = do_info_balloon, + .mhandler.info_async = do_info_balloon, + .async = 1, }, { .name = "qtree", |