From 1374208d3bca8ca1c0ae8160781278d27ac9c5eb Mon Sep 17 00:00:00 2001 From: Joan Date: Fri, 18 Oct 2013 12:59:50 +0200 Subject: [PATCH 1/2] Implemente the option maxmem in xen-tools allowing to set a maximum value to enable dynamic memory ballooning. --- bin/xen-create-image | 15 +++++++++++++++ bin/xt-create-xen-config | 15 +++++++++++++++ etc/xen-tools.conf | 1 + etc/xm-nfs.tmpl | 5 +++++ etc/xm.tmpl | 5 +++++ 5 files changed, 41 insertions(+) diff --git a/bin/xen-create-image b/bin/xen-create-image index bc9b978..2e40375 100755 --- a/bin/xen-create-image +++ b/bin/xen-create-image @@ -134,6 +134,13 @@ and EVMS EXAMPLE. "MB", "G" and "GB" (case does not matter). If there's no unit given, megabytes are assumed. + --maxmem=size + Setup the maximum amount of memory that can be allocated + to the new instance. As suffix recognized size units are "M", + "MB", "G" and "GB" (case does not matter). If there's + no unit given, megabytes are assumed. + Required for dynamic memory ballooning. + --modules=/path/to/modules Set the path to the kernel modules to use for domU. If modules are specified they must exist. @@ -418,6 +425,7 @@ Create a Xen configuration file in so that xm/xl can start the new domain. size = 2Gb # Disk image size. image = full # Allocate the full disk size immediately. memory = 128Mb # Memory size + maxmem = 512Mb # Memory size swap = 128Mb # Swap size fs = ext3 # use EXT3 filesystems dist = stable # Default distribution to install. @@ -1511,6 +1519,7 @@ sub checkOption swap => 'integerWithSuffix', image => 'imageType', memory => 'integerWithSuffix', + maxmem => 'integerWithSuffix', kernel => 'existingFile', initrd => 'existingFile', modules => 'existingDir', @@ -1609,6 +1618,7 @@ sub parseCommandLineArguments "noswap", \&checkOption, "image=s", \&checkOption, "memory=s", \&checkOption, + "maxmem=s", \&checkOption, "vcpus=i", \&checkOption, # Locations @@ -2641,6 +2651,11 @@ sub showSummary logprint("Image type : $CONFIG{'image'}\n"); logprint("Memory size : $CONFIG{'memory'}\n"); + if ( defined( $CONFIG{ 'maxmem' } ) ) + { + logprint("Max mem size : $CONFIG{'maxmem'}\n"); + } + if ( defined( $CONFIG{ 'kernel' } ) && length( $CONFIG{ 'kernel' } ) ) { logprint("Kernel path : $CONFIG{'kernel'}\n"); diff --git a/bin/xt-create-xen-config b/bin/xt-create-xen-config index b9109ba..3bd35de 100755 --- a/bin/xt-create-xen-config +++ b/bin/xt-create-xen-config @@ -374,6 +374,21 @@ sub createXenConfig $ENV{ 'memory' } = $1; } + # + # The maxmem size: Convert Gb -> Mb. + # + if ( $ENV{ 'maxmem' } =~ /^(\d+)Gb?.*$/i ) + { + $ENV{ 'maxmem' } = $1 * 1024; + } + + # + # Remove any trailing Mb. + # + if ( $ENV{ 'maxmem' } =~ /^(\d+)Mb?.*$/i ) + { + $ENV{ 'maxmem' } = $1; + } # # Images as presented to Xen - either loopback images, or LVM partitions. diff --git a/etc/xen-tools.conf b/etc/xen-tools.conf index b934996..c132a09 100644 --- a/etc/xen-tools.conf +++ b/etc/xen-tools.conf @@ -127,6 +127,7 @@ install-method = debootstrap # size = 4G # Root disk, suffix (G, M, k) required memory = 128M # Suffix (G, M, k) required +#maxmem = 256M # Suffix (G, M, k) optional swap = 128M # Suffix (G, M, k) required # noswap = 1 # Don't use swap at all for new systems. fs = ext3 # Default file system for any disk diff --git a/etc/xm-nfs.tmpl b/etc/xm-nfs.tmpl index 478a21e..8e00010 100644 --- a/etc/xm-nfs.tmpl +++ b/etc/xm-nfs.tmpl @@ -17,6 +17,11 @@ } } memory = '{$memory}' +{ if ( $maxmem ) + { + $OUT .= "maxmem = '$maxmem'\n"; + } +} # Name diff --git a/etc/xm.tmpl b/etc/xm.tmpl index 543fac1..9b24faf 100644 --- a/etc/xm.tmpl +++ b/etc/xm.tmpl @@ -37,6 +37,11 @@ } vcpus = '{$vcpus}' memory = '{$memory}' +{ if ( $maxmem ) + { + $OUT .= "maxmem = '$maxmem'\n"; + } +} # # Disk device(s). From b51936e6ee40d8c6a949aeab2c9dedb2f0a16f51 Mon Sep 17 00:00:00 2001 From: Joan Date: Fri, 18 Oct 2013 14:09:59 +0200 Subject: [PATCH 2/2] Updated changelog --- debian/changelog | 1 + 1 file changed, 1 insertion(+) diff --git a/debian/changelog b/debian/changelog index 13f1d2e..5ed1443 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,5 +1,6 @@ xen-tools (4.4~dev-1) UNRELEASED; urgency=low + * Added --maxmem flag to set a maximum value for dynamic memory ballooning * Also switch from cdn.debian.net to http.debian.net in xen-tools.conf * Do not run "passwd" via runCommand as that one captures STDOUT for logging. Makes --passwd usable again. Thanks to Christian Herzog for