ia64/xen-unstable

changeset 12205:444496ecb14e

[XEN] Extend dom0_mem syntax to support min/max clamps.

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.

Notes:
1. <amt> is clamped from below by <min_amt> and from above by available
memory and <max_amt>
2. <min_amt> is clamped from above by available memory and <max_amt>
3. <min_amt> is ignored if it is greater than <max_amt>
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.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Wed Nov 01 11:18:29 2006 +0000 (2006-11-01)
parents 9b553a9787cf
children 201a824f8240
files docs/src/user.tex xen/arch/ia64/xen/domain.c xen/arch/powerpc/domain_build.c xen/arch/x86/domain_build.c xen/arch/x86/e820.c xen/common/lib.c xen/common/page_alloc.c xen/include/xen/lib.h
line diff
     1.1 --- a/docs/src/user.tex	Wed Nov 01 10:41:44 2006 +0000
     1.2 +++ b/docs/src/user.tex	Wed Nov 01 11:18:29 2006 +0000
     1.3 @@ -3202,12 +3202,21 @@ editing \path{grub.conf}.
     1.4    ignored. This parameter may be specified with a B, K, M or G suffix,
     1.5    representing bytes, kilobytes, megabytes and gigabytes respectively.
     1.6    The default unit, if no suffix is specified, is kilobytes.
     1.7 -\item [ dom0\_mem=xxx ] Set the amount of memory to be allocated to
     1.8 -  domain0. In Xen 3.x the parameter may be specified with a B, K, M or
     1.9 +\item [ dom0\_mem=$<$specifier list$>$ ] Set the amount of memory to
    1.10 +  be allocated to domain 0. This is a comma-separated list containing
    1.11 +  the following optional components:
    1.12 +  \begin{description}
    1.13 +  \item[ min:$<$min\_amt$>$ ] Minimum amount to allocate to domain 0
    1.14 +  \item[ max:$<$min\_amt$>$ ] Maximum amount to allocate to domain 0
    1.15 +  \item[ $<$amt$>$ ] Precise amount to allocate to domain 0
    1.16 +  \end{description}
    1.17 +  Each numeric parameter may be specified with a B, K, M or
    1.18    G suffix, representing bytes, kilobytes, megabytes and gigabytes
    1.19    respectively; if no suffix is specified, the parameter defaults to
    1.20 -  kilobytes. In previous versions of Xen, suffixes were not supported
    1.21 -  and the value is always interpreted as kilobytes.
    1.22 +  kilobytes. Negative values are subtracted from total available
    1.23 +  memory. If $<$amt$>$ is not specified, it defaults to all available
    1.24 +  memory less a small amount (clamped to 128MB) for uses such as DMA
    1.25 +  buffers.
    1.26  \item [ dom0\_vcpus\_pin ] Pins domain 0 VCPUs on their respective
    1.27    physical CPUS (default=false).
    1.28  \item [ tbuf\_size=xxx ] Set the size of the per-cpu trace buffers, in
     2.1 --- a/xen/arch/ia64/xen/domain.c	Wed Nov 01 10:41:44 2006 +0000
     2.2 +++ b/xen/arch/ia64/xen/domain.c	Wed Nov 01 11:18:29 2006 +0000
     2.3 @@ -1177,6 +1177,6 @@ void sync_vcpu_execstate(struct vcpu *v)
     2.4  
     2.5  static void parse_dom0_mem(char *s)
     2.6  {
     2.7 -	dom0_size = parse_size_and_unit(s);
     2.8 +	dom0_size = parse_size_and_unit(s, NULL);
     2.9  }
    2.10  custom_param("dom0_mem", parse_dom0_mem);
     3.1 --- a/xen/arch/powerpc/domain_build.c	Wed Nov 01 10:41:44 2006 +0000
     3.2 +++ b/xen/arch/powerpc/domain_build.c	Wed Nov 01 11:18:29 2006 +0000
     3.3 @@ -40,7 +40,7 @@ static void parse_dom0_mem(char *s)
     3.4  {
     3.5      unsigned long long bytes;
     3.6  
     3.7 -    bytes = parse_size_and_unit(s);
     3.8 +    bytes = parse_size_and_unit(s, NULL);
     3.9      dom0_nrpages = bytes >> PAGE_SHIFT;
    3.10  }
    3.11  custom_param("dom0_mem", parse_dom0_mem);
     4.1 --- a/xen/arch/x86/domain_build.c	Wed Nov 01 10:41:44 2006 +0000
     4.2 +++ b/xen/arch/x86/domain_build.c	Wed Nov 01 11:18:29 2006 +0000
     4.3 @@ -33,28 +33,45 @@
     4.4  extern unsigned long initial_images_nrpages(void);
     4.5  extern void discard_initial_images(void);
     4.6  
     4.7 -static long dom0_nrpages;
     4.8 +static long dom0_nrpages, dom0_min_nrpages, dom0_max_nrpages = LONG_MAX;
     4.9  
    4.10  /*
    4.11 - * dom0_mem:
    4.12 - *  If +ve:
    4.13 - *   * The specified amount of memory is allocated to domain 0.
    4.14 - *  If -ve:
    4.15 - *   * All of memory is allocated to domain 0, minus the specified amount.
    4.16 - *  If not specified: 
    4.17 - *   * All of memory is allocated to domain 0, minus 1/16th which is reserved
    4.18 - *     for uses such as DMA buffers (the reservation is clamped to 128MB).
    4.19 + * dom0_mem=[min:<min_amt>,][max:<max_amt>,][<amt>]
    4.20 + * 
    4.21 + * <min_amt>: The minimum amount of memory which should be allocated for dom0.
    4.22 + * <max_amt>: The maximum amount of memory which should be allocated for dom0.
    4.23 + * <amt>:     The precise amount of memory to allocate for dom0.
    4.24 + * 
    4.25 + * Notes:
    4.26 + *  1. <amt> is clamped from below by <min_amt> and from above by available
    4.27 + *     memory and <max_amt>
    4.28 + *  2. <min_amt> is clamped from above by available memory and <max_amt>
    4.29 + *  3. <min_amt> is ignored if it is greater than <max_amt>
    4.30 + *  4. If <amt> is not specified, it is calculated as follows:
    4.31 + *     "All of memory is allocated to domain 0, minus 1/16th which is reserved
    4.32 + *      for uses such as DMA buffers (the reservation is clamped to 128MB)."
    4.33 + * 
    4.34 + * Each value can be specified as positive or negative:
    4.35 + *  If +ve: The specified amount is an absolute value.
    4.36 + *  If -ve: The specified amount is subtracted from total available memory.
    4.37   */
    4.38 +static long parse_amt(char *s, char **ps)
    4.39 +{
    4.40 +    long pages = parse_size_and_unit((*s == '-') ? s+1 : s, ps) >> PAGE_SHIFT;
    4.41 +    return (*s == '-') ? -pages : pages;
    4.42 +}
    4.43  static void parse_dom0_mem(char *s)
    4.44  {
    4.45 -    unsigned long long bytes;
    4.46 -    char *t = s;
    4.47 -    if ( *s == '-' )
    4.48 -        t++;
    4.49 -    bytes = parse_size_and_unit(t);
    4.50 -    dom0_nrpages = bytes >> PAGE_SHIFT;
    4.51 -    if ( *s == '-' )
    4.52 -        dom0_nrpages = -dom0_nrpages;
    4.53 +    do {
    4.54 +        if ( !strncmp(s, "min:", 4) )
    4.55 +            dom0_min_nrpages = parse_amt(s+4, &s);
    4.56 +        else if ( !strncmp(s, "max:", 4) )
    4.57 +            dom0_max_nrpages = parse_amt(s+4, &s);
    4.58 +        else
    4.59 +            dom0_nrpages = parse_amt(s, &s);
    4.60 +        if ( *s != ',' )
    4.61 +            break;
    4.62 +    } while ( *s++ == ',' );
    4.63  }
    4.64  custom_param("dom0_mem", parse_dom0_mem);
    4.65  
    4.66 @@ -103,6 +120,35 @@ static struct page_info *alloc_chunk(str
    4.67      return page;
    4.68  }
    4.69  
    4.70 +static unsigned long compute_dom0_nr_pages(void)
    4.71 +{
    4.72 +    unsigned long avail = avail_domheap_pages() + initial_images_nrpages();
    4.73 +
    4.74 +    /*
    4.75 +     * If domain 0 allocation isn't specified, reserve 1/16th of available
    4.76 +     * memory for things like DMA buffers. This reservation is clamped to 
    4.77 +     * a maximum of 128MB.
    4.78 +     */
    4.79 +    if ( dom0_nrpages == 0 )
    4.80 +    {
    4.81 +        dom0_nrpages = avail;
    4.82 +        dom0_nrpages = min(dom0_nrpages / 16, 128L << (20 - PAGE_SHIFT));
    4.83 +        dom0_nrpages = -dom0_nrpages;
    4.84 +    }
    4.85 +
    4.86 +    /* Negative memory specification means "all memory - specified amount". */
    4.87 +    if ( dom0_nrpages     < 0 ) dom0_nrpages     += avail;
    4.88 +    if ( dom0_min_nrpages < 0 ) dom0_min_nrpages += avail;
    4.89 +    if ( dom0_max_nrpages < 0 ) dom0_max_nrpages += avail;
    4.90 +
    4.91 +    /* Clamp dom0 memory according to min/max limits and available memory. */
    4.92 +    dom0_nrpages = max(dom0_nrpages, dom0_min_nrpages);
    4.93 +    dom0_nrpages = min(dom0_nrpages, dom0_max_nrpages);
    4.94 +    dom0_nrpages = min(dom0_nrpages, (long)avail);
    4.95 +
    4.96 +    return dom0_nrpages;
    4.97 +}
    4.98 +
    4.99  static void process_dom0_ioports_disable(void)
   4.100  {
   4.101      unsigned long io_from, io_to;
   4.102 @@ -269,25 +315,7 @@ int construct_dom0(struct domain *d,
   4.103  
   4.104      d->max_pages = ~0U;
   4.105  
   4.106 -    /*
   4.107 -     * If domain 0 allocation isn't specified, reserve 1/16th of available
   4.108 -     * memory for things like DMA buffers. This reservation is clamped to 
   4.109 -     * a maximum of 128MB.
   4.110 -     */
   4.111 -    if ( dom0_nrpages == 0 )
   4.112 -    {
   4.113 -        dom0_nrpages = avail_domheap_pages() + initial_images_nrpages();
   4.114 -        dom0_nrpages = min(dom0_nrpages / 16, 128L << (20 - PAGE_SHIFT));
   4.115 -        dom0_nrpages = -dom0_nrpages;
   4.116 -    }
   4.117 -
   4.118 -    /* Negative memory specification means "all memory - specified amount". */
   4.119 -    if ( dom0_nrpages < 0 )
   4.120 -        nr_pages = avail_domheap_pages() + initial_images_nrpages() +
   4.121 -            dom0_nrpages;
   4.122 -    else
   4.123 -        nr_pages = min(avail_domheap_pages() + initial_images_nrpages(),
   4.124 -                       (unsigned long)dom0_nrpages);
   4.125 +    nr_pages = compute_dom0_nr_pages();
   4.126  
   4.127      if ( (rc = parseelfimage(&dsi)) != 0 )
   4.128          return rc;
     5.1 --- a/xen/arch/x86/e820.c	Wed Nov 01 10:41:44 2006 +0000
     5.2 +++ b/xen/arch/x86/e820.c	Wed Nov 01 11:18:29 2006 +0000
     5.3 @@ -6,7 +6,7 @@
     5.4  
     5.5  /* opt_mem: Limit of physical RAM. Any RAM beyond this point is ignored. */
     5.6  unsigned long long opt_mem;
     5.7 -static void parse_mem(char *s) { opt_mem = parse_size_and_unit(s); }
     5.8 +static void parse_mem(char *s) { opt_mem = parse_size_and_unit(s, NULL); }
     5.9  custom_param("mem", parse_mem);
    5.10  
    5.11  struct e820map e820;
     6.1 --- a/xen/common/lib.c	Wed Nov 01 10:41:44 2006 +0000
     6.2 +++ b/xen/common/lib.c	Wed Nov 01 11:18:29 2006 +0000
     6.3 @@ -439,21 +439,28 @@ s64 __moddi3(s64 a, s64 b)
     6.4  
     6.5  #endif /* BITS_PER_LONG == 32 */
     6.6  
     6.7 -unsigned long long parse_size_and_unit(char *s)
     6.8 +unsigned long long parse_size_and_unit(const char *s, char **ps)
     6.9  {
    6.10 -	unsigned long long ret = simple_strtoull(s, &s, 0);
    6.11 +	unsigned long long ret = simple_strtoull(s, (char **)&s, 0);
    6.12  
    6.13  	switch (*s) {
    6.14  	case 'G': case 'g':
    6.15  		ret <<= 10;
    6.16  	case 'M': case 'm':
    6.17  		ret <<= 10;
    6.18 -	case 'K': case 'k': default:
    6.19 +	case 'K': case 'k':
    6.20  		ret <<= 10;
    6.21  	case 'B': case 'b':
    6.22 +		s++;
    6.23 +		break;
    6.24 +	default:
    6.25 +		ret <<= 10; /* default to kB */
    6.26  		break;
    6.27  	}
    6.28  
    6.29 +	if (ps != NULL)
    6.30 +		*ps = (char *)s;
    6.31 +
    6.32  	return ret;
    6.33  }
    6.34  
     7.1 --- a/xen/common/page_alloc.c	Wed Nov 01 10:41:44 2006 +0000
     7.2 +++ b/xen/common/page_alloc.c	Wed Nov 01 11:18:29 2006 +0000
     7.3 @@ -54,7 +54,7 @@ static unsigned long lowmem_emergency_po
     7.4  static void parse_lowmem_emergency_pool(char *s)
     7.5  {
     7.6      unsigned long long bytes;
     7.7 -    bytes = parse_size_and_unit(s);
     7.8 +    bytes = parse_size_and_unit(s, NULL);
     7.9      lowmem_emergency_pool_pages = bytes >> PAGE_SHIFT;
    7.10  }
    7.11  custom_param("lowmem_emergency_pool", parse_lowmem_emergency_pool);
     8.1 --- a/xen/include/xen/lib.h	Wed Nov 01 10:41:44 2006 +0000
     8.2 +++ b/xen/include/xen/lib.h	Wed Nov 01 11:18:29 2006 +0000
     8.3 @@ -86,7 +86,7 @@ long long simple_strtoll(
     8.4  unsigned long long simple_strtoull(
     8.5      const char *cp,char **endp, unsigned int base);
     8.6  
     8.7 -unsigned long long parse_size_and_unit(char *s);
     8.8 +unsigned long long parse_size_and_unit(const char *s, char **ps);
     8.9  
    8.10  #define TAINT_UNSAFE_SMP                (1<<0)
    8.11  #define TAINT_MACHINE_CHECK             (1<<1)