David Vrabel
2013-Apr-04 17:13 UTC
[PATCHv2 0/2] xl: enable/disable autoballooning automatically
This series allows xl to enable/disable autoballooning automatically based on the presence of the dom0_mem Xen command line option. Typically, if dom0_mem is used then autoballoon must also be disabled. Changes in v2: - use a regex to match the dom0_mem option. - switch the default to "auto" David
David Vrabel
2013-Apr-04 17:13 UTC
[PATCH 1/2] xl: extend autoballoon xl.conf option with an "auto" option
From: David Vrabel <david.vrabel@citrix.com> autoballoon=1 is not recommened if dom0_mem was used to reduce the amount of dom0 memory. Instead of requiring users to change xl.conf if they do this, extend the autoballoon option with a new choice: "auto". With autoballoon="auto", autoballooning will be disabled if dom0_mem was used on the Xen command line. For consistency, accept "on" and "off" as valid autoballoon options (1 and 0 are still accepted). The default remains "on" for now. Signed-off-by: David Vrabel <david.vrabel@citrix.com> --- docs/man/xl.conf.pod.5 | 21 ++++++++++++++------- tools/examples/xl.conf | 7 ++++--- tools/libxl/xl.c | 36 ++++++++++++++++++++++++++++++++++-- 3 files changed, 52 insertions(+), 12 deletions(-) diff --git a/docs/man/xl.conf.pod.5 b/docs/man/xl.conf.pod.5 index 82c6b20..959f494 100644 --- a/docs/man/xl.conf.pod.5 +++ b/docs/man/xl.conf.pod.5 @@ -45,15 +45,22 @@ The semantics of each C<KEY> defines which form of C<VALUE> is required. =over 4 -=item B<autoballoon=BOOLEAN> +=item B<autoballoon="off"|"on"|"auto"> -If disabled then C<xl> will not attempt to reduce the amount of memory -assigned to domain 0 in order to create free memory when starting a -new domain. You are strongly recommended to set this to C<0> -(C<False>) if you use the C<dom0_mem> hypervisor command line to -reduce the amount of memory given to domain 0 by default. +If set to "on" then C<xl> will automatically reduce the amount of +memory assigned to domain 0 in order to free memory for new domains. -Default: C<1> +If set to "off" then C<xl> will not automatically reduce the amount of +domain 0 memory. + +If set to "auto" then auto-ballooning will be disabled if the +C<dom0_mem> option was provided on the Xen command line. + +You are strongly recommended to set this to C<"off"> (or C<"auto">) if +you use the C<dom0_mem> hypervisor command line to reduce the amount +of memory given to domain 0 by default. + +Default: C<"on"> =item B<run_hotplug_scripts=BOOLEAN> diff --git a/tools/examples/xl.conf b/tools/examples/xl.conf index 28ab796..e770b08 100644 --- a/tools/examples/xl.conf +++ b/tools/examples/xl.conf @@ -1,8 +1,9 @@ ## Global XL config file ## -# automatically balloon down dom0 when xen doesn''t have enough free -# memory to create a domain -#autoballoon=1 +# Control whether dom0 is ballooned down when xen doesn''t have enough +# free memory to create a domain. "auto" means only balloon if dom0 +# starts with all the host''s memory. +#autoballoon="auto" # full path of the lockfile used by xl during domain creation #lockfile="/var/lock/xl" diff --git a/tools/libxl/xl.c b/tools/libxl/xl.c index ecbcd3b..951ae50 100644 --- a/tools/libxl/xl.c +++ b/tools/libxl/xl.c @@ -26,6 +26,7 @@ #include <fcntl.h> #include <ctype.h> #include <inttypes.h> +#include <regex.h> #include "libxl.h" #include "libxl_utils.h" @@ -47,6 +48,29 @@ enum output_format default_output_format = OUTPUT_FORMAT_JSON; static xentoollog_level minmsglevel = XTL_PROGRESS; +/* Get autoballoon option based on presence of dom0_mem Xen command + line option. */ +static int auto_autoballoon(void) +{ + const libxl_version_info *info; + regex_t regex; + int ret; + + info = libxl_get_version_info(ctx); + if (!info) + return 1; /* default to on */ + + ret = regcomp(®ex, + "(^| )dom0_mem=((|min:|max:)[0-9]+[bBkKmMgG]?,?)+($| )", + REG_NOSUB | REG_EXTENDED); + if (ret) + return 1; + + ret = regexec(®ex, info->commandline, 0, NULL, 0); + regfree(®ex); + return ret == REG_NOMATCH; +} + static void parse_global_config(const char *configfile, const char *configfile_data, int configfile_len) @@ -68,8 +92,16 @@ static void parse_global_config(const char *configfile, exit(1); } - if (!xlu_cfg_get_long (config, "autoballoon", &l, 0)) - autoballoon = l; + if (!xlu_cfg_get_string(config, "autoballoon", &buf, 0)) { + if (!strcmp(buf, "on") || !strcmp(buf, "1")) + autoballoon = 1; + else if (!strcmp(buf, "off") || !strcmp(buf, "0")) + autoballoon = 0; + else if (!strcmp(buf, "auto")) + autoballoon = auto_autoballoon(); + else + fprintf(stderr, "invalid autoballoon option"); + } if (!xlu_cfg_get_long (config, "run_hotplug_scripts", &l, 0)) run_hotplug_scripts = l; -- 1.7.2.5
From: David Vrabel <david.vrabel@citrix.com> In xl.conf, autoballoon="auto" will do the right thing for most people. Make it the default (instead of "on"). Signed-off-by: David Vrabel <david.vrabel@citrix.com> --- docs/man/xl.conf.pod.5 | 2 +- tools/libxl/xl.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/man/xl.conf.pod.5 b/docs/man/xl.conf.pod.5 index 959f494..de55b86 100644 --- a/docs/man/xl.conf.pod.5 +++ b/docs/man/xl.conf.pod.5 @@ -60,7 +60,7 @@ You are strongly recommended to set this to C<"off"> (or C<"auto">) if you use the C<dom0_mem> hypervisor command line to reduce the amount of memory given to domain 0 by default. -Default: C<"on"> +Default: C<"auto"> =item B<run_hotplug_scripts=BOOLEAN> diff --git a/tools/libxl/xl.c b/tools/libxl/xl.c index 951ae50..64ec887 100644 --- a/tools/libxl/xl.c +++ b/tools/libxl/xl.c @@ -38,7 +38,7 @@ xentoollog_logger_stdiostream *logger; int dryrun_only; int force_execution; -int autoballoon = 1; +int autoballoon = -1; char *blkdev_start; int run_hotplug_scripts = 1; char *lockfile; @@ -98,10 +98,12 @@ static void parse_global_config(const char *configfile, else if (!strcmp(buf, "off") || !strcmp(buf, "0")) autoballoon = 0; else if (!strcmp(buf, "auto")) - autoballoon = auto_autoballoon(); + autoballoon = -1; else fprintf(stderr, "invalid autoballoon option"); } + if (autoballoon == -1) + autoballoon = auto_autoballoon(); if (!xlu_cfg_get_long (config, "run_hotplug_scripts", &l, 0)) run_hotplug_scripts = l; -- 1.7.2.5
Ian Jackson
2013-Apr-08 16:06 UTC
Re: [PATCH 1/2] xl: extend autoballoon xl.conf option with an "auto" option
David Vrabel writes ("[Xen-devel] [PATCH 1/2] xl: extend autoballoon xl.conf option with an "auto" option"):> From: David Vrabel <david.vrabel@citrix.com> > > autoballoon=1 is not recommened if dom0_mem was used to reduce the > amount of dom0 memory. Instead of requiring users to change xl.conf > if they do this, extend the autoballoon option with a new choice: > "auto".Thanks, that''s great, I have applied both. Ian.
David Vrabel
2013-Apr-12 11:45 UTC
Re: [PATCH 1/2] xl: extend autoballoon xl.conf option with an "auto" option
On 08/04/13 17:06, Ian Jackson wrote:> David Vrabel writes ("[Xen-devel] [PATCH 1/2] xl: extend autoballoon xl.conf option with an "auto" option"): >> From: David Vrabel <david.vrabel@citrix.com> >> >> autoballoon=1 is not recommened if dom0_mem was used to reduce the >> amount of dom0 memory. Instead of requiring users to change xl.conf >> if they do this, extend the autoballoon option with a new choice: >> "auto". > > Thanks, that''s great, I have applied both.Since this is useful for distro packagers. Is this something that could be backported to Xen 4.2? David
Ian Jackson
2013-Apr-12 15:13 UTC
Re: [PATCH 1/2] xl: extend autoballoon xl.conf option with an "auto" option
David Vrabel writes ("Re: [Xen-devel] [PATCH 1/2] xl: extend autoballoon xl.conf option with an "auto" option"):> On 08/04/13 17:06, Ian Jackson wrote: > > Thanks, that''s great, I have applied both. > > Since this is useful for distro packagers. Is this something that could > be backported to Xen 4.2?Well, other distro packagers would probably prefer us not to update our stable tree with new features. And we are currently in the release process for 4.2.2. It''s a very small patch and applies cleanly to 4.2.x so I would say that distros who want it should simply dump it in their patch queue. Ian.