Skip to contentSkip to conversation

Bulk mem-share identical domains

PATCH Superseded Tamas K Lengyel 4 participants 16 messages Oct 4, 2015 – Oct 9, 2015

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover Bulk mem-share identical domains

The following patches add a convenience memop to the mem_sharing system, allowing for the rapid deduplication of memory pages between identical domains.

The envisioned use-case for this is the following:
1) Create two domains from the same snapshot using xl.
This step can also be performed by piping an existing domain's memory with
"xl save -c <domain> <pipe> | xl restore -p <new_cfg> <pipe>"
It is up for the user to create the appropriate configuration for the clone, including setting up a CoW-disk as well.
2) Enable memory sharing on both domains
3) Execute bulk dedup between the domains.

Performing memory deduplication this way reduces the number of hypercalls that need to be performed, thus significantly speeding up the operation.

The subsystem is currently orphaned and without a maintainer. AFAIK I'm the only active user of this subsystem.

These patches are also available via git at
https://github.com/tklengyel/xen/tree/memshr_bulk

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Cc George Dunlap <[email protected]>
Cc Keir Fraser <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>

Tamas K Lengyel (2):
x86/mem-sharing: Bulk mem-sharing entire domains tests/mem-sharing: Add bulk option to memshrtool

 tools/libxc/include/xenctrl.h        | 11 +++++
 tools/libxc/xc_memshr.c              | 14 ++++++
 tools/tests/mem-sharing/memshrtool.c | 20 ++++++++
 xen/arch/x86/mm/mem_sharing.c        | 90 +++++++++++++++++++++++++++++++++++-
 xen/arch/x86/x86_64/compat/mm.c      |  6 ++-
 xen/arch/x86/x86_64/mm.c             |  6 ++-
 xen/include/asm-x86/mem_sharing.h    |  3 +-
 xen/include/public/memory.h          |  1 +
 8 files changed, 144 insertions(+), 7 deletions(-)
Signature · 1 line
2.1.4
#1 lore raw

PATCH 1/2 x86/mem-sharing: Bulk mem-sharing entire domains

Currently mem-sharing can be performed on a page-by-page base from the control domain. However, when completely deduplicating (cloning) a VM, this requires at least 3 hypercalls per page. As the user has to loop through all pages up to max_gpfn, this process is very slow and wasteful.

This patch introduces a new mem_sharing memop for bulk deduplication where the user doesn't have to separately nominate each page in both the source and destination domain, and the looping over all pages happen in the hypervisor. This significantly reduces the overhead of completely deduplicating entire domains.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Cc George Dunlap <[email protected]>
Cc Keir Fraser <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
---
 tools/libxc/include/xenctrl.h     | 11 +++++
 tools/libxc/xc_memshr.c           | 14 ++++++
 xen/arch/x86/mm/mem_sharing.c     | 90 ++++++++++++++++++++++++++++++++++++++-
 xen/arch/x86/x86_64/compat/mm.c   |  6 ++-
 xen/arch/x86/x86_64/mm.c          |  6 ++-
 xen/include/asm-x86/mem_sharing.h |  3 +-
 xen/include/public/memory.h       |  1 +
 7 files changed, 124 insertions(+), 7 deletions(-)
tools/libxc/include/xenctrl.h +11 -0
index 3bfa00b..dd82549 100644
@@ -2594,6 +2594,17 @@ int xc_memshr_add_to_physmap(xc_interface *xch,
                     domid_t client_domain,
                     unsigned long client_gfn);
 
