WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] [XEN] Extend dom0_mem syntax to support m

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] [XEN] Extend dom0_mem syntax to support min/max clamps.
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Thu, 02 Nov 2006 22:10:07 +0000
Delivery-date: Thu, 02 Nov 2006 21:42:58 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User kfraser@xxxxxxxxxxxxxxxxxxxxx
# Node ID 444496ecb14e79f69fac012b4dc19613ad5f7c06
# Parent  9b553a9787cf109d9aaeb8857f7608f4472b5b86
[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@xxxxxxxxxxxxx>
---
 docs/src/user.tex               |   17 +++++-
 xen/arch/ia64/xen/domain.c      |    2 
 xen/arch/powerpc/domain_build.c |    2 
 xen/arch/x86/domain_build.c     |  100 +++++++++++++++++++++++++---------------
 xen/arch/x86/e820.c             |    2 
 xen/common/lib.c                |   17 ++++--
 xen/common/page_alloc.c         |    2 
 xen/include/xen/lib.h           |    2 
 8 files changed, 94 insertions(+), 50 deletions(-)

diff -r 9b553a9787cf -r 444496ecb14e docs/src/user.tex
--- a/docs/src/user.tex Wed Nov 01 10:41:44 2006 +0000
+++ b/docs/src/user.tex Wed Nov 01 11:18:29 2006 +0000
@@ -3202,12 +3202,21 @@ editing \path{grub.conf}.
   ignored. This parameter may be specified with a B, K, M or G suffix,
   representing bytes, kilobytes, megabytes and gigabytes respectively.
   The default unit, if no suffix is specified, is kilobytes.
-\item [ dom0\_mem=xxx ] Set the amount of memory to be allocated to
-  domain0. In Xen 3.x the parameter may be specified with a B, K, M or
+\item [ dom0\_mem=$<$specifier list$>$ ] Set the amount of memory to
+  be allocated to domain 0. This is a comma-separated list containing
+  the following optional components:
+  \begin{description}
+  \item[ min:$<$min\_amt$>$ ] Minimum amount to allocate to domain 0
+  \item[ max:$<$min\_amt$>$ ] Maximum amount to allocate to domain 0
+  \item[ $<$amt$>$ ] Precise amount to allocate to domain 0
+  \end{description}
+  Each numeric parameter may be specified with a B, K, M or
   G suffix, representing bytes, kilobytes, megabytes and gigabytes
   respectively; if no suffix is specified, the parameter defaults to
-  kilobytes. In previous versions of Xen, suffixes were not supported
-  and the value is always interpreted as kilobytes.
+  kilobytes. Negative values are subtracted from total available
+  memory. If $<$amt$>$ is not specified, it defaults to all available
+  memory less a small amount (clamped to 128MB) for uses such as DMA
+  buffers.
 \item [ dom0\_vcpus\_pin ] Pins domain 0 VCPUs on their respective
   physical CPUS (default=false).
 \item [ tbuf\_size=xxx ] Set the size of the per-cpu trace buffers, in
diff -r 9b553a9787cf -r 444496ecb14e xen/arch/ia64/xen/domain.c
--- a/xen/arch/ia64/xen/domain.c        Wed Nov 01 10:41:44 2006 +0000
+++ b/xen/arch/ia64/xen/domain.c        Wed Nov 01 11:18:29 2006 +0000
@@ -1177,6 +1177,6 @@ void sync_vcpu_execstate(struct vcpu *v)
 
 static void parse_dom0_mem(char *s)
 {
-       dom0_size = parse_size_and_unit(s);
+       dom0_size = parse_size_and_unit(s, NULL);
 }
 custom_param("dom0_mem", parse_dom0_mem);
diff -r 9b553a9787cf -r 444496ecb14e xen/arch/powerpc/domain_build.c
--- a/xen/arch/powerpc/domain_build.c   Wed Nov 01 10:41:44 2006 +0000
+++ b/xen/arch/powerpc/domain_build.c   Wed Nov 01 11:18:29 2006 +0000
@@ -40,7 +40,7 @@ static void parse_dom0_mem(char *s)
 {
     unsigned long long bytes;
 
-    bytes = parse_size_and_unit(s);
+    bytes = parse_size_and_unit(s, NULL);
     dom0_nrpages = bytes >> PAGE_SHIFT;
 }
 custom_param("dom0_mem", parse_dom0_mem);
diff -r 9b553a9787cf -r 444496ecb14e xen/arch/x86/domain_build.c
--- a/xen/arch/x86/domain_build.c       Wed Nov 01 10:41:44 2006 +0000
+++ b/xen/arch/x86/domain_build.c       Wed Nov 01 11:18:29 2006 +0000
@@ -33,28 +33,45 @@ extern unsigned long initial_images_nrpa
 extern unsigned long initial_images_nrpages(void);
 extern void discard_initial_images(void);
 
-static long dom0_nrpages;
+static long dom0_nrpages, dom0_min_nrpages, dom0_max_nrpages = LONG_MAX;
 
 /*
- * dom0_mem:
- *  If +ve:
- *   * The specified amount of memory is allocated to domain 0.
- *  If -ve:
- *   * All of memory is allocated to domain 0, minus the specified amount.
- *  If not specified: 
- *   * 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).
+ * 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.
  */
+static long parse_amt(char *s, char **ps)
+{
+    long pages = parse_size_and_unit((*s == '-') ? s+1 : s, ps) >> PAGE_SHIFT;
+    return (*s == '-') ? -pages : pages;
+}
 static void parse_dom0_mem(char *s)
 {
-    unsigned long long bytes;
-    char *t = s;
-    if ( *s == '-' )
-        t++;
-    bytes = parse_size_and_unit(t);
-    dom0_nrpages = bytes >> PAGE_SHIFT;
-    if ( *s == '-' )
-        dom0_nrpages = -dom0_nrpages;
+    do {
+        if ( !strncmp(s, "min:", 4) )
+            dom0_min_nrpages = parse_amt(s+4, &s);
+        else if ( !strncmp(s, "max:", 4) )
+            dom0_max_nrpages = parse_amt(s+4, &s);
+        else
+            dom0_nrpages = parse_amt(s, &s);
+        if ( *s != ',' )
+            break;
+    } while ( *s++ == ',' );
 }
 custom_param("dom0_mem", parse_dom0_mem);
 
@@ -101,6 +118,35 @@ static struct page_info *alloc_chunk(str
         if ( order-- == 0 )
             break;
     return page;
+}
+
+static unsigned long compute_dom0_nr_pages(void)
+{
+    unsigned long avail = avail_domheap_pages() + initial_images_nrpages();
+
+    /*
+     * If domain 0 allocation isn't specified, reserve 1/16th of available
+     * memory for things like DMA buffers. This reservation is clamped to 
+     * a maximum of 128MB.
+     */
+    if ( dom0_nrpages == 0 )
+    {
+        dom0_nrpages = avail;
+        dom0_nrpages = min(dom0_nrpages / 16, 128L << (20 - PAGE_SHIFT));
+        dom0_nrpages = -dom0_nrpages;
+    }
+
+    /* Negative memory specification means "all memory - specified amount". */
+    if ( dom0_nrpages     < 0 ) dom0_nrpages     += avail;
+    if ( dom0_min_nrpages < 0 ) dom0_min_nrpages += avail;
+    if ( dom0_max_nrpages < 0 ) dom0_max_nrpages += avail;
+
+    /* Clamp dom0 memory according to min/max limits and available memory. */
+    dom0_nrpages = max(dom0_nrpages, dom0_min_nrpages);
+    dom0_nrpages = min(dom0_nrpages, dom0_max_nrpages);
+    dom0_nrpages = min(dom0_nrpages, (long)avail);
+
+    return dom0_nrpages;
 }
 
 static void process_dom0_ioports_disable(void)
@@ -269,25 +315,7 @@ int construct_dom0(struct domain *d,
 
     d->max_pages = ~0U;
 
-    /*
-     * If domain 0 allocation isn't specified, reserve 1/16th of available
-     * memory for things like DMA buffers. This reservation is clamped to 
-     * a maximum of 128MB.
-     */
-    if ( dom0_nrpages == 0 )
-    {
-        dom0_nrpages = avail_domheap_pages() + initial_images_nrpages();
-        dom0_nrpages = min(dom0_nrpages / 16, 128L << (20 - PAGE_SHIFT));
-        dom0_nrpages = -dom0_nrpages;
-    }
-
-    /* Negative memory specification means "all memory - specified amount". */
-    if ( dom0_nrpages < 0 )
-        nr_pages = avail_domheap_pages() + initial_images_nrpages() +
-            dom0_nrpages;
-    else
-        nr_pages = min(avail_domheap_pages() + initial_images_nrpages(),
-                       (unsigned long)dom0_nrpages);
+    nr_pages = compute_dom0_nr_pages();
 
     if ( (rc = parseelfimage(&dsi)) != 0 )
         return rc;
diff -r 9b553a9787cf -r 444496ecb14e xen/arch/x86/e820.c
--- a/xen/arch/x86/e820.c       Wed Nov 01 10:41:44 2006 +0000
+++ b/xen/arch/x86/e820.c       Wed Nov 01 11:18:29 2006 +0000
@@ -6,7 +6,7 @@
 
 /* opt_mem: Limit of physical RAM. Any RAM beyond this point is ignored. */
 unsigned long long opt_mem;
-static void parse_mem(char *s) { opt_mem = parse_size_and_unit(s); }
+static void parse_mem(char *s) { opt_mem = parse_size_and_unit(s, NULL); }
 custom_param("mem", parse_mem);
 
 struct e820map e820;
diff -r 9b553a9787cf -r 444496ecb14e xen/common/lib.c
--- a/xen/common/lib.c  Wed Nov 01 10:41:44 2006 +0000
+++ b/xen/common/lib.c  Wed Nov 01 11:18:29 2006 +0000
@@ -439,20 +439,27 @@ s64 __moddi3(s64 a, s64 b)
 
 #endif /* BITS_PER_LONG == 32 */
 
-unsigned long long parse_size_and_unit(char *s)
-{
-       unsigned long long ret = simple_strtoull(s, &s, 0);
+unsigned long long parse_size_and_unit(const char *s, char **ps)
+{
+       unsigned long long ret = simple_strtoull(s, (char **)&s, 0);
 
        switch (*s) {
        case 'G': case 'g':
                ret <<= 10;
        case 'M': case 'm':
                ret <<= 10;
-       case 'K': case 'k': default:
+       case 'K': case 'k':
                ret <<= 10;
        case 'B': case 'b':
+               s++;
                break;
-       }
+       default:
+               ret <<= 10; /* default to kB */
+               break;
+       }
+
+       if (ps != NULL)
+               *ps = (char *)s;
 
        return ret;
 }
diff -r 9b553a9787cf -r 444496ecb14e xen/common/page_alloc.c
--- a/xen/common/page_alloc.c   Wed Nov 01 10:41:44 2006 +0000
+++ b/xen/common/page_alloc.c   Wed Nov 01 11:18:29 2006 +0000
@@ -54,7 +54,7 @@ static void parse_lowmem_emergency_pool(
 static void parse_lowmem_emergency_pool(char *s)
 {
     unsigned long long bytes;
-    bytes = parse_size_and_unit(s);
+    bytes = parse_size_and_unit(s, NULL);
     lowmem_emergency_pool_pages = bytes >> PAGE_SHIFT;
 }
 custom_param("lowmem_emergency_pool", parse_lowmem_emergency_pool);
diff -r 9b553a9787cf -r 444496ecb14e xen/include/xen/lib.h
--- a/xen/include/xen/lib.h     Wed Nov 01 10:41:44 2006 +0000
+++ b/xen/include/xen/lib.h     Wed Nov 01 11:18:29 2006 +0000
@@ -86,7 +86,7 @@ unsigned long long simple_strtoull(
 unsigned long long simple_strtoull(
     const char *cp,char **endp, unsigned int base);
 
-unsigned long long parse_size_and_unit(char *s);
+unsigned long long parse_size_and_unit(const char *s, char **ps);
 
 #define TAINT_UNSAFE_SMP                (1<<0)
 #define TAINT_MACHINE_CHECK             (1<<1)

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] [XEN] Extend dom0_mem syntax to support min/max clamps., Xen patchbot-unstable <=