Skip to contentSkip to conversation

xen/x86: support setting dom0_mem depending on host size

PATCH Superseded Juergen Gross 3 participants 14 messages Nov 22, 2018 – Nov 28, 2018 3 messages not in the archive

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover xen/x86: support setting dom0_mem depending on host size

Setting the memory size of dom0 on a server for the non autoballooning case requires always specification of a boot parameter today. The value to set will depend mostly on the host memory size.

In order to support that scenario add the possibility to set dom0_mem depending on the amount of physical memory by allowing to specify a percentage of host memory (e.g. 10%) with an offset (like 1G+10%).

To make it easy for a distributor to use such a setting as the default make the standard setting for dom0_mem configurable via Kconfig.

Juergen Gross (3):
xen/x86: delay parsing of dom0_mem parameter until needed xen/x86: add dom0 memory sizing variants xen/x86: add CONFIG item for default dom0 memory size

 docs/misc/xen-command-line.markdown | 21 ++++++++----
 xen/arch/x86/Kconfig                |  9 +++++
 xen/arch/x86/dom0_build.c           | 67 +++++++++++++++++++++++++++----------
 3 files changed, 73 insertions(+), 24 deletions(-)
Signature · 7 lines
2.16.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

PATCH 1/3 xen/x86: delay parsing of dom0_mem parameter until needed

Instead of parsing the dom0_mem command line parameter as custom parameter do that only when building dom0. This will enable a later addition of specifying the memory size by fractions of the host memory size, which isn't known when doing custom parameter parsing.

As this is needed later anyway move the logic for negative values into the parameter parsing, too.

---
 xen/arch/x86/dom0_build.c | 35 +++++++++++++++++++++--------------
 1 file changed, 21 insertions(+), 14 deletions(-)
xen/arch/x86/dom0_build.c +21 -14
index 5e2ad4bd56..e34022a9b8 100644
@@ -24,6 +24,8 @@ static long __initdata dom0_nrpages;
 static long __initdata dom0_min_nrpages;
 static long __initdata dom0_max_nrpages = LONG_MAX;
 
+static char __initdata dom0_mem_par[64];
+
 /*
  * dom0_mem=[min:<min_amt>,][max:<max_amt>,][<amt>]
  * 
@@ -44,14 +46,20 @@ static long __initdata dom0_max_nrpages = LONG_MAX;
  *  If +ve: The specified amount is an absolute value.
  *  If -ve: The specified amount is subtracted from total available memory.
  */
-static long __init parse_amt(const char *s, const char **ps)
+static unsigned long __init parse_amt(const char *s, const char **ps,
+                                      unsigned long avail)
 {
-    long pages = parse_size_and_unit((*s == '-') ? s+1 : s, ps) >> PAGE_SHIFT;
-    return (*s == '-') ? -pages : pages;
+    unsigned int minus = (*s == '-') ? 1 : 0;
+    unsigned long pages = parse_size_and_unit(s + minus, ps) >> PAGE_SHIFT;
+
+    /* Negative specification means "all memory - specified amount". */
+    return minus ? avail - pages : pages;
 }
 
