ia64/xen-unstable

changeset 17935:0c5183e764d8

xenballoond (memory overcommit) scripts

See the README and conf files for more info.

Signed-off-by: Dan Magenheimer <dan.magenheimer@oracle.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Jul 01 11:40:07 2008 +0100 (2008-07-01)
parents 73a4fbdfe0c4
children 0b7f7c564c83
files tools/xenballoon/xenballoon-monitor tools/xenballoon/xenballoon.conf tools/xenballoon/xenballoond tools/xenballoon/xenballoond.README tools/xenballoon/xenballoond.init
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tools/xenballoon/xenballoon-monitor	Tue Jul 01 11:40:07 2008 +0100
     1.3 @@ -0,0 +1,43 @@
     1.4 +#!/bin/bash
     1.5 +#
     1.6 +# xenballoon-monitor - monitor certain stats from xenballoond
     1.7 +#   (run in dom0 with "watch -d xenballoon-monitor" for xentop-like output)
     1.8 +#
     1.9 +# Copyright (C) 2009 Oracle Corporation and/or its affiliates.
    1.10 +# All rights reserved
    1.11 +# Written by: Dan Magenheimer <dan.magenheimer@oracle.com>
    1.12 +#
    1.13 +# Hint: Use "xm sched-credit -d 0 -w 2000" to watch on heavily loaded machines
    1.14 +#
    1.15 +echo "id   mem-kb  tgt-kb  commit   swapin  swapout      pgin     pgout active(sec)"
    1.16 +for i in `xenstore-list /local/domain`; do
    1.17 + if [ "$i" -ne 0 ]; then
    1.18 + tot=0; tgt=0; sin=0; sout=0; pgin=0; pgout=0; cmt=0; up=0; idle=0; act=0;
    1.19 + if xenstore-exists /local/domain/$i/memory/meminfo; then
    1.20 +  tot=`xenstore-read /local/domain/$i/memory/meminfo | grep MemTotal \
    1.21 +   | sed 's/[^1-9]*\([1-9][0-9]*\).*/\1/'`
    1.22 +  cmt=`xenstore-read /local/domain/$i/memory/meminfo | grep Committed_AS \
    1.23 +   | sed 's/[^1-9]*\([1-9][0-9]*\).*/\1/'`
    1.24 + fi
    1.25 + if xenstore-exists /local/domain/$i/memory/selftarget; then
    1.26 +  tgt=`xenstore-read /local/domain/$i/memory/selftarget`
    1.27 + fi
    1.28 + if xenstore-exists /local/domain/$i/memory/vmstat; then
    1.29 +  sin=`xenstore-read /local/domain/$i/memory/vmstat | grep pswpin \
    1.30 + 	| cut -d" " -f2`
    1.31 +  sout=`xenstore-read /local/domain/$i/memory/vmstat | grep pswpout \
    1.32 + 	| cut -d" " -f2`
    1.33 +  pgin=`xenstore-read /local/domain/$i/memory/vmstat | grep pgpgin \
    1.34 + 	| cut -d" " -f2`
    1.35 +  pgout=`xenstore-read /local/domain/$i/memory/vmstat | grep pgout \
    1.36 +  	| cut -d" " -f2`
    1.37 + fi
    1.38 + if xenstore-exists /local/domain/$i/memory/uptime; then
    1.39 +  up=`xenstore-read /local/domain/$i/memory/uptime | cut -d" " -f1`
    1.40 +  idle=`xenstore-read /local/domain/$i/memory/uptime | cut -d" " -f2`
    1.41 +  act=`echo $up - $idle | bc -iq`
    1.42 + fi
    1.43 + printf "%2d %8d%8d%8d%9d%9d%10d%10d%10.2f\n" $i $tot $tgt $cmt $sin $sout $pgin $pgout $act
    1.44 + fi
    1.45 +done
    1.46 +echo Free memory: `xm info | grep free | sed 's/[^1-9]*\([1-9][0-9]*\).*/\1/'` MB
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/tools/xenballoon/xenballoon.conf	Tue Jul 01 11:40:07 2008 +0100
     2.3 @@ -0,0 +1,91 @@
     2.4 +## Path: System/xen
     2.5 +## Description: xen domain start/stop on boot
     2.6 +## Type: string
     2.7 +## Default: 
     2.8 +
     2.9 +# NOTE: "xenbus is enabled" means not only that /proc/xen/xenbus exists
    2.10 +# but also that /usr/bin/xenstore-* tools are installed.
    2.11 +
    2.12 +## Type: boolean
    2.13 +## Default: false
    2.14 +#
    2.15 +# If XENBALLOON_SELF is true, selfballooning will occur, meaning the
    2.16 +# balloon driver will grow and shrink according to available memory.
    2.17 +# If xenbus is enabled, may be overridden by {memory/selfballoon}==0
    2.18 +# If false but xenballoond is able to communicate with domain0 via
    2.19 +# xenbus, balloon targets will be set by domain0
    2.20 +# 
    2.21 +XENBALLOON_SELF=false
    2.22 +
    2.23 +## Type: integer (must be > 0)
    2.24 +## Default: 1
    2.25 +#
    2.26 +# If self-ballooning, number of seconds between checks/adjustments.
    2.27 +# If xenbus is enabled, may be overridden by {memory/interval}
    2.28 +XENBALLOON_SELF_INTERVAL=1
    2.29 +
    2.30 +## Type: integer (must be > 0)
    2.31 +## Default: 1
    2.32 +#
    2.33 +# If NOT self-ballooning but xenbus is enabled, number of seconds between
    2.34 +# checks/adjustments. May be overridden by {memory/interval}
    2.35 +XENBALLOON_INTERVAL=1
    2.36 +
    2.37 +## Type: integer (must be > 0)
    2.38 +## Default: 10
    2.39 +#
    2.40 +# When current > target, reduces rate at which target memory is ballooned
    2.41 +# out.  For a value of n, 1/n of the difference will be ballooned.
    2.42 +# This value applies both to selfballooning and directed ballooning.
    2.43 +# May be overridden by {memory/downhysteresis}
    2.44 +XENBALLOON_AUTO_DOWNHYSTERESIS=10
    2.45 +
    2.46 +## Type: integer (must be > 0)
    2.47 +## Default: 1
    2.48 +#
    2.49 +# When current < target, reduces rate at which target memory is reclaimed
    2.50 +# (if available).  For a value of n, 1/n of the difference will be ballooned.
    2.51 +# This value applies both to selfballooning and directed ballooning.
    2.52 +# May be overridden by {memory/uphysteresis}
    2.53 +XENBALLOON_AUTO_UPHYSTERESIS=1
    2.54 +
    2.55 +## Type: integer (must be >= 0)
    2.56 +## Default: 0
    2.57 +#
    2.58 +# In order to avoid ballooning so much memory that a guest experiences
    2.59 +# out-of-memory errors (OOMs), memory will not be ballooned out below
    2.60 +# a minimum target, in MB.  If this value is 0 (default), an heuristic
    2.61 +# based on the maximum amount of memory will be used.  (The heuristic
    2.62 +# provides the same minimum as recent versions of the balloon driver but
    2.63 +# early versions of the balloon driver did not enforce a minimum.)
    2.64 +XENBALLOON_MINMEM=0
    2.65 +
    2.66 +## Type: string
    2.67 +## Default: "/var/run/xenballoon-maxmem"
    2.68 +#
    2.69 +# Location where memory high-water mark is stored; if a guest supports
    2.70 +# hot-add memory, maxmem might increase across time and the minimum
    2.71 +# target heuristic is based on max memory. NOTE: Reboot after changing
    2.72 +# this variable, else overballooning may occur.
    2.73 +XENBALLOON_MAXMEMFILE=/var/run/xenballoon-maxmem
    2.74 +
    2.75 +## Type: integer (0 or 1)
    2.76 +## Default: 1
    2.77 +#
    2.78 +# If xenbus is enabled, whether selfballooning or directed ballooning,
    2.79 +# place the result of 'cat /proc/meminfo" on xenbus at memory/meminfo
    2.80 +XENBALLOON_SEND_MEMINFO=1
    2.81 +
    2.82 +## Type: integer (0 or 1)
    2.83 +## Default: 1
    2.84 +#
    2.85 +# If xenbus is enabled, whether selfballooning or directed ballooning,
    2.86 +# place the result of 'cat /proc/vmstat" on xenbus at memory/vmstat
    2.87 +XENBALLOON_SEND_VMSTAT=1
    2.88 +
    2.89 +## Type: integer (0 or 1)
    2.90 +## Default: 1
    2.91 +#
    2.92 +# If xenbus is enabled, whether selfballooning or directed ballooning,
    2.93 +# place the result of 'cat /proc/uptime" on xenbus at memory/uptime
    2.94 +XENBALLOON_SEND_UPTIME=1
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tools/xenballoon/xenballoond	Tue Jul 01 11:40:07 2008 +0100
     3.3 @@ -0,0 +1,205 @@
     3.4 +#!/bin/bash
     3.5 +#
     3.6 +# Copyright (C) 2008 Oracle Corporation and/or its affiliates.
     3.7 +# All rights reserved.
     3.8 +# Written by: Dan Magenheimer <dan.magenheimer@oracle.com>
     3.9 +#
    3.10 +# xenballoond - In-guest engine for Xen memory ballooning
    3.11 +# Version: 080630
    3.12 +#
    3.13 +# Two "policies" are implemented:
    3.14 +# - Selfballooning: Adjust memory periodically, with no (or little) input
    3.15 +#     from domain0.  Target memory is determined solely by the
    3.16 +#     Committed_AS line in /proc/meminfo, but parameters may adjust
    3.17 +#     the rate at which the target is achieved.
    3.18 +# - Directed ballooning: Adjust memory solely as directed by domain0
    3.19 +#
    3.20 +# Under some circumstances, "output" may also be generated; the contents
    3.21 +# of /proc/meminfo and /proc/vmstat may be periodically placed on xenbus.
    3.22 +#
    3.23 +# If xenbus is running and the /usr/bin/xenstore-* tools are installed,
    3.24 +# "xenbus is enabled".
    3.25 +#
    3.26 +# Parameters are documented in /etc/sysconfig/xenballoon.conf. Although 
    3.27 +# some are not used with directed ballooning, all must be set properly.
    3.28 +# If xenbus is enabled, some of these parameters may be overridden by values
    3.29 +# set by domain0 via xenbus.
    3.30 +
    3.31 +minmb() {
    3.32 +	RETVAL=$XENBALLOON_MINMEM
    3.33 +	if [ $RETVAL -ne 0 ]; then
    3.34 +		return $RETVAL
    3.35 +	fi
    3.36 +	kb=`cat $XENBALLOON_MAXMEMFILE`
    3.37 +	let "mb=$kb/1024"
    3.38 +	let "pages=$kb/4"
    3.39 +	# this algorithm from drivers/xen/balloon/balloon.c:minimum_target()
    3.40 +	# which was added to balloon.c in 2008 to avoid ballooning too small
    3.41 +	# it is unnecessary here except to accomodate pre-2008 balloon drivers
    3.42 +	# note that ranges are adjusted because a VM with "memory=1024"
    3.43 +	# gets somewhat less than 1024MB
    3.44 +	if [ $mb -lt 125 ]; then
    3.45 +		let RETVAL="$(( 8 + ($pages >> 9) ))"
    3.46 +	elif [ $mb -lt 500 ]; then
    3.47 +		let RETVAL="$(( 40 + ($pages >> 10) ))"
    3.48 +	elif [ $mb -lt 2000 ]; then
    3.49 +		let RETVAL="$(( 104 + ($pages >> 11) ))"
    3.50 +	else
    3.51 +		let RETVAL="$(( 296 + ($pages >> 13) ))"
    3.52 +	fi
    3.53 +	return	# value returned in RETVAL in mB
    3.54 +}
    3.55 +
    3.56 +curkb() {
    3.57 +	kb=`grep MemTotal /proc/meminfo | sed 's/  */ /' | \
    3.58 +		cut -f2 -d' '`
    3.59 +	RETVAL=$kb
    3.60 +	return  # value returned in RETVAL in kB
    3.61 +}
    3.62 +
    3.63 +downhysteresis() {
    3.64 +	RETVAL=$XENBALLOON_AUTO_DOWNHYSTERESIS
    3.65 +	if [ $xenstore_enabled = "true" ]; then
    3.66 +		if xenstore-exists memory/downhysteresis ; then
    3.67 +			RETVAL=`xenstore-read memory/downhysteresis`
    3.68 +		fi
    3.69 +	fi
    3.70 +	return
    3.71 +}
    3.72 +
    3.73 +uphysteresis() {
    3.74 +	RETVAL=$XENBALLOON_AUTO_UPHYSTERESIS
    3.75 +	if [ $xenstore_enabled = "true" ]; then
    3.76 +		if xenstore-exists memory/uphysteresis ; then
    3.77 +			RETVAL=`xenstore-read memory/uphysteresis`
    3.78 +		fi
    3.79 +	fi
    3.80 +	return
    3.81 +}
    3.82 +
    3.83 +selfballoon_eval() {
    3.84 +	if [ $xenstore_enabled = "true" ]; then
    3.85 +		if xenstore-exists memory/selfballoon; then
    3.86 +			RETVAL=`xenstore-read memory/selfballoon`
    3.87 +			if [ $RETVAL -eq 1 ]; then
    3.88 +				selfballoon_enabled=true
    3.89 +				return
    3.90 +			fi
    3.91 +		fi
    3.92 +	fi
    3.93 +	selfballoon_enabled=$XENBALLOON_SELF
    3.94 +	return
    3.95 +}
    3.96 +
    3.97 +selftarget() {
    3.98 +	tgtkb=`grep Committed_AS /proc/meminfo | sed 's/  */ /' | cut -f2 -d' '`
    3.99 +	minmb
   3.100 +	let "minbytes=$RETVAL*1024*1024"
   3.101 +	let "tgtbytes=$tgtkb*1024"
   3.102 +	if [ $tgtbytes -lt $minbytes ]; then
   3.103 +		let "tgtbytes=$minbytes"
   3.104 +	fi
   3.105 +	RETVAL=$tgtbytes  # value returned in RETVAL in bytes
   3.106 +	return
   3.107 +}
   3.108 +
   3.109 +# $1 == 1 means use selftarget, else target in kB
   3.110 +balloon_to_target() {
   3.111 +	if [ "$1" -eq 1 ]; then
   3.112 +		selftarget
   3.113 +		tgtbytes=$RETVAL
   3.114 +	else
   3.115 +		let "tgtbytes=$(( $1 * 1024 ))"
   3.116 +	fi
   3.117 +	curkb
   3.118 +	let "curbytes=$RETVAL*1024"
   3.119 +	if [ $curbytes -gt $tgtbytes ]; then
   3.120 +		downhysteresis
   3.121 +		downhys=$RETVAL
   3.122 +		if [ $downhys -ne 0 ]; then
   3.123 +			let "tgtbytes=$(( $curbytes - \
   3.124 +				( ( $curbytes - $tgtbytes ) / $downhys ) ))"
   3.125 +		fi
   3.126 +	else if [ $curbytes -lt $tgtbytes ]; then
   3.127 +		uphysteresis
   3.128 +		uphys=$RETVAL
   3.129 +		let "tgtbytes=$(( $curbytes + \
   3.130 +				( ( $tgtbytes - $curbytes ) / $uphys ) ))"
   3.131 +		fi
   3.132 +	fi
   3.133 +	echo $tgtbytes > /proc/xen/balloon
   3.134 +	if [ $xenstore_enabled = "true" ]; then
   3.135 +		let "tgtkb=$(( $tgtbytes/1024 ))"
   3.136 +		xenstore-write memory/selftarget $tgtkb
   3.137 +	fi
   3.138 +}
   3.139 +
   3.140 +send_memory_stats() {
   3.141 +	if [ ! $xenstore_enabled = "true" ]; then
   3.142 +		return
   3.143 +	fi
   3.144 +	if [ $XENBALLOON_SEND_MEMINFO ]; then
   3.145 +		xenstore-write memory/meminfo "`cat /proc/meminfo`"
   3.146 +	fi
   3.147 +	if [ $XENBALLOON_SEND_VMSTAT ]; then
   3.148 +		xenstore-write memory/vmstat "`cat /proc/vmstat`"
   3.149 +	fi
   3.150 +	if [ $XENBALLOON_SEND_UPTIME ]; then
   3.151 +		xenstore-write memory/uptime "`cat /proc/uptime`"
   3.152 +	fi
   3.153 +}
   3.154 +
   3.155 +if [ ! -f /proc/xen/balloon ]; then
   3.156 +	echo "$0: no balloon driver installed"
   3.157 +	exit 0
   3.158 +fi
   3.159 +if [ ! -f /proc/meminfo ]; then
   3.160 +	echo "$0: can't read /proc/meminfo"
   3.161 +	exit 0
   3.162 +fi
   3.163 +xenstore_enabled=true
   3.164 +if [ -f /usr/bin/xenstore-exists -a -f /usr/bin/xenstore-read -a \
   3.165 +     -f /usr/bin/xenstore-write ]; then
   3.166 +	xenstore_enabled=true
   3.167 +else
   3.168 +	echo "$0: missing /usr/bin/xenstore-* tools, disabling directed ballooning"
   3.169 +	xenstore_enabled=false
   3.170 +fi
   3.171 +
   3.172 +. /etc/sysconfig/xenballoon.conf
   3.173 +
   3.174 +while true;
   3.175 +do
   3.176 +	# handle special case for PV domains with hot-add memory
   3.177 +	if [ ! -f $XENBALLOON_MAXMEMFILE ]; then
   3.178 +		maxkb=0
   3.179 +	else
   3.180 +		maxkb=`cat $XENBALLOON_MAXMEMFILE`
   3.181 +	fi
   3.182 +	curkb=`grep MemTotal /proc/meminfo | sed 's/  */ /' | cut -f2 -d' '`
   3.183 +	if [ $curkb -gt $maxkb ]; then
   3.184 +		echo $curkb > $XENBALLOON_MAXMEMFILE
   3.185 +	fi
   3.186 +	interval=$XENBALLOON_INTERVAL
   3.187 +	# do self-ballooning
   3.188 +	selfballoon_eval
   3.189 +	if [ $selfballoon_enabled = "true" ]; then
   3.190 +		balloon_to_target 1
   3.191 +		interval=$XENBALLOON_SELF_INTERVAL
   3.192 +	# or do directed ballooning
   3.193 +	elif [ $xenstore_enabled = "true" ]; then
   3.194 +		if xenstore-exists memory/target ; then
   3.195 +			tgtkb=`xenstore-read memory/target`
   3.196 +			balloon_to_target $tgtkb
   3.197 +		fi
   3.198 +		interval=$XENBALLOON_INTERVAL
   3.199 +	fi
   3.200 +	send_memory_stats
   3.201 +	if [ $xenstore_enabled = "true" ]; then
   3.202 +		if xenstore-exists memory/interval ; then
   3.203 +			interval=`xenstore-read memory/interval`
   3.204 +		fi
   3.205 +	fi
   3.206 +	sleep $interval
   3.207 +done &
   3.208 +
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/tools/xenballoon/xenballoond.README	Tue Jul 01 11:40:07 2008 +0100
     4.3 @@ -0,0 +1,82 @@
     4.4 +Xenballoond.README
     4.5 +Preliminary version 0.1, 2008/06/30
     4.6 +
     4.7 +Copyright (C) 2008 Oracle Corporation and/or its affiliates.
     4.8 +All rights reserved.
     4.9 +Written by Dan Magenheimer <dan.magenheimer@oracle.com>
    4.10 +
    4.11 +INTRODUCTION
    4.12 +
    4.13 +Xenballoond runs in guest domains and both implements selfballooning and
    4.14 +provides metrics to dom0 for (future) directed ballooning.  Both capabilities
    4.15 +provide a foundation for basic "memory overcommit" functionality.
    4.16 +
    4.17 +With selfballooning enabled, xenballoond uses the Committed_AS value found
    4.18 +in /proc/meminfo as a first approximation of how much memory is required
    4.19 +by the guest and feeds this statistic back to the balloon driver to inflate
    4.20 +or deflate the balloon as required to achieve the target guest memory size.
    4.21 +Hysteresis parameters may be adjusted to rate-limit balloon inflation
    4.22 +and deflation.
    4.23 +
    4.24 +If configured, certain selfballooning parameters -- including notably
    4.25 +enabling/disabling of self-ballooning -- can be controlled from domain0.
    4.26 +(These are fully documented in xenballoon.conf.)
    4.27 +
    4.28 +If configured, the following guest statistics are sent back to domain0:
    4.29 +- /proc/meminfo
    4.30 +- /proc/vmstat
    4.31 +- /proc/uptime
    4.32 +In a future release, some of these values will be used by a policy module
    4.33 +in domain0 to control guest balloon size and provide memory balancing
    4.34 +across all guests on a given system.
    4.35 +
    4.36 +Note that no page sharing (content-based or otherwise) is implemented
    4.37 +and no VMM-based swapping is necessary.
    4.38 +
    4.39 +For more information, see:
    4.40 +http://www.xen.org/files/xensummitboston08/MemoryOvercommit-XenSummit2008.pdf
    4.41 +http://wiki.xensource.com/xenwiki/Open_Topics_For_Discussion?action=AttachFile&do=get&target=Memory+Overcommit.pdf
    4.42 +
    4.43 +INSTALLATION AND DEPLOYMENT
    4.44 +
    4.45 +In this preliminary release:
    4.46 +- directed ballooning is not implemented, though a monitor is provided
    4.47 +- only Redhat-based guests are supported
    4.48 +
    4.49 +Guest prerequisites to use xenballoond:
    4.50 +- each guest must be configured with adequate[1] swap space
    4.51 +- each guest must have the balloon driver installed (/proc/xen/balloon exists) 
    4.52 +- if directed ballooning (or monitoring) is desired, xenstore tools must be
    4.53 +  installed in each guest in /usr/bin [2]
    4.54 +
    4.55 +[1] for best results, for a guest that is configured with maxmem=N and
    4.56 +    requires Z MB of swap space without xenballoond, available swap should
    4.57 +    be increased to N+Z MB when xenballoond is running
    4.58 +[2] specifically xenstore-read, xenstore-exists, and xenstore-write must
    4.59 +    be installed.  Binaries can be obtained, for example, by building
    4.60 +    xen-vvv.gz/tools in a guest-binary-compatible development tree
    4.61 +
    4.62 +Instructions to install/deploy xenballoond (in Redhat-based system):
    4.63 +- in each guest:
    4.64 +  - ensure pre-requisites are met (see above)
    4.65 +  - place xenballoon.conf in /etc/sysconfig
    4.66 +  - place xenballoond in /usr/sbin
    4.67 +  - copy xenballoond.init to /etc/rc.d/init.d/xenballoond (note file rename)
    4.68 +  - edit /etc/sysconfig/xenballoond.conf as desired (especially note that
    4.69 +    selfballooning defaults as off)
    4.70 +  - start xenballoond with "service xenballoond start", and/or configure
    4.71 +    xenballoond to start at init (e.g. "chkconfig xenballoond on")
    4.72 +- in domain0:
    4.73 +  - if monitoring is desired, xenballoon-monitor may be installed in /usr/sbin
    4.74 +- note that certain xenballoond.conf variables may be overridden by domain0
    4.75 +  if xenstore is running in the guest; these are fully documented in
    4.76 +  xenballoond.conf
    4.77 +
    4.78 +TODO:
    4.79 +080630 modifications to support SUSE-based and debian-based guests
    4.80 +080630 domain0 ballooning policy module
    4.81 +080630 experiment with more aggressive (optionally) memory minimum targets
    4.82 +080630 BUG: xenballoond doesn't properly record the fact that it's running;
    4.83 +       e.g. flipping between run levels 5 and 3 launches additional daemons
    4.84 +080630 BUG: reports of possible incompatibilites between ballooning and
    4.85 +       save/restore/migrate have not been duplicated
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/tools/xenballoon/xenballoond.init	Tue Jul 01 11:40:07 2008 +0100
     5.3 @@ -0,0 +1,91 @@
     5.4 +#!/bin/bash
     5.5 +#
     5.6 +# xenballoond	Script to start and stop Xen ballooning daemon.
     5.7 +#
     5.8 +# Copyright (C) 2008 Oracle Corporation and/or its affiliates.
     5.9 +# All rights reserved.
    5.10 +# Written by: Dan Magenheimer <dan.magenheimer@oracle.com>
    5.11 +#
    5.12 +# chkconfig: 2345 98 01
    5.13 +# description: Starts and stops the Xen control daemon.
    5.14 +### BEGIN INIT INFO
    5.15 +# Provides:          xenballoond
    5.16 +# Required-Start:    $syslog $remote_fs
    5.17 +# Should-Start:
    5.18 +# Required-Stop:     $syslog $remote_fs
    5.19 +# Should-Stop:
    5.20 +# Default-Start:     3 4 5
    5.21 +# Default-Stop:      0 1 2 6
    5.22 +# Default-Enabled:   yes
    5.23 +# Short-Description: Start/stop xend
    5.24 +# Description:       Starts and stops the Xen ballooning daemon.
    5.25 +### END INIT INFO
    5.26 +
    5.27 +# Source function library
    5.28 +. /etc/init.d/functions
    5.29 +
    5.30 +#don't use in domain0
    5.31 +[ -f /proc/xen/capabilities ] && \
    5.32 +	grep -q "control_d" /proc/xen/capabilities && exit 0
    5.33 +
    5.34 +if [ -f /etc/sysconfig/xenballoon.conf ]; then
    5.35 +	. /etc/sysconfig/xenballoon.conf
    5.36 +fi
    5.37 +
    5.38 +# Check that balloon driver is present
    5.39 +[ ! -f /proc/xen/balloon ] && exit 0
    5.40 +
    5.41 +# Record original memory (in kB)
    5.42 +[ -z "$XENBALLOON_MAXMEMFILE" ] && exit 0
    5.43 +let maxmem=`grep MemTotal /proc/meminfo | sed 's/  */ /' | cut -f2 -d' '`
    5.44 +if [ -f "$XENBALLOON_MAXMEMFILE" ]; then
    5.45 +	let oldmax=`cat $XENBALLOON_MAXMEMFILE`
    5.46 +	if [ $oldmax -gt $maxmem ]; then
    5.47 +		let maxmem=oldmax
    5.48 +	fi
    5.49 +fi
    5.50 +echo $maxmem > $XENBALLOON_MAXMEMFILE
    5.51 +
    5.52 +RETVAL=0
    5.53 +prog="xenballoond"
    5.54 +
    5.55 +start() {
    5.56 +        # Start daemons.
    5.57 +        echo -n $"Starting $prog: "
    5.58 +        daemon xenballoond $OPTIONS
    5.59 +	RETVAL=$?
    5.60 +        echo
    5.61 +	return $RETVAL
    5.62 +}
    5.63 +
    5.64 +stop() {
    5.65 +        echo -n $"Shutting down $prog: "
    5.66 +	killproc xenballoond
    5.67 +	RETVAL=$?
    5.68 +        echo
    5.69 +	return $RETVAL
    5.70 +}
    5.71 +
    5.72 +# See how we were called.
    5.73 +case "$1" in
    5.74 +  start)
    5.75 +	start
    5.76 +        ;;
    5.77 +  stop)
    5.78 +	stop
    5.79 +        ;;
    5.80 +  status)
    5.81 +	status xenballoond
    5.82 +	RETVAL=$?
    5.83 +	;;
    5.84 +  restart|reload)
    5.85 +	stop
    5.86 +	start
    5.87 +	RETVAL=$?
    5.88 +	;;
    5.89 +  *)
    5.90 +        echo $"Usage: $0 {start|stop|restart|status}"
    5.91 +        exit 1
    5.92 +esac
    5.93 +
    5.94 +exit $RETVAL