Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L8Kfi-0000fg-Ck for qemu-devel@nongnu.org; Thu, 04 Dec 2008 15:19:38 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L8Kfh-0000f9-Mq for qemu-devel@nongnu.org; Thu, 04 Dec 2008 15:19:37 -0500 Received: from [199.232.76.173] (port=42246 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L8Kfh-0000f3-Bs for qemu-devel@nongnu.org; Thu, 04 Dec 2008 15:19:37 -0500 Received: from savannah.gnu.org ([199.232.41.3]:45048 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1L8Kfh-00069t-5X for qemu-devel@nongnu.org; Thu, 04 Dec 2008 15:19:37 -0500 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1L8Kfg-0007VT-HE for qemu-devel@nongnu.org; Thu, 04 Dec 2008 20:19:36 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1L8Kfg-0007VP-1o for qemu-devel@nongnu.org; Thu, 04 Dec 2008 20:19:36 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Thu, 04 Dec 2008 20:19:36 +0000 Subject: [Qemu-devel] [5873] Add ballooning infrastructure. Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 5873 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5873 Author: aliguori Date: 2008-12-04 20:19:35 +0000 (Thu, 04 Dec 2008) Log Message: ----------- Add ballooning infrastructure. Balloon devices allow you to ask the guest to allocate memory. This allows you to release that memory. It's mostly useful for freeing up large chunks of memory from cooperative guests. Ballooning is supported by both Xen and VirtIO. Signed-off-by: Anthony Liguori Modified Paths: -------------- trunk/monitor.c trunk/vl.c Modified: trunk/monitor.c =================================================================== --- trunk/monitor.c 2008-12-04 20:08:06 UTC (rev 5872) +++ trunk/monitor.c 2008-12-04 20:19:35 UTC (rev 5873) @@ -34,6 +34,7 @@ #include "block.h" #include "audio/audio.h" #include "disas.h" +#include "balloon.h" #include #include "qemu-timer.h" #include "migration.h" @@ -1390,6 +1391,23 @@ } #endif +static void do_balloon(int value) +{ + ram_addr_t target = value; + qemu_balloon(target << 20); +} + +static void do_info_balloon(void) +{ + ram_addr_t actual; + + actual = qemu_balloon_status(); + if (actual == 0) + term_printf("Ballooning not activated in VM\n"); + else + term_printf("balloon: actual=%d\n", (int)(actual >> 20)); +} + static const term_cmd_t term_cmds[] = { { "help|?", "s?", do_help, "[cmd]", "show the help" }, @@ -1475,6 +1493,8 @@ "", "cancel the current VM migration" }, { "migrate_set_speed", "s", do_migrate_set_speed, "value", "set maximum speed (in bytes) for migrations" }, + { "balloon", "i", do_balloon, + "target", "request VM to change it's memory allocation (in MB)" }, { NULL, NULL, }, }; @@ -1542,6 +1562,8 @@ "", "show SLIRP statistics", }, #endif { "migrate", "", do_info_migrate, "", "show migration status" }, + { "balloon", "", do_info_balloon, + "", "show balloon information" }, { NULL, NULL, }, }; Modified: trunk/vl.c =================================================================== --- trunk/vl.c 2008-12-04 20:08:06 UTC (rev 5872) +++ trunk/vl.c 2008-12-04 20:19:35 UTC (rev 5873) @@ -40,6 +40,7 @@ #include "audio/audio.h" #include "migration.h" #include "kvm.h" +#include "balloon.h" #include #include @@ -514,7 +515,32 @@ va_end(ap); abort(); } + +/***************/ +/* ballooning */ +static QEMUBalloonEvent *qemu_balloon_event; +void *qemu_balloon_event_opaque; + +void qemu_add_balloon_handler(QEMUBalloonEvent *func, void *opaque) +{ + qemu_balloon_event = func; + qemu_balloon_event_opaque = opaque; +} + +void qemu_balloon(ram_addr_t target) +{ + if (qemu_balloon_event) + qemu_balloon_event(qemu_balloon_event_opaque, target); +} + +ram_addr_t qemu_balloon_status(void) +{ + if (qemu_balloon_event) + return qemu_balloon_event(qemu_balloon_event_opaque, 0); + return 0; +} + /***********************************************************/ /* keyboard/mouse */