+/* Allows to deduplicate the entire memory of a client domain in bulk. Using
+ * this function is equivalent of calling xc_memshr_nominate_gfn for each gfn
+ * in the two domains followed by xc_memshr_share_gfns.
+ *
+ * May fail with EINVAL if the source and client domain have different
+ * memory size or if memory sharing is not enabled on either of the domains.
+ */
+int xc_memshr_bulk_dedup(xc_interface *xch,
+                         domid_t source_domain,
+                         domid_t client_domain);
+
 /* Debug calls: return the number of pages referencing the shared frame backing
  * the input argument. Should be one or greater. 
  *
tools/libxc/xc_memshr.c +14 -0
index deb0aa4..ecb0f5c 100644
@@ -181,6 +181,20 @@ int xc_memshr_add_to_physmap(xc_interface *xch,
     return xc_memshr_memop(xch, source_domain, &mso);
 }
 
+int xc_memshr_bulk_dedup(xc_interface *xch,
+                         domid_t source_domain,
+                         domid_t client_domain)
+{
+    xen_mem_sharing_op_t mso;
+
+    memset(&mso, 0, sizeof(mso));
+
+    mso.op = XENMEM_sharing_op_bulk_dedup;
+    mso.u.share.client_domain = client_domain;
+
+    return xc_memshr_memop(xch, source_domain, &mso);
+}
+
 int xc_memshr_domain_resume(xc_interface *xch,
                             domid_t domid)
 {
xen/arch/x86/mm/mem_sharing.c +88 -2

109 lines not on this page · raw message

xen/arch/x86/x86_64/compat/mm.c +4 -2
index d034bd0..15cf16f 100644
@@ -53,8 +53,9 @@ int compat_arch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
     compat_pfn_t mfn;
     unsigned int i;
     int rc = 0;
+    int op = cmd & MEMOP_CMD_MASK;
 
-    switch ( cmd )
+    switch ( op )
     {
     case XENMEM_set_memory_map:
     {
@@ -190,7 +191,8 @@ int compat_arch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         return mem_paging_memop(guest_handle_cast(arg, xen_mem_paging_op_t));
 
     case XENMEM_sharing_op:
-        return mem_sharing_memop(guest_handle_cast(arg, xen_mem_sharing_op_t));
+        return mem_sharing_memop(cmd,
+                                 guest_handle_cast(arg, xen_mem_sharing_op_t));
 
     default:
         rc = -ENOSYS;
xen/arch/x86/x86_64/mm.c +4 -2
index d918002..14c2d33 100644
@@ -930,8 +930,9 @@ long subarch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
     xen_pfn_t mfn, last_mfn;
     unsigned int i;
     long rc = 0;
+    int op = cmd & MEMOP_CMD_MASK;
 
-    switch ( cmd )
+    switch ( op )
     {
     case XENMEM_machphys_mfn_list:
         if ( copy_from_guest(&xmml, arg, 1) )
@@ -1011,7 +1012,8 @@ long subarch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         return mem_paging_memop(guest_handle_cast(arg, xen_mem_paging_op_t));
 
     case XENMEM_sharing_op:
-        return mem_sharing_memop(guest_handle_cast(arg, xen_mem_sharing_op_t));
+        return mem_sharing_memop(cmd,
+                                 guest_handle_cast(arg, xen_mem_sharing_op_t));
 
     default:
         rc = -ENOSYS;
xen/include/asm-x86/mem_sharing.h +2 -1
index 3840a14..6d344d2 100644
@@ -89,7 +89,8 @@ static inline int mem_sharing_unshare_page(struct domain *d,
  */
 int mem_sharing_notify_enomem(struct domain *d, unsigned long gfn,
                                 bool_t allow_sleep);
-int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg);
+long mem_sharing_memop(unsigned long cmd,
+                       XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg);
 int mem_sharing_domctl(struct domain *d, 
                        xen_domctl_mem_sharing_op_t *mec);
 int mem_sharing_audit(void);
xen/include/public/memory.h +1 -0
index 320de91..4bc9fc9 100644
@@ -447,6 +447,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_mem_access_op_t);
 #define XENMEM_sharing_op_debug_gref        5
 #define XENMEM_sharing_op_add_physmap       6
 #define XENMEM_sharing_op_audit             7
+#define XENMEM_sharing_op_bulk_dedup        8
 
 #define XENMEM_SHARING_OP_S_HANDLE_INVALID  (-10)
 #define XENMEM_SHARING_OP_C_HANDLE_INVALID  (-9)
