Discussion:
[Xen-devel] [PATCH v3 2/3] xen/x86: add dom0 memory sizing variants
Juergen Gross
2018-12-10 14:52:52 UTC
Permalink
Today the memory size of dom0 can be specified only in terms of bytes
(either an absolute value or "host-mem - value"). When dom0 shouldn't
be auto-ballooned this requires nearly always a manual adaption of the
Xen boot parameters to reflect the actual host memory size.
dom0_mem= List of ( min:<size> | max:<size> | <size> )
with <size> being a positive or negative size value (e.g. 1G).
dom0_mem= List of ( min:<sz> | max:<sz> | <sz> )
<sz>: <size> | [<size>+]<frac>%
<frac>: integer value < 100
<frac>% specifies a fraction of host memory size in percent.
<sz> is a percentage of host memory plus an offset.
So <sz> being 1G+25% on a 256G host would result in 65G.
Once again
-static long __init parse_amt(const char *s, const char **ps)
+static int __init parse_amt(const char *s, const char **ps, struct memsize *sz)
{
- long pages = parse_size_and_unit((*s == '-') ? s+1 : s, ps) >> PAGE_SHIFT;
- return (*s == '-') ? -pages : pages;
+ unsigned long val;
+ struct memsize tmp = { };
+ unsigned int items = 0;
+
+ tmp.minus = (*s == '-');
+ if ( tmp.minus )
+ s++;
+
+ do
+ {
+ if ( !isdigit(*s) )
+ return -EINVAL;
+
+ val = parse_size_and_unit(s, ps);
+ s = *ps;
+ if ( *s == '%' )
+ {
+ if ( val >= 100 )
+ return -EINVAL;
+ tmp.percent = val;
+ s++;
+ items++; /* No other item allowed. */
Isn't this unnecessary with ...
+ }
+ else
+ {
+ /* <size> item must be first one. */
+ if ( items )
+ return -EINVAL;
+ tmp.nr_pages = val >> PAGE_SHIFT;
+ }
+ items++;
... this? However, allowing <frac>%+<size> would apparently have
been easy (and add further flexibility).
That would require two booleans instead. Otherwise <frac>%+<frac>%
wouldn't be rejected. In case anyone else thinks this would be better
I can change it, of course.


Juergen
Jan Beulich
2018-12-10 14:45:12 UTC
Permalink
Today the memory size of dom0 can be specified only in terms of bytes
(either an absolute value or "host-mem - value"). When dom0 shouldn't
be auto-ballooned this requires nearly always a manual adaption of the
Xen boot parameters to reflect the actual host memory size.
dom0_mem= List of ( min:<size> | max:<size> | <size> )
with <size> being a positive or negative size value (e.g. 1G).
dom0_mem= List of ( min:<sz> | max:<sz> | <sz> )
<sz>: <size> | [<size>+]<frac>%
<frac>: integer value < 100
<frac>% specifies a fraction of host memory size in percent.
<sz> is a percentage of host memory plus an offset.
So <sz> being 1G+25% on a 256G host would result in 65G.
Once again
-static long __init parse_amt(const char *s, const char **ps)
+static int __init parse_amt(const char *s, const char **ps, struct memsize *sz)
{
- long pages = parse_size_and_unit((*s == '-') ? s+1 : s, ps) >> PAGE_SHIFT;
- return (*s == '-') ? -pages : pages;
+ unsigned long val;
+ struct memsize tmp = { };
+ unsigned int items = 0;
+
+ tmp.minus = (*s == '-');
+ if ( tmp.minus )
+ s++;
+
+ do
+ {
+ if ( !isdigit(*s) )
+ return -EINVAL;
+
+ val = parse_size_and_unit(s, ps);
+ s = *ps;
+ if ( *s == '%' )
+ {
+ if ( val >= 100 )
+ return -EINVAL;
+ tmp.percent = val;
+ s++;
+ items++; /* No other item allowed. */
Isn't this unnecessary with ...
+ }
+ else
+ {
+ /* <size> item must be first one. */
+ if ( items )
+ return -EINVAL;
+ tmp.nr_pages = val >> PAGE_SHIFT;
+ }
+ items++;
... this? However, allowing <frac>%+<size> would apparently have
been easy (and add further flexibility).

Jan
Jan Beulich
2018-12-10 14:39:21 UTC
Permalink
Modify parse_size_and_unit() to support a value followed by a '%'
character. In this case ps is required to be non-NULL to ensure the
caller can detect that case. The returned value will be the integer
value s was pointing to and *ps will point to the '%' character.
Reviewed-by: Jan Beulich <***@suse.com>
Juergen Gross
2018-12-10 11:44:22 UTC
Permalink
With being able to specify a dom0_mem value depending on host memory
size on x86 make it easy for distros to specify a default dom0 size by
adding a CONFIG_DOM0_MEM item which presets the dom0_mem boot parameter
value.

It will be used only if no dom0_mem parameter was specified in the
boot parameters.

Signed-off-by: Juergen Gross <***@suse.com>
Reviewed-by: Jan Beulich <***@suse.com>
---
xen/arch/arm/domain_build.c | 7 +++++++
xen/arch/x86/dom0_build.c | 6 ++++++
xen/common/Kconfig | 13 +++++++++++++
3 files changed, 26 insertions(+)

diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index b0ec3f0b72..d2c63a89ca 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -32,9 +32,12 @@ static unsigned int __initdata opt_dom0_max_vcpus;
integer_param("dom0_max_vcpus", opt_dom0_max_vcpus);

static u64 __initdata dom0_mem;
+static bool __initdata dom0_mem_set;

static int __init parse_dom0_mem(const char *s)
{
+ dom0_mem_set = true;
+
dom0_mem = parse_size_and_unit(s, &s);

return *s ? -EINVAL : 0;
@@ -2114,6 +2117,10 @@ int __init construct_dom0(struct domain *d)
BUG_ON(d->domain_id != 0);

printk("*** LOADING DOMAIN 0 ***\n");
+
+ if ( !dom0_mem_set && CONFIG_DOM0_MEM[0] )
+ parse_dom0_mem(CONFIG_DOM0_MEM);
+
if ( dom0_mem <= 0 )
{
warning_add("PLEASE SPECIFY dom0_mem PARAMETER - USING 512M FOR NOW\n");
diff --git a/xen/arch/x86/dom0_build.c b/xen/arch/x86/dom0_build.c
index 673b3ee4e6..54737daf6a 100644
--- a/xen/arch/x86/dom0_build.c
+++ b/xen/arch/x86/dom0_build.c
@@ -29,6 +29,7 @@ struct memsize {
static struct memsize __initdata dom0_size;
static struct memsize __initdata dom0_min_size;
static struct memsize __initdata dom0_max_size = { .nr_pages = LONG_MAX };
+static bool __initdata dom0_mem_set;

static bool __init memsize_gt_zero(const struct memsize *sz)
{
@@ -117,6 +118,8 @@ static int __init parse_dom0_mem(const char *s)
{
int ret;

+ dom0_mem_set = true;
+
/* xen-shim uses shim_mem parameter instead of dom0_mem */
if ( pv_shim )
{
@@ -339,6 +342,9 @@ unsigned long __init dom0_compute_nr_pages(
unsigned long avail = 0, nr_pages, min_pages, max_pages;
bool need_paging;

+ if ( !dom0_mem_set && CONFIG_DOM0_MEM[0] )
+ parse_dom0_mem(CONFIG_DOM0_MEM);
+
for_each_node_mask ( node, dom0_nodes )
avail += avail_domheap_pages_region(node, 0, 0) +
initial_images_nrpages(node);
diff --git a/xen/common/Kconfig b/xen/common/Kconfig
index 68132a3a10..155a9a45e8 100644
--- a/xen/common/Kconfig
+++ b/xen/common/Kconfig
@@ -323,4 +323,17 @@ config CMDLINE_OVERRIDE

This is used to work around broken bootloaders. This should
be set to 'N' under normal conditions.
+
+config DOM0_MEM
+ string "Default value for dom0_mem boot parameter"
+ default ""
+ ---help---
+ Sets a default value for dom0_mem, e.g. "512M".
+ The specified string will be used for the dom0_mem parameter in
+ case it was not specified on the command line.
+
+ See docs/misc/xen-command-line.markdown for the supported syntax.
+
+ Leave empty if you are not sure what to specify.
+
endmenu
--
2.16.4
Loading...