aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorkaf24@labyrinth.cl.cam.ac.uk <kaf24@labyrinth.cl.cam.ac.uk>2003-03-03 15:43:22 +0000
committerkaf24@labyrinth.cl.cam.ac.uk <kaf24@labyrinth.cl.cam.ac.uk>2003-03-03 15:43:22 +0000
commitdfca2c82d597482bab554fd1256cdb13154efba7 (patch)
tree8c4c3d724d509a1e14015f139cdde1d8b51cb4d5 /tools
parent4f13d2a61fc684ddbc11d482f91f8c6cc788fd9e (diff)
parentf456b7444e6fa5a931a76960606bf0b4bc9b26fa (diff)
downloadxen-dfca2c82d597482bab554fd1256cdb13154efba7.tar.gz
xen-dfca2c82d597482bab554fd1256cdb13154efba7.tar.bz2
xen-dfca2c82d597482bab554fd1256cdb13154efba7.zip
bitkeeper revision 1.105.1.8 (3e63781aEVDfQh1rIWk8m6mnaO7HtA)
Merge labyrinth.cl.cam.ac.uk:/usr/groups/xeno/BK/xeno.bk into labyrinth.cl.cam.ac.uk:/local/scratch/kaf24/bd-xeno
Diffstat (limited to 'tools')
-rw-r--r--tools/balloon/Makefile9
-rw-r--r--tools/balloon/README17
-rw-r--r--tools/balloon/balloon.c114
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;
+}
+
+
+