Skip to contentSkip to conversation

Remus support for Migration-v2

PATCH Superseded Yang Hongyang 3 participants 21 messages May 14, 2015 – May 15, 2015

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v5 cover Remus support for Migration-v2

This patchset implement the Remus support for Migration v2 but without memory compressing.

Git tree available at:
https://github.com/macrosheep/xen/tree/Remus-newmig-v5

This patchset is based on
[PATCH v6 00/16] Misc patches to aid migration v2 Remus support
https://github.com/macrosheep/xen/tree/misc-remus-v6

Yang Hongyang (2):
libxc/save: implement Remus checkpointed save libxc/restore: implement Remus checkpointed restore

 tools/libxc/xc_sr_common.h  |  14 ++++++
 tools/libxc/xc_sr_restore.c | 113 ++++++++++++++++++++++++++++++++++++++++----
 tools/libxc/xc_sr_save.c    |  80 +++++++++++++++++++++++--------
 3 files changed, 178 insertions(+), 29 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH v5 1/2 libxc/save: implement Remus checkpointed save

With Remus, the save flow should be:
live migration->{ periodically save(checkpointed save) }

---
 tools/libxc/xc_sr_save.c | 80 ++++++++++++++++++++++++++++++++++++------------
 1 file changed, 61 insertions(+), 19 deletions(-)
tools/libxc/xc_sr_save.c +61 -19
index 1d0a46d..1c5d199 100644
@@ -57,6 +57,16 @@ static int write_end_record(struct xc_sr_context *ctx)
 }
 
 /*
+ * Writes an CHECKPOINT record into the stream.
+ */
+static int write_checkpoint_record(struct xc_sr_context *ctx)
+{
+    struct xc_sr_record checkpoint = { REC_TYPE_CHECKPOINT, 0, NULL };
+
+    return write_record(ctx, &checkpoint);
+}
+
+/*
  * Writes a batch of memory as a PAGE_DATA record into the stream.  The batch
  * is constructed in ctx->save.batch_pfns.
  *
@@ -467,6 +477,14 @@ static int send_domain_memory_live(struct xc_sr_context *ctx)
     DECLARE_HYPERCALL_BUFFER_SHADOW(unsigned long, dirty_bitmap,
                                     &ctx->save.dirty_bitmap_hbuf);
 
+    /*
+     * With Remus, we will enter checkpointed save after live migration.
+     * In checkpointed save loop, we skip the live part and pause straight
+     * away to send dirty pages between checkpoints.
+     */
+    if ( !ctx->save.live )
+        goto last_iter;
+
     rc = enable_logdirty(ctx);
     if ( rc )
         goto out;
@@ -505,6 +523,7 @@ static int send_domain_memory_live(struct xc_sr_context *ctx)
             goto out;
     }
 
+ last_iter:
     rc = suspend_domain(ctx);
     if ( rc )
         goto out;
@@ -667,29 +686,52 @@ static int save(struct xc_sr_context *ctx, uint16_t guest_type)
     if ( rc )
         goto err;
 
-    rc = ctx->save.ops.start_of_checkpoint(ctx);
-    if ( rc )
-        goto err;
+    do {
+        rc = ctx->save.ops.start_of_checkpoint(ctx);
+        if ( rc )
+            goto err;
 
-    if ( ctx->save.live )
-        rc = send_domain_memory_live(ctx);
-    else
-        rc = send_domain_memory_nonlive(ctx);
+        if ( ctx->save.live || ctx->save.checkpointed )
+            rc = send_domain_memory_live(ctx);
+        else
+            rc = send_domain_memory_nonlive(ctx);
 
-    if ( rc )
-        goto err;
+        if ( rc )
+            goto err;
 
-    if ( !ctx->dominfo.shutdown ||
-         (ctx->dominfo.shutdown_reason != SHUTDOWN_suspend) )
-    {
-        ERROR("Domain has not been suspended");
-        rc = -1;
-        goto err;
-    }
+        if ( !ctx->dominfo.shutdown ||
+            (ctx->dominfo.shutdown_reason != SHUTDOWN_suspend) )
+        {
+            ERROR("Domain has not been suspended");
+            rc = -1;
+            goto err;
+        }
 
-    rc = ctx->save.ops.end_of_checkpoint(ctx);
-    if ( rc )
-        goto err;
+        rc = ctx->save.ops.end_of_checkpoint(ctx);
+        if ( rc )
+            goto err;
+
+        if ( ctx->save.checkpointed )
+        {
+            if ( ctx->save.live )
+            {
+                /* End of live migration, we are sending checkpointed stream */
+                ctx->save.live = false;
+            }
+
+            rc = write_checkpoint_record(ctx);
+            if ( rc )
+                goto err;
+
+            ctx->save.callbacks->postcopy(ctx->save.callbacks->data);
+
+            rc = ctx->save.callbacks->checkpoint(ctx->save.callbacks->data);
+            if ( rc > 0 )
+                xc_report_progress_single(xch, "Checkpointed save");
+            else
+                ctx->save.checkpointed = false;
+        }
+    } while ( ctx->save.checkpointed );
 
     xc_report_progress_single(xch, "End of stream");
 
Signature · 1 line
1.9.1
#2 lore raw

Re: [PATCH Remus v5 1/2] libxc/save: implement Remus checkpointed save

Quoted 17 lines · Yang Hongyang

With Remus, the save flow should be:
live migration->{ periodically save(checkpointed save) }

---
 tools/libxc/xc_sr_save.c | 80 ++++++++++++++++++++++++++++++++++++------------
 1 file changed, 61 insertions(+), 19 deletions(-)
tools/libxc/xc_sr_save.c +0 -0
index 1d0a46d..1c5d199 100644

tools/libxc/xc_sr_save.c static int write_end_record(struct xc_sr_context *ctx) · line 60

Quoted 4 lines
tools/libxc/xc_sr_save.c +1 -0
@@ -57,6 +57,16 @@ static int write_end_record(struct xc_sr_context *ctx)
 }
 
 /*
+ * Writes an CHECKPOINT record into the stream.

"a CHECKPOINT"

Quoted 13 lines
tools/libxc/xc_sr_save.c +9 -0
+ */
+static int write_checkpoint_record(struct xc_sr_context *ctx)
+{
+    struct xc_sr_record checkpoint = { REC_TYPE_CHECKPOINT, 0, NULL };
+
+    return write_record(ctx, &checkpoint);
+}
+
+/*
  * Writes a batch of memory as a PAGE_DATA record into the stream.  The batch
  * is constructed in ctx->save.batch_pfns.
  *

tools/libxc/xc_sr_save.c static int send_domain_memory_live(struct xc_sr_context *ctx) · line 486

Quoted 10 lines
tools/libxc/xc_sr_save.c +7 -0
@@ -467,6 +477,14 @@ static int send_domain_memory_live(struct xc_sr_context *ctx)
     DECLARE_HYPERCALL_BUFFER_SHADOW(unsigned long, dirty_bitmap,
                                     &ctx->save.dirty_bitmap_hbuf);
 
+    /*
+     * With Remus, we will enter checkpointed save after live migration.
+     * In checkpointed save loop, we skip the live part and pause straight
+     * away to send dirty pages between checkpoints.
+     */
+    if ( !ctx->save.live )
+        goto last_iter;

Rather than use goto would it work to refactor everything from here to the label into some sort of helper and just call that in the "actually live" case?

Or perhaps everything from the label to the end should be a helper function which the caller can also use in thecheckpoint case instead of calling send_domain_memory_live (and which s_d_m_l also calls of course).

tools/libxc/xc_sr_save.c static int save(struct xc_sr_context *ctx, uint16_t guest_type) · line 719

Quoted 6 lines
tools/libxc/xc_sr_save.c +6 -0
+        if ( ctx->save.checkpointed )
+        {
+            if ( ctx->save.live )
+            {
+                /* End of live migration, we are sending checkpointed stream */
+                ctx->save.live = false;

I think I'm misunderstanding either the purpose of this code or the comment (or both).

Is it the case that a checkpoint starts with an iteration of live (to transfer everything over) and then drops into sending periodical non-live updates at each checkpoint?

If so then I think a more useful comment would be:

/*
* We have now completed the initial live portion of the
checkpoint
* process. Therefore switch into periodically sending synchronous
* batches of pages.
*/

Personally I don't have a problem with just a direct assignment without the if, since assigning false to an already flase value is a nop.

Quoted 18 lines
tools/libxc/xc_sr_save.c +15 -0
+            }
+
+            rc = write_checkpoint_record(ctx);
+            if ( rc )
+                goto err;
+
+            ctx->save.callbacks->postcopy(ctx->save.callbacks->data);
+
+            rc = ctx->save.callbacks->checkpoint(ctx->save.callbacks->data);
+            if ( rc > 0 )
+                xc_report_progress_single(xch, "Checkpointed save");
+            else
+                ctx->save.checkpointed = false;
+        }
+    } while ( ctx->save.checkpointed );
 
     xc_report_progress_single(xch, "End of stream");
