Skip to contentSkip to conversation

Optimized some code for COLO

PATCH Superseded leirao 2 participants 7 messages Sep 19, 2020 – Sep 22, 2020 Networking

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

leirao

author
#0 lore raw

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    | 12 ++++++++++++
 net/colo-compare.c |  6 +-----
 softmmu/vl.c       |  1 +
 3 files changed, 14 insertions(+), 5 deletions(-)

--
1.8.3.1

author
#1 lore raw

PATCH 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
Reviewed-by on v1 1/3
#2 lore raw

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

Quoted 4 lines · leirao

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

Quoted 21 lines
---
  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)
author
#3 lore raw

PATCH 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 | 12 ++++++++++++
 1 file changed, 12 insertions(+)
migration/ram.c +12 -0
index 76d4fee..6a2b6c1 100644
@@ -3019,6 +3019,17 @@ static void decompress_data_with_multi_threads(QEMUFile *f,
 }
 
 /*
+ * 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_set_ram_state(RAMState *rsp)
+{
+    rsp->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
  * to call this helper.
@@ -3062,6 +3073,7 @@ int colo_init_ram_cache(void)
     }
 
     ram_state_init(&ram_state);
+    colo_set_ram_state(ram_state);
     return 0;
 }
 
Signature · 1 line
1.8.3.1
#4 lore raw

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

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 | 12 ++++++++++++
  1 file changed, 12 insertions(+)
migration/ram.c +0 -0
index 76d4fee..6a2b6c1 100644

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

Quoted 9 lines
migration/ram.c +6 -0
@@ -3019,6 +3019,17 @@ static void decompress_data_with_multi_threads(QEMUFile *f,
  }
 
  /*
+ * 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_set_ram_state(RAMState *rsp)

this function name is too general, how about

colo_init_ram_state(ram_state)

{
    ram_state_init(&ram_state);
    ram_state->ram_bulk_stage = false;
}

Thanks
Zhijian

Quoted 16 lines
migration/ram.c +6 -0
+{
+    rsp->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
   * to call this helper.
@@ -3062,6 +3073,7 @@ int colo_init_ram_cache(void)
      }
 
      ram_state_init(&ram_state);
+    colo_set_ram_state(ram_state);
      return 0;
  }
 
author
#5 lore raw

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

Got it.
It looks more reasonable. Will be changed in V2.

Thanks,
Lei.

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

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 | 12 ++++++++++++
  1 file changed, 12 insertions(+)
migration/ram.c index 76d4fee..6a2b6c1 renamed from migration/ram.c +0 -0

100644

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

Quoted 9 lines
migration/ram.c +6 -0
@@ -3019,6 +3019,17 @@ static void decompress_data_with_multi_threads(QEMUFile *f,
  }
 
  /*
+ * 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_set_ram_state(RAMState *rsp)

this function name is too general, how about

colo_init_ram_state(ram_state)

{
     ram_state_init(&ram_state);
     ram_state->ram_bulk_stage = false;
}

Thanks
Zhijian

Quoted 16 lines
migration/ram.c +6 -0
+{
+    rsp->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
   * to call this helper.
@@ -3062,6 +3073,7 @@ int colo_init_ram_cache(void)
      }
 
      ram_state_init(&ram_state);
+    colo_set_ram_state(ram_state);
      return 0;
  }
 
author
#6 lore raw

PATCH 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