Skip to contentSkip to conversation

Introduce migration precopy policy

PATCH In review Jennifer Herbert 3 participants 11 messages Sep 25, 2017 – Sep 26, 2017

lore
Share & tools
lore
#0 lore raw

v3 cover Introduce migration precopy policy

Hi all,

v3:

In patch 2/3, have changed/added comments, removed iteration parmeter from update_progress_string and made a few formatting corrections.

v2:

Have tidied some formatting, s.o.b Joshua, and added a RFC patch showing how to use this in libxl.

v1:

Here I present a updated/modified subset of patch 7/20, part of Joshua Otto's "Add postcopy live migration support." patch, dated 27th March 2017. As indicated on the original thread, I wish to make use of this this within the XenServer product, and hence am trying to get this subset pulled in now. I also hope this will aid Josh in pushing the remainder of his series.

Here I present two patches, the first which does some tidy up, removing unused and unhelpful paramaters to xc_domain_save(), and the second which allows a precopy callback to be specified, providing the test for when to end the live phase of migration should end. If none is provided, a default policy of the current behaviour is used.

Jennifer Herbert (3):
Tidy libxc xc_domain_save
Introduce migration precopy policy
RFC: migration: defer precopy policy to libxl

 tools/libxc/include/xenguest.h     |  41 ++++++++++++--
 tools/libxc/xc_nomigrate.c         |   3 +-
 tools/libxc/xc_sr_common.h         |   6 +-
 tools/libxc/xc_sr_save.c           | 113 +++++++++++++++++++++++++------------
 tools/libxl/libxl_dom_save.c       |  20 +++++++
 tools/libxl/libxl_save_callout.c   |   4 +-
 tools/libxl/libxl_save_helper.c    |   7 +--
 tools/libxl/libxl_save_msgs_gen.pl |   4 +-
 8 files changed, 142 insertions(+), 56 deletions(-)
Signature · 7 lines
1.8.3.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw

PATCH v3 1/3 Tidy libxc xc_domain_save

Tidy up libxc's xc_domain_save, removing unused paramaters max_iters and max_factor, making matching changes to libxl.

---
 tools/libxc/include/xenguest.h   | 4 ++--
 tools/libxc/xc_nomigrate.c       | 3 +--
 tools/libxc/xc_sr_save.c         | 8 +++-----
 tools/libxl/libxl_save_callout.c | 4 ++--
 tools/libxl/libxl_save_helper.c  | 7 ++-----
 5 files changed, 10 insertions(+), 16 deletions(-)
tools/libxc/include/xenguest.h +2 -2
index 5cd8111..6626f0c 100644
@@ -100,8 +100,8 @@ typedef enum {
  *        doesn't use checkpointing
  * @return 0 on success, -1 on failure
  */
-int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iters,
-                   uint32_t max_factor, uint32_t flags /* XCFLAGS_xxx */,
+int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom,
+                   uint32_t flags /* XCFLAGS_xxx */,
                    struct save_callbacks* callbacks, int hvm,
                    xc_migration_stream_t stream_type, int recv_fd);
 
tools/libxc/xc_nomigrate.c +1 -2
index 317c8ce..fe8f68c 100644
@@ -20,8 +20,7 @@
 #include <xenctrl.h>
 #include <xenguest.h>
 
-int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iters,
-                   uint32_t max_factor, uint32_t flags,
+int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t flags,
                    struct save_callbacks* callbacks, int hvm,
                    xc_migration_stream_t stream_type, int recv_fd)
 {
tools/libxc/xc_sr_save.c +3 -5
index ca6913b..1e7502d 100644
@@ -916,9 +916,8 @@ static int save(struct xc_sr_context *ctx, uint16_t guest_type)
 };
 
 int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom,
