Commit df751fa8bfed4408ca091a7badd75c5ab80f71de

Authored by aliguori
1 parent 8d371d4b

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



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5873 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 2 changed files with 48 additions and 0 deletions
monitor.c
... ... @@ -34,6 +34,7 @@
34 34 #include "block.h"
35 35 #include "audio/audio.h"
36 36 #include "disas.h"
  37 +#include "balloon.h"
37 38 #include <dirent.h>
38 39 #include "qemu-timer.h"
39 40 #include "migration.h"
... ... @@ -1390,6 +1391,23 @@ static void do_inject_nmi(int cpu_index)
1390 1391 }
1391 1392 #endif
1392 1393  
  1394 +static void do_balloon(int value)
  1395 +{
  1396 + ram_addr_t target = value;
  1397 + qemu_balloon(target << 20);
  1398 +}
  1399 +
  1400 +static void do_info_balloon(void)
  1401 +{
  1402 + ram_addr_t actual;
  1403 +
  1404 + actual = qemu_balloon_status();
  1405 + if (actual == 0)
  1406 + term_printf("Ballooning not activated in VM\n");
  1407 + else
  1408 + term_printf("balloon: actual=%d\n", (int)(actual >> 20));
  1409 +}
  1410 +
1393 1411 static const term_cmd_t term_cmds[] = {
1394 1412 { "help|?", "s?", do_help,
1395 1413 "[cmd]", "show the help" },
... ... @@ -1475,6 +1493,8 @@ static const term_cmd_t term_cmds[] = {
1475 1493 "", "cancel the current VM migration" },
1476 1494 { "migrate_set_speed", "s", do_migrate_set_speed,
1477 1495 "value", "set maximum speed (in bytes) for migrations" },
  1496 + { "balloon", "i", do_balloon,
  1497 + "target", "request VM to change it's memory allocation (in MB)" },
1478 1498 { NULL, NULL, },
1479 1499 };
1480 1500  
... ... @@ -1542,6 +1562,8 @@ static const term_cmd_t info_cmds[] = {
1542 1562 "", "show SLIRP statistics", },
1543 1563 #endif
1544 1564 { "migrate", "", do_info_migrate, "", "show migration status" },
  1565 + { "balloon", "", do_info_balloon,
  1566 + "", "show balloon information" },
1545 1567 { NULL, NULL, },
1546 1568 };
1547 1569  
... ...
... ... @@ -40,6 +40,7 @@
40 40 #include "audio/audio.h"
41 41 #include "migration.h"
42 42 #include "kvm.h"
  43 +#include "balloon.h"
43 44  
44 45 #include <unistd.h>
45 46 #include <fcntl.h>
... ... @@ -514,6 +515,31 @@ void hw_error(const char *fmt, ...)
514 515 va_end(ap);
515 516 abort();
516 517 }
  518 +
  519 +/***************/
  520 +/* ballooning */
  521 +
  522 +static QEMUBalloonEvent *qemu_balloon_event;
  523 +void *qemu_balloon_event_opaque;
  524 +
  525 +void qemu_add_balloon_handler(QEMUBalloonEvent *func, void *opaque)
  526 +{
  527 + qemu_balloon_event = func;
  528 + qemu_balloon_event_opaque = opaque;
  529 +}
  530 +
  531 +void qemu_balloon(ram_addr_t target)
  532 +{
  533 + if (qemu_balloon_event)
  534 + qemu_balloon_event(qemu_balloon_event_opaque, target);
  535 +}
  536 +
  537 +ram_addr_t qemu_balloon_status(void)
  538 +{
  539 + if (qemu_balloon_event)
  540 + return qemu_balloon_event(qemu_balloon_event_opaque, 0);
  541 + return 0;
  542 +}
517 543  
518 544 /***********************************************************/
519 545 /* keyboard/mouse */
... ...