提交 df751fa8 编写于 作者: A aliguori

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: NAnthony Liguori <aliguori@us.ibm.com>



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5873 c046a42c-6fe2-441c-8c8c-71466251a162
上级 8d371d4b
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "block.h" #include "block.h"
#include "audio/audio.h" #include "audio/audio.h"
#include "disas.h" #include "disas.h"
#include "balloon.h"
#include <dirent.h> #include <dirent.h>
#include "qemu-timer.h" #include "qemu-timer.h"
#include "migration.h" #include "migration.h"
...@@ -1390,6 +1391,23 @@ static void do_inject_nmi(int cpu_index) ...@@ -1390,6 +1391,23 @@ static void do_inject_nmi(int cpu_index)
} }
#endif #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[] = { static const term_cmd_t term_cmds[] = {
{ "help|?", "s?", do_help, { "help|?", "s?", do_help,
"[cmd]", "show the help" }, "[cmd]", "show the help" },
...@@ -1475,6 +1493,8 @@ static const term_cmd_t term_cmds[] = { ...@@ -1475,6 +1493,8 @@ static const term_cmd_t term_cmds[] = {
"", "cancel the current VM migration" }, "", "cancel the current VM migration" },
{ "migrate_set_speed", "s", do_migrate_set_speed, { "migrate_set_speed", "s", do_migrate_set_speed,
"value", "set maximum speed (in bytes) for migrations" }, "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, }, { NULL, NULL, },
}; };
...@@ -1542,6 +1562,8 @@ static const term_cmd_t info_cmds[] = { ...@@ -1542,6 +1562,8 @@ static const term_cmd_t info_cmds[] = {
"", "show SLIRP statistics", }, "", "show SLIRP statistics", },
#endif #endif
{ "migrate", "", do_info_migrate, "", "show migration status" }, { "migrate", "", do_info_migrate, "", "show migration status" },
{ "balloon", "", do_info_balloon,
"", "show balloon information" },
{ NULL, NULL, }, { NULL, NULL, },
}; };
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include "audio/audio.h" #include "audio/audio.h"
#include "migration.h" #include "migration.h"
#include "kvm.h" #include "kvm.h"
#include "balloon.h"
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
...@@ -515,6 +516,31 @@ void hw_error(const char *fmt, ...) ...@@ -515,6 +516,31 @@ void hw_error(const char *fmt, ...)
abort(); 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 */ /* keyboard/mouse */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册