diff options
author | kaf24@labyrinth.cl.cam.ac.uk <kaf24@labyrinth.cl.cam.ac.uk> | 2003-03-03 15:43:06 +0000 |
---|---|---|
committer | kaf24@labyrinth.cl.cam.ac.uk <kaf24@labyrinth.cl.cam.ac.uk> | 2003-03-03 15:43:06 +0000 |
commit | f456b7444e6fa5a931a76960606bf0b4bc9b26fa (patch) | |
tree | 9d66ab06c457e50148b6be2b072a994fc4543d8f /tools | |
parent | 20989dbdb2adad8912e687ed18f5fe32c2770d86 (diff) | |
download | xen-f456b7444e6fa5a931a76960606bf0b4bc9b26fa.tar.gz xen-f456b7444e6fa5a931a76960606bf0b4bc9b26fa.tar.bz2 xen-f456b7444e6fa5a931a76960606bf0b4bc9b26fa.zip |
bitkeeper revision 1.102.1.1 (3e63780anLue1rOR9-4fOlXH3ejAhA)
dom_mem_ops.h, balloon.c, Makefile, dom_mem_ops.c, README:
new file
Many files:
Boris's balloon driver.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/balloon/Makefile | 9 | ||||
-rw-r--r-- | tools/balloon/README | 17 | ||||
-rw-r--r-- | tools/balloon/balloon.c | 114 |
3 files changed, 140 insertions, 0 deletions
diff --git a/tools/balloon/Makefile b/tools/balloon/Makefile new file mode 100644 index 0000000000..49bab90077 --- /dev/null +++ b/tools/balloon/Makefile @@ -0,0 +1,9 @@ +CC = gcc +TARGET=balloon + +TARGET: balloon.c + $(CC) -O2 -Wall -o $(TARGET) balloon.c + +clean: + $(RM) *.o $(TARGET) *~ + diff --git a/tools/balloon/README b/tools/balloon/README new file mode 100644 index 0000000000..430e8f41bf --- /dev/null +++ b/tools/balloon/README @@ -0,0 +1,17 @@ +Xeno Balloon driver supports two operations: + +1. Inflating - which means domain giving up pages of mem to xen. +2. Deflating - which means reclaiming memory pages from xen. + +Currently, domain can only claim pages from xen up to the number of +previously released ones. This is to change. + +Example: + +# balloon inflate 1000 + +Give up 1000 pages to xen. + +# balloon deflate 1000 + +Claim 1000 pages from xen. diff --git a/tools/balloon/balloon.c b/tools/balloon/balloon.c new file mode 100644 index 0000000000..9c90a7ab62 --- /dev/null +++ b/tools/balloon/balloon.c @@ -0,0 +1,114 @@ +/****************************************************************************** + * balloon.c + * + * Xeno balloon driver userspace control tool. Used to shrink/grow domain's + * memory. + * + * Copyright (c) 2003, B Dragovic + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + +#define INFLATE_BALLOON "inflate" /* return mem to hypervisor */ +#define DEFLATE_BALLOON "deflate" /* claim mem from hypervisor */ + +/* THIS IS TAKEN FROM XENOLINUX BALLOON DRIVER */ +#define USER_INFLATE_BALLOON 1 /* return mem to hypervisor */ +#define USER_DEFLATE_BALLOON 2 /* claim mem from hypervisor */ +typedef struct user_balloon_op { + unsigned int op; + unsigned long size; +} user_balloon_op_t; +/* END OF CODE TAKEN FROM XENOLINUX BALLOON DRIVER */ + + +static int open_balloon_proc() +{ + return open("/proc/xeno/balloon", O_RDWR); +} + +/* inflate balloon function signals to kernel it should relinquish memory */ +static int inflate_balloon(unsigned long num_pages) +{ + user_balloon_op_t bop; + int proc_fd; + + if((proc_fd = open_balloon_proc()) <= 0){ + printf("Error opening balloon proc file.\n"); + return 0; + } + + bop.op = USER_INFLATE_BALLOON; + bop.size = num_pages; + if ( write(proc_fd, &bop, sizeof(bop)) <= 0 ) + { + printf("Error writing to balloon proc file.\n"); + return 0; + } + + close(proc_fd); + return 1; +} + +/* deflate balloon function signals to kernel it should claim memory */ +static int deflate_balloon(unsigned long num_pages) +{ + user_balloon_op_t bop; + int proc_fd; + + if((proc_fd = open_balloon_proc()) <= 0){ + printf("Error opening balloon proc file.\n"); + return 0; + } + + bop.op = USER_DEFLATE_BALLOON; + bop.size = num_pages; + if(write(proc_fd, &bop, sizeof(bop)) <= 0){ + printf("Error writing to balloon proc file.\n"); + return 0; + } + + close(proc_fd); + return 1; +} + +int main(int argc, char *argv[]) +{ + unsigned long num_pages; + + if(argc < 2){ + printf("Usage: balloon <inflate|deflate> <num_pages>\n"); + return -1; + } + + num_pages = atol(argv[2]); + + if(!strcmp(argv[1], INFLATE_BALLOON)){ + if(!inflate_balloon(num_pages)){ + perror("Inflating balloon failed"); + return -1; + } + + } else if (!strcmp(argv[1], DEFLATE_BALLOON)){ + if(!deflate_balloon(num_pages)){ + perror("Deflating balloon failed"); + return -1; + } + + } else { + printf("Unrecognized command line argument.\n"); + return -1; + } + + return 0; +} + + + |