#3 lore raw

Re: [PATCH Remus v5 1/2] libxc/save: implement Remus checkpointed save

Quoted 53 lines · Ian Campbell
Quoted 17 lines · Yang Hongyang

With Remus, the save flow should be:
live migration->{ periodically save(checkpointed save) }

---
  tools/libxc/xc_sr_save.c | 80 ++++++++++++++++++++++++++++++++++++------------
  1 file changed, 61 insertions(+), 19 deletions(-)
tools/libxc/xc_sr_save.c +0 -0
index 1d0a46d..1c5d199 100644

tools/libxc/xc_sr_save.c static int write_end_record(struct xc_sr_context *ctx) · line 60

Quoted 4 lines
tools/libxc/xc_sr_save.c +1 -0
@@ -57,6 +57,16 @@ static int write_end_record(struct xc_sr_context *ctx)
  }
 
  /*
+ * Writes an CHECKPOINT record into the stream.

"a CHECKPOINT"

Quoted 13 lines
tools/libxc/xc_sr_save.c +9 -0
+ */
+static int write_checkpoint_record(struct xc_sr_context *ctx)
+{
+    struct xc_sr_record checkpoint = { REC_TYPE_CHECKPOINT, 0, NULL };
+
+    return write_record(ctx, &checkpoint);
+}
+
+/*
   * Writes a batch of memory as a PAGE_DATA record into the stream.  The batch
   * is constructed in ctx->save.batch_pfns.
   *

tools/libxc/xc_sr_save.c static int send_domain_memory_live(struct xc_sr_context *ctx) · line 486

Quoted 10 lines
tools/libxc/xc_sr_save.c +7 -0
@@ -467,6 +477,14 @@ static int send_domain_memory_live(struct xc_sr_context *ctx)
      DECLARE_HYPERCALL_BUFFER_SHADOW(unsigned long, dirty_bitmap,
                                      &ctx->save.dirty_bitmap_hbuf);
 
+    /*
+     * With Remus, we will enter checkpointed save after live migration.
+     * In checkpointed save loop, we skip the live part and pause straight
+     * away to send dirty pages between checkpoints.
+     */
+    if ( !ctx->save.live )
+        goto last_iter;

Rather than use goto would it work to refactor everything from here to the label into some sort of helper and just call that in the "actually live" case?

Quoted 4 lines

Or perhaps everything from the label to the end should be a helper function which the caller can also use in thecheckpoint case instead of calling send_domain_memory_live (and which s_d_m_l also calls of course).

I'm going to refactor the send_domain_memory_live() as follows:

split the send_domain_memory_live() into three helper function:
- send_memory_live() do the actually live case
- suspend_and_send_dirty() suspend the guest and send dirty pages
- send_memory_verify()

then:
- send_domain_memory_live() combination of those three helper functions
- send_domain_momory_checkpointed() calls suspend_and_send_dirty() and send_memory_verify()
- send_domain_memory_nonlive() stay as it is

Does it make sense?

Quoted 15 lines

tools/libxc/xc_sr_save.c static int save(struct xc_sr_context *ctx, uint16_t guest_type) · line 719

Quoted 7 lines
tools/libxc/xc_sr_save.c +6 -0
+        if ( ctx->save.checkpointed )
+        {
+            if ( ctx->save.live )
+            {
+                /* End of live migration, we are sending checkpointed stream */
+                ctx->save.live = false;

I think I'm misunderstanding either the purpose of this code or the comment (or both).

Is it the case that a checkpoint starts with an iteration of live (to transfer everything over) and then drops into sending periodical non-live updates at each checkpoint?

Quoted 9 lines

If so then I think a more useful comment would be:

/*
* We have now completed the initial live portion of the
checkpoint
* process. Therefore switch into periodically sending synchronous
* batches of pages.
*/

This is much better, Thank you!

Quoted 2 lines

Personally I don't have a problem with just a direct assignment without the if, since assigning false to an already flase value is a nop.

Will drop the if.

Quoted 23 lines
Quoted 9 lines
tools/libxc/xc_sr_save.c +7 -0
+            }
+
+            rc = write_checkpoint_record(ctx);
+            if ( rc )
+                goto err;
+
+            ctx->save.callbacks->postcopy(ctx->save.callbacks->data);

tools/libxc/xc_sr_save.c static int save(struct xc_sr_context *ctx, uint16_t guest_type) · line 736

Quoted 10 lines
tools/libxc/xc_sr_save.c +8 -0
+
+            rc = ctx->save.callbacks->checkpoint(ctx->save.callbacks->data);
+            if ( rc > 0 )
+                xc_report_progress_single(xch, "Checkpointed save");
+            else
+                ctx->save.checkpointed = false;
+        }
+    } while ( ctx->save.checkpointed );
 
      xc_report_progress_single(xch, "End of stream");

.

Signature · 2 lines
Thanks,
Yang.
#4 lore raw

Re: [PATCH Remus v5 1/2] libxc/save: implement Remus checkpointed save

Quoted 32 lines · Yang Hongyang
Quoted 20 lines
Quoted 11 lines
tools/libxc/xc_sr_save.c +2 -0
@@ -467,6 +477,14 @@ static int send_domain_memory_live(struct
 xc_sr_context *ctx)
      DECLARE_HYPERCALL_BUFFER_SHADOW(unsigned long, dirty_bitmap,
                                      &ctx->save.dirty_bitmap_hbuf);
 
+    /*
+     * With Remus, we will enter checkpointed save after live

migration.
+ * In checkpointed save loop, we skip the live part and pause
straight

tools/libxc/xc_sr_save.c static int send_domain_memory_live(struct xc_sr_context *ctx) · line 486

Quoted 4 lines
tools/libxc/xc_sr_save.c +4 -0
+     * away to send dirty pages between checkpoints.
+     */
+    if ( !ctx->save.live )
+        goto last_iter;

Rather than use goto would it work to refactor everything from here to the label into some sort of helper and just call that in the "actually live" case?

Quoted 4 lines

Or perhaps everything from the label to the end should be a helper function which the caller can also use in thecheckpoint case instead of calling send_domain_memory_live (and which s_d_m_l also calls of course).

I'm going to refactor the send_domain_memory_live() as follows:

split the send_domain_memory_live() into three helper function:
- send_memory_live() do the actually live case
- suspend_and_send_dirty() suspend the guest and send dirty pages
- send_memory_verify()

Quoted 6 lines

then:
- send_domain_memory_live() combination of those three helper functions
- send_domain_momory_checkpointed() calls suspend_and_send_dirty() and send_memory_verify()
- send_domain_memory_nonlive() stay as it is
Does it make sense?

verify mode is only a debugging tool, and shouldn't be used in general. (It is actually a lot less useful in retrospect than one would imagine.)

However, the rest of the split looks plausible.

~Andrew

#5 lore raw

Re: [PATCH Remus v5 1/2] libxc/save: implement Remus checkpointed save

Quoted 40 lines · Andrew Cooper
Quoted 32 lines · Yang Hongyang
Quoted 20 lines
Quoted 11 lines
tools/libxc/xc_sr_save.c +2 -0
@@ -467,6 +477,14 @@ static int send_domain_memory_live(struct
 xc_sr_context *ctx)
       DECLARE_HYPERCALL_BUFFER_SHADOW(unsigned long, dirty_bitmap,
                                       &ctx->save.dirty_bitmap_hbuf);
 
+    /*
+     * With Remus, we will enter checkpointed save after live

migration.
+ * In checkpointed save loop, we skip the live part and pause
straight

tools/libxc/xc_sr_save.c static int send_domain_memory_live(struct xc_sr_context *ctx) · line 486

Quoted 4 lines
tools/libxc/xc_sr_save.c +4 -0
+     * away to send dirty pages between checkpoints.
+     */
+    if ( !ctx->save.live )
+        goto last_iter;