Signature · 1 line
2.1.4
#2 lore raw

Re: [PATCH 1/2] x86/mem-sharing: Bulk mem-sharing entire domains

Quoted 4 lines · Tamas K Lengyel

Currently mem-sharing can be performed on a page-by-page base from the control domain. However, when completely deduplicating (cloning) a VM, this requires at least 3 hypercalls per page. As the user has to loop through all pages up to max_gpfn, this process is very slow and wasteful.

Indeed.

Quoted 6 lines

This patch introduces a new mem_sharing memop for bulk deduplication where the user doesn't have to separately nominate each page in both the source and destination domain, and the looping over all pages happen in the hypervisor. This significantly reduces the overhead of completely deduplicating entire domains.

Looks good in principle.

Quoted 36 lines
xen/arch/x86/mm/mem_sharing.c +32 -0
@@ -1467,6 +1503,56 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg)
         }
         break;
 
+        case XENMEM_sharing_op_bulk_dedup:
+        {
+            unsigned long max_sgfn, max_cgfn;
+            struct domain *cd;
+
+            rc = -EINVAL;
+            if ( !mem_sharing_enabled(d) )
+                goto out;
+
+            rc = rcu_lock_live_remote_domain_by_id(mso.u.share.client_domain,
+                                                   &cd);
+            if ( rc )
+                goto out;
+
+            rc = xsm_mem_sharing_op(XSM_DM_PRIV, d, cd, mso.op);
+            if ( rc )
+            {
+                rcu_unlock_domain(cd);
+                goto out;
+            }
+
+            if ( !mem_sharing_enabled(cd) )
+            {
+                rcu_unlock_domain(cd);
+                rc = -EINVAL;
+                goto out;
+            }
+
+            max_sgfn = domain_get_maximum_gpfn(d);
+            max_cgfn = domain_get_maximum_gpfn(cd);
+
+            if ( max_sgfn != max_cgfn || max_sgfn < start_iter )

xen/arch/x86/mm/mem_sharing.c int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg) · line 1547

Quoted 10 lines
xen/arch/x86/mm/mem_sharing.c +10 -0
+            {
+                rcu_unlock_domain(cd);
+                rc = -EINVAL;
+                goto out;
+            }
+
+            rc = bulk_share(d, cd, max_sgfn, start_iter, MEMOP_CMD_MASK);
+            if ( rc > 0 )
+            {
+                ASSERT(!(rc & MEMOP_CMD_MASK));

The way other continuations like this work is to shift the remaining work left by MEMOP_EXTENT_SHIFT.

This avoids bulk_share() needing to know MEMOP_CMD_MASK, but does chop 6 bits off the available max_sgfn.

However, a better alternative would be to extend xen_mem_sharing_op and stash the continue information in a new union. That would avoid the mask games, and also avoid limiting the maximum potential gfn.

~Andrew

#3 lore raw

Re: [PATCH 1/2] x86/mem-sharing: Bulk mem-sharing entire domains

Quoted 54 lines

Review int

Quoted 2 lines
(quoted diff) +0 -0
@@ -1467,6 +1503,56 @@ int

mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg)

xen/arch/x86/mm/mem_sharing.c int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg)

Quoted 13 lines
xen/arch/x86/mm/mem_sharing.c +10 -0
         }
         break;
 
+        case XENMEM_sharing_op_bulk_dedup:
+        {
+            unsigned long max_sgfn, max_cgfn;
+            struct domain *cd;
+
+            rc = -EINVAL;
+            if ( !mem_sharing_enabled(d) )
+                goto out;
+
+            rc =

rcu_lock_live_remote_domain_by_id(mso.u.share.client_domain,

Quoted 19 lines
xen/arch/x86/mm/mem_sharing.c +19 -0
+                                                   &cd);
+            if ( rc )
+                goto out;
+
+            rc = xsm_mem_sharing_op(XSM_DM_PRIV, d, cd, mso.op);
+            if ( rc )
+            {
+                rcu_unlock_domain(cd);
+                goto out;
+            }
+
+            if ( !mem_sharing_enabled(cd) )
+            {
+                rcu_unlock_domain(cd);
+                rc = -EINVAL;
+                goto out;
+            }
+
+            max_sgfn = domain_get_maximum_gpfn(d);

xen/arch/x86/mm/mem_sharing.c int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg)

Quoted 10 lines
xen/arch/x86/mm/mem_sharing.c +10 -0
+            max_cgfn = domain_get_maximum_gpfn(cd);
+
+            if ( max_sgfn != max_cgfn || max_sgfn < start_iter )
+            {
+                rcu_unlock_domain(cd);
+                rc = -EINVAL;
+                goto out;
+            }
+
+            rc = bulk_share(d, cd, max_sgfn, start_iter,

MEMOP_CMD_MASK);

xen/arch/x86/mm/mem_sharing.c int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg) · line 1547

Quoted 3 lines
xen/arch/x86/mm/mem_sharing.c +3 -0
+            if ( rc > 0 )
+            {
+                ASSERT(!(rc & MEMOP_CMD_MASK));

The way other continuations like this work is to shift the remaining work left by MEMOP_EXTENT_SHIFT.

Quoted 8 lines

This avoids bulk_share() needing to know MEMOP_CMD_MASK, but does chop 6 bits off the available max_sgfn.

However, a better alternative would be to extend xen_mem_sharing_op and stash the continue information in a new union. That would avoid the mask games, and also avoid limiting the maximum potential gfn.

~Andrew

I agree, I was thinking of extending it anyway to return the number of pages that was shared, so this could be looped in there too.

Thanks,
Tamas

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Acked-by on v1 1/2
#4 lore raw

Re: [PATCH 1/2] x86/mem-sharing: Bulk mem-sharing entire domains

In reply to Tamas K Lengyel
Quoted 64 lines · Tamas K Lengyel

Currently mem-sharing can be performed on a page-by-page base from the control domain. However, when completely deduplicating (cloning) a VM, this requires at least 3 hypercalls per page. As the user has to loop through all pages up to max_gpfn, this process is very slow and wasteful.

This patch introduces a new mem_sharing memop for bulk deduplication where the user doesn't have to separately nominate each page in both the source and destination domain, and the looping over all pages happen in the hypervisor. This significantly reduces the overhead of completely deduplicating entire domains.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Cc George Dunlap <[email protected]>
Cc Keir Fraser <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
---
 tools/libxc/include/xenctrl.h     | 11 +++++
 tools/libxc/xc_memshr.c           | 14 ++++++
 xen/arch/x86/mm/mem_sharing.c     | 90 ++++++++++++++++++++++++++++++++++++++-
 xen/arch/x86/x86_64/compat/mm.c   |  6 ++-
 xen/arch/x86/x86_64/mm.c          |  6 ++-
 xen/include/asm-x86/mem_sharing.h |  3 +-
 xen/include/public/memory.h       |  1 +
 7 files changed, 124 insertions(+), 7 deletions(-)
tools/libxc/include/xenctrl.h +11 -0
index 3bfa00b..dd82549 100644
@@ -2594,6 +2594,17 @@ int xc_memshr_add_to_physmap(xc_interface *xch,
                     domid_t client_domain,
                     unsigned long client_gfn);
 
+/* Allows to deduplicate the entire memory of a client domain in bulk. Using
+ * this function is equivalent of calling xc_memshr_nominate_gfn for each gfn
+ * in the two domains followed by xc_memshr_share_gfns.
+ *
+ * May fail with EINVAL if the source and client domain have different
+ * memory size or if memory sharing is not enabled on either of the domains.
+ */
+int xc_memshr_bulk_dedup(xc_interface *xch,
+                         domid_t source_domain,
+                         domid_t client_domain);
+
 /* Debug calls: return the number of pages referencing the shared frame backing
  * the input argument. Should be one or greater. 
  *
tools/libxc/xc_memshr.c +4 -0
index deb0aa4..ecb0f5c 100644
@@ -181,6 +181,20 @@ int xc_memshr_add_to_physmap(xc_interface *xch,
     return xc_memshr_memop(xch, source_domain, &mso);
 }
 
+int xc_memshr_bulk_dedup(xc_interface *xch,
+                         domid_t source_domain,
+                         domid_t client_domain)
+{

tools/libxc/xc_memshr.c int xc_memshr_add_to_physmap(xc_interface *xch, · line 197

Quoted 10 lines
tools/libxc/xc_memshr.c +10 -0
+    xen_mem_sharing_op_t mso;
+
+    memset(&mso, 0, sizeof(mso));
+
+    mso.op = XENMEM_sharing_op_bulk_dedup;
+    mso.u.share.client_domain = client_domain;
+
+    return xc_memshr_memop(xch, source_domain, &mso);
+}
+

Tools bits:

#5 lore raw

PATCH 2/2 tests/mem-sharing: Add bulk option to memshrtool

In reply to Tamas K Lengyel

Add the bulk option to the test tool to perform complete deduplication between domains.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
---
 tools/tests/mem-sharing/memshrtool.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
tools/tests/mem-sharing/memshrtool.c +20 -0
index 6454bc3..18dc970 100644
@@ -23,6 +23,8 @@ static int usage(const char* prog)
     printf("  nominate <domid> <gfn>  - Nominate a page for sharing.\n");
     printf("  share <domid> <gfn> <handle> <source> <source-gfn> <source-handle>\n");
     printf("                          - Share two pages.\n");
+    printf("  bulk <source-domid> <destination-domid>\n");
+    printf("                          - Share all pages between domains.\n");
     printf("  unshare <domid> <gfn>   - Unshare a page by grabbing a writable map.\n");
     printf("  add-to-physmap <domid> <gfn> <source> <source-gfn> <source-handle>\n");
     printf("                          - Populate a page in a domain with a shared page.\n");
@@ -179,6 +181,24 @@ int main(int argc, const char** argv)
         }
         printf("Audit returned %d errors.\n", rc);
     }
+    else if( !strcasecmp(cmd, "bulk") )
+    {
+        domid_t sdomid, cdomid;
+        int rc;
+
+        if( argc != 4 )
+            return usage(argv[0]);
+
+        sdomid = strtol(argv[2], NULL, 0);
+        cdomid = strtol(argv[3], NULL, 0);
 
+        rc = xc_memshr_bulk_dedup(xch, sdomid, cdomid);
+        if ( rc < 0 )
+        {
+            printf("error executing xc_memshr_bulk_dedup: %s\n", strerror(errno));
+            return rc;
+        }
+        printf("Successfully cloned the domains\n");
+    }
     return 0;
 }
Signature · 1 line
2.1.4
Acked-by on v1 2/2
#6 lore raw

Re: [PATCH 2/2] tests/mem-sharing: Add bulk option to memshrtool

Quoted 8 lines · Tamas K Lengyel

Add the bulk option to the test tool to perform complete deduplication between domains.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Quoted 4 lines
---
 tools/tests/mem-sharing/memshrtool.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

An unrelated note: do you think it make sense to move mem-sharing out of tests/ ? It doesn't look like a test to me.

#7 lore raw

Re: [PATCH 2/2] tests/mem-sharing: Add bulk option to memshrtool

Quoted 2 lines · Wei Liu

An unrelated note: do you think it make sense to move mem-sharing out of tests/ ? It doesn't look like a test to me.

It was originally a sort of "unit test" / "manually poke it" type utility rather than end user usable functionality. That might have changed though (or be in the process of doing so).

Ian.

#8 lore raw

Re: [PATCH 2/2] tests/mem-sharing: Add bulk option to memshrtool

Quoted 10 lines · Ian Campbell
Quoted 2 lines · Wei Liu

An unrelated note: do you think it make sense to move mem-sharing out of tests/ ? It doesn't look like a test to me.

It was originally a sort of "unit test" / "manually poke it" type utility rather than end user usable functionality. That might have changed though (or be in the process of doing so).

Ian

I'm not intending to make it into a end-user tool either though it could be now actually have some value for end-users doing cloning. For me it's just a reference implementation.

Tamas

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#9 lore raw
In reply to Tamas K Lengyel
Quoted 4 lines · Tamas K Lengyel

The following patches add a convenience memop to the mem_sharing system, allowing for the rapid deduplication of memory pages between identical domains.

Quoted 10 lines

The envisioned use-case for this is the following:
1) Create two domains from the same snapshot using xl.
This step can also be performed by piping an existing domain's memory
with
"xl save -c <domain> <pipe> | xl restore -p <new_cfg> <pipe>"
It is up for the user to create the appropriate configuration for the
clone,
including setting up a CoW-disk as well.
2) Enable memory sharing on both domains
3) Execute bulk dedup between the domains.

This is a neat trick, but has the downside of first shovelling all the data over a pipe and then needing to allocate it transiently before dedupping it again.

Have you looked at the possibility of doing the save+restore in the same process with a cut through for the RAM part which just dups the page into the target domain?

Once upon a time (migr v1) that would certainly have been impossibly hard, but with migr v2 it might be a lot easier to integrate something like that (although surely not as easy as what you've done here!).

Just an idea, and not intended at all as an argument for not taking this series or anything.

Ian.

#10 lore raw
Quoted 23 lines · Ian Campbell
Quoted 4 lines · Tamas K Lengyel

The following patches add a convenience memop to the mem_sharing system, allowing for the rapid deduplication of memory pages between identical domains.

Quoted 10 lines

The envisioned use-case for this is the following:
1) Create two domains from the same snapshot using xl.
This step can also be performed by piping an existing domain's memory
with
"xl save -c <domain> <pipe> | xl restore -p <new_cfg> <pipe>"
It is up for the user to create the appropriate configuration for the
clone,
including setting up a CoW-disk as well.
2) Enable memory sharing on both domains
3) Execute bulk dedup between the domains.

This is a neat trick, but has the downside of first shovelling all the data over a pipe and then needing to allocate it transiently before dedupping it again.

Have you looked at the possibility of doing the save+restore in the same process with a cut through for the RAM part which just dups the page into the target domain?

Quoted 6 lines

Once upon a time (migr v1) that would certainly have been impossibly hard, but with migr v2 it might be a lot easier to integrate something like that (although surely not as easy as what you've done here!).

Just an idea, and not intended at all as an argument for not taking this series or anything.

If we are making modifications like this, make something like XEN_DOMCTL_domain_clone which takes a source domid (must exist), pauses it, creates a new domain, copies some state and shares all memory CoW from source to the new domain.

This will be far more efficient still than moving all the memory through userspace in dom0.

~Andrew

#11 lore raw
Quoted 40 lines · Andrew Cooper
Quoted 15 lines · Ian Campbell
Quoted 4 lines · Tamas K Lengyel

The following patches add a convenience memop to the mem_sharing system, allowing for the rapid deduplication of memory pages between identical domains.

Quoted 10 lines

The envisioned use-case for this is the following:
1) Create two domains from the same snapshot using xl.
This step can also be performed by piping an existing domain's memory
with
"xl save -c <domain> <pipe> | xl restore -p <new_cfg> <pipe>"
It is up for the user to create the appropriate configuration for the
clone,
including setting up a CoW-disk as well.
2) Enable memory sharing on both domains
3) Execute bulk dedup between the domains.

Quoted 1 line

This is a neat trick, but has the downside of first shovelling all the

data

Quoted 1 line

over a pipe and then needing to allocate it transiently before dedupping

it

Quoted 7 lines

again.

Have you looked at the possibility of doing the save+restore in the same process with a cut through for the RAM part which just dups the page into the target domain?

Once upon a time (migr v1) that would certainly have been impossibly

hard,

Quoted 1 line

but with migr v2 it might be a lot easier to integrate something like

that

Quoted 4 lines

(although surely not as easy as what you've done here!).

Just an idea, and not intended at all as an argument for not taking this series or anything.

If we are making modifications like this, make something like XEN_DOMCTL_domain_clone which takes a source domid (must exist), pauses it, creates a new domain, copies some state and shares all memory CoW from source to the new domain.

Quoted 5 lines

This will be far more efficient still than moving all the memory through userspace in dom0.

~Andrew

It would be far more efficient, but unfortunately there is more to cloning then just the hypervisor side. Andres already made and suggested using xc_memshr_add_to_physmap, which could be used during domain creation to do something similar. However, 1) there is no reference implementation on how to do that domain creation cleanly 2) cloning HVM domains also requires cloning QEMU. As the only reference implementation on how to create an HVM domain from scratch is in libxl right now, it's a pretty huge task to untangle it to make something like this happen (at least for me). I've been staring at this from time-to-time for the past couple years and I'm still no closer to a working solution. In the interim, this patch at least improves something that I know that works and requires minimal changes to the tools/hypervisor.

Tamas

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#12 lore raw
In reply to Ian Campbell
Quoted 16 lines · Ian Campbell
Quoted 4 lines · Tamas K Lengyel

The following patches add a convenience memop to the mem_sharing system, allowing for the rapid deduplication of memory pages between identical domains.

Quoted 10 lines

The envisioned use-case for this is the following:
1) Create two domains from the same snapshot using xl.
This step can also be performed by piping an existing domain's memory
with
"xl save -c <domain> <pipe> | xl restore -p <new_cfg> <pipe>"
It is up for the user to create the appropriate configuration for the
clone,
including setting up a CoW-disk as well.
2) Enable memory sharing on both domains
3) Execute bulk dedup between the domains.

Quoted 4 lines

This is a neat trick, but has the downside of first shovelling all the data over a pipe and then needing to allocate it transiently before dedupping it again.

Precisely.

Quoted 5 lines

Have you looked at the possibility of doing the save+restore in the same process with a cut through for the RAM part which just dups the page into the target domain?

I have, but I have to stay untangling the internals of xl is pretty daunting..

Quoted 8 lines

Once upon a time (migr v1) that would certainly have been impossibly hard, but with migr v2 it might be a lot easier to integrate something like that (although surely not as easy as what you've done here!).

Just an idea, and not intended at all as an argument for not taking this series or anything.

So another trick that works pretty well for PV domains is to simply create them paused:
xl create -p <cfg>

This takes pretty much no time and can be followed up by the bulk memory deduplication. The clone is fully functional afterwards. Unfortunately for HVM domains this is not sufficient as QEMU needs to be setup as well, for which right now only xl restore works. I experimented with saving the QEMU state separately, creating the paused HVM domain, killing it's qemu process, then starting a new one with the exact same parameters but with the extra -loadvm flag (reserving an extra page plus trying to wire up the hvmparams). Unfortunately this still crashes the guest after unpause so I'm pretty much stuck on that side. So yea, any help with that would be greatly appreciated ;) If there was an xl option to do what "xl restore" is doing, but to only load the QEMU state, that would be awesome.

Tamas

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#13 lore raw
Quoted 50 lines · Tamas K Lengyel
Quoted 16 lines · Ian Campbell
Quoted 4 lines · Tamas K Lengyel

The following patches add a convenience memop to the mem_sharing system, allowing for the rapid deduplication of memory pages between identical domains.

Quoted 10 lines

The envisioned use-case for this is the following:
1) Create two domains from the same snapshot using xl.
This step can also be performed by piping an existing domain's memory
with
"xl save -c <domain> <pipe> | xl restore -p <new_cfg> <pipe>"
It is up for the user to create the appropriate configuration for the
clone,
including setting up a CoW-disk as well.
2) Enable memory sharing on both domains
3) Execute bulk dedup between the domains.

Quoted 4 lines

This is a neat trick, but has the downside of first shovelling all the data over a pipe and then needing to allocate it transiently before dedupping it again.

Precisely.

Quoted 5 lines

Have you looked at the possibility of doing the save+restore in the same process with a cut through for the RAM part which just dups the page into the target domain?

I have, but I have to stay untangling the internals of xl is pretty daunting..

Quoted 8 lines

Once upon a time (migr v1) that would certainly have been impossibly hard, but with migr v2 it might be a lot easier to integrate something like that (although surely not as easy as what you've done here!).

Just an idea, and not intended at all as an argument for not taking this series or anything.

So another trick that works pretty well for PV domains is to simply create them paused:
xl create -p <cfg>

Quoted 13 lines

This takes pretty much no time and can be followed up by the bulk memory deduplication. The clone is fully functional afterwards. Unfortunately for HVM domains this is not sufficient as QEMU needs to be setup as well, for which right now only xl restore works. I experimented with saving the QEMU state separately, creating the paused HVM domain, killing it's qemu process, then starting a new one with the exact same parameters but with the extra -loadvm flag (reserving an extra page plus trying to wire up the hvmparams). Unfortunately this still crashes the guest after unpause so I'm pretty much stuck on that side. So yea, any help with that would be greatly appreciated ;) If there was an xl option to do what "xl restore" is doing, but to only load the QEMU state, that would be awesome.

In case you miss it, there is now soft-reset support which dumps all memory plus various states from one domain to another, and toolstack will take care of QEMU and various userspace bits. This might be useful to you?

To be clear, this is just FYI, not suggesting we block this series.

Wei.

Quoted 1 line

Tamas

#14 lore raw

In case you miss it, there is now soft-reset support which dumps all

Quoted 8 lines

memory plus various states from one domain to another, and toolstack will take care of QEMU and various userspace bits. This might be useful to you?

To be clear, this is just FYI, not suggesting we block this series.

Wei.

Hi Wei,
it might be very useful but on a casual scan I couldn't really find much on the soft-reset option (no xl cmdline option and only a single call to xc_domain_soft_reset in libxl.c). For cloning I would need the origin domain to remain loaded as before (at least the memory, qemu can be killed) and then I would only need the QEMU setup bits from soft-reset. Any pointers on how to go about this would be very helpful ;)

Thanks,
Tamas

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#15 lore raw
Quoted 10 lines · Tamas K Lengyel

In case you miss it, there is now soft-reset support which dumps all

Quoted 8 lines

memory plus various states from one domain to another, and toolstack will take care of QEMU and various userspace bits. This might be useful to you?

To be clear, this is just FYI, not suggesting we block this series.

Wei.

Quoted 8 lines

Hi Wei,
it might be very useful but on a casual scan I couldn't really find much on the soft-reset option (no xl cmdline option and only a single call to xc_domain_soft_reset in libxl.c). For cloning I would need the origin domain to remain loaded as before (at least the memory, qemu can be killed) and then I would only need the QEMU setup bits from soft-reset. Any pointers on how to go about this would be very helpful ;)

Soft-reset is in fact a slightly modified version of save / restore. I don't think you can directly use soft-reset to clone a domain. What I meant was you might be able to reuse some of the code in soft-reset, at least on toolstack side.

For example, you can invent a hypercall to share all pages and transfer states from a guest to another. In toolstack, you create a new domain, save original domain's QEMU state, issue aforementioned hypercall (*), and restore QEMU. It would still require some coding to disentangle toolstack code to do what you need, but these different phases already exist in toolstack code for soft-reset except for the hypercall.

What makes your need different from soft-reset is that, a) the hypercall is different b) you don't destroy the original domain afterwards.

YMMV.

Wei.

Quoted 2 lines

Thanks,
Tamas