Skip to contentSkip to conversation

libxl_set_memory_target: retain the same maxmem offset on top of the current target

PATCH Superseded Stefano Stabellini 2 participants 5 messages Feb 25, 2015 – Feb 27, 2015

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 libxl_set_memory_target: retain the same maxmem offset on top of the current target

In libxl_set_memory_target when setting the new maxmem, retain the same offset on top of the current target. In the future the offset will include memory allocated by QEMU for rom files.

---

Changes in v4:
- remove new_target_memkb <= 0 check.

Changes in v3:
- move call to libxl__uuid2string and libxl_dominfo_dispose earlier;
- error out if new_target_memkb <= 0.

Changes in v2:
- remove LIBXL_MAXMEM_CONSTANT from LIBXL__LOG_ERRNO.

---
 tools/libxl/libxl.c |   12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
tools/libxl/libxl.c +7 -5
index 52a783a..143cb3e 100644
@@ -4681,6 +4681,12 @@ int libxl_set_memory_target(libxl_ctx *ctx, uint32_t domid,
     char *uuid;
     xs_transaction_t t;
 
+    if (libxl_domain_info(ctx, &ptr, domid) < 0)
+        goto out_no_transaction;
+
+    uuid = libxl__uuid2string(gc, ptr.uuid);
+    libxl_dominfo_dispose(&ptr);
+
 retry_transaction:
     t = xs_transaction_start(ctx->xsh);
 
@@ -4756,7 +4762,7 @@ retry_transaction:
     }
 
     if (enforce) {
-        memorykb = new_target_memkb + videoram;
+        memorykb = ptr.max_memkb - current_target_memkb + new_target_memkb;
         rc = xc_domain_setmaxmem(ctx->xch, domid, memorykb);
         if (rc != 0) {
             LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,
@@ -4786,12 +4792,8 @@ retry_transaction:
         goto out;
     }
 
-    libxl_dominfo_init(&ptr);
-    xcinfo2xlinfo(ctx, &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);
-    libxl_dominfo_dispose(&ptr);
 
 out:
     if (!xs_transaction_end(ctx->xsh, t, abort_transaction)
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 26 lines · Stefano Stabellini

In libxl_set_memory_target when setting the new maxmem, retain the same offset on top of the current target. In the future the offset will include memory allocated by QEMU for rom files.

---

Changes in v4:
- remove new_target_memkb <= 0 check.

Changes in v3:
- move call to libxl__uuid2string and libxl_dominfo_dispose earlier;
- error out if new_target_memkb <= 0.

Changes in v2:
- remove LIBXL_MAXMEM_CONSTANT from LIBXL__LOG_ERRNO.

---
 tools/libxl/libxl.c |   12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
tools/libxl/libxl.c +0 -0
index 52a783a..143cb3e 100644

tools/libxl/libxl.c int libxl_set_memory_target(libxl_ctx *ctx, uint32_t domid, · line 4683

Quoted 3 lines
tools/libxl/libxl.c +0 -0
@@ -4681,6 +4681,12 @@ int libxl_set_memory_target(libxl_ctx *ctx, uint32_t domid,
     char *uuid;
     xs_transaction_t t;
 

Should have:

        libxl_dominfo_init(&ptr);

tools/libxl/libxl.c int libxl_set_memory_target(libxl_ctx *ctx, uint32_t domid, · line 4689

Quoted 6 lines
tools/libxl/libxl.c +6 -0
+    if (libxl_domain_info(ctx, &ptr, domid) < 0)
+        goto out_no_transaction;
+
+    uuid = libxl__uuid2string(gc, ptr.uuid);
+    libxl_dominfo_dispose(&ptr);
+

Since you need to use ptr later, you cannot dispose it here.

You can safely call dispose before returning to caller.

Quoted 13 lines
tools/libxl/libxl.c +1 -1
 retry_transaction:
     t = xs_transaction_start(ctx->xsh);
 
@@ -4756,7 +4762,7 @@ retry_transaction:
     }
 
     if (enforce) {
-        memorykb = new_target_memkb + videoram;
+        memorykb = ptr.max_memkb - current_target_memkb + new_target_memkb;
         rc = xc_domain_setmaxmem(ctx->xch, domid, memorykb);
         if (rc != 0) {
             LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,

tools/libxl/libxl.c retry_transaction: · line 4790

Quoted 5 lines
tools/libxl/libxl.c +0 -2
@@ -4786,12 +4792,8 @@ retry_transaction:
         goto out;
     }
 
-    libxl_dominfo_init(&ptr);
-    xcinfo2xlinfo(ctx, &info, &ptr);

If I'm not mistaken, &info is only used here. I think you can delete info and relevant code all together.

Wei.

Quoted 9 lines
tools/libxl/libxl.c +0 -2
-    uuid = libxl__uuid2string(gc, ptr.uuid);
     libxl__xs_write(gc, t, libxl__sprintf(gc, "/vm/%s/memory", uuid),
             "%"PRIu32, new_target_memkb / 1024);
-    libxl_dominfo_dispose(&ptr);
 
 out:
     if (!xs_transaction_end(ctx->xsh, t, abort_transaction)
Signature · 1 line
1.7.10.4
#2 lore raw
Quoted 62 lines · Wei Liu
Quoted 26 lines · Stefano Stabellini

In libxl_set_memory_target when setting the new maxmem, retain the same offset on top of the current target. In the future the offset will include memory allocated by QEMU for rom files.

---

Changes in v4:
- remove new_target_memkb <= 0 check.

Changes in v3:
- move call to libxl__uuid2string and libxl_dominfo_dispose earlier;
- error out if new_target_memkb <= 0.

Changes in v2:
- remove LIBXL_MAXMEM_CONSTANT from LIBXL__LOG_ERRNO.

---
 tools/libxl/libxl.c |   12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
tools/libxl/libxl.c +0 -0
index 52a783a..143cb3e 100644

tools/libxl/libxl.c int libxl_set_memory_target(libxl_ctx *ctx, uint32_t domid, · line 4683

Quoted 3 lines
tools/libxl/libxl.c +0 -0
@@ -4681,6 +4681,12 @@ int libxl_set_memory_target(libxl_ctx *ctx, uint32_t domid,
     char *uuid;
     xs_transaction_t t;
 

Should have:

        libxl_dominfo_init(&ptr);

tools/libxl/libxl.c int libxl_set_memory_target(libxl_ctx *ctx, uint32_t domid, · line 4689

Quoted 6 lines
tools/libxl/libxl.c +6 -0
+    if (libxl_domain_info(ctx, &ptr, domid) < 0)
+        goto out_no_transaction;
+
+    uuid = libxl__uuid2string(gc, ptr.uuid);
+    libxl_dominfo_dispose(&ptr);
+

Since you need to use ptr later, you cannot dispose it here.

You can safely call dispose before returning to caller.

Quoted 16 lines
tools/libxl/libxl.c +1 -1
 retry_transaction:
     t = xs_transaction_start(ctx->xsh);
 
@@ -4756,7 +4762,7 @@ retry_transaction:
     }
 
     if (enforce) {
-        memorykb = new_target_memkb + videoram;
+        memorykb = ptr.max_memkb - current_target_memkb + new_target_memkb;
         rc = xc_domain_setmaxmem(ctx->xch, domid, memorykb);
         if (rc != 0) {
             LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR,
@@ -4786,12 +4792,8 @@ retry_transaction:
         goto out;
     }
 
Quoted 5 lines

tools/libxl/libxl.c retry_transaction: · line 4790

Quoted 2 lines
tools/libxl/libxl.c +0 -2
-    libxl_dominfo_init(&ptr);
-    xcinfo2xlinfo(ctx, &info, &ptr);

If I'm not mistaken, &info is only used here. I think you can delete info and relevant code all together.

info is used later as an argument to xc_domain_getinfolist

Quoted 11 lines
Quoted 10 lines
tools/libxl/libxl.c +0 -2
-    uuid = libxl__uuid2string(gc, ptr.uuid);
     libxl__xs_write(gc, t, libxl__sprintf(gc, "/vm/%s/memory", uuid),
             "%"PRIu32, new_target_memkb / 1024);
-    libxl_dominfo_dispose(&ptr);
 
 out:
     if (!xs_transaction_end(ctx->xsh, t, abort_transaction)
Signature · 1 line
1.7.10.4
#3 lore raw

On Thu, Feb 26, 2015 at 06:53:29PM +0000, Stefano Stabellini wrote:
[...]

Quoted 11 lines
Quoted 7 lines

tools/libxl/libxl.c retry_transaction: · line 4790

Quoted 4 lines
     }
tools/libxl/libxl.c +0 -2
-    libxl_dominfo_init(&ptr);
-    xcinfo2xlinfo(ctx, &info, &ptr);

If I'm not mistaken, &info is only used here. I think you can delete info and relevant code all together.

info is used later as an argument to xc_domain_getinfolist

What I meant was, the sole purpose of info and two function calls xc_domain_getinfolist + xcinfo2xlinfo is to fill in ptr, which is done by a single call to libxl_domain_info at the beginning of your patch, so it's possible to remove info and those two function calls all together.

Wei.

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
tools/libxl/libxl.c +0 -2
-    uuid = libxl__uuid2string(gc, ptr.uuid);
     libxl__xs_write(gc, t, libxl__sprintf(gc, "/vm/%s/memory", uuid),
             "%"PRIu32, new_target_memkb / 1024);
-    libxl_dominfo_dispose(&ptr);
 
 out:
     if (!xs_transaction_end(ctx->xsh, t, abort_transaction)
Signature · 1 line
1.7.10.4
#4 lore raw
Quoted 14 lines · Wei Liu

On Thu, Feb 26, 2015 at 06:53:29PM +0000, Stefano Stabellini wrote:
[...]

Quoted 11 lines
Quoted 7 lines

tools/libxl/libxl.c retry_transaction: · line 4790

Quoted 4 lines
     }
tools/libxl/libxl.c +0 -2
-    libxl_dominfo_init(&ptr);
-    xcinfo2xlinfo(ctx, &info, &ptr);

If I'm not mistaken, &info is only used here. I think you can delete info and relevant code all together.

info is used later as an argument to xc_domain_getinfolist

Quoted 5 lines

What I meant was, the sole purpose of info and two function calls xc_domain_getinfolist + xcinfo2xlinfo is to fill in ptr, which is done by a single call to libxl_domain_info at the beginning of your patch, so it's possible to remove info and those two function calls all together.

You are right! I'll resend.