Skip to contentSkip to conversation

migration/colo: Optimize COLO framework code

PATCH Superseded Zhang Chen 2 participants 6 messages Jun 4, 2020 – Jun 7, 2020

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Zhang Chen

author
#0 lore raw

v2 cover migration/colo: Optimize COLO framework code

From: Zhang Chen <[email protected]>

This series optimize some code of COLO, please review.

Zhang Chen (2):
migration/colo: Optimize COLO boot code path
migration/colo: Update checkpoint time lately

 migration/colo.c      |  7 ++-----
 migration/migration.c | 17 ++++++++++-------
 2 files changed, 12 insertions(+), 12 deletions(-)
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH v2 1/2 migration/colo: Optimize COLO boot code path

From: Zhang Chen <[email protected]>

No need to reuse MIGRATION_STATUS_ACTIVE boot COLO.

---
 migration/colo.c      |  2 --
 migration/migration.c | 17 ++++++++++-------
 2 files changed, 10 insertions(+), 9 deletions(-)
migration/colo.c +0 -2
index ea7d1e9d4e..91c76789fa 100644
@@ -670,8 +670,6 @@ void migrate_start_colo_process(MigrationState *s)
                                 colo_checkpoint_notify, s);
 
     qemu_sem_init(&s->colo_exit_sem, 0);
-    migrate_set_state(&s->state, MIGRATION_STATUS_ACTIVE,
-                      MIGRATION_STATUS_COLO);
     colo_process_checkpoint(s);
     qemu_mutex_lock_iothread();
 }
migration/migration.c +10 -7
index b63ad91d34..7f3f82a715 100644
@@ -2972,7 +2972,10 @@ static void migration_completion(MigrationState *s)
         goto fail_invalidate;
     }
 
-    if (!migrate_colo_enabled()) {
+    if (migrate_colo_enabled()) {
+        migrate_set_state(&s->state, current_active_state,
+                          MIGRATION_STATUS_COLO);
+    } else {
         migrate_set_state(&s->state, current_active_state,
                           MIGRATION_STATUS_COMPLETED);
     }
@@ -3304,12 +3307,7 @@ static void migration_iteration_finish(MigrationState *s)
         migration_calculate_complete(s);
         runstate_set(RUN_STATE_POSTMIGRATE);
         break;
-
-    case MIGRATION_STATUS_ACTIVE:
-        /*
-         * We should really assert here, but since it's during
-         * migration, let's try to reduce the usage of assertions.
-         */
+    case MIGRATION_STATUS_COLO:
         if (!migrate_colo_enabled()) {
             error_report("%s: critical error: calling COLO code without "
                          "COLO enabled", __func__);
@@ -3319,6 +3317,11 @@ static void migration_iteration_finish(MigrationState *s)
          * Fixme: we will run VM in COLO no matter its old running state.
          * After exited COLO, we will keep running.
          */
+    case MIGRATION_STATUS_ACTIVE:
+        /*
+         * We should really assert here, but since it's during
+         * migration, let's try to reduce the usage of assertions.
+         */
         s->vm_was_running = true;
         /* Fallthrough */
     case MIGRATION_STATUS_FAILED:
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH V2 1/2] migration/colo: Optimize COLO boot code path

Quoted 55 lines · On Thu, 4 Jun 2020 16:55:32 +0800 Zhang Chen <[email protected] > wrote:

From: Zhang Chen <[email protected]>

No need to reuse MIGRATION_STATUS_ACTIVE boot COLO.

---
 migration/colo.c      |  2 --
 migration/migration.c | 17 ++++++++++-------
 2 files changed, 10 insertions(+), 9 deletions(-)
migration/colo.c +0 -2
index ea7d1e9d4e..91c76789fa 100644
@@ -670,8 +670,6 @@ void migrate_start_colo_process(MigrationState *s)
                                 colo_checkpoint_notify, s);
 
     qemu_sem_init(&s->colo_exit_sem, 0);
