[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen master] tools: add --maxmem parameter to init-xenstore-domain



commit 80dd5b401eb4e99f963ac8103424ddfd5274a837
Author:     Juergen Gross <jgross@xxxxxxxx>
AuthorDate: Mon Aug 8 10:28:27 2016 +0200
Commit:     Wei Liu <wei.liu2@xxxxxxxxxx>
CommitDate: Tue Sep 6 11:19:19 2016 +0100

    tools: add --maxmem parameter to init-xenstore-domain
    
    Add a parameter to specify the maximum memory size of the xenstore
    domain. In case the xenstore domain supports ballooning it will be
    capable to adjust its own size according to its memory needs.
    
    The maximum memory size can be specified as an absolute value in
    MiB, as a fraction of the host's memory, or as a combination of
    both (the maximum of the absolute and the fraction value):
    
    --maxmem <m>             maxmem is <m> MiB
    --maxmem <a>/<b>         maxmem is hostmem * a / b
    --maxmem <m>:<a>/<b>     maxmem is max(<m> MiB, hostmem * a / b)
    
    Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
    Acked-by: Wei Liu <wei.liu2@xxxxxxxxxx>
    Acked-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---
 tools/helpers/init-xenstore-domain.c | 83 +++++++++++++++++++++++++++++++++++-
 1 file changed, 81 insertions(+), 2 deletions(-)

diff --git a/tools/helpers/init-xenstore-domain.c 
b/tools/helpers/init-xenstore-domain.c
index 53b4b01..a7c97d7 100644
--- a/tools/helpers/init-xenstore-domain.c
+++ b/tools/helpers/init-xenstore-domain.c
@@ -23,6 +23,7 @@ static char *flask;
 static char *param;
 static char *name = "Xenstore";
 static int memory;
+static int maxmem;
 
 static struct option options[] = {
     { "kernel", 1, NULL, 'k' },
@@ -31,6 +32,7 @@ static struct option options[] = {
     { "ramdisk", 1, NULL, 'r' },
     { "param", 1, NULL, 'p' },
     { "name", 1, NULL, 'n' },
+    { "maxmem", 1, NULL, 'M' },
     { NULL, 0, NULL, 0 }
 };
 
@@ -48,7 +50,11 @@ static void usage(void)
 "  --flask <flask-label>      optional flask label of the domain\n"
 "  --ramdisk <ramdisk-file>   optional ramdisk file for the domain\n"
 "  --param <cmdline>          optional additional parameters for the domain\n"
-"  --name <name>              name of the domain (default: Xenstore)\n");
+"  --name <name>              name of the domain (default: Xenstore)\n"
+"  --maxmem <max size>        maximum memory size in the format:\n"
+"                             <MB val>|<a>/<b>|<MB val>:<a>/<b>\n"
+"                             (an absolute value in MB, a fraction a/b of\n"
+"                             the host memory, or the maximum of both)\n");
 }
 
 static int build(xc_interface *xch)
@@ -58,7 +64,7 @@ static int build(xc_interface *xch)
     xen_domain_handle_t handle = { 0 };
     int rv, xs_fd;
     struct xc_dom_image *dom = NULL;
-    int limit_kb = (memory + 1) * 1024;
+    int limit_kb = (maxmem ? : (memory + 1)) * 1024;
 
     xs_fd = open("/dev/xen/xenbus_backend", O_RDWR);
     if ( xs_fd == -1 )
@@ -223,6 +229,63 @@ static int check_domain(xc_interface *xch)
     return 0;
 }
 
+static int parse_maxmem(xc_interface *xch, char *str)
+{
+    xc_physinfo_t info;
+    int rv;
+    unsigned long mb = 0, a = 0, b = 0;
+    unsigned long val;
+    unsigned long *res;
+    char buf[16];
+    char *p;
+    char *s = str;
+
+    rv = xc_physinfo(xch, &info);
+    if ( rv )
+    {
+        fprintf(stderr, "xc_physinfo failed\n");
+        return -1;
+    }
+
+    res = &mb;
+    for (p = s; *p; s = p + 1)
+    {
+        val = strtoul(s, &p, 10);
+        if ( val == 0 || val >= INT_MAX / 1024 )
+            goto err;
+        if ( *p == '/' )
+        {
+            if ( res != &mb || a != 0 )
+                goto err;
+            a = val;
+            res = &b;
+            continue;
+        }
+        if ( *res != 0 )
+            goto err;
+        *res = val;
+        if ( *p != 0 && *p != ':' )
+            goto err;
+        res = &mb;
+    }
+    if ( a && !b )
+        goto err;
+
+    val = a ? info.total_pages * a / (b * 1024 * 1024 / XC_PAGE_SIZE) : 0;
+    if ( val >= INT_MAX / 1024 )
+        goto err;
+
+    maxmem = mb < val ? val : mb;
+    if ( maxmem < memory )
+        maxmem = 0;
+
+    return maxmem;
+
+err:
+    fprintf(stderr, "illegal value for maxmem: %s\n", str);
+    return -1;
+}
+
 static void do_xs_write(struct xs_handle *xsh, char *path, char *val)
 {
     if ( !xs_write(xsh, XBT_NULL, path, val, strlen(val)) )
@@ -244,6 +307,7 @@ int main(int argc, char** argv)
     struct xs_handle *xsh;
     char buf[16];
     int rv, fd;
+    char *maxmem_str = NULL;
 
     while ( (opt = getopt_long(argc, argv, "", options, NULL)) != -1 )
     {
@@ -267,6 +331,9 @@ int main(int argc, char** argv)
         case 'n':
             name = optarg;
             break;
+        case 'M':
+            maxmem_str = optarg;
+            break;
         default:
             usage();
             return 2;
@@ -286,6 +353,16 @@ int main(int argc, char** argv)
         return 1;
     }
 
+    if ( maxmem_str )
+    {
+        maxmem = parse_maxmem(xch, maxmem_str);
+        if ( maxmem < 0 )
+        {
+            xc_interface_close(xch);
+            return 1;
+        }
+    }
+
     rv = check_domain(xch);
 
     if ( !rv )
@@ -314,6 +391,8 @@ int main(int argc, char** argv)
     do_xs_write_dom(xsh, "name", name);
     snprintf(buf, 16, "%d", memory * 1024);
     do_xs_write_dom(xsh, "memory/target", buf);
+    if (maxmem)
+        snprintf(buf, 16, "%d", maxmem * 1024);
     do_xs_write_dom(xsh, "memory/static-max", buf);
     xs_close(xsh);
 
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.