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

[Xen-devel] [PATCH v4 1/4] xl: Allow user to configure xl mem-set behavior



Add mem_set_enforce_limit option to xl.conf file and equivalent xl
command line option. Those two things give a chance to align xl mem-set
behavior to xm mem-set behavior. Default xl mem-set behavior is not
changed.

v4 - suggestions/fixes:
   - add limit check for mem_set_enforce_limit=0 case,
   - fix some error messages.

v3 - suggestions/fixes:
   - add xl command line option
     (suggested by Ian Jackson).

Signed-off-by: Daniel Kiper <daniel.kiper@xxxxxxxxxx>
---
 tools/libxl/libxl.c       |   25 ++++++++++++++++++-------
 tools/libxl/xl.c          |    4 ++++
 tools/libxl/xl.h          |    1 +
 tools/libxl/xl_cmdimpl.c  |   16 ++++++++++------
 tools/libxl/xl_cmdtable.c |    3 ++-
 5 files changed, 35 insertions(+), 14 deletions(-)

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 30302c7..9906224 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -3517,7 +3517,7 @@ int libxl_domain_setmaxmem(libxl_ctx *ctx, uint32_t 
domid, uint32_t max_memkb)
     }
 
     if (max_memkb < memorykb) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "memory_static_max must be 
greater than or or equal to memory_dynamic_max\n");
+        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "memory_xen_max must be 
greater than or equal to memory_dynamic_max\n");
         goto out;
     }
     rc = xc_domain_setmaxmem(ctx->xch, domid, max_memkb + 
LIBXL_MAXMEM_CONSTANT);
@@ -3678,6 +3678,16 @@ retry_transaction:
             goto out;
         }
     }
+
+    rc = xc_domain_getinfolist(ctx->xch, domid, 1, &info);
+
+    if (rc != 1 || info.domain != domid) {
+        abort_transaction = 1;
+        goto out;
+    }
+
+    xcinfo2xlinfo(&info, &ptr);
+
     memmax = libxl__xs_read(gc, t, libxl__sprintf(gc,
                 "%s/memory/static-max", dompath));
     if (!memmax) {
@@ -3733,6 +3743,12 @@ retry_transaction:
             abort_transaction = 1;
             goto out;
         }
+    } else if (new_target_memkb > ptr.max_memkb - LIBXL_MAXMEM_CONSTANT) {
+        LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
+                "memory_dynamic_max must be less than or equal to"
+                " memory_xen_max\n");
+        abort_transaction = 1;
+        goto out;
     }
 
     new_target_memkb -= videoram;
@@ -3749,12 +3765,7 @@ retry_transaction:
 
     libxl__xs_write(gc, t, libxl__sprintf(gc, "%s/memory/target",
                 dompath), "%"PRIu32, new_target_memkb);
-    rc = xc_domain_getinfolist(ctx->xch, domid, 1, &info);
-    if (rc != 1 || info.domain != domid) {
-        abort_transaction = 1;
-        goto out;
-    }
-    xcinfo2xlinfo(&info, &ptr);
+
     uuid = libxl__uuid2string(gc, ptr.uuid);
     libxl__xs_write(gc, t, libxl__sprintf(gc, "/vm/%s/memory", uuid),
             "%"PRIu32, new_target_memkb / 1024);
diff --git a/tools/libxl/xl.c b/tools/libxl/xl.c
index 3c141bf..2023230 100644
--- a/tools/libxl/xl.c
+++ b/tools/libxl/xl.c
@@ -39,6 +39,7 @@ xentoollog_logger_stdiostream *logger;
 int dryrun_only;
 int force_execution;
 int autoballoon = -1;
+int mem_set_enforce_limit = 1;
 char *blkdev_start;
 int run_hotplug_scripts = 1;
 char *lockfile;
@@ -107,6 +108,9 @@ static void parse_global_config(const char *configfile,
     if (autoballoon == -1)
         autoballoon = auto_autoballoon();
 
+    if (!xlu_cfg_get_long (config, "mem_set_enforce_limit", &l, 0))
+        mem_set_enforce_limit = l;
+
     if (!xlu_cfg_get_long (config, "run_hotplug_scripts", &l, 0))
         run_hotplug_scripts = l;
 
diff --git a/tools/libxl/xl.h b/tools/libxl/xl.h
index 771b4af..2281535 100644
--- a/tools/libxl/xl.h
+++ b/tools/libxl/xl.h
@@ -144,6 +144,7 @@ int xl_child_pid(xlchildnum); /* returns 0 if child struct 
is not in use */
 
 /* global options */
 extern int autoballoon;
+extern int mem_set_enforce_limit;
 extern int run_hotplug_scripts;
 extern int dryrun_only;
 extern libxl_defbool claim_mode;
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index c1a969b..76799fc 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -2475,7 +2475,7 @@ int main_memmax(int argc, char **argv)
     return 0;
 }
 
-static void set_memory_target(uint32_t domid, const char *mem)
+static void set_memory_target(uint32_t domid, const char *mem, int 
enforce_limit)
 {
     long long int memorykb;
 
@@ -2485,23 +2485,27 @@ static void set_memory_target(uint32_t domid, const 
char *mem)
         exit(3);
     }
 
-    libxl_set_memory_target(ctx, domid, memorykb, 0, /* enforce */ 1);
+    libxl_set_memory_target(ctx, domid, memorykb, 0, enforce_limit);
 }
 
 int main_memset(int argc, char **argv)
 {
     uint32_t domid;
-    int opt = 0;
+    int enforce_limit, opt = 0;
     const char *mem;
 
-    SWITCH_FOREACH_OPT(opt, "", NULL, "mem-set", 2) {
-        /* No options */
+    enforce_limit = mem_set_enforce_limit;
+
+    SWITCH_FOREACH_OPT(opt, "e:", NULL, "mem-set", 2) {
+    case 'e':
+        enforce_limit = atoi(optarg) ? 1 : 0;
+        break;
     }
 
     domid = find_domain(argv[optind]);
     mem = argv[optind + 1];
 
-    set_memory_target(domid, mem);
+    set_memory_target(domid, mem, enforce_limit);
     return 0;
 }
 
diff --git a/tools/libxl/xl_cmdtable.c b/tools/libxl/xl_cmdtable.c
index 347302c..8918a57 100644
--- a/tools/libxl/xl_cmdtable.c
+++ b/tools/libxl/xl_cmdtable.c
@@ -196,7 +196,8 @@ struct cmd_spec cmd_table[] = {
     { "mem-set",
       &main_memset, 0, 1,
       "Set the current memory usage for a domain",
-      "<Domain> <MemMB['b'[bytes]|'k'[KB]|'m'[MB]|'g'[GB]|'t'[TB]]>",
+      "[-e <0|1>] <Domain> 
<MemMB['b'[bytes]|'k'[KB]|'m'[MB]|'g'[GB]|'t'[TB]]>",
+      "-e <0|1> (Not)Enforce maximum memory allocation for a domain"
     },
     { "button-press",
       &main_button_press, 0, 1,
-- 
1.7.10.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

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