Hello,
I'm unsure whether this question is for xen-devel or for the (dead?)
xen-api mailinglist?
Inspired by Dan Magenheimers xenballoond patch ("[PATCH] xenballoond
(memory overcommit) scripts"), I'd like to program the xenballoond for a
Dom0, so that there is no need to run it in every DomU, which improves
the possibility for policing and probably the monitoring.
My question is what api I should use to program it? xenapi or libvirt?
And how do I get values that are in xenstored? I didn't find a function
in the xenapi or libvirt? Are there any examples?
My first implementation of the program, was made in the bash, but I
guess C or python is the better way for it.
The first implementation was based on the attached kernel patch, which
only make the memory information of the domU kernel accessible by
xenstore, if CONFIG_XEN_DAEMON_BALLOON is set.
Attached to this email is my first implementation of the program. It
looks every second whether a domain needs more or less memory and change
the value.
greetings
Viets
--- linux-2.6.18-xen.hg-xenU/drivers/xen/Kconfig 2008-05-20
13:48:59.576488000 +0200
+++ linux-2.6.18-xen.hg-xenU.bak/drivers/xen/Kconfig 2008-07-03
11:08:30.185692418 +0200
@@ -255,6 +255,13 @@
Disable serial port drivers, allowing the Xen console driver
to provide a serial console at ttyS0.
+config XEN_DAEMON_BALLOON_SUPPORT
+ bool "Enable xen daemon balloon support"
+ depends XEN_UNPRIVILEGED_GUEST
+ default n
+ help
+ Enable xen daemon balloon support
+
config XEN_SYSFS
tristate "Export Xen attributes in sysfs"
depends on SYSFS
--- linux-2.6.18-xen.hg-xenU/fs/proc/proc_misc.c 2008-05-20
13:49:00.866441000 +0200
+++ linux-2.6.18-xen.hg-xenU.bak/fs/proc/proc_misc.c 2008-07-03
11:15:09.735692418 +0200
@@ -52,6 +52,10 @@
#include <asm/div64.h>
#include "internal.h"
+#ifdef CONFIG_XEN_DAEMON_BALLOON_SUPPORT
+#include <xen/xenbus.h>
+#endif
+
#define LOAD_INT(x) ((x) >> FSHIFT)
#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
/*
@@ -203,6 +207,13 @@
vmi.used >> 10,
vmi.largest_chunk >> 10
);
+#ifdef CONFIG_XEN_DAEMON_BALLOON_SUPPORT
+ (void)xenbus_printf(XBT_NIL, "memory", "Committed_AS",
+ "%lu", K(committed) );
+ (void)xenbus_printf(XBT_NIL, "memory", "MemTotal",
+ "%lu", K(i.totalram) );
+#endif
+
len += hugetlb_report_meminfo(page + len);
#/bin/bash
curkb() {
kb=$(xenstore-read /local/domain/$1/memory/MemTotal);
RETVAL=$kb
return # value returned in RETVAL in kB
}
downhysteresis() {
# RETVAL=$XENBALLOON_AUTO_DOWNHYSTERESIS
# if [ $xenstore_enabled = "true" ]; then
# if xenstore-exists memory/downhysteresis ; then
# RETVAL=`xenstore-read memory/downhysteresis`
# fi
# fi
RETVAL=10;
return;
}
uphysteresis() {
# RETVAL=$XENBALLOON_AUTO_UPHYSTERESIS
# if [ $xenstore_enabled = "true" ]; then
# if xenstore-exists memory/uphysteresis ; then
# RETVAL=`xenstore-read memory/uphysteresis`
# fi
# fi
RETVAL=1;
return
}
minmb() {
RETVAL=$XENBALLOON_MINMEM;
if [ $RETVAL -ne 0 ]; then
return $RETVAL
fi
kb=$(cat $maxkb);
let "mb=$kb/1024";
let "pages=$kb/4";
# this algorithm from drivers/xen/balloon/balloon.c:minimum_target()
# which was added to balloon.c in 2008 to avoid ballooning too small
# it is unnecessary here except to accomodate pre-2008 balloon drivers
# note that ranges are adjusted because a VM with "memory=1024"
# gets somewhat less than 1024MB
if [ $mb -lt 125 ]; then
let RETVAL="$(( 8 + ($pages >> 9) ))"
elif [ $mb -lt 500 ]; then
let RETVAL="$(( 40 + ($pages >> 10) ))"
elif [ $mb -lt 2000 ]; then
let RETVAL="$(( 104 + ($pages >> 11) ))"
else
let RETVAL="$(( 296 + ($pages >> 13) ))"
fi
return # value returned in RETVAL in mB
}
selftarget() {
tgtkb=$(xenstore-read /local/domain/$1/memory/Committed_AS);
minmb;
let "minbytes=$RETVAL*1024*1024";
let "tgtbytes=$tgtkb*1024";
if [ $tgtbytes -lt $minbytes ]; then
let "tgtbytes=$minbytes";
fi
RETVAL=$tgtbytes # value returned in RETVAL in bytes
return
}
balloon_to_target() {
if [ "$2" -eq 1 ]; then
selftarget $1;
tgtbytes=$RETVAL;
else
let "tgtbytes=$(( $1 * 1024 ))";
fi;
curkb $1;
let "curbytes=$RETVAL*1024"
if [ $curbytes -gt $tgtbytes ]; then
downhysteresis;
downhys=$RETVAL
if [ $downhys -ne 0 ]; then
let "tgtbytes=$(( $curbytes - \
( ( $curbytes - $tgtbytes ) / $downhys ) ))"
fi
else if [ $curbytes -lt $tgtbytes ]; then
uphysteresis
uphys=$RETVAL
let "tgtbytes=$(( $curbytes + \
( ( $tgtbytes - $curbytes ) / $uphys ) ))"
fi
fi
let "tgt=$(( $tgtbytes/1024/1024 ))";
xm mem-set $1 $tgt;
let "tgtkb=$(( $tgtbytes/1024 ))"
xenstore-write /local/domain/$1/memory/selftarget $tgtkb
}
selfballoon_eval() {
if xenstore-exists /local/domain/$1/memory/selfballoon; then
RETVAL=$(xenstore-read /local/domain/$1/memory/selfballoon);
if [ $RETVAL -eq 1 ]; then
selfballoon_enabled=true;
return;
fi;
fi;
selfballoon_enabled=$XENBALLOON_SELF;
return;
}
maxkb=1073741824;
. /etc/sysconfig/xenballoon.conf
while true; do
for i in $(xm list | awk '{print $2;'} | fgrep -v 'ID' | fgrep -v '0'); do
# curkb=$(xenstore-read /local/domain/$i/memory/MemTotal);
selfballoon_eval $i;
# if [ $selfballoon_enabled = "true" ]; then
tgtkb=$(xenstore-read /local/domain/$i/memory/target);
balloon_to_target $i $tgtkb;
# fi;
done;
sleep $XENBALLOON_INTERVAL;
done
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|