-                   uint32_t max_iters, uint32_t max_factor, uint32_t flags,
-                   struct save_callbacks* callbacks, int hvm,
-                   xc_migration_stream_t stream_type, int recv_fd)
+                   uint32_t flags, struct save_callbacks* callbacks,
+                   int hvm, xc_migration_stream_t stream_type, int recv_fd)
 {
     struct xc_sr_context ctx =
         {
@@ -955,8 +954,7 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom,
     if ( ctx.save.checkpointed == XC_MIG_STREAM_COLO )
         assert(callbacks->wait_checkpoint);
 
-    DPRINTF("fd %d, dom %u, max_iters %u, max_factor %u, flags %u, hvm %d",
-            io_fd, dom, max_iters, max_factor, flags, hvm);
+    DPRINTF("fd %d, dom %u, flags %u, hvm %d", io_fd, dom, flags, hvm);
 
     if ( xc_domain_getinfo(xch, dom, 1, &ctx.dominfo) != 1 )
     {
tools/libxl/libxl_save_callout.c +2 -2
index 891c669..6452d70 100644
@@ -89,8 +89,8 @@ void libxl__xc_domain_save(libxl__egc *egc, libxl__domain_save_state *dss,
         libxl__srm_callout_enumcallbacks_save(&shs->callbacks.save.a);
 
     const unsigned long argnums[] = {
-        dss->domid, 0, 0, dss->xcflags, dss->hvm,
-        cbflags, dss->checkpointed_stream,
+        dss->domid, dss->xcflags, dss->hvm, cbflags,
+        dss->checkpointed_stream,
     };
 
     shs->ao = ao;
tools/libxl/libxl_save_helper.c +2 -5
index 1dece23..38089a0 100644
@@ -251,8 +251,6 @@ int main(int argc, char **argv)
         io_fd =                             atoi(NEXTARG);
         recv_fd =                           atoi(NEXTARG);
         uint32_t dom =                      strtoul(NEXTARG,0,10);
-        uint32_t max_iters =                strtoul(NEXTARG,0,10);
-        uint32_t max_factor =               strtoul(NEXTARG,0,10);
         uint32_t flags =                    strtoul(NEXTARG,0,10);
         int hvm =                           atoi(NEXTARG);
         unsigned cbflags =                  strtoul(NEXTARG,0,10);
@@ -264,9 +262,8 @@ int main(int argc, char **argv)
         startup("save");
         setup_signals(save_signal_handler);
 
-        r = xc_domain_save(xch, io_fd, dom, max_iters, max_factor, flags,
-                           &helper_save_callbacks, hvm, stream_type,
-                           recv_fd);
+        r = xc_domain_save(xch, io_fd, dom, flags, &helper_save_callbacks,
+                           hvm, stream_type, recv_fd);
         complete(r);
 
     } else if (!strcmp(mode,"--restore-domain")) {
Signature · 7 lines
1.8.3.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#2 lore raw

PATCH v3 2/3 Introduce migration precopy policy

In reply to Jennifer Herbert

This Patch allows a migration precopy policy to be specified.

The precopy phase of the xc_domain_save() live migration algorithm has historically been implemented to run until either a) (almost) no pages are dirty or b) some fixed, hard-coded maximum number of precopy iterations has been exceeded. This policy and its implementation are less than ideal for a few reasons:
- the logic of the policy is intertwined with the control flow of the mechanism of the precopy stage
- it can't take into account facts external to the immediate migration context, such external state transfer state, interactive user input, or the passage of wall-clock time.
- it does not permit the user to change their mind, over time, about what to do at the end of the precopy (they get an unconditional transition into the stop-and-copy phase of the migration)

To permit callers to implement arbitrary higher-level policies governing when the live migration precopy phase should end, and what should be done next:
- add a precopy_policy() callback to the xc_domain_save() user-supplied callbacks
- during the precopy phase of live migrations, consult this policy after each batch of pages transmitted and take the dictated action, which may be to a) abort the migration entirely, b) continue with the precopy, or c) proceed to the stop-and-copy phase.
- provide an implementation of the old policy, used when precopy_policy callback is not provided.

---

v3:

Have changed/added comments, removed iteration parmeter from update_progress_string and made a few formatting corrections.

v2:

Have made a few formatting corrections, added typedef as suggested.

This is updated/modified subset of patch 7/20, part of Joshua Otto's "Add postcopy live migration support." patch, dated 27th March 2017. As indicated on the original thread, I wish to make use of this this within the XenServer product. I hope this will aid Josh in pushing the remainder of his series.

---
 tools/libxc/include/xenguest.h |  37 +++++++++++++--
 tools/libxc/xc_sr_common.h     |   6 +--
 tools/libxc/xc_sr_save.c       | 105 ++++++++++++++++++++++++++++-------------
 3 files changed, 109 insertions(+), 39 deletions(-)
tools/libxc/include/xenguest.h +34 -3
index 6626f0c..de97f1b 100644
@@ -39,6 +39,20 @@
  */
 struct xenevtchn_handle;
 