Rather than use goto would it work to refactor everything from here to the label into some sort of helper and just call that in the "actually live" case?

Quoted 4 lines

Or perhaps everything from the label to the end should be a helper function which the caller can also use in thecheckpoint case instead of calling send_domain_memory_live (and which s_d_m_l also calls of course).

I'm going to refactor the send_domain_memory_live() as follows:

split the send_domain_memory_live() into three helper function:
- send_memory_live() do the actually live case
- suspend_and_send_dirty() suspend the guest and send dirty pages
- send_memory_verify()

Quoted 6 lines

then:
- send_domain_memory_live() combination of those three helper functions
- send_domain_momory_checkpointed() calls suspend_and_send_dirty() and send_memory_verify()
- send_domain_memory_nonlive() stay as it is
Does it make sense?

Quoted 2 lines

verify mode is only a debugging tool, and shouldn't be used in general. (It is actually a lot less useful in retrospect than one would imagine.)

Do you mean we do not need this in checkpointed stream? Currently, tt is conditioned under 'if ( ctx->save.debug )', both in live migration and checkpointed stream.

Quoted 6 lines

However, the rest of the split looks plausible.

~Andrew
.

Signature · 2 lines
Thanks,
Yang.
#6 lore raw

Re: [PATCH Remus v5 1/2] libxc/save: implement Remus checkpointed save

Quoted 46 lines · Yang Hongyang
Quoted 43 lines · Andrew Cooper
Quoted 41 lines · Yang Hongyang
Quoted 20 lines
Quoted 11 lines
tools/libxc/xc_sr_save.c +2 -0
@@ -467,6 +477,14 @@ static int send_domain_memory_live(struct
 xc_sr_context *ctx)
       DECLARE_HYPERCALL_BUFFER_SHADOW(unsigned long, dirty_bitmap,
                                       &ctx->save.dirty_bitmap_hbuf);
 
+    /*
+     * With Remus, we will enter checkpointed save after live

migration.
+ * In checkpointed save loop, we skip the live part and pause
straight

tools/libxc/xc_sr_save.c static int send_domain_memory_live(struct xc_sr_context *ctx) · line 486

Quoted 4 lines
tools/libxc/xc_sr_save.c +4 -0
+     * away to send dirty pages between checkpoints.
+     */
+    if ( !ctx->save.live )
+        goto last_iter;

Rather than use goto would it work to refactor everything from here to the label into some sort of helper and just call that in the "actually live" case?

Quoted 5 lines

Or perhaps everything from the label to the end should be a helper function which the caller can also use in thecheckpoint case instead of
calling send_domain_memory_live (and which s_d_m_l also calls of course).

I'm going to refactor the send_domain_memory_live() as follows:

split the send_domain_memory_live() into three helper function:
- send_memory_live() do the actually live case
- suspend_and_send_dirty() suspend the guest and send dirty pages
- send_memory_verify()

then:
- send_domain_memory_live() combination of those three helper
functions
- send_domain_momory_checkpointed() calls
suspend_and_send_dirty() and
send_memory_verify()
- send_domain_memory_nonlive() stay as it is
Does it make sense?

Quoted 6 lines
Quoted 2 lines

verify mode is only a debugging tool, and shouldn't be used in general. (It is actually a lot less useful in retrospect than one would imagine.)

Do you mean we do not need this in checkpointed stream? Currently, tt is conditioned under 'if ( ctx->save.debug )', both in live migration and checkpointed stream.

Ah - you absolutely don't want it in a checkpointed stream. As soon as that option has been set, the restoring side can no longer resume the domain.

Basically, it tells the restore side to start doing memcmp() instead of memcpy() on the incoming page data. The initial hope was to detect memory corruption, but it turns out that there is natural memory corruption to be had anyway when PV drivers are in use.

(This is another area which is around for compatibility with legacy, rather than actually of being much use in practice)

~Andrew

#7 lore raw

Re: [PATCH Remus v5 1/2] libxc/save: implement Remus checkpointed save

Quoted 50 lines · Andrew Cooper
Quoted 49 lines · Yang Hongyang
Quoted 45 lines · Andrew Cooper
Quoted 33 lines · Yang Hongyang
Quoted 20 lines
Quoted 11 lines
tools/libxc/xc_sr_save.c +2 -0
@@ -467,6 +477,14 @@ static int send_domain_memory_live(struct
 xc_sr_context *ctx)
        DECLARE_HYPERCALL_BUFFER_SHADOW(unsigned long, dirty_bitmap,
                                        &ctx->save.dirty_bitmap_hbuf);
 
+    /*
+     * With Remus, we will enter checkpointed save after live

migration.
+ * In checkpointed save loop, we skip the live part and pause
straight

tools/libxc/xc_sr_save.c static int send_domain_memory_live(struct xc_sr_context *ctx) · line 486

Quoted 4 lines
tools/libxc/xc_sr_save.c +4 -0
+     * away to send dirty pages between checkpoints.
+     */
+    if ( !ctx->save.live )
+        goto last_iter;

Rather than use goto would it work to refactor everything from here to the label into some sort of helper and just call that in the "actually live" case?

Quoted 5 lines

Or perhaps everything from the label to the end should be a helper function which the caller can also use in thecheckpoint case instead of
calling send_domain_memory_live (and which s_d_m_l also calls of course).

I'm going to refactor the send_domain_memory_live() as follows:

split the send_domain_memory_live() into three helper function:
- send_memory_live() do the actually live case
- suspend_and_send_dirty() suspend the guest and send dirty pages
- send_memory_verify()

Quoted 8 lines

then:
- send_domain_memory_live() combination of those three helper
functions
- send_domain_momory_checkpointed() calls
suspend_and_send_dirty() and
send_memory_verify()
- send_domain_memory_nonlive() stay as it is
Does it make sense?

verify mode is only a debugging tool, and shouldn't be used in general. (It is actually a lot less useful in retrospect than one would imagine.)

Quoted 7 lines
Quoted 3 lines

Do you mean we do not need this in checkpointed stream? Currently, tt is conditioned under 'if ( ctx->save.debug )', both in live migration and checkpointed stream.

Ah - you absolutely don't want it in a checkpointed stream. As soon as that option has been set, the restoring side can no longer resume the domain.

So it needs to be conditioned under
if ( ctx->save.debug && !ctx->save.checkpointed )

if it is a checkpointed stream, we just ignore this flag, is it OK?

Quoted 12 lines

Basically, it tells the restore side to start doing memcmp() instead of memcpy() on the incoming page data. The initial hope was to detect memory corruption, but it turns out that there is natural memory corruption to be had anyway when PV drivers are in use.

(This is another area which is around for compatibility with legacy, rather than actually of being much use in practice)

~Andrew
.

Signature · 2 lines
Thanks,
Yang.
#8 lore raw

PATCH v5 2/2 libxc/restore: implement Remus checkpointed restore

In reply to Yang Hongyang

With Remus, the restore flow should be:
the first full migration stream -> { periodically restore stream }

---
 tools/libxc/xc_sr_common.h  |  14 ++++++
 tools/libxc/xc_sr_restore.c | 113 ++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 117 insertions(+), 10 deletions(-)
tools/libxc/xc_sr_common.h +14 -0
index f8121e7..3bf27f1 100644
@@ -208,6 +208,20 @@ struct xc_sr_context
             /* Plain VM, or checkpoints over time. */
             bool checkpointed;
 
+            /* Currently buffering records between a checkpoint */
+            bool buffer_all_records;
+
+/*
+ * With Remus, we buffer the records sent by the primary at checkpoint,
+ * in case the primary will fail, we can recover from the last
+ * checkpoint state.
+ * This should be enough because primary only send dirty pages at
+ * checkpoint.
+ */
+#define MAX_BUF_RECORDS 1024
+            struct xc_sr_record *buffered_records;
+            unsigned buffered_rec_num;
+
             /*
              * Xenstore and Console parameters.
              * INPUT:  evtchn & domid
tools/libxc/xc_sr_restore.c +103 -10

161 lines not on this page · raw message

Signature · 1 line
1.9.1
Reviewed-by on v5 2/2
#9 lore raw

Re: [PATCH Remus v5 2/2] libxc/restore: implement Remus checkpointed restore

Quoted 8 lines · Yang Hongyang

With Remus, the restore flow should be:
the first full migration stream -> { periodically restore stream }

Quoted 201 lines
---
 tools/libxc/xc_sr_common.h  |  14 ++++++
 tools/libxc/xc_sr_restore.c | 113 ++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 117 insertions(+), 10 deletions(-)
tools/libxc/xc_sr_common.h +14 -0
index f8121e7..3bf27f1 100644
@@ -208,6 +208,20 @@ struct xc_sr_context
             /* Plain VM, or checkpoints over time. */
             bool checkpointed;
 
+            /* Currently buffering records between a checkpoint */
+            bool buffer_all_records;
+
+/*
+ * With Remus, we buffer the records sent by the primary at checkpoint,
+ * in case the primary will fail, we can recover from the last
+ * checkpoint state.
+ * This should be enough because primary only send dirty pages at
+ * checkpoint.
+ */
+#define MAX_BUF_RECORDS 1024
+            struct xc_sr_record *buffered_records;
+            unsigned buffered_rec_num;
+
             /*
              * Xenstore and Console parameters.
              * INPUT:  evtchn & domid
tools/libxc/xc_sr_restore.c +103 -10
index 9ab5760..8468ffc 100644
@@ -468,11 +468,69 @@ static int handle_page_data(struct xc_sr_context *ctx, struct xc_sr_record *rec)
     return rc;
 }
 
+static int process_record(struct xc_sr_context *ctx, struct xc_sr_record *rec);
+static int handle_checkpoint(struct xc_sr_context *ctx)
+{
+    xc_interface *xch = ctx->xch;
+    int rc = 0;
+    unsigned i;
+
+    if ( !ctx->restore.checkpointed )
+    {
+        ERROR("Found checkpoint in non-checkpointed stream");
+        rc = -1;
+        goto err;
+    }
+
+    if ( ctx->restore.buffer_all_records )
+    {
+        IPRINTF("All records buffered");
+
+        /*
+         * We need to set buffer_all_records to false in
+         * order to process records instead of buffer records.
+         * buffer_all_records should be set back to true after
+         * we successfully processed all records.
+         */
+        ctx->restore.buffer_all_records = false;
+        for ( i = 0; i < ctx->restore.buffered_rec_num; i++ )
+        {
+            rc = process_record(ctx, &ctx->restore.buffered_records[i]);
+            if ( rc )
+                goto err;
+        }
+        ctx->restore.buffered_rec_num = 0;
+        ctx->restore.buffer_all_records = true;
+        IPRINTF("All records processed");
+    }
+    else
+        ctx->restore.buffer_all_records = true;
+
+ err:
+    return rc;
+}
+
 static int process_record(struct xc_sr_context *ctx, struct xc_sr_record *rec)
 {
     xc_interface *xch = ctx->xch;
     int rc = 0;
 
+    if ( ctx->restore.buffer_all_records &&
+         rec->type != REC_TYPE_END &&
+         rec->type != REC_TYPE_CHECKPOINT )
+    {
+        if ( ctx->restore.buffered_rec_num >= MAX_BUF_RECORDS )
+        {
+            ERROR("There are too many records within a checkpoint");
+            return -1;
+        }
+
+        memcpy(&ctx->restore.buffered_records[ctx->restore.buffered_rec_num++],
+               rec, sizeof(*rec));
+
+        return 0;
+    }
+
     switch ( rec->type )
     {
     case REC_TYPE_END:
@@ -487,12 +545,17 @@ static int process_record(struct xc_sr_context *ctx, struct xc_sr_record *rec)
         ctx->restore.verify = true;
         break;
 
+    case REC_TYPE_CHECKPOINT:
+        rc = handle_checkpoint(ctx);
+        break;
+
     default:
         rc = ctx->restore.ops.process_record(ctx, rec);
         break;
     }
 
     free(rec->data);
+    rec->data = NULL;
 
     if ( rc == RECORD_NOT_PROCESSED )
     {
@@ -529,6 +592,15 @@ static int setup(struct xc_sr_context *ctx)
         goto err;
     }
 
+    ctx->restore.buffered_records = malloc(
+        MAX_BUF_RECORDS * sizeof(struct xc_sr_record));
+    if ( !ctx->restore.buffered_records )
+    {
+        ERROR("Unable to allocate memory for buffered records");
+        rc = -1;
+        goto err;
+    }
+
  err:
     return rc;
 }
@@ -536,7 +608,12 @@ static int setup(struct xc_sr_context *ctx)
 static void cleanup(struct xc_sr_context *ctx)
 {
     xc_interface *xch = ctx->xch;
+    unsigned i;
+
+    for ( i = 0; i < ctx->restore.buffered_rec_num; i++ )
+        free(ctx->restore.buffered_records[i].data);
 
+    free(ctx->restore.buffered_records);
     free(ctx->restore.populated_pfns);
     if ( ctx->restore.ops.cleanup(ctx) )
         PERROR("Failed to clean up");
@@ -564,7 +641,27 @@ static int restore(struct xc_sr_context *ctx)
     {
         rc = read_record(ctx, &rec);
         if ( rc )
-            goto err;
+        {
+            if ( ctx->restore.buffer_all_records )
+                goto remus_failover;
+            else
+                goto err;
+        }
+
+#ifdef XG_LIBXL_HVM_COMPAT
+        if ( ctx->dominfo.hvm &&
+             (rec.type == REC_TYPE_END || rec.type == REC_TYPE_CHECKPOINT) )
+        {
+            rc = read_qemu(ctx);
+            if ( rc )
+            {
+                if ( ctx->restore.buffer_all_records )
+                    goto remus_failover;
+                else
+                    goto err;
+            }
+        }
+#endif
 
         rc = process_record(ctx, &rec);
         if ( rc )
@@ -572,15 +669,11 @@ static int restore(struct xc_sr_context *ctx)
 
     } while ( rec.type != REC_TYPE_END );
 
-#ifdef XG_LIBXL_HVM_COMPAT
-    if ( ctx->dominfo.hvm )
-    {
-        rc = read_qemu(ctx);
-        if ( rc )
-            goto err;
-    }
-#endif
-
+ remus_failover:
+    /*
+     * With Remus, if we reach here, there must be some error on primary,
+     * failover from the last checkpoint state.
+     */
     rc = ctx->restore.ops.stream_complete(ctx);
     if ( rc )
         goto err;
#10 lore raw

Re: [PATCH Remus v5 2/2] libxc/restore: implement Remus checkpointed restore

In reply to Yang Hongyang
Quoted 20 lines · Yang Hongyang

With Remus, the restore flow should be:
the first full migration stream -> { periodically restore stream }

---
 tools/libxc/xc_sr_common.h  |  14 ++++++
 tools/libxc/xc_sr_restore.c | 113 ++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 117 insertions(+), 10 deletions(-)
tools/libxc/xc_sr_common.h +0 -0
index f8121e7..3bf27f1 100644
@@ -208,6 +208,20 @@ struct xc_sr_context
             /* Plain VM, or checkpoints over time. */
             bool checkpointed;

tools/libxc/xc_sr_common.h struct xc_sr_context · line 219

Quoted 10 lines
tools/libxc/xc_sr_common.h +9 -0
 
+            /* Currently buffering records between a checkpoint */
+            bool buffer_all_records;
+
+/*
+ * With Remus, we buffer the records sent by the primary at checkpoint,
+ * in case the primary will fail, we can recover from the last
+ * checkpoint state.
+ * This should be enough because primary only send dirty pages at
+ * checkpoint.

I'm not sure how it then follows that 1024 buffers is guaranteed to be enough, unless there is something on the sending side arranging it to be so?

Quoted 17 lines
tools/libxc/xc_sr_common.h +5 -0
+ */
+#define MAX_BUF_RECORDS 1024
+            struct xc_sr_record *buffered_records;
+            unsigned buffered_rec_num;
+
             /*
              * Xenstore and Console parameters.
              * INPUT:  evtchn & domid
tools/libxc/xc_sr_restore.c +1 -0
index 9ab5760..8468ffc 100644
@@ -468,11 +468,69 @@ static int handle_page_data(struct xc_sr_context *ctx, struct xc_sr_record *rec)
     return rc;
 }
 
+static int process_record(struct xc_sr_context *ctx, struct xc_sr_record *rec);

tools/libxc/xc_sr_restore.c static int handle_page_data(struct xc_sr_context *ctx, struct xc_sr_record *rec) · line 481

Quoted 10 lines
tools/libxc/xc_sr_restore.c +10 -0
+static int handle_checkpoint(struct xc_sr_context *ctx)
+{
+    xc_interface *xch = ctx->xch;
+    int rc = 0;
+    unsigned i;
+
+    if ( !ctx->restore.checkpointed )
+    {
+        ERROR("Found checkpoint in non-checkpointed stream");
+        rc = -1;

Is it usual in migrv2 to set errno as well?

Quoted 4 lines
tools/libxc/xc_sr_restore.c +4 -0
+        goto err;
+    }
+
+    if ( ctx->restore.buffer_all_records )

tools/libxc/xc_sr_restore.c static int handle_page_data(struct xc_sr_context *ctx, struct xc_sr_record *rec) · line 495

Quoted 10 lines
tools/libxc/xc_sr_restore.c +10 -0
+    {
+        IPRINTF("All records buffered");
+
+        /*
+         * We need to set buffer_all_records to false in
+         * order to process records instead of buffer records.
+         * buffer_all_records should be set back to true after
+         * we successfully processed all records.
+         */
+        ctx->restore.buffer_all_records = false;

I'm not personally a fan of changing global state in order to simulate the action of what should be a parameter to a function.

Preferable IMHO would be to have process_record gain a parameter to override the ctx state but become an internal helper (perhaps with a name change) and then have API function process_record and process_buffered_records or some such which call it in the right way.

Andy may have a differing opinion though.

#11 lore raw

Re: [PATCH Remus v5 2/2] libxc/restore: implement Remus checkpointed restore

Quoted 51 lines · Ian Campbell
Quoted 20 lines · Yang Hongyang

With Remus, the restore flow should be:
the first full migration stream -> { periodically restore stream }

---
 tools/libxc/xc_sr_common.h  |  14 ++++++
 tools/libxc/xc_sr_restore.c | 113 ++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 117 insertions(+), 10 deletions(-)
tools/libxc/xc_sr_common.h +0 -0
index f8121e7..3bf27f1 100644
@@ -208,6 +208,20 @@ struct xc_sr_context
             /* Plain VM, or checkpoints over time. */
             bool checkpointed;

tools/libxc/xc_sr_common.h struct xc_sr_context · line 219

Quoted 10 lines
tools/libxc/xc_sr_common.h +9 -0
 
+            /* Currently buffering records between a checkpoint */
+            bool buffer_all_records;
+
+/*
+ * With Remus, we buffer the records sent by the primary at checkpoint,
+ * in case the primary will fail, we can recover from the last
+ * checkpoint state.
+ * This should be enough because primary only send dirty pages at
+ * checkpoint.

I'm not sure how it then follows that 1024 buffers is guaranteed to be enough, unless there is something on the sending side arranging it to be so?

Quoted 16 lines
tools/libxc/xc_sr_common.h +5 -0
+ */
+#define MAX_BUF_RECORDS 1024
+            struct xc_sr_record *buffered_records;
+            unsigned buffered_rec_num;
+
             /*
              * Xenstore and Console parameters.
              * INPUT:  evtchn & domid
tools/libxc/xc_sr_restore.c +0 -0
index 9ab5760..8468ffc 100644
@@ -468,11 +468,69 @@ static int handle_page_data(struct xc_sr_context *ctx, struct xc_sr_record *rec)
     return rc;
 }
 
Quoted 12 lines

tools/libxc/xc_sr_restore.c static int handle_page_data(struct xc_sr_context *ctx, struct xc_sr_record *rec) · line 481

Quoted 11 lines
tools/libxc/xc_sr_restore.c +11 -0
+static int process_record(struct xc_sr_context *ctx, struct xc_sr_record *rec);
+static int handle_checkpoint(struct xc_sr_context *ctx)
+{
+    xc_interface *xch = ctx->xch;
+    int rc = 0;
+    unsigned i;
+
+    if ( !ctx->restore.checkpointed )
+    {
+        ERROR("Found checkpoint in non-checkpointed stream");
+        rc = -1;

Is it usual in migrv2 to set errno as well?

If a relevant errno is to be had.

There are a lot of cases which are waiting for some real libxc error codes before they can propagate numeric error information, although in all cases the log messages will be accurate (and hopefully helpful).

~Andrew

Quoted 18 lines
Quoted 5 lines
tools/libxc/xc_sr_restore.c +4 -0
+        goto err;
+    }
+
+    if ( ctx->restore.buffer_all_records )

tools/libxc/xc_sr_restore.c static int handle_page_data(struct xc_sr_context *ctx, struct xc_sr_record *rec) · line 495

Quoted 10 lines
tools/libxc/xc_sr_restore.c +10 -0
+    {
+        IPRINTF("All records buffered");
+
+        /*
+         * We need to set buffer_all_records to false in
+         * order to process records instead of buffer records.
+         * buffer_all_records should be set back to true after
+         * we successfully processed all records.
+         */
+        ctx->restore.buffer_all_records = false;

I'm not personally a fan of changing global state in order to simulate the action of what should be a parameter to a function.

Quoted 6 lines

Preferable IMHO would be to have process_record gain a parameter to override the ctx state but become an internal helper (perhaps with a name change) and then have API function process_record and process_buffered_records or some such which call it in the right way.

Andy may have a differing opinion though.

Hmm yes - it would be nice to split the buffering logic away from the processing logic.

However, the two are slightly related.

Perhaps a process_or_buffer_record() helper, and removing all buffering logic from process_record().

~Andrew

#12 lore raw

Re: [PATCH Remus v5 2/2] libxc/restore: implement Remus checkpointed restore

Quoted 65 lines · Andrew Cooper
Quoted 51 lines · Ian Campbell
Quoted 20 lines · Yang Hongyang

With Remus, the restore flow should be:
the first full migration stream -> { periodically restore stream }

---
 tools/libxc/xc_sr_common.h  |  14 ++++++
 tools/libxc/xc_sr_restore.c | 113 ++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 117 insertions(+), 10 deletions(-)
tools/libxc/xc_sr_common.h +0 -0
index f8121e7..3bf27f1 100644
@@ -208,6 +208,20 @@ struct xc_sr_context
             /* Plain VM, or checkpoints over time. */
             bool checkpointed;

tools/libxc/xc_sr_common.h struct xc_sr_context · line 219

Quoted 10 lines
tools/libxc/xc_sr_common.h +9 -0
 
+            /* Currently buffering records between a checkpoint */
+            bool buffer_all_records;
+
+/*
+ * With Remus, we buffer the records sent by the primary at checkpoint,
+ * in case the primary will fail, we can recover from the last
+ * checkpoint state.
+ * This should be enough because primary only send dirty pages at
+ * checkpoint.

I'm not sure how it then follows that 1024 buffers is guaranteed to be enough, unless there is something on the sending side arranging it to be so?

Quoted 16 lines
tools/libxc/xc_sr_common.h +5 -0
+ */
+#define MAX_BUF_RECORDS 1024
+            struct xc_sr_record *buffered_records;
+            unsigned buffered_rec_num;
+
             /*
              * Xenstore and Console parameters.
              * INPUT:  evtchn & domid
tools/libxc/xc_sr_restore.c +0 -0
index 9ab5760..8468ffc 100644
@@ -468,11 +468,69 @@ static int handle_page_data(struct xc_sr_context *ctx, struct xc_sr_record *rec)
     return rc;
 }
 
Quoted 12 lines

tools/libxc/xc_sr_restore.c static int handle_page_data(struct xc_sr_context *ctx, struct xc_sr_record *rec) · line 481

Quoted 11 lines
tools/libxc/xc_sr_restore.c +11 -0
+static int process_record(struct xc_sr_context *ctx, struct xc_sr_record *rec);
+static int handle_checkpoint(struct xc_sr_context *ctx)
+{
+    xc_interface *xch = ctx->xch;
+    int rc = 0;
+    unsigned i;
+
+    if ( !ctx->restore.checkpointed )
+    {
+        ERROR("Found checkpoint in non-checkpointed stream");
+        rc = -1;

Is it usual in migrv2 to set errno as well?

Quoted 1 line

If a relevant errno is to be had.

EINVAL or ENOSYS perhaps?

Quoted 32 lines

There are a lot of cases which are waiting for some real libxc error codes before they can propagate numeric error information, although in all cases the log messages will be accurate (and hopefully helpful).

~Andrew

Quoted 18 lines
Quoted 5 lines
tools/libxc/xc_sr_restore.c +4 -0
+        goto err;
+    }
+
+    if ( ctx->restore.buffer_all_records )

tools/libxc/xc_sr_restore.c static int handle_page_data(struct xc_sr_context *ctx, struct xc_sr_record *rec) · line 495

Quoted 10 lines
tools/libxc/xc_sr_restore.c +10 -0
+    {
+        IPRINTF("All records buffered");
+
+        /*
+         * We need to set buffer_all_records to false in
+         * order to process records instead of buffer records.
+         * buffer_all_records should be set back to true after
+         * we successfully processed all records.
+         */
+        ctx->restore.buffer_all_records = false;

I'm not personally a fan of changing global state in order to simulate the action of what should be a parameter to a function.

Quoted 6 lines

Preferable IMHO would be to have process_record gain a parameter to override the ctx state but become an internal helper (perhaps with a name change) and then have API function process_record and process_buffered_records or some such which call it in the right way.

Andy may have a differing opinion though.

Quoted 7 lines

Hmm yes - it would be nice to split the buffering logic away from the processing logic.

However, the two are slightly related.

Perhaps a process_or_buffer_record() helper, and removing all buffering logic from process_record().

That seems like it would work.

#13 lore raw

Re: [PATCH Remus v5 2/2] libxc/restore: implement Remus checkpointed restore

Quoted 104 lines · Ian Campbell
Quoted 65 lines · Andrew Cooper
Quoted 51 lines · Ian Campbell
Quoted 20 lines · Yang Hongyang

With Remus, the restore flow should be:
the first full migration stream -> { periodically restore stream }

---
  tools/libxc/xc_sr_common.h  |  14 ++++++
  tools/libxc/xc_sr_restore.c | 113 ++++++++++++++++++++++++++++++++++++++++----
  2 files changed, 117 insertions(+), 10 deletions(-)
tools/libxc/xc_sr_common.h +0 -0
index f8121e7..3bf27f1 100644
@@ -208,6 +208,20 @@ struct xc_sr_context
              /* Plain VM, or checkpoints over time. */
              bool checkpointed;

tools/libxc/xc_sr_common.h struct xc_sr_context · line 219

Quoted 10 lines
tools/libxc/xc_sr_common.h +9 -0
 
+            /* Currently buffering records between a checkpoint */
+            bool buffer_all_records;
+
+/*
+ * With Remus, we buffer the records sent by the primary at checkpoint,
+ * in case the primary will fail, we can recover from the last
+ * checkpoint state.
+ * This should be enough because primary only send dirty pages at
+ * checkpoint.

I'm not sure how it then follows that 1024 buffers is guaranteed to be enough, unless there is something on the sending side arranging it to be so?

Quoted 16 lines
tools/libxc/xc_sr_common.h +5 -0
+ */
+#define MAX_BUF_RECORDS 1024
+            struct xc_sr_record *buffered_records;
+            unsigned buffered_rec_num;
+
              /*
               * Xenstore and Console parameters.
               * INPUT:  evtchn & domid
tools/libxc/xc_sr_restore.c +0 -0
index 9ab5760..8468ffc 100644
@@ -468,11 +468,69 @@ static int handle_page_data(struct xc_sr_context *ctx, struct xc_sr_record *rec)
      return rc;
  }
 
Quoted 12 lines

tools/libxc/xc_sr_restore.c static int handle_page_data(struct xc_sr_context *ctx, struct xc_sr_record *rec) · line 481

Quoted 11 lines
tools/libxc/xc_sr_restore.c +11 -0
+static int process_record(struct xc_sr_context *ctx, struct xc_sr_record *rec);
+static int handle_checkpoint(struct xc_sr_context *ctx)
+{
+    xc_interface *xch = ctx->xch;
+    int rc = 0;
+    unsigned i;
+
+    if ( !ctx->restore.checkpointed )
+    {
+        ERROR("Found checkpoint in non-checkpointed stream");
+        rc = -1;

Is it usual in migrv2 to set errno as well?

Quoted 1 line

If a relevant errno is to be had.

EINVAL or ENOSYS perhaps?

Quoted 35 lines

There are a lot of cases which are waiting for some real libxc error codes before they can propagate numeric error information, although in all cases the log messages will be accurate (and hopefully helpful).

~Andrew

Quoted 18 lines
Quoted 5 lines
tools/libxc/xc_sr_restore.c +4 -0
+        goto err;
+    }
+
+    if ( ctx->restore.buffer_all_records )

tools/libxc/xc_sr_restore.c static int handle_page_data(struct xc_sr_context *ctx, struct xc_sr_record *rec) · line 495

Quoted 10 lines
tools/libxc/xc_sr_restore.c +10 -0
+    {
+        IPRINTF("All records buffered");
+
+        /*
+         * We need to set buffer_all_records to false in
+         * order to process records instead of buffer records.
+         * buffer_all_records should be set back to true after
+         * we successfully processed all records.
+         */
+        ctx->restore.buffer_all_records = false;

I'm not personally a fan of changing global state in order to simulate the action of what should be a parameter to a function.

Quoted 6 lines

Preferable IMHO would be to have process_record gain a parameter to override the ctx state but become an internal helper (perhaps with a name change) and then have API function process_record and process_buffered_records or some such which call it in the right way.

Andy may have a differing opinion though.

Hmm yes - it would be nice to split the buffering logic away from the processing logic.

Quoted 6 lines
Quoted 4 lines

However, the two are slightly related.

Perhaps a process_or_buffer_record() helper, and removing all buffering logic from process_record().

That seems like it would work.

Good idea, add a buffer_record() helper should be an improvement to the code and make it more clearer, thank you!

Quoted 5 lines

.

Signature · 2 lines
Thanks,
Yang.
#14 lore raw

Re: [PATCH Remus v5 2/2] libxc/restore: implement Remus checkpointed restore

In reply to Ian Campbell
Quoted 22 lines · Ian Campbell
Quoted 21 lines · Yang Hongyang

With Remus, the restore flow should be:
the first full migration stream -> { periodically restore stream }

---
  tools/libxc/xc_sr_common.h  |  14 ++++++
  tools/libxc/xc_sr_restore.c | 113 ++++++++++++++++++++++++++++++++++++++++----
  2 files changed, 117 insertions(+), 10 deletions(-)
tools/libxc/xc_sr_common.h +0 -0
index f8121e7..3bf27f1 100644
@@ -208,6 +208,20 @@ struct xc_sr_context
              /* Plain VM, or checkpoints over time. */
              bool checkpointed;
 
Quoted 13 lines

tools/libxc/xc_sr_common.h struct xc_sr_context · line 219

Quoted 9 lines
tools/libxc/xc_sr_common.h +9 -0
+            /* Currently buffering records between a checkpoint */
+            bool buffer_all_records;
+
+/*
+ * With Remus, we buffer the records sent by the primary at checkpoint,
+ * in case the primary will fail, we can recover from the last
+ * checkpoint state.
+ * This should be enough because primary only send dirty pages at
+ * checkpoint.

I'm not sure how it then follows that 1024 buffers is guaranteed to be enough, unless there is something on the sending side arranging it to be so?

There are only few records at every checkpoint in my test, mostly under 10, probably because I don't do much operations in the Guest. I thought This limit can be adjusted later by further testing.
Since you and Andy both have doubts on this, I have to reconsider on this, perhaps there should be no limit. Even if the 1024 limit works for most of the cases, there might be cases that exceed the limit. So I will add another member 'allocated_rec_num' in the context, when the 'buffered_rec_num' exceed the 'allocated_rec_num', I will reallocate the buffer. The initial buffer size will be 1024 records which will work for most cases.

/*
* With Remus, we buffer the records sent by the primary at checkpoint,
* in case the primary will fail, we can recover from the last
* checkpoint state.
* This should be enough for most of the cases because primary only send
* dirty pages at checkpoint.
*/

#define DEFAULT_BUF_RECORDS 1024
            struct xc_sr_record *buffered_records;
            unsigned allocated_rec_num;
            unsigned buffered_rec_num;
Quoted 60 lines
Quoted 18 lines
tools/libxc/xc_sr_common.h +5 -0
+ */
+#define MAX_BUF_RECORDS 1024
+            struct xc_sr_record *buffered_records;
+            unsigned buffered_rec_num;
+
              /*
               * Xenstore and Console parameters.
               * INPUT:  evtchn & domid
tools/libxc/xc_sr_restore.c +1 -0
index 9ab5760..8468ffc 100644
@@ -468,11 +468,69 @@ static int handle_page_data(struct xc_sr_context *ctx, struct xc_sr_record *rec)
      return rc;
  }
 
+static int process_record(struct xc_sr_context *ctx, struct xc_sr_record *rec);

tools/libxc/xc_sr_restore.c static int handle_page_data(struct xc_sr_context *ctx, struct xc_sr_record *rec) · line 481

Quoted 10 lines
tools/libxc/xc_sr_restore.c +10 -0
+static int handle_checkpoint(struct xc_sr_context *ctx)
+{
+    xc_interface *xch = ctx->xch;
+    int rc = 0;
+    unsigned i;
+
+    if ( !ctx->restore.checkpointed )
+    {
+        ERROR("Found checkpoint in non-checkpointed stream");
+        rc = -1;

Is it usual in migrv2 to set errno as well?

Quoted 4 lines
tools/libxc/xc_sr_restore.c +4 -0
+        goto err;
+    }
+
+    if ( ctx->restore.buffer_all_records )

tools/libxc/xc_sr_restore.c static int handle_page_data(struct xc_sr_context *ctx, struct xc_sr_record *rec) · line 495

Quoted 10 lines
tools/libxc/xc_sr_restore.c +10 -0
+    {
+        IPRINTF("All records buffered");
+
+        /*
+         * We need to set buffer_all_records to false in
+         * order to process records instead of buffer records.
+         * buffer_all_records should be set back to true after
+         * we successfully processed all records.
+         */
+        ctx->restore.buffer_all_records = false;

I'm not personally a fan of changing global state in order to simulate the action of what should be a parameter to a function.

Preferable IMHO would be to have process_record gain a parameter to override the ctx state but become an internal helper (perhaps with a name change) and then have API function process_record and process_buffered_records or some such which call it in the right way.

Andy may have a differing opinion though.

.

Signature · 2 lines
Thanks,
Yang.
#15 lore raw

Re: [PATCH Remus v5 2/2] libxc/restore: implement Remus checkpointed restore

Quoted 38 lines · Yang Hongyang
Quoted 22 lines · Ian Campbell
Quoted 21 lines · Yang Hongyang

With Remus, the restore flow should be:
the first full migration stream -> { periodically restore stream }

---
  tools/libxc/xc_sr_common.h  |  14 ++++++
  tools/libxc/xc_sr_restore.c | 113 ++++++++++++++++++++++++++++++++++++++++----
  2 files changed, 117 insertions(+), 10 deletions(-)
tools/libxc/xc_sr_common.h +0 -0
index f8121e7..3bf27f1 100644
@@ -208,6 +208,20 @@ struct xc_sr_context
              /* Plain VM, or checkpoints over time. */
              bool checkpointed;
 
Quoted 13 lines

tools/libxc/xc_sr_common.h struct xc_sr_context · line 219

Quoted 9 lines
tools/libxc/xc_sr_common.h +9 -0
+            /* Currently buffering records between a checkpoint */
+            bool buffer_all_records;
+
+/*
+ * With Remus, we buffer the records sent by the primary at checkpoint,
+ * in case the primary will fail, we can recover from the last
+ * checkpoint state.
+ * This should be enough because primary only send dirty pages at
+ * checkpoint.

I'm not sure how it then follows that 1024 buffers is guaranteed to be enough, unless there is something on the sending side arranging it to be so?

Quoted 3 lines

There are only few records at every checkpoint in my test, mostly under 10, probably because I don't do much operations in the Guest. I thought This limit can be adjusted later by further testing.

For some reason I thought these buffers included the page data, is that not true? I was expecting the bulk of the records to be dirty page data.

Quoted 6 lines

Since you and Andy both have doubts on this, I have to reconsider on this, perhaps there should be no limit. Even if the 1024 limit works for most of the cases, there might be cases that exceed the limit. So I will add another member 'allocated_rec_num' in the context, when the 'buffered_rec_num' exceed the 'allocated_rec_num', I will reallocate the buffer. The initial buffer size will be 1024 records which will work for most cases.

That seems easy enough to be worth doing even if I was wrong about paged data.

#16 lore raw

Re: [PATCH Remus v5 2/2] libxc/restore: implement Remus checkpointed restore

Quoted 39 lines · Ian Campbell
Quoted 38 lines · Yang Hongyang
Quoted 35 lines · Ian Campbell
Quoted 20 lines · Yang Hongyang

With Remus, the restore flow should be:
the first full migration stream -> { periodically restore stream }

---
   tools/libxc/xc_sr_common.h  |  14 ++++++
   tools/libxc/xc_sr_restore.c | 113 ++++++++++++++++++++++++++++++++++++++++----
   2 files changed, 117 insertions(+), 10 deletions(-)
tools/libxc/xc_sr_common.h +0 -0
index f8121e7..3bf27f1 100644
@@ -208,6 +208,20 @@ struct xc_sr_context
               /* Plain VM, or checkpoints over time. */
               bool checkpointed;

tools/libxc/xc_sr_common.h struct xc_sr_context · line 219

Quoted 10 lines
tools/libxc/xc_sr_common.h +9 -0
 
+            /* Currently buffering records between a checkpoint */
+            bool buffer_all_records;
+
+/*
+ * With Remus, we buffer the records sent by the primary at checkpoint,
+ * in case the primary will fail, we can recover from the last
+ * checkpoint state.
+ * This should be enough because primary only send dirty pages at
+ * checkpoint.

I'm not sure how it then follows that 1024 buffers is guaranteed to be enough, unless there is something on the sending side arranging it to be so?

Quoted 6 lines
Quoted 3 lines

There are only few records at every checkpoint in my test, mostly under 10, probably because I don't do much operations in the Guest. I thought This limit can be adjusted later by further testing.

For some reason I thought these buffers included the page data, is that not true? I was expecting the bulk of the records to be dirty page data.

The page data is not stored in this buffer, but it's pointer stored in this buffer(rec->data). This buffer is the bulk of the struct xc_sr_record.

Quoted 10 lines
Quoted 7 lines

Since you and Andy both have doubts on this, I have to reconsider on this, perhaps there should be no limit. Even if the 1024 limit works for most of the cases, there might be cases that exceed the limit. So I will add another member 'allocated_rec_num' in the context, when the 'buffered_rec_num' exceed the 'allocated_rec_num', I will reallocate the buffer. The initial buffer size will be 1024 records which will work for most cases.

That seems easy enough to be worth doing even if I was wrong about paged data.

done.

Quoted 4 lines

.

Signature · 2 lines
Thanks,
Yang.
#17 lore raw

Re: [PATCH Remus v5 2/2] libxc/restore: implement Remus checkpointed restore

Quoted 45 lines · Yang Hongyang
Quoted 43 lines · Ian Campbell
Quoted 41 lines · Yang Hongyang
Quoted 22 lines · Ian Campbell
Quoted 21 lines · Yang Hongyang

With Remus, the restore flow should be:
the first full migration stream -> { periodically restore stream }

---
   tools/libxc/xc_sr_common.h  |  14 ++++++
   tools/libxc/xc_sr_restore.c | 113 ++++++++++++++++++++++++++++++++++++++++----
   2 files changed, 117 insertions(+), 10 deletions(-)
tools/libxc/xc_sr_common.h +0 -0
index f8121e7..3bf27f1 100644
@@ -208,6 +208,20 @@ struct xc_sr_context
               /* Plain VM, or checkpoints over time. */
               bool checkpointed;
 
Quoted 13 lines

tools/libxc/xc_sr_common.h struct xc_sr_context · line 219

Quoted 9 lines
tools/libxc/xc_sr_common.h +9 -0
+            /* Currently buffering records between a checkpoint */
+            bool buffer_all_records;
+
+/*
+ * With Remus, we buffer the records sent by the primary at checkpoint,
+ * in case the primary will fail, we can recover from the last
+ * checkpoint state.
+ * This should be enough because primary only send dirty pages at
+ * checkpoint.

I'm not sure how it then follows that 1024 buffers is guaranteed to be enough, unless there is something on the sending side arranging it to be so?

There are only few records at every checkpoint in my test, mostly under 10, probably because I don't do much operations in the Guest. I thought This limit can be adjusted later by further testing.

Quoted 5 lines
Quoted 2 lines

For some reason I thought these buffers included the page data, is that not true? I was expecting the bulk of the records to be dirty page data.

The page data is not stored in this buffer, but it's pointer stored in this buffer(rec->data). This buffer is the bulk of the struct xc_sr_record.

OK, so there are (approximately) as many xc_sr_records as there are buffered dirty pages? I'd expect this would easily reach 1024 in some circumstances (e..g run a fork bomb in the domain or something)

Quoted 17 lines
Quoted 9 lines
Quoted 6 lines

Since you and Andy both have doubts on this, I have to reconsider on this, perhaps there should be no limit. Even if the 1024 limit works for most of the cases, there might be cases that exceed the limit. So I will add another member 'allocated_rec_num' in the context, when the 'buffered_rec_num' exceed the 'allocated_rec_num', I will reallocate the buffer. The initial buffer size will be 1024 records which will work for most cases.

That seems easy enough to be worth doing even if I was wrong about paged data.

done.

Quoted 4 lines

.

#18 lore raw

Re: [PATCH Remus v5 2/2] libxc/restore: implement Remus checkpointed restore

Quoted 41 lines · Ian Campbell
Quoted 40 lines · Yang Hongyang
Quoted 39 lines · Ian Campbell
Quoted 38 lines · Yang Hongyang
Quoted 22 lines · Ian Campbell
Quoted 21 lines · Yang Hongyang

With Remus, the restore flow should be:
the first full migration stream -> { periodically restore stream }

---
   tools/libxc/xc_sr_common.h  |  14 ++++++
   tools/libxc/xc_sr_restore.c | 113 ++++++++++++++++++++++++++++++++++++++++----
   2 files changed, 117 insertions(+), 10 deletions(-)
tools/libxc/xc_sr_common.h +0 -0
index f8121e7..3bf27f1 100644
@@ -208,6 +208,20 @@ struct xc_sr_context
               /* Plain VM, or checkpoints over time. */
               bool checkpointed;
 
Quoted 12 lines

tools/libxc/xc_sr_common.h struct xc_sr_context · line 219

Quoted 9 lines
tools/libxc/xc_sr_common.h +9 -0
+            /* Currently buffering records between a checkpoint */
+            bool buffer_all_records;
+
+/*
+ * With Remus, we buffer the records sent by the primary at checkpoint,
+ * in case the primary will fail, we can recover from the last
+ * checkpoint state.
+ * This should be enough because primary only send dirty pages at
+ * checkpoint.

I'm not sure how it then follows that 1024 buffers is guaranteed to be enough, unless there is something on the sending side arranging it to be so?

There are only few records at every checkpoint in my test, mostly under 10, probably because I don't do much operations in the Guest. I thought This limit can be adjusted later by further testing.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

For some reason I thought these buffers included the page data, is that not true? I was expecting the bulk of the records to be dirty page data.

The page data is not stored in this buffer, but it's pointer stored in this buffer(rec->data). This buffer is the bulk of the struct xc_sr_record.

OK, so there are (approximately) as many xc_sr_records as there are buffered dirty pages?

Every PAGE_DATA record can have as many pages in it as it wishes, subject to the (arbitrary) 8MB max record length.

The sending side will typically put 1024 pages in an individual record.

~Andrew

#19 lore raw

Re: [PATCH Remus v5 2/2] libxc/restore: implement Remus checkpointed restore

In reply to Ian Campbell
Quoted 49 lines · Ian Campbell
Quoted 48 lines · Yang Hongyang
Quoted 45 lines · Ian Campbell
Quoted 38 lines · Yang Hongyang
Quoted 22 lines · Ian Campbell
Quoted 21 lines · Yang Hongyang

With Remus, the restore flow should be:
the first full migration stream -> { periodically restore stream }

---
    tools/libxc/xc_sr_common.h  |  14 ++++++
    tools/libxc/xc_sr_restore.c | 113 ++++++++++++++++++++++++++++++++++++++++----
    2 files changed, 117 insertions(+), 10 deletions(-)
tools/libxc/xc_sr_common.h +0 -0
index f8121e7..3bf27f1 100644
@@ -208,6 +208,20 @@ struct xc_sr_context
                /* Plain VM, or checkpoints over time. */
                bool checkpointed;
 
Quoted 13 lines

tools/libxc/xc_sr_common.h struct xc_sr_context · line 219

Quoted 9 lines
tools/libxc/xc_sr_common.h +9 -0
+            /* Currently buffering records between a checkpoint */
+            bool buffer_all_records;
+
+/*
+ * With Remus, we buffer the records sent by the primary at checkpoint,
+ * in case the primary will fail, we can recover from the last
+ * checkpoint state.
+ * This should be enough because primary only send dirty pages at
+ * checkpoint.

I'm not sure how it then follows that 1024 buffers is guaranteed to be enough, unless there is something on the sending side arranging it to be so?

Quoted 3 lines

There are only few records at every checkpoint in my test, mostly under 10, probably because I don't do much operations in the Guest. I thought This limit can be adjusted later by further testing.

For some reason I thought these buffers included the page data, is that not true? I was expecting the bulk of the records to be dirty page data.

Quoted 6 lines
Quoted 2 lines

The page data is not stored in this buffer, but it's pointer stored in this buffer(rec->data). This buffer is the bulk of the struct xc_sr_record.

OK, so there are (approximately) as many xc_sr_records as there are buffered dirty pages? I'd expect this would easily reach 1024 in some circumstances (e..g run a fork bomb in the domain or something)

No, a record may contain up to 1024 pages, so the record number is less than dirty page number.

Quoted 22 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

Since you and Andy both have doubts on this, I have to reconsider on this, perhaps there should be no limit. Even if the 1024 limit works for most of the cases, there might be cases that exceed the limit. So I will add another member 'allocated_rec_num' in the context, when the 'buffered_rec_num' exceed the 'allocated_rec_num', I will reallocate the buffer. The initial buffer size will be 1024 records which will work for most cases.

Quoted 10 lines
Quoted 2 lines

That seems easy enough to be worth doing even if I was wrong about paged data.

done.

Quoted 4 lines

.

.

Signature · 2 lines
Thanks,
Yang.
#20 lore raw

Re: [PATCH Remus v5 2/2] libxc/restore: implement Remus checkpointed restore

Quoted 54 lines · Yang Hongyang
Quoted 52 lines · Ian Campbell
Quoted 50 lines · Yang Hongyang
Quoted 39 lines · Ian Campbell
Quoted 38 lines · Yang Hongyang
Quoted 35 lines · Ian Campbell
Quoted 20 lines · Yang Hongyang

With Remus, the restore flow should be:
the first full migration stream -> { periodically restore stream }

---
    tools/libxc/xc_sr_common.h  |  14 ++++++
    tools/libxc/xc_sr_restore.c | 113 ++++++++++++++++++++++++++++++++++++++++----
    2 files changed, 117 insertions(+), 10 deletions(-)
tools/libxc/xc_sr_common.h +0 -0
index f8121e7..3bf27f1 100644
@@ -208,6 +208,20 @@ struct xc_sr_context
                /* Plain VM, or checkpoints over time. */
                bool checkpointed;

tools/libxc/xc_sr_common.h struct xc_sr_context · line 219

Quoted 10 lines
tools/libxc/xc_sr_common.h +9 -0
 
+            /* Currently buffering records between a checkpoint */
+            bool buffer_all_records;
+
+/*
+ * With Remus, we buffer the records sent by the primary at checkpoint,
+ * in case the primary will fail, we can recover from the last
+ * checkpoint state.
+ * This should be enough because primary only send dirty pages at
+ * checkpoint.

I'm not sure how it then follows that 1024 buffers is guaranteed to be enough, unless there is something on the sending side arranging it to be so?

Quoted 6 lines
Quoted 3 lines

There are only few records at every checkpoint in my test, mostly under 10, probably because I don't do much operations in the Guest. I thought This limit can be adjusted later by further testing.

For some reason I thought these buffers included the page data, is that not true? I was expecting the bulk of the records to be dirty page data.

The page data is not stored in this buffer, but it's pointer stored in this buffer(rec->data). This buffer is the bulk of the struct xc_sr_record.

Quoted 6 lines
Quoted 3 lines

OK, so there are (approximately) as many xc_sr_records as there are buffered dirty pages? I'd expect this would easily reach 1024 in some circumstances (e..g run a fork bomb in the domain or something)

No, a record may contain up to 1024 pages, so the record number is less than dirty page number.

OK so 1024 records equates to ... <sounds of maths> .... around 4GB of actual data at most (but I suppose not all recs will use the full 1024 pages).

I suppose a guest would be working quite hard to dirty that without retriggering a checkpoint (even with colo's more relaxed approach to resync).

In any case, making the array grow is clearly a good thing to do and you've already done it, so no need to keep thinking about this case ;-)