Juergen Gross
2018-12-10 14:52:52 UTC
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(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.
-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 ...+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. */
+ }
+ 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+ else
+ {
+ /* <size> item must be first one. */
+ if ( items )
+ return -EINVAL;
+ tmp.nr_pages = val >> PAGE_SHIFT;
+ }
+ items++;
been easy (and add further flexibility).
wouldn't be rejected. In case anyone else thinks this would be better
I can change it, of course.
Juergen