-    migrate_set_state(&s->state, MIGRATION_STATUS_ACTIVE,
-                      MIGRATION_STATUS_COLO);
     colo_process_checkpoint(s);
     qemu_mutex_lock_iothread();
 }
migration/migration.c +5 -7
index b63ad91d34..7f3f82a715 100644
@@ -2972,7 +2972,10 @@ static void migration_completion(MigrationState *s)
         goto fail_invalidate;
     }
 
-    if (!migrate_colo_enabled()) {
+    if (migrate_colo_enabled()) {
+        migrate_set_state(&s->state, current_active_state,
+                          MIGRATION_STATUS_COLO);
+    } else {
         migrate_set_state(&s->state, current_active_state,
                           MIGRATION_STATUS_COMPLETED);
     }
@@ -3304,12 +3307,7 @@ static void migration_iteration_finish(MigrationState *s)
         migration_calculate_complete(s);
         runstate_set(RUN_STATE_POSTMIGRATE);
         break;
-
-    case MIGRATION_STATUS_ACTIVE:
-        /*
-         * We should really assert here, but since it's during
-         * migration, let's try to reduce the usage of assertions.
-         */
+    case MIGRATION_STATUS_COLO:
         if (!migrate_colo_enabled()) {
             error_report("%s: critical error: calling COLO code without "
                          "COLO enabled", __func__);

migration/migration.c static void migration_iteration_finish(MigrationState *s) · line 3324

Quoted 8 lines
migration/migration.c +5 -0
@@ -3319,6 +3317,11 @@ static void migration_iteration_finish(MigrationState *s)
          * Fixme: we will run VM in COLO no matter its old running state.
          * After exited COLO, we will keep running.
          */
+    case MIGRATION_STATUS_ACTIVE:
+        /*
+         * We should really assert here, but since it's during
+         * migration, let's try to reduce the usage of assertions.
+         */

I think this case should be removed, because arriving here with MIGRATION_STATUS_ACTIVE is invalid. It should be handled by the default case.

Regards,
Lukas Straub

Quoted 3 lines
migration/migration.c +0 -0
         s->vm_was_running = true;
         /* Fallthrough */
     case MIGRATION_STATUS_FAILED:
#3 lore raw

RE: [PATCH V2 1/2] migration/colo: Optimize COLO boot code path

Quoted 80 lines

-----Original Message-----
From: Lukas Straub <[email protected]>
Sent: Sunday, June 7, 2020 3:57 AM
To: Zhang, Chen <[email protected]>
Cc: Dr . David Alan Gilbert <[email protected]>; qemu-dev <qemu- [email protected]>; Zhanghailiang <[email protected]>; Zhang Chen <[email protected]>
Subject: Re: [PATCH V2 1/2] migration/colo: Optimize COLO boot code path

migration/migration.c static void migration_completion(MigrationState

Quoted 29 lines · On Thu, 4 Jun 2020 16:55:32 +0800 Zhang Chen <[email protected] > wrote:

From: Zhang Chen <[email protected]>

No need to reuse MIGRATION_STATUS_ACTIVE boot COLO.

---
 migration/colo.c      |  2 --
 migration/migration.c | 17 ++++++++++-------
 2 files changed, 10 insertions(+), 9 deletions(-)
migration/colo.c index renamed from migration/colo.c +0 -0

ea7d1e9d4e..91c76789fa 100644

migration/colo.c +0 -2
@@ -670,8 +670,6 @@ void migrate_start_colo_process(MigrationState *s)
                                 colo_checkpoint_notify, s);
 
     qemu_sem_init(&s->colo_exit_sem, 0);
-    migrate_set_state(&s->state, MIGRATION_STATUS_ACTIVE,
-                      MIGRATION_STATUS_COLO);
     colo_process_checkpoint(s);
     qemu_mutex_lock_iothread();
 }
migration/migration.c index renamed from migration/migration.c +0 -0

b63ad91d34..7f3f82a715 100644

migration/migration.c +0 -0
@@ -2972,7 +2972,10 @@ static void migration_completion(MigrationState

*s)

migration/migration.c static void

Quoted 12 lines
migration/migration.c +4 -1
         goto fail_invalidate;
     }
 