-static int __init parse_dom0_mem(const char *s)
+static int __init parse_dom0_mem(unsigned long avail)
 {
+    const char *s = dom0_mem_par;
+
     /* xen-shim uses shim_mem parameter instead of dom0_mem */
     if ( pv_shim )
     {
@@ -61,16 +69,16 @@ static int __init parse_dom0_mem(const char *s)
 
     do {
         if ( !strncmp(s, "min:", 4) )
-            dom0_min_nrpages = parse_amt(s+4, &s);
+            dom0_min_nrpages = parse_amt(s + 4, &s, avail);
         else if ( !strncmp(s, "max:", 4) )
-            dom0_max_nrpages = parse_amt(s+4, &s);
+            dom0_max_nrpages = parse_amt(s + 4, &s, avail);
         else
-            dom0_nrpages = parse_amt(s, &s);
+            dom0_nrpages = parse_amt(s, &s, avail);
     } while ( *s++ == ',' );
 
     return s[-1] ? -EINVAL : 0;
 }
-custom_param("dom0_mem", parse_dom0_mem);
+string_param("dom0_mem", dom0_mem_par);
 
 static unsigned int __initdata opt_dom0_max_vcpus_min = 1;
 static unsigned int __initdata opt_dom0_max_vcpus_max = UINT_MAX;
@@ -298,6 +306,10 @@ unsigned long __init dom0_compute_nr_pages(
         (!iommu_hap_pt_share || !paging_mode_hap(d));
     for ( ; ; need_paging = false )
     {
+        if ( dom0_mem_par[0] && parse_dom0_mem(avail) )
+            printk("Invalid dom0_mem parameter value \"%s\", ignoring\n",
+                   dom0_mem_par);
+
         nr_pages = dom0_nrpages;
         min_pages = dom0_min_nrpages;
         max_pages = dom0_max_nrpages;
@@ -308,14 +320,9 @@ unsigned long __init dom0_compute_nr_pages(
          * maximum of 128MB.
          */
         if ( !nr_pages )
-            nr_pages = -(pv_shim ? pv_shim_mem(avail)
+            nr_pages = avail - (pv_shim ? pv_shim_mem(avail)
                                  : min(avail / 16, 128UL << (20 - PAGE_SHIFT)));
 
-        /* Negative specification means "all memory - specified amount". */
-        if ( (long)nr_pages  < 0 ) nr_pages  += avail;
-        if ( (long)min_pages < 0 ) min_pages += avail;
-        if ( (long)max_pages < 0 ) max_pages += avail;
-
         /* Clamp according to min/max limits and available memory. */
         nr_pages = max(nr_pages, min_pages);
         nr_pages = min(nr_pages, max_pages);
Signature · 7 lines
2.16.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#2 lore raw

Re: [PATCH 1/3] xen/x86: delay parsing of dom0_mem parameter until needed

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 22.11.18 at 17:40, <[email protected]> wrote:

Instead of parsing the dom0_mem command line parameter as custom parameter do that only when building dom0. This will enable a later addition of specifying the memory size by fractions of the host memory size, which isn't known when doing custom parameter parsing.

But you don't need to know memory size at the time of parsing. All you need to do is store all specified values in __initdata variables and do the calculations when available memory is known. The reason I'd like to avoid going the route you chose is because ...

xen/arch/x86/dom0_build.c static long __initdata dom0_nrpages; · line 27

Quoted 7 lines
xen/arch/x86/dom0_build.c +1 -0
@@ -24,6 +24,8 @@ static long __initdata dom0_nrpages;
 static long __initdata dom0_min_nrpages;
 static long __initdata dom0_max_nrpages = LONG_MAX;
 
+static char __initdata dom0_mem_par[64];

... I was really hoping to see go away all such statically dimensioned arrays used to store command line pieces. This is even more so since I've seen already in patch 2 you feel the need to bump its size.

Quoted 6 lines
xen/arch/x86/dom0_build.c +1 -1
@@ -44,14 +46,20 @@ static long __initdata dom0_max_nrpages = LONG_MAX;
  *  If +ve: The specified amount is an absolute value.
  *  If -ve: The specified amount is subtracted from total available memory.
  */
-static long __init parse_amt(const char *s, const char **ps)
+static unsigned long __init parse_amt(const char *s, const char **ps,

xen/arch/x86/dom0_build.c static long __initdata dom0_max_nrpages = LONG_MAX; · line 57

Quoted 10 lines
xen/arch/x86/dom0_build.c +6 -2
+                                      unsigned long avail)
 {
-    long pages = parse_size_and_unit((*s == '-') ? s+1 : s, ps) >> PAGE_SHIFT;
-    return (*s == '-') ? -pages : pages;
+    unsigned int minus = (*s == '-') ? 1 : 0;
+    unsigned long pages = parse_size_and_unit(s + minus, ps) >> PAGE_SHIFT;
+
+    /* Negative specification means "all memory - specified amount". */
+    return minus ? avail - pages : pages;
 }

I don't think any of this should be done in a patch with the given title.

Quoted 8 lines
xen/arch/x86/dom0_build.c +1 -2
@@ -61,16 +69,16 @@ static int __init parse_dom0_mem(const char *s)
 
     do {
         if ( !strncmp(s, "min:", 4) )
-            dom0_min_nrpages = parse_amt(s+4, &s);
+            dom0_min_nrpages = parse_amt(s + 4, &s, avail);
         else if ( !strncmp(s, "max:", 4) )
-            dom0_max_nrpages = parse_amt(s+4, &s);

xen/arch/x86/dom0_build.c static int __init parse_dom0_mem(const char *s) · line 81

Quoted 10 lines
xen/arch/x86/dom0_build.c +3 -2
+            dom0_max_nrpages = parse_amt(s + 4, &s, avail);
         else
-            dom0_nrpages = parse_amt(s, &s);
+            dom0_nrpages = parse_amt(s, &s, avail);
     } while ( *s++ == ',' );
 
     return s[-1] ? -EINVAL : 0;
 }
-custom_param("dom0_mem", parse_dom0_mem);
+string_param("dom0_mem", dom0_mem_par);

In the event of my objection to the delayed parsing getting overruled:
This would then belong next to the array. And if the array remained, please make the suffix "_param", or even better be consistent with other command line option holding variable names and call it opt_dom0_mem.

xen/arch/x86/dom0_build.c unsigned long __init dom0_compute_nr_pages( · line 311

Quoted 7 lines
xen/arch/x86/dom0_build.c +3 -0
@@ -298,6 +306,10 @@ unsigned long __init dom0_compute_nr_pages(
         (!iommu_hap_pt_share || !paging_mode_hap(d));
     for ( ; ; need_paging = false )
     {
+        if ( dom0_mem_par[0] && parse_dom0_mem(avail) )
+            printk("Invalid dom0_mem parameter value \"%s\", ignoring\n",
+                   dom0_mem_par);

Looking at how the parsing function works I don't think the entire command line would necessarily be ignored in case of error. I think the log message shouldn't give a wrong impression.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw

Re: [PATCH 1/3] xen/x86: delay parsing of dom0_mem parameter until needed

Quoted 10 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 22.11.18 at 17:40, <[email protected]> wrote:

Instead of parsing the dom0_mem command line parameter as custom parameter do that only when building dom0. This will enable a later addition of specifying the memory size by fractions of the host memory size, which isn't known when doing custom parameter parsing.

But you don't need to know memory size at the time of parsing. All you need to do is store all specified values in __initdata variables and do the calculations when available memory is known. The reason I'd like to avoid going the route you chose is because ...

Okay, so this would require additional dom0_min_frac, dom0_max_frac and dom0_frac (or similar). I can change it this way if you like that better.

Quoted 7 lines
Quoted 7 lines
xen/arch/x86/dom0_build.c +0 -0
@@ -24,6 +24,8 @@ static long __initdata dom0_nrpages;
 static long __initdata dom0_min_nrpages;
 static long __initdata dom0_max_nrpages = LONG_MAX;
 
Quoted 5 lines

xen/arch/x86/dom0_build.c static long __initdata dom0_nrpages; · line 27

Quoted 1 line
xen/arch/x86/dom0_build.c +1 -0
+static char __initdata dom0_mem_par[64];

... I was really hoping to see go away all such statically dimensioned arrays used to store command line pieces. This is even more so since I've seen already in patch 2 you feel the need to bump its size.

Uh, the bumping was a leftover from a previous version. But nevertheless I can understand your concern here.

Quoted 12 lines
Quoted 12 lines
xen/arch/x86/dom0_build.c +3 -3
@@ -44,14 +46,20 @@ static long __initdata dom0_max_nrpages = LONG_MAX;
  *  If +ve: The specified amount is an absolute value.
  *  If -ve: The specified amount is subtracted from total available memory.
  */
-static long __init parse_amt(const char *s, const char **ps)
+static unsigned long __init parse_amt(const char *s, const char **ps,
+                                      unsigned long avail)
 {
-    long pages = parse_size_and_unit((*s == '-') ? s+1 : s, ps) >> PAGE_SHIFT;
-    return (*s == '-') ? -pages : pages;
+    unsigned int minus = (*s == '-') ? 1 : 0;
Quoted 8 lines

xen/arch/x86/dom0_build.c static long __initdata dom0_max_nrpages = LONG_MAX; · line 57

Quoted 5 lines
xen/arch/x86/dom0_build.c +4 -0
+    unsigned long pages = parse_size_and_unit(s + minus, ps) >> PAGE_SHIFT;
+
+    /* Negative specification means "all memory - specified amount". */
+    return minus ? avail - pages : pages;
 }

I don't think any of this should be done in a patch with the given title.

Going the other route will result in merging patches 1 and 2, I guess.

Quoted 26 lines
Quoted 9 lines
xen/arch/x86/dom0_build.c +1 -2
@@ -61,16 +69,16 @@ static int __init parse_dom0_mem(const char *s)
 
     do {
         if ( !strncmp(s, "min:", 4) )
-            dom0_min_nrpages = parse_amt(s+4, &s);
+            dom0_min_nrpages = parse_amt(s + 4, &s, avail);
         else if ( !strncmp(s, "max:", 4) )
-            dom0_max_nrpages = parse_amt(s+4, &s);

xen/arch/x86/dom0_build.c static int __init parse_dom0_mem(const char *s) · line 81

Quoted 10 lines
xen/arch/x86/dom0_build.c +3 -2
+            dom0_max_nrpages = parse_amt(s + 4, &s, avail);
         else
-            dom0_nrpages = parse_amt(s, &s);
+            dom0_nrpages = parse_amt(s, &s, avail);
     } while ( *s++ == ',' );
 
     return s[-1] ? -EINVAL : 0;
 }
-custom_param("dom0_mem", parse_dom0_mem);
+string_param("dom0_mem", dom0_mem_par);

In the event of my objection to the delayed parsing getting overruled:
This would then belong next to the array. And if the array remained, please make the suffix "_param", or even better be consistent with other command line option holding variable names and call it opt_dom0_mem.

Quoted 11 lines

xen/arch/x86/dom0_build.c unsigned long __init dom0_compute_nr_pages( · line 311

Quoted 7 lines
xen/arch/x86/dom0_build.c +3 -0
@@ -298,6 +306,10 @@ unsigned long __init dom0_compute_nr_pages(
         (!iommu_hap_pt_share || !paging_mode_hap(d));
     for ( ; ; need_paging = false )
     {
+        if ( dom0_mem_par[0] && parse_dom0_mem(avail) )
+            printk("Invalid dom0_mem parameter value \"%s\", ignoring\n",
+                   dom0_mem_par);

Looking at how the parsing function works I don't think the entire command line would necessarily be ignored in case of error. I think the log message shouldn't give a wrong impression.

The message is referencing the dom0_mem value only. And this would be ignored. I don't see your concern here.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#5 lore raw

Re: [PATCH 1/3] xen/x86: delay parsing of dom0_mem parameter until needed

Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 28.11.18 at 16:33, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 22.11.18 at 17:40, <[email protected]> wrote:
xen/arch/x86/dom0_build.c +3 -3
@@ -44,14 +46,20 @@ static long __initdata dom0_max_nrpages = LONG_MAX;
  *  If +ve: The specified amount is an absolute value.
  *  If -ve: The specified amount is subtracted from total available memory.
  */
-static long __init parse_amt(const char *s, const char **ps)
+static unsigned long __init parse_amt(const char *s, const char **ps,
+                                      unsigned long avail)
 {
-    long pages = parse_size_and_unit((*s == '-') ? s+1 : s, ps) >> PAGE_SHIFT;
-    return (*s == '-') ? -pages : pages;
+    unsigned int minus = (*s == '-') ? 1 : 0;
Quoted 8 lines

xen/arch/x86/dom0_build.c static long __initdata dom0_max_nrpages = LONG_MAX; · line 57

Quoted 5 lines
xen/arch/x86/dom0_build.c +4 -0
+    unsigned long pages = parse_size_and_unit(s + minus, ps) >> PAGE_SHIFT;
+
+    /* Negative specification means "all memory - specified amount". */
+    return minus ? avail - pages : pages;
 }

I don't think any of this should be done in a patch with the given title.

Quoted 1 line

Going the other route will result in merging patches 1 and 2, I guess.

Well, you could easily do here what you do _besides_ the actual topic of the patch, just then with its title changed.

Quoted 12 lines
Quoted 11 lines

xen/arch/x86/dom0_build.c unsigned long __init dom0_compute_nr_pages( · line 311

Quoted 7 lines
xen/arch/x86/dom0_build.c +3 -0
@@ -298,6 +306,10 @@ unsigned long __init dom0_compute_nr_pages(
         (!iommu_hap_pt_share || !paging_mode_hap(d));
     for ( ; ; need_paging = false )
     {
+        if ( dom0_mem_par[0] && parse_dom0_mem(avail) )
+            printk("Invalid dom0_mem parameter value \"%s\", ignoring\n",
+                   dom0_mem_par);

Looking at how the parsing function works I don't think the entire command line would necessarily be ignored in case of error. I think the log message shouldn't give a wrong impression.

Quoted 2 lines

The message is referencing the dom0_mem value only. And this would be ignored. I don't see your concern here.

The function may have updated all three of dom0_{,max_,min_}nrpages before hitting en error condition. Hence a fair part of what was specified may not be ignored despite the error.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#6 lore raw

PATCH 2/3 xen/x86: add dom0 memory sizing variants

In reply to Juergen Gross

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.

Add more possibilities to specify memory sizes. Today we have:

dom0_mem= List of ( min:<size> | max:<size> | <size> )

with <size> being a positive or negative size value (e.g. 1G).

Modify that to:

dom0_mem= List of ( min:<sz> | max:<sz> | <sz> )
<sz>: <size> | [<size>+]<frac>%
<frac>: integer value < 100

With the following semantics:

<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.

---
 docs/misc/xen-command-line.markdown | 21 ++++++++++++++-------
 xen/arch/x86/dom0_build.c           | 36 +++++++++++++++++++++++++++++++-----
 2 files changed, 45 insertions(+), 12 deletions(-)
docs/misc/xen-command-line.markdown +14 -7
index 9028bcde2e..e471d32404 100644
@@ -759,17 +759,17 @@ Set the amount of memory for the initial domain (dom0). It must be
 greater than zero. This parameter is required.
 
 ### dom0\_mem (x86)
-> `= List of ( min:<size> | max:<size> | <size> )`
-
+> `= List of ( min:<sz> | max:<sz> | <sz> )`
+ 
 Set the amount of memory for the initial domain (dom0). If a size is
 positive, it represents an absolute value.  If a size is negative, it
 is subtracted from the total available memory.
 
-* `<size>` specifies the exact amount of memory.
-* `min:<size>` specifies the minimum amount of memory.
-* `max:<size>` specifies the maximum amount of memory.
+* `<sz>` specifies the exact amount of memory.
+* `min:<sz>` specifies the minimum amount of memory.
+* `max:<sz>` specifies the maximum amount of memory.
 
-If `<size>` is not specified, the default is all the available memory
+If `<sz>` is not specified, the default is all the available memory
 minus some reserve.  The reserve is 1/16 of the available memory or
 128 MB (whichever is smaller).
 
@@ -777,13 +777,20 @@ The amount of memory will be at least the minimum but never more than
 the maximum (i.e., `max` overrides the `min` option).  If there isn't
 enough memory then as much as possible is allocated.
 
-`max:<size>` also sets the maximum reservation (the maximum amount of
+`max:<sz>` also sets the maximum reservation (the maximum amount of
 memory dom0 can balloon up to).  If this is omitted then the maximum
 reservation is unlimited.
 
 For example, to set dom0's initial memory allocation to 512MB but
 allow it to balloon up as far as 1GB use `dom0_mem=512M,max:1G`
 
+> `<sz>` is: `<size> | [<size>+]<frac>%`
+> `<frac>` is an integer < 100
+
+* `<frac>` specifies a fraction of host memory size in percent.
+
+So `<sz>` being `1G+25%` on a 256 GB host would result in 65 GB.
+    
 If you use this option then it is highly recommended that you disable
 any dom0 autoballooning feature present in your toolstack. See the
 _xl.conf(5)_ man page or [Xen Best
xen/arch/x86/dom0_build.c +31 -5
index e34022a9b8..6929b204ef 100644
@@ -24,15 +24,20 @@ static long __initdata dom0_nrpages;
 static long __initdata dom0_min_nrpages;
 static long __initdata dom0_max_nrpages = LONG_MAX;
 
-static char __initdata dom0_mem_par[64];
+static char __initdata dom0_mem_par[256];
 
 /*
  * dom0_mem=[min:<min_amt>,][max:<max_amt>,][<amt>]
- * 
+ *
  * <min_amt>: The minimum amount of memory which should be allocated for dom0.
  * <max_amt>: The maximum amount of memory which should be allocated for dom0.
  * <amt>:     The precise amount of memory to allocate for dom0.
- * 
+ *
+ * The format of <min_amt>, <max_amt> and <amt> is as follows:
+ * <size> | <frac>% | <size>+<frac>%
+ * <size> is a size value like 1G (1 GByte), <frac> is percentage of host
+ * memory (so 1G+10% means 10 percent of host memory + 1 GByte).
+ *
  * Notes:
  *  1. <amt> is clamped from below by <min_amt> and from above by available
  *     memory and <max_amt>
@@ -41,7 +46,7 @@ static char __initdata dom0_mem_par[64];
  *  4. If <amt> is not specified, it is calculated as follows:
  *     "All of memory is allocated to domain 0, minus 1/16th which is reserved
  *      for uses such as DMA buffers (the reservation is clamped to 128MB)."
- * 
+ *
  * Each value can be specified as positive or negative:
  *  If +ve: The specified amount is an absolute value.
  *  If -ve: The specified amount is subtracted from total available memory.
@@ -50,7 +55,28 @@ static unsigned long __init parse_amt(const char *s, const char **ps,
                                       unsigned long avail)
 {
     unsigned int minus = (*s == '-') ? 1 : 0;
-    unsigned long pages = parse_size_and_unit(s + minus, ps) >> PAGE_SHIFT;
+    unsigned long val, pages = 0;
+
+    /* Avoid accessing s[-1] in case value starts with '%'. */
+    if ( *s == '%' )
+        return 0;
+
+    s += minus;
+    while ( isdigit(*s) )
+    {
+        val = parse_size_and_unit(s, ps);
+        s = *ps;
+        if ( *s == '%' && isdigit(*(s - 1)) && val < (100 << 10) )
+        {
+            pages += (val >> 10) * avail / 100;
+            s++;
+        }
+        else
+            pages += val >> PAGE_SHIFT;
+        if ( *s == '+' )
+            s++;
+    }
+    *ps = s;
 
     /* Negative specification means "all memory - specified amount". */
     return minus ? avail - pages : pages;
Signature · 7 lines
2.16.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#7 lore raw

Re: [PATCH 2/3] xen/x86: add dom0 memory sizing variants

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 22.11.18 at 17:40, <[email protected]> wrote:
docs/misc/xen-command-line.markdown +0 -0
@@ -777,13 +777,20 @@ The amount of memory will be at least the minimum but never more than
 the maximum (i.e., `max` overrides the `min` option).  If there isn't
 enough memory then as much as possible is allocated.
 

docs/misc/xen-command-line.markdown The amount of memory will be at least the minimum but never more than · line 788

Quoted 10 lines
docs/misc/xen-command-line.markdown +3 -1
-`max:<size>` also sets the maximum reservation (the maximum amount of
+`max:<sz>` also sets the maximum reservation (the maximum amount of
 memory dom0 can balloon up to).  If this is omitted then the maximum
 reservation is unlimited.
 
 For example, to set dom0's initial memory allocation to 512MB but
 allow it to balloon up as far as 1GB use `dom0_mem=512M,max:1G`
 
+> `<sz>` is: `<size> | [<size>+]<frac>%`
+> `<frac>` is an integer < 100

It is probably fine to state it like this here, but the implementation should take care of not allowing <size>+<frac>% to be greater than available memory.

Quoted 7 lines
xen/arch/x86/dom0_build.c +2 -1
@@ -50,7 +55,28 @@ static unsigned long __init parse_amt(const char *s, const char **ps,
                                       unsigned long avail)
 {
     unsigned int minus = (*s == '-') ? 1 : 0;
-    unsigned long pages = parse_size_and_unit(s + minus, ps) >> PAGE_SHIFT;
+    unsigned long val, pages = 0;
+

xen/arch/x86/dom0_build.c static unsigned long __init parse_amt(const char *s, const char **ps, · line 69

Quoted 10 lines
xen/arch/x86/dom0_build.c +10 -0
+    /* Avoid accessing s[-1] in case value starts with '%'. */
+    if ( *s == '%' )
+        return 0;
+
+    s += minus;
+    while ( isdigit(*s) )
+    {
+        val = parse_size_and_unit(s, ps);
+        s = *ps;
+        if ( *s == '%' && isdigit(*(s - 1)) && val < (100 << 10) )

In the comment above you talk about s[-1] - why do you use a more complicated (even if just slightly) expression here?

Review static unsigned long __init parse_amt(const char *s, const char **ps, · line 71

Quoted 2 lines
(quoted diff) +2 -0
+        {
+            pages += (val >> 10) * avail / 100;

The scaling by 10 bits here and above make it rather desirable to slightly change parse_size_and_unit() instead: I think it could easily be made not do the scaling if it finds % as the next input character. Otherwise at least a brief comment should be put here.

Despite the comments - I very much like the added flexibility.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

A message that is not in the archive (sent off-list or not yet received): [email protected]

#9 lore raw

Re: [PATCH 2/3] xen/x86: add dom0 memory sizing variants

Quoted 13 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 22.11.18 at 17:40, <[email protected]> wrote:
docs/misc/xen-command-line.markdown +1 -1
@@ -777,13 +777,20 @@ The amount of memory will be at least the minimum but never more than
 the maximum (i.e., `max` overrides the `min` option).  If there isn't
 enough memory then as much as possible is allocated.
 
-`max:<size>` also sets the maximum reservation (the maximum amount of
+`max:<sz>` also sets the maximum reservation (the maximum amount of
 memory dom0 can balloon up to).  If this is omitted then the maximum
 reservation is unlimited.
 
 For example, to set dom0's initial memory allocation to 512MB but
 allow it to balloon up as far as 1GB use `dom0_mem=512M,max:1G`
 
Quoted 6 lines

docs/misc/xen-command-line.markdown The amount of memory will be at least the minimum but never more than · line 788

Quoted 2 lines
docs/misc/xen-command-line.markdown +2 -0
+> `<sz>` is: `<size> | [<size>+]<frac>%`
+> `<frac>` is an integer < 100

It is probably fine to state it like this here, but the implementation should take care of not allowing <size>+<frac>% to be greater than available memory.

dom0_compute_nr_pages() is making sure the size is limited by the available memory.

Quoted 13 lines
Quoted 13 lines
xen/arch/x86/dom0_build.c +7 -1
@@ -50,7 +55,28 @@ static unsigned long __init parse_amt(const char *s, const char **ps,
                                       unsigned long avail)
 {
     unsigned int minus = (*s == '-') ? 1 : 0;
-    unsigned long pages = parse_size_and_unit(s + minus, ps) >> PAGE_SHIFT;
+    unsigned long val, pages = 0;
+
+    /* Avoid accessing s[-1] in case value starts with '%'. */
+    if ( *s == '%' )
+        return 0;
+
+    s += minus;
Quoted 8 lines

xen/arch/x86/dom0_build.c static unsigned long __init parse_amt(const char *s, const char **ps, · line 69

Quoted 5 lines
xen/arch/x86/dom0_build.c +5 -0
+    while ( isdigit(*s) )
+    {
+        val = parse_size_and_unit(s, ps);
+        s = *ps;
+        if ( *s == '%' && isdigit(*(s - 1)) && val < (100 << 10) )

In the comment above you talk about s[-1] - why do you use a more complicated (even if just slightly) expression here?

I dislike using s[-1] in code. In case you prefer it I can use it here.

Quoted 8 lines

Review static unsigned long __init parse_amt(const char *s, const char **ps, · line 71

Quoted 3 lines
(quoted diff) +2 -0
+        {
+            pages += (val >> 10) * avail / 100;

The scaling by 10 bits here and above make it rather desirable to slightly change parse_size_and_unit() instead: I think it could easily be made not do the scaling if it finds % as the next input character. Otherwise at least a brief comment should be put here.

I'm fine with either solution. In case nobody else speaks up I'll modify parse_size_and_unit() to do no scaling in case of '%' following the value.

Quoted 1 line

Despite the comments - I very much like the added flexibility.

Thanks. That was the main hurdle. Implementation details can be sorted out easily. :-)

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#10 lore raw

Re: [PATCH 2/3] xen/x86: add dom0 memory sizing variants

Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 28.11.18 at 16:43, <[email protected]> wrote:
Quoted 13 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 22.11.18 at 17:40, <[email protected]> wrote:
xen/arch/x86/dom0_build.c +7 -1
@@ -50,7 +55,28 @@ static unsigned long __init parse_amt(const char *s, const char **ps,
                                       unsigned long avail)
 {
     unsigned int minus = (*s == '-') ? 1 : 0;
-    unsigned long pages = parse_size_and_unit(s + minus, ps) >> PAGE_SHIFT;
+    unsigned long val, pages = 0;
+
+    /* Avoid accessing s[-1] in case value starts with '%'. */
+    if ( *s == '%' )
+        return 0;
+
+    s += minus;
Quoted 8 lines

xen/arch/x86/dom0_build.c static unsigned long __init parse_amt(const char *s, const char **ps, · line 69

Quoted 5 lines
xen/arch/x86/dom0_build.c +5 -0
+    while ( isdigit(*s) )
+    {
+        val = parse_size_and_unit(s, ps);
+        s = *ps;
+        if ( *s == '%' && isdigit(*(s - 1)) && val < (100 << 10) )

In the comment above you talk about s[-1] - why do you use a more complicated (even if just slightly) expression here?

Quoted 1 line

I dislike using s[-1] in code. In case you prefer it I can use it here.

It makes more obvious what is meant imo. And we have a number of instances in the tree already.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#11 lore raw

PATCH 3/3 xen/x86: add CONFIG item for default dom0 memory size

In reply to Juergen Gross

With being able to specify a dom0_mem value depending on host memory size 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.

---
 xen/arch/x86/Kconfig      | 9 +++++++++
 xen/arch/x86/dom0_build.c | 2 +-
 2 files changed, 10 insertions(+), 1 deletion(-)
xen/arch/x86/Kconfig +9 -0
index 5c2d1070b6..a44f523730 100644
@@ -176,6 +176,15 @@ config PV_SHIM_EXCLUSIVE
 	  firmware, and will not function correctly in other scenarios.
 
 	  If unsure, say N.
+
+config DOM0_MEM
+	string "Default value for dom0_mem boot parameter"
+	---help---
+	  Sets a default value for dom0_mem, e.g. "min:1G,max:64G,256M+10%".
+	  See docs/misc/xen-command-line.markdown for the supported syntax.
+
+	  Leave empty if you are not sure what to specify.
+
 endmenu
 
 source "common/Kconfig"
xen/arch/x86/dom0_build.c +1 -1
index 6929b204ef..7e3c215fbd 100644
@@ -24,7 +24,7 @@ static long __initdata dom0_nrpages;
 static long __initdata dom0_min_nrpages;
 static long __initdata dom0_max_nrpages = LONG_MAX;
 
-static char __initdata dom0_mem_par[256];
+static char __initdata dom0_mem_par[256] = CONFIG_DOM0_MEM;
 
 /*
  * dom0_mem=[min:<min_amt>,][max:<max_amt>,][<amt>]
Signature · 7 lines
2.16.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#12 lore raw

Re: [PATCH 3/3] xen/x86: add CONFIG item for default dom0 memory size

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 22.11.18 at 17:40, <[email protected]> wrote:
xen/arch/x86/Kconfig +0 -0
@@ -176,6 +176,15 @@ config PV_SHIM_EXCLUSIVE
 	  firmware, and will not function correctly in other scenarios.

xen/arch/x86/Kconfig config PV_SHIM_EXCLUSIVE · line 186

Quoted 10 lines
xen/arch/x86/Kconfig +8 -0
 
 	  If unsure, say N.
+
+config DOM0_MEM
+	string "Default value for dom0_mem boot parameter"
+	---help---
+	  Sets a default value for dom0_mem, e.g. "min:1G,max:64G,256M+10%".
+	  See docs/misc/xen-command-line.markdown for the supported syntax.
+
+	  Leave empty if you are not sure what to specify.

The latest here I'm with Julien - this should not be x86-specific.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

A message that is not in the archive (sent off-list or not yet received): [email protected]

#14 lore raw

Re: [PATCH 3/3] xen/x86: add CONFIG item for default dom0 memory size

Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 22.11.18 at 17:40, <[email protected]> wrote:
xen/arch/x86/Kconfig +0 -0
@@ -176,6 +176,15 @@ config PV_SHIM_EXCLUSIVE
 	  firmware, and will not function correctly in other scenarios.
 
Quoted 11 lines

xen/arch/x86/Kconfig config PV_SHIM_EXCLUSIVE · line 186

Quoted 9 lines
xen/arch/x86/Kconfig +8 -0
 	  If unsure, say N.
+
+config DOM0_MEM
+	string "Default value for dom0_mem boot parameter"
+	---help---
+	  Sets a default value for dom0_mem, e.g. "min:1G,max:64G,256M+10%".
+	  See docs/misc/xen-command-line.markdown for the supported syntax.
+
+	  Leave empty if you are not sure what to specify.

The latest here I'm with Julien - this should not be x86-specific.

Adding ARM-support for this patch is easy.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#15 lore raw
In reply to Juergen Gross

Hi Juergen,

I don't mean to scope-creep your series, and I think it is fine if you don't want to do it, but it would be fantastic if you took the opportunity to make dom0_mem common across architectures.

On ARM, we parse it in xen/arch/arm/domain_build.c:parse_dom0_mem. I think the ARM and x86 implementations should be the same.

Cheers,

Stefano

Quoted 16 lines · Juergen Gross

Setting the memory size of dom0 on a server for the non autoballooning case requires always specification of a boot parameter today. The value to set will depend mostly on the host memory size.

In order to support that scenario add the possibility to set dom0_mem depending on the amount of physical memory by allowing to specify a percentage of host memory (e.g. 10%) with an offset (like 1G+10%).

To make it easy for a distributor to use such a setting as the default make the standard setting for dom0_mem configurable via Kconfig.

Juergen Gross (3):
xen/x86: delay parsing of dom0_mem parameter until needed xen/x86: add dom0 memory sizing variants xen/x86: add CONFIG item for default dom0 memory size

Quoted 7 lines
 docs/misc/xen-command-line.markdown | 21 ++++++++----
 xen/arch/x86/Kconfig                |  9 +++++
 xen/arch/x86/dom0_build.c           | 67 +++++++++++++++++++++++++++----------
 3 files changed, 73 insertions(+), 24 deletions(-)
Signature · 1 line
2.16.4

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#16 lore raw
Quoted 8 lines · Stefano Stabellini

Hi Juergen,

I don't mean to scope-creep your series, and I think it is fine if you don't want to do it, but it would be fantastic if you took the opportunity to make dom0_mem common across architectures.

On ARM, we parse it in xen/arch/arm/domain_build.c:parse_dom0_mem. I think the ARM and x86 implementations should be the same.

This should be done by someone more familiar with the ARM requirements and internals.

A major difference between ARM and x86 seems to be the default size of
dom0: on ARM it is limited to 512MB, while on x86 it is most of the host's memory. I guess there is a reason for that difference, but I don't really know why.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel