Skip to contentSkip to conversation

Optimized some code for COLO

PATCH In review leirao 3 participants 8 messages Sep 22, 2020 – Sep 23, 2020 Networking

lore
Share & tools
lore

leirao

author
#0 lore raw

v2 cover Optimized some code for COLO

Optimized some code for COLO and fixed a qemu crash when guest shutdown in COLO mode.

leirao (3):
Optimize seq_sorter function for colo-compare Reduce the time of checkpoint for COLO
Fix the qemu crash when guest shutdown in COLO mode

 migration/ram.c    | 14 +++++++++++++-
 net/colo-compare.c |  6 +-----
 softmmu/vl.c       |  1 +
 3 files changed, 15 insertions(+), 6 deletions(-)

--
1.8.3.1

author
#1 lore raw

PATCH v2 1/3 Optimize seq_sorter function for colo-compare

The seq of tcp has been filled in fill_pkt_tcp_info, it can be used directly here.

---
 net/colo-compare.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
net/colo-compare.c +1 -5
index 3a45d64..86980ce 100644
@@ -196,11 +196,7 @@ static void colo_compare_inconsistency_notify(CompareState *s)
 
 static gint seq_sorter(Packet *a, Packet *b, gpointer data)
 {
-    struct tcp_hdr *atcp, *btcp;
-
-    atcp = (struct tcp_hdr *)(a->transport_header);
-    btcp = (struct tcp_hdr *)(b->transport_header);
-    return ntohl(atcp->th_seq) - ntohl(btcp->th_seq);
+    return a->tcp_seq - b->tcp_seq;
 }
 
 static void fill_pkt_tcp_info(void *data, uint32_t *max_ack)
Signature · 1 line
1.8.3.1
author
#3 lore raw

PATCH v2 2/3 Reduce the time of checkpoint for COLO

In reply to leirao

we should set ram_bulk_stage to false after ram_state_init, otherwise the bitmap will be unused in migration_bitmap_find_dirty. all pages in ram cache will be flushed to the ram of secondary guest for each checkpoint.

---
 migration/ram.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
migration/ram.c +13 -1
index 76d4fee..59ff0cf 100644
@@ -3018,6 +3018,18 @@ static void decompress_data_with_multi_threads(QEMUFile *f,
     qemu_mutex_unlock(&decomp_done_lock);
 }
 
+ /*
+  * we must set ram_bulk_stage to fasle, otherwise in
+  * migation_bitmap_find_dirty the bitmap will be unused and
+  * all the pages in ram cache wil be flushed to the ram of
+  * secondary VM.
+  */
+static void colo_init_ram_state(void)
+{
+    ram_state_init(&ram_state);
+    ram_state->ram_bulk_stage = false;
+}
+
 /*
  * colo cache: this is for secondary VM, we cache the whole
  * memory of the secondary VM, it is need to hold the global lock
@@ -3061,7 +3073,7 @@ int colo_init_ram_cache(void)
         }
     }
 
-    ram_state_init(&ram_state);
+    colo_init_ram_state();
     return 0;
 }
 
Signature · 1 line
1.8.3.1
author
#6 lore raw

PATCH v2 3/3 Fix the qemu crash when guest shutdown in COLO mode

In reply to leirao

In COLO mode, if the startup parameters of QEMU include "no-shutdown", QEMU will crash when the guest shutdown. The root cause is when the guest shutdown, the state of VM will switch COLO to SHUTDOWN. When do checkpoint again, the state will be changed to COLO. But the state switch is undefined in runstate_transitions_def, we should add it. This patch fixes the following:
qemu-system-x86_64: invalid runstate transition: 'shutdown' -> 'colo' Aborted

---
 softmmu/vl.c | 1 +
 1 file changed, 1 insertion(+)
softmmu/vl.c +1 -0
index f7b1034..c21606c 100644
@@ -631,6 +631,7 @@ static const RunStateTransition runstate_transitions_def[] = {
     { RUN_STATE_SHUTDOWN, RUN_STATE_PAUSED },
     { RUN_STATE_SHUTDOWN, RUN_STATE_FINISH_MIGRATE },
     { RUN_STATE_SHUTDOWN, RUN_STATE_PRELAUNCH },
+    { RUN_STATE_SHUTDOWN, RUN_STATE_COLO },
 
     { RUN_STATE_DEBUG, RUN_STATE_SUSPENDED },
     { RUN_STATE_RUNNING, RUN_STATE_SUSPENDED },
Signature · 1 line
1.8.3.1
Reviewed-by on v2 1/3
#2 lore raw

RE: [PATCH v2 1/3] Optimize seq_sorter function for colo-compare

In reply to leirao
Quoted 11 lines

-----Original Message-----
From: Rao, Lei <[email protected]>
Sent: Tuesday, September 22, 2020 5:25 PM
To: Zhang, Chen <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; Rao, Lei <[email protected]>
Subject: [PATCH v2 1/3] Optimize seq_sorter function for colo-compare

Quoted 3 lines

The seq of tcp has been filled in fill_pkt_tcp_info, it can be used directly here.

By the way, please add Zhijian's reviewed-by in new version of patches.

Thanks
Zhang Chen

Quoted 23 lines
---
 net/colo-compare.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
net/colo-compare.c index renamed from net/colo-compare.c +0 -0

3a45d64..86980ce 100644

net/colo-compare.c +1 -6
@@ -196,11 +196,7 @@ static void
 colo_compare_inconsistency_notify(CompareState *s)
 
 static gint seq_sorter(Packet *a, Packet *b, gpointer data)  {
-    struct tcp_hdr *atcp, *btcp;
-
-    atcp = (struct tcp_hdr *)(a->transport_header);
-    btcp = (struct tcp_hdr *)(b->transport_header);
-    return ntohl(atcp->th_seq) - ntohl(btcp->th_seq);
+    return a->tcp_seq - b->tcp_seq;
 }
 
 static void fill_pkt_tcp_info(void *data, uint32_t *max_ack)
--

1.8.3.1

Reviewed-by on v2 2/3
#4 lore raw

RE: [PATCH v2 2/3] Reduce the time of checkpoint for COLO

In reply to leirao
Quoted 11 lines

-----Original Message-----
From: Rao, Lei <[email protected]>
Sent: Tuesday, September 22, 2020 5:25 PM
To: Zhang, Chen <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; Rao, Lei <[email protected]>
Subject: [PATCH v2 2/3] Reduce the time of checkpoint for COLO

Quoted 6 lines

we should set ram_bulk_stage to false after ram_state_init, otherwise the bitmap will be unused in migration_bitmap_find_dirty.
all pages in ram cache will be flushed to the ram of secondary guest for each checkpoint.

Thanks
Zhang Chen

Quoted 38 lines
---
 migration/ram.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
migration/ram.c +12 -0
@@ -3018,6 +3018,18 @@ static void
 decompress_data_with_multi_threads(QEMUFile *f,
     qemu_mutex_unlock(&decomp_done_lock);
 }
 
+ /*
+  * we must set ram_bulk_stage to fasle, otherwise in
+  * migation_bitmap_find_dirty the bitmap will be unused and
+  * all the pages in ram cache wil be flushed to the ram of
+  * secondary VM.
+  */
+static void colo_init_ram_state(void)
+{
+    ram_state_init(&ram_state);
+    ram_state->ram_bulk_stage = false;
+}
+
 /*
  * colo cache: this is for secondary VM, we cache the whole

* memory of the secondary VM, it is need to hold the global lock @@ -
3061,7 +3073,7 @@ int colo_init_ram_cache(void)

         }
     }
migration/ram.c +1 -2
-    ram_state_init(&ram_state);
+    colo_init_ram_state();
     return 0;
 }
 
--

1.8.3.1

Reviewed-by on v2 3/3
#7 lore raw

RE: [PATCH v2 3/3] Fix the qemu crash when guest shutdown in COLO mode

In reply to leirao
Quoted 21 lines

-----Original Message-----
From: Rao, Lei <[email protected]>
Sent: Tuesday, September 22, 2020 5:25 PM
To: Zhang, Chen <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; Rao, Lei <[email protected]>
Subject: [PATCH v2 3/3] Fix the qemu crash when guest shutdown in COLO mode

In COLO mode, if the startup parameters of QEMU include "no-shutdown", QEMU will crash when the guest shutdown. The root cause is when the guest shutdown, the state of VM will switch COLO to SHUTDOWN. When do checkpoint again, the state will be changed to COLO. But the state switch is undefined in runstate_transitions_def, we should add it.
This patch fixes the following:
qemu-system-x86_64: invalid runstate transition: 'shutdown' -> 'colo' Aborted

Quoted 1 line

Thanks
Zhang Chen

Quoted 18 lines
---
 softmmu/vl.c | 1 +
 1 file changed, 1 insertion(+)
softmmu/vl.c +1 -0
@@ -631,6 +631,7 @@ static const RunStateTransition
 runstate_transitions_def[] = {
     { RUN_STATE_SHUTDOWN, RUN_STATE_PAUSED },
     { RUN_STATE_SHUTDOWN, RUN_STATE_FINISH_MIGRATE },
     { RUN_STATE_SHUTDOWN, RUN_STATE_PRELAUNCH },
+    { RUN_STATE_SHUTDOWN, RUN_STATE_COLO },
 
     { RUN_STATE_DEBUG, RUN_STATE_SUSPENDED },

{ RUN_STATE_RUNNING, RUN_STATE_SUSPENDED },
--
1.8.3.1

Reviewed-by on v2 2/3
#5 lore raw

Re: [PATCH v2 2/3] Reduce the time of checkpoint for COLO

In reply to leirao
Quoted 15 lines · leirao

we should set ram_bulk_stage to false after ram_state_init, otherwise the bitmap will be unused in migration_bitmap_find_dirty. all pages in ram cache will be flushed to the ram of secondary guest for each checkpoint.

---
  migration/ram.c | 14 +++++++++++++-
  1 file changed, 13 insertions(+), 1 deletion(-)
migration/ram.c +0 -0
index 76d4fee..59ff0cf 100644

migration/ram.c static void decompress_data_with_multi_threads(QEMUFile *f, · line 3022

Quoted 5 lines
migration/ram.c +2 -0
@@ -3018,6 +3018,18 @@ static void decompress_data_with_multi_threads(QEMUFile *f,
      qemu_mutex_unlock(&decomp_done_lock);
  }
 
+ /*
+  * we must set ram_bulk_stage to fasle, otherwise in

a typo: s/fasle/false

Quoted 22 lines
migration/ram.c +11 -1
+  * migation_bitmap_find_dirty the bitmap will be unused and
+  * all the pages in ram cache wil be flushed to the ram of
+  * secondary VM.
+  */
+static void colo_init_ram_state(void)
+{
+    ram_state_init(&ram_state);
+    ram_state->ram_bulk_stage = false;
+}
+
  /*
   * colo cache: this is for secondary VM, we cache the whole
   * memory of the secondary VM, it is need to hold the global lock
@@ -3061,7 +3073,7 @@ int colo_init_ram_cache(void)
          }
      }
 
-    ram_state_init(&ram_state);
+    colo_init_ram_state();
      return 0;
  }