-    if (!migrate_colo_enabled()) {
+    if (migrate_colo_enabled()) {
+        migrate_set_state(&s->state, current_active_state,
+                          MIGRATION_STATUS_COLO);
+    } else {
         migrate_set_state(&s->state, current_active_state,
                           MIGRATION_STATUS_COMPLETED);
     }
@@ -3304,12 +3307,7 @@ static void

migration_iteration_finish(MigrationState *s)

Quoted 12 lines
migration/migration.c +1 -6
         migration_calculate_complete(s);
         runstate_set(RUN_STATE_POSTMIGRATE);
         break;
-
-    case MIGRATION_STATUS_ACTIVE:
-        /*
-         * We should really assert here, but since it's during
-         * migration, let's try to reduce the usage of assertions.
-         */
+    case MIGRATION_STATUS_COLO:
         if (!migrate_colo_enabled()) {
             error_report("%s: critical error: calling COLO code without "

migration/migration.c static void migration_iteration_finish(MigrationState *s)

Quoted 10 lines
migration/migration.c +6 -0
                          "COLO enabled", __func__); @@ -3319,6
+3317,11 @@ static void migration_iteration_finish(MigrationState *s)
          * Fixme: we will run VM in COLO no matter its old running state.
          * After exited COLO, we will keep running.
          */
+    case MIGRATION_STATUS_ACTIVE:
+        /*
+         * We should really assert here, but since it's during
+         * migration, let's try to reduce the usage of assertions.
+         */
Quoted 3 lines

I think this case should be removed, because arriving here with MIGRATION_STATUS_ACTIVE is invalid. It should be handled by the default case.

OK, looks good here. I will add this part in V3.

Thanks
Zhang Chen

Quoted 7 lines

Regards,
Lukas Straub

Quoted 3 lines
         s->vm_was_running = true;
         /* Fallthrough */
     case MIGRATION_STATUS_FAILED:
author
#4 lore raw

PATCH v2 2/2 migration/colo: Update checkpoint time lately

In reply to Zhang Chen

From: Zhang Chen <[email protected]>

Previous operation(like vm_start and replication_start_all) will consume extra time for first forced synchronization, so reduce it in this patch.

---
 migration/colo.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
migration/colo.c +2 -3
index 91c76789fa..2b837e1255 100644
@@ -532,7 +532,6 @@ static void colo_process_checkpoint(MigrationState *s)
 {
     QIOChannelBuffer *bioc;
     QEMUFile *fb = NULL;
-    int64_t current_time = qemu_clock_get_ms(QEMU_CLOCK_HOST);
     Error *local_err = NULL;
     int ret;
 
@@ -581,8 +580,8 @@ static void colo_process_checkpoint(MigrationState *s)
     qemu_mutex_unlock_iothread();
     trace_colo_vm_state_change("stop", "run");
 
-    timer_mod(s->colo_delay_timer,
-            current_time + s->parameters.x_checkpoint_delay);
+    timer_mod(s->colo_delay_timer, qemu_clock_get_ms(QEMU_CLOCK_HOST) +
+              s->parameters.x_checkpoint_delay);
 
     while (s->state == MIGRATION_STATUS_COLO) {
         if (failover_get_state() != FAILOVER_STATUS_NONE) {
Signature · 1 line
2.17.1
Reviewed-by Tested-by on v2 2/2
#5 lore raw

Re: [PATCH V2 2/2] migration/colo: Update checkpoint time lately

Quoted 8 lines · On Thu, 4 Jun 2020 16:55:33 +0800 Zhang Chen <[email protected] > wrote:

From: Zhang Chen <[email protected]>

Previous operation(like vm_start and replication_start_all) will consume extra time for first forced synchronization, so reduce it in this patch.

---

Hi,
Looks good and works well in my tests.

Regards,
Lukas Straub