+/* For save's precopy_policy(). */
+struct precopy_stats
+{
+    unsigned int iteration;
+    unsigned int total_written;
+    long dirty_count; /* -1 if unknown */
+};
+
+/*
+ * A precopy_policy callback may not be running in the same address
+ * space as libxc an so precopy_stats is passed by value.
+ */
+typedef int (*precopy_policy_t)(struct precopy_stats, void *);
+
 /* callbacks provided by xc_domain_save */
 struct save_callbacks {
     /* Called after expiration of checkpoint interval,
@@ -46,7 +60,22 @@ struct save_callbacks {
      */
     int (*suspend)(void* data);
 
-    /* Called after the guest's dirty pages have been
+    /*
+     * Called before and after every batch of page data sent during
+     * the precopy phase of a live migration to ask the caller what
+     * to do next based on the current state of the precopy migration.
+     *
+     * Should return one of the values listed below:
+     */
+#define XGS_POLICY_ABORT          (-1) /* Abandon the migration entirely
+                                        * and tidy up. */
+#define XGS_POLICY_CONTINUE_PRECOPY 0  /* Remain in the precopy phase. */
+#define XGS_POLICY_STOP_AND_COPY    1  /* Immediately suspend and transmit the
+                                        * remaining dirty pages. */
+    precopy_policy_t precopy_policy;
+
+    /*
+     * Called after the guest's dirty pages have been
      *  copied into an output buffer.
      * Callback function resumes the guest & the device model,
      *  returns to xc_domain_save.
@@ -55,7 +84,8 @@ struct save_callbacks {
      */
     int (*postcopy)(void* data);
 
-    /* Called after the memory checkpoint has been flushed
+    /*
+     * Called after the memory checkpoint has been flushed
      * out into the network. Typical actions performed in this
      * callback include:
      *   (a) send the saved device model state (for HVM guests),
@@ -65,7 +95,8 @@ struct save_callbacks {
      *
      * returns:
      * 0: terminate checkpointing gracefully
-     * 1: take another checkpoint */
+     * 1: take another checkpoint
+     */
     int (*checkpoint)(void* data);
 
     /*
tools/libxc/xc_sr_common.h +2 -4
index a83f22a..3635704 100644
@@ -198,12 +198,10 @@ struct xc_sr_context
             /* Further debugging information in the stream. */
             bool debug;
 
-            /* Parameters for tweaking live migration. */
-            unsigned max_iterations;
-            unsigned dirty_threshold;
-
             unsigned long p2m_size;
 
+            struct precopy_stats stats;
+
             xen_pfn_t *batch_pfns;
             unsigned nr_batch_pfns;
             unsigned long *deferred_pages;
tools/libxc/xc_sr_save.c +73 -32

153 lines not on this page · raw message

Signature · 7 lines
1.8.3.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Acked-by on v3 2/3
#3 lore raw
Quoted 28 lines · Jennifer Herbert

This Patch allows a migration precopy policy to be specified.

The precopy phase of the xc_domain_save() live migration algorithm has historically been implemented to run until either a) (almost) no pages are dirty or b) some fixed, hard-coded maximum number of precopy iterations has been exceeded. This policy and its implementation are less than ideal for a few reasons:
- the logic of the policy is intertwined with the control flow of the mechanism of the precopy stage
- it can't take into account facts external to the immediate migration context, such external state transfer state, interactive user input, or the passage of wall-clock time.
- it does not permit the user to change their mind, over time, about what to do at the end of the precopy (they get an unconditional transition into the stop-and-copy phase of the migration)

To permit callers to implement arbitrary higher-level policies governing when the live migration precopy phase should end, and what should be done next:
- add a precopy_policy() callback to the xc_domain_save() user-supplied callbacks
- during the precopy phase of live migrations, consult this policy after each batch of pages transmitted and take the dictated action, which may be to a) abort the migration entirely, b) continue with the precopy, or c) proceed to the stop-and-copy phase.
- provide an implementation of the old policy, used when precopy_policy callback is not provided.

Quoted 3 lines

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

#4 lore raw
In reply to Jennifer Herbert
Quoted 4 lines · Jennifer Herbert

+/*
+ * A precopy_policy callback may not be running in the same address
+ * space as libxc an so precopy_stats is passed by value.
+ */

Please take a step back and thing about what is written here...

As I've said repeatedly, the structure vs pointer argument here is entirely unrelated to the IPC boundary.

I am also unhappy that, after multiple review requests saying "turn this into a pointer", its remained being passed by value.  It is not ok to hack things like this up simply because its the easier cause of action.

~Andrew

tools/libxc/include/xenguest.h line 58

Quoted 6 lines
tools/libxc/include/xenguest.h +2 -0
+typedef int (*precopy_policy_t)(struct precopy_stats, void *);
+
 /* callbacks provided by xc_domain_save */
 struct save_callbacks {
     /* Called after expiration of checkpoint interval,

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

#5 lore raw
Quoted 5 lines · Andrew Cooper
Quoted 4 lines · Jennifer Herbert

+/*
+ * A precopy_policy callback may not be running in the same address
+ * space as libxc an so precopy_stats is passed by value.
+ */

Quoted 8 lines

Please take a step back and thing about what is written here...

As I've said repeatedly, the structure vs pointer argument here is entirely unrelated to the IPC boundary.

I am also unhappy that, after multiple review requests saying "turn this into a pointer", its remained being passed by value. It is not ok to hack things like this up simply because its the easier cause of action.

Passing tiny structures by value is not a hack - it is perfectly valid C. Bare in mind that a pointer is not a zero
sized entity - it itself needs to be copied. Passing by value here is quite possibly faster, and use less memory. Furthermore, the multiple reviews concluded that this was related to IPC boundary, and that the tiny struct size was acceptable.

Maybe you could elaborate on why you do not think it is related to the IPC boundary.

Instead, we could pass each element of the structure, as an individual parameters. This would seem a retrograde step to me, but would address your sensitivities.

-jenny

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

#6 lore raw
In reply to Jennifer Herbert

tools/libxc/include/xenguest.h struct save_callbacks { · line 66

Quoted 9 lines · Jennifer Herbert
tools/libxc/include/xenguest.h +4 -1
@@ -46,7 +60,22 @@ struct save_callbacks {
      */
     int (*suspend)(void* data);
 
-    /* Called after the guest's dirty pages have been
+    /*
+     * Called before and after every batch of page data sent during
+     * the precopy phase of a live migration to ask the caller what
+     * to do next based on the current state of the precopy migration.

How is the callback supposed to determine whether it is before or ahead of the data batch?

As far as I can tell, its not possible.

~Andrew

Quoted 6 lines
tools/libxc/include/xenguest.h +5 -0
+     *
+     * Should return one of the values listed below:
+     */
+#define XGS_POLICY_ABORT          (-1) /* Abandon the migration entirely
+                                        * and tidy up. */

tools/libxc/include/xenguest.h struct save_callbacks { · line 81

Quoted 10 lines
tools/libxc/include/xenguest.h +7 -0
+#define XGS_POLICY_CONTINUE_PRECOPY 0  /* Remain in the precopy phase. */
+#define XGS_POLICY_STOP_AND_COPY    1  /* Immediately suspend and transmit the
+                                        * remaining dirty pages. */
+    precopy_policy_t precopy_policy;
+
+    /*
+     * Called after the guest's dirty pages have been
      *  copied into an output buffer.
      * Callback function resumes the guest & the device model,
      *  returns to xc_domain_save.

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

#7 lore raw
Quoted 13 lines · Andrew Cooper

tools/libxc/include/xenguest.h struct save_callbacks { · line 66

Quoted 9 lines · Jennifer Herbert
tools/libxc/include/xenguest.h +4 -1
@@ -46,7 +60,22 @@ struct save_callbacks {
       */
      int (*suspend)(void* data);
 
-    /* Called after the guest's dirty pages have been
+    /*
+     * Called before and after every batch of page data sent during
+     * the precopy phase of a live migration to ask the caller what
+     * to do next based on the current state of the precopy migration.

How is the callback supposed to determine whether it is before or ahead of the data batch?

Quoted 3 lines

As far as I can tell, its not possible.

~Andrew

You look at the dirty_count. It works well for me. I can add that info to the comment.

-jenny

Quoted 8 lines
Quoted 8 lines
tools/libxc/include/xenguest.h +8 -0
+     *
+     * Should return one of the values listed below:
+     */
+#define XGS_POLICY_ABORT          (-1) /* Abandon the migration entirely
+                                        * and tidy up. */
+#define XGS_POLICY_CONTINUE_PRECOPY 0  /* Remain in the precopy phase. */
+#define XGS_POLICY_STOP_AND_COPY    1  /* Immediately suspend and transmit the
+                                        * remaining dirty pages. */
Quoted 8 lines

tools/libxc/include/xenguest.h struct save_callbacks { · line 81

Quoted 8 lines
tools/libxc/include/xenguest.h +4 -0
+    precopy_policy_t precopy_policy;
+
+    /*
+     * Called after the guest's dirty pages have been
       *  copied into an output buffer.
       * Callback function resumes the guest & the device model,
       *  returns to xc_domain_save.

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

#8 lore raw

PATCH v3 3/3 RFC: migration: defer precopy policy to libxl

In reply to Jennifer Herbert

Provide an implementation of the old policy as a callback in libxl and plumb it through the IPC machinery to libxc.

This serves as an example for defining a libxl policy, and provides no advantage over the default policy in libxc.

---
 tools/libxl/libxl_dom_save.c       | 20 ++++++++++++++++++++
 tools/libxl/libxl_save_msgs_gen.pl |  4 +++-
 2 files changed, 23 insertions(+), 1 deletion(-)
tools/libxl/libxl_dom_save.c +20 -0
index 77fe30e..6d28cce 100644
@@ -328,6 +328,25 @@ int libxl__save_emulator_xenstore_data(libxl__domain_save_state *dss,
     return rc;
 }
 
+/*
+ * This is the live migration precopy policy - it's called periodically during
+ * the precopy phase of live migrations, and is responsible for deciding when
+ * the precopy phase should terminate and what should be done next.
+ *
+ * The policy implemented here behaves identically to the policy previously
+ * hard-coded into xc_domain_save() - it proceeds to the stop-and-copy phase of
+ * the live migration when there are either fewer than 50 dirty pages, or more
+ * than 5 precopy rounds have completed.
+ */
+static int libxl__save_live_migration_simple_precopy_policy(
+    struct precopy_stats stats, void *user)
+{
+    return ((stats.dirty_count >= 0 && stats.dirty_count < 50) ||
+            stats.iteration >= 5)
+        ? XGS_POLICY_STOP_AND_COPY
+        : XGS_POLICY_CONTINUE_PRECOPY;
+}
+
 /*----- main code for saving, in order of execution -----*/
 
 void libxl__domain_save(libxl__egc *egc, libxl__domain_save_state *dss)
@@ -401,6 +420,7 @@ void libxl__domain_save(libxl__egc *egc, libxl__domain_save_state *dss)
     if (dss->checkpointed_stream == LIBXL_CHECKPOINTED_STREAM_NONE)
         callbacks->suspend = libxl__domain_suspend_callback;
 
+    callbacks->precopy_policy = libxl__save_live_migration_simple_precopy_policy;
     callbacks->switch_qemu_logdirty = libxl__domain_suspend_common_switch_qemu_logdirty;
 
     dss->sws.ao  = dss->ao;
tools/libxl/libxl_save_msgs_gen.pl +3 -1
index 3ae7373..bb1d4e9 100755
@@ -33,6 +33,7 @@ our @msgs = (
                                               'xen_pfn_t', 'console_gfn'] ],
     [  9, 'srW',    "complete",              [qw(int retval
                                                  int errnoval)] ],
+    [ 10, 'scxW',   "precopy_policy", ['struct precopy_stats', 'stats'] ]
 );
 
 #----------------------------------------
@@ -141,7 +142,8 @@ static void bytes_put(unsigned char *const buf, int *len,
 
 END
 
-foreach my $simpletype (qw(int uint16_t uint32_t unsigned), 'unsigned long', 'xen_pfn_t') {
+foreach my $simpletype (qw(int uint16_t uint32_t unsigned),
+                        'unsigned long', 'xen_pfn_t', 'struct precopy_stats') {
     my $typeid = typeid($simpletype);
     $out_body{'callout'} .= <<END;
 static int ${typeid}_get(const unsigned char **msg,
Signature · 7 lines
1.8.3.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#9 lore raw

Re: [PATCH v3 3/3] RFC: migration: defer precopy policy to libxl

Quoted 8 lines · Jennifer Herbert

Provide an implementation of the old policy as a callback in libxl and plumb it through the IPC machinery to libxc.

This serves as an example for defining a libxl policy, and provides no advantage over the default policy in libxc.

The code looks plausible but it is not really usable by libxl users as-is, because a public API is still missing.

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

#10 lore raw

Re: [PATCH v3 3/3] RFC: migration: defer precopy policy to libxl

Quoted 11 lines · Wei Liu
Quoted 8 lines · Jennifer Herbert

Provide an implementation of the old policy as a callback in libxl and plumb it through the IPC machinery to libxc.

This serves as an example for defining a libxl policy, and provides no advantage over the default policy in libxc.

The code looks plausible but it is not really usable by libxl users as-is, because a public API is still missing.

This is why I excluded it to start with, and now labelled it RFC. Its only the first two patches I would like to see pulled atm.

Cheers

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