Skip to contentSkip to conversation

migration: always initial RAMBlock.bmap to 1 for new migration

PATCH In review Ivan Ren 4 participants 7 messages Jul 14, 2019 – Aug 2, 2019

lore
Share & tools
lore

Ivan Ren

author
#0 lore raw

PATCH 1/1 migration: always initial RAMBlock.bmap to 1 for new migration

Reproduce the problem:
migrate
migrate_cancel
migrate

Error happen for memory migration

The reason as follows:
1. qemu start, ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION] all set to 1 by a series of cpu_physical_memory_set_dirty_range
2. migration start:ram_init_bitmaps
- memory_global_dirty_log_start: begin log diry
- memory_global_dirty_log_sync: sync dirty bitmap to ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION]
- migration_bitmap_sync_range: sync ram_list. dirty_memory[DIRTY_MEMORY_MIGRATION] to RAMBlock.bmap and ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION] is set to zero
3. migration data...
4. migrate_cancel, will stop log dirty
5. migration start:ram_init_bitmaps
- memory_global_dirty_log_start: begin log diry
- memory_global_dirty_log_sync: sync dirty bitmap to ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION]
- migration_bitmap_sync_range: sync ram_list. dirty_memory[DIRTY_MEMORY_MIGRATION] to RAMBlock.bmap and ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION] is set to zero

Here RAMBlock.bmap only have new logged dirty pages, don't contain the whole guest pages.

---
 migration/ram.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
migration/ram.c +8 -7
index 908517fc2b..bbebaee0c1 100644
@@ -3173,11 +3173,11 @@ static int ram_state_init(RAMState **rsp)
     QSIMPLEQ_INIT(&(*rsp)->src_page_requests);
 
     /*
+     * Count the total number of pages used by ram blocks not including any
+     * gaps due to alignment or unplugs.
      * This must match with the initial values of dirty bitmap.
-     * Currently we initialize the dirty bitmap to all zeros so
-     * here the total dirty page count is zero.
      */
-    (*rsp)->migration_dirty_pages = 0;
+    (*rsp)->migration_dirty_pages = ram_bytes_total() >> TARGET_PAGE_BITS;
     ram_state_reset(*rsp);
 
     return 0;
@@ -3196,12 +3196,13 @@ static void ram_list_init_bitmaps(void)
              * The initial dirty bitmap for migration must be set with all
              * ones to make sure we'll migrate every guest RAM page to
              * destination.
-             * Here we didn't set RAMBlock.bmap simply because it is already
-             * set in ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION] in
-             * ram_block_add, and that's where we'll sync the dirty bitmaps.
-             * Here setting RAMBlock.bmap would be fine too but not necessary.
+             * Here we set RAMBlock.bmap all to 1 because when rebegin a
+             * new migration after a failed migration, ram_list.
+             * dirty_memory[DIRTY_MEMORY_MIGRATION] don't include the whole
+             * guest memory.
              */
             block->bmap = bitmap_new(pages);
+            bitmap_set(block->bmap, 0, pages);
             if (migrate_postcopy_ram()) {
                 block->unsentmap = bitmap_new(pages);
                 bitmap_set(block->unsentmap, 0, pages);
Signature · 1 line
2.17.2 (Apple Git-113)
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Ivan Ren

Reproduce the problem:
migrate
migrate_cancel
migrate

Error happen for memory migration

Can mention "this mostly revert 0315851938 but with comments kept" when merge...

Quoted 21 lines

The reason as follows:
1. qemu start, ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION] all set to 1 by a series of cpu_physical_memory_set_dirty_range
2. migration start:ram_init_bitmaps
- memory_global_dirty_log_start: begin log diry
- memory_global_dirty_log_sync: sync dirty bitmap to ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION]
- migration_bitmap_sync_range: sync ram_list. dirty_memory[DIRTY_MEMORY_MIGRATION] to RAMBlock.bmap and ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION] is set to zero
3. migration data...
4. migrate_cancel, will stop log dirty
5. migration start:ram_init_bitmaps
- memory_global_dirty_log_start: begin log diry
- memory_global_dirty_log_sync: sync dirty bitmap to ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION]
- migration_bitmap_sync_range: sync ram_list. dirty_memory[DIRTY_MEMORY_MIGRATION] to RAMBlock.bmap and ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION] is set to zero

Quoted 2 lines

Here RAMBlock.bmap only have new logged dirty pages, don't contain the whole guest pages.

Fixes 03158519384f158
Quoted 2 lines

I think this is a bit severe and should be rc2 material. Dave/Juan?

Thanks,

Signature · 1 line
Peter Xu
#2 lore raw
Quoted 35 lines · * Peter Xu ([email protected]) wrote:
Quoted 6 lines · Ivan Ren

Reproduce the problem:
migrate
migrate_cancel
migrate

Error happen for memory migration

Can mention "this mostly revert 0315851938 but with comments kept" when merge...

Quoted 21 lines

The reason as follows:
1. qemu start, ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION] all set to 1 by a series of cpu_physical_memory_set_dirty_range
2. migration start:ram_init_bitmaps
- memory_global_dirty_log_start: begin log diry
- memory_global_dirty_log_sync: sync dirty bitmap to ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION]
- migration_bitmap_sync_range: sync ram_list. dirty_memory[DIRTY_MEMORY_MIGRATION] to RAMBlock.bmap and ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION] is set to zero
3. migration data...
4. migrate_cancel, will stop log dirty
5. migration start:ram_init_bitmaps
- memory_global_dirty_log_start: begin log diry
- memory_global_dirty_log_sync: sync dirty bitmap to ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION]
- migration_bitmap_sync_range: sync ram_list. dirty_memory[DIRTY_MEMORY_MIGRATION] to RAMBlock.bmap and ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION] is set to zero

Quoted 2 lines

Here RAMBlock.bmap only have new logged dirty pages, don't contain the whole guest pages.

Quoted 8 lines
Fixes 03158519384f158
Quoted 2 lines

I think this is a bit severe and should be rc2 material. Dave/Juan?

Yes agreed; I've added it to the planning/4.1 page.

Quoted 4 lines

Thanks,

Signature · 1 line
Peter Xu

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#3 lore raw
In reply to Ivan Ren
Quoted 6 lines · * Ivan Ren ([email protected]) wrote:

Reproduce the problem:
migrate
migrate_cancel
migrate

Error happen for memory migration

Can we fix this by just reverting 03158519384 ?

Dave

Quoted 68 lines

The reason as follows:
1. qemu start, ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION] all set to 1 by a series of cpu_physical_memory_set_dirty_range
2. migration start:ram_init_bitmaps
- memory_global_dirty_log_start: begin log diry
- memory_global_dirty_log_sync: sync dirty bitmap to ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION]
- migration_bitmap_sync_range: sync ram_list. dirty_memory[DIRTY_MEMORY_MIGRATION] to RAMBlock.bmap and ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION] is set to zero
3. migration data...
4. migrate_cancel, will stop log dirty
5. migration start:ram_init_bitmaps
- memory_global_dirty_log_start: begin log diry
- memory_global_dirty_log_sync: sync dirty bitmap to ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION]
- migration_bitmap_sync_range: sync ram_list. dirty_memory[DIRTY_MEMORY_MIGRATION] to RAMBlock.bmap and ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION] is set to zero

Here RAMBlock.bmap only have new logged dirty pages, don't contain the whole guest pages.

---
 migration/ram.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
migration/ram.c +8 -7
index 908517fc2b..bbebaee0c1 100644
@@ -3173,11 +3173,11 @@ static int ram_state_init(RAMState **rsp)
     QSIMPLEQ_INIT(&(*rsp)->src_page_requests);
 
     /*
+     * Count the total number of pages used by ram blocks not including any
+     * gaps due to alignment or unplugs.
      * This must match with the initial values of dirty bitmap.
-     * Currently we initialize the dirty bitmap to all zeros so
-     * here the total dirty page count is zero.
      */
-    (*rsp)->migration_dirty_pages = 0;
+    (*rsp)->migration_dirty_pages = ram_bytes_total() >> TARGET_PAGE_BITS;
     ram_state_reset(*rsp);
 
     return 0;
@@ -3196,12 +3196,13 @@ static void ram_list_init_bitmaps(void)
              * The initial dirty bitmap for migration must be set with all
              * ones to make sure we'll migrate every guest RAM page to
              * destination.
-             * Here we didn't set RAMBlock.bmap simply because it is already
-             * set in ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION] in
-             * ram_block_add, and that's where we'll sync the dirty bitmaps.
-             * Here setting RAMBlock.bmap would be fine too but not necessary.
+             * Here we set RAMBlock.bmap all to 1 because when rebegin a
+             * new migration after a failed migration, ram_list.
+             * dirty_memory[DIRTY_MEMORY_MIGRATION] don't include the whole
+             * guest memory.
              */
             block->bmap = bitmap_new(pages);
+            bitmap_set(block->bmap, 0, pages);
             if (migrate_postcopy_ram()) {
                 block->unsentmap = bitmap_new(pages);
                 bitmap_set(block->unsentmap, 0, pages);
Signature · 1 line
2.17.2 (Apple Git-113)

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

Reviewed-by on v1 1/1
#4 lore raw
In reply to Ivan Ren

Thanks, I didn't notice this case.

Quoted 5 lines · Ivan Ren

Reproduce the problem:
migrate
migrate_cancel
migrate

Quoted 7 lines

Error happen for memory migration

The reason as follows:
1. qemu start, ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION] all set to 1 by a series of cpu_physical_memory_set_dirty_range
2. migration start:ram_init_bitmaps
- memory_global_dirty_log_start: begin log diry

s/diry/dirty/

Quoted 9 lines

- memory_global_dirty_log_sync: sync dirty bitmap to ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION]
- migration_bitmap_sync_range: sync ram_list. dirty_memory[DIRTY_MEMORY_MIGRATION] to RAMBlock.bmap and ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION] is set to zero
3. migration data...
4. migrate_cancel, will stop log dirty
5. migration start:ram_init_bitmaps
- memory_global_dirty_log_start: begin log diry

same as above

Quoted 34 lines

- memory_global_dirty_log_sync: sync dirty bitmap to ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION]
- migration_bitmap_sync_range: sync ram_list. dirty_memory[DIRTY_MEMORY_MIGRATION] to RAMBlock.bmap and ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION] is set to zero

Here RAMBlock.bmap only have new logged dirty pages, don't contain the whole guest pages.

---
migration/ram.c | 15 ++++++++-------

1 file changed, 8 insertions(+), 7 deletions(-)
migration/ram.c +3 -3
index 908517fc2b..bbebaee0c1 100644
@@ -3173,11 +3173,11 @@ static int ram_state_init(RAMState **rsp)
    QSIMPLEQ_INIT(&(*rsp)->src_page_requests);
 
    /*
+     * Count the total number of pages used by ram blocks not including any
+     * gaps due to alignment or unplugs.
     * This must match with the initial values of dirty bitmap.
-     * Currently we initialize the dirty bitmap to all zeros so
-     * here the total dirty page count is zero.
     */
-    (*rsp)->migration_dirty_pages = 0;
+    (*rsp)->migration_dirty_pages = ram_bytes_total() >> TARGET_PAGE_BITS;
    ram_state_reset(*rsp);
 
    return 0;

migration/ram.c static void ram_list_init_bitmaps(void) · line 3200

Quoted 9 lines
migration/ram.c +2 -4
@@ -3196,12 +3196,13 @@ static void ram_list_init_bitmaps(void)
             * The initial dirty bitmap for migration must be set with all
             * ones to make sure we'll migrate every guest RAM page to
             * destination.
-             * Here we didn't set RAMBlock.bmap simply because it is already
-             * set in ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION] in
-             * ram_block_add, and that's where we'll sync the dirty bitmaps.
-             * Here setting RAMBlock.bmap would be fine too but not necessary.
+             * Here we set RAMBlock.bmap all to 1 because when rebegin a
+             * new migration after a failed migration, ram_list.

It is after failure or cancel?

Quoted 11 lines
migration/ram.c +3 -0
+             * dirty_memory[DIRTY_MEMORY_MIGRATION] don't include the whole
+             * guest memory.
             */
            block->bmap = bitmap_new(pages);
+            bitmap_set(block->bmap, 0, pages);
            if (migrate_postcopy_ram()) {
                block->unsentmap = bitmap_new(pages);
                bitmap_set(block->unsentmap, 0, pages);
Signature · 1 line
2.17.2 (Apple Git-113)
Signature · 2 lines
Wei Yang
Help you, Help me
author
#5 lore raw
Quoted 1 line
Quoted 1 line

- * Here we didn't set RAMBlock.bmap simply because it is

already

Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +0 -2
-             * set in ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION] in
-             * ram_block_add, and that's where we'll sync the dirty

bitmaps.

Quoted 1 line
Quoted 1 line

- * Here setting RAMBlock.bmap would be fine too but not

necessary.

Quoted 4 lines

migration/ram.c static void ram_list_init_bitmaps(void) · line 3200

Quoted 2 lines
migration/ram.c +2 -0
+             * Here we set RAMBlock.bmap all to 1 because when rebegin a
+             * new migration after a failed migration, ram_list.

It is after failure or cancel?

Here we can treat cancel as a special fail.

Thanks.

Quoted 102 lines · Wei Yang

Thanks, I didn't notice this case.

Quoted 5 lines · Ivan Ren

Reproduce the problem:
migrate
migrate_cancel
migrate

Quoted 7 lines

Error happen for memory migration

The reason as follows:
1. qemu start, ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION] all set to 1 by a series of cpu_physical_memory_set_dirty_range
2. migration start:ram_init_bitmaps
- memory_global_dirty_log_start: begin log diry

s/diry/dirty/

Quoted 9 lines

- memory_global_dirty_log_sync: sync dirty bitmap to ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION]
- migration_bitmap_sync_range: sync ram_list. dirty_memory[DIRTY_MEMORY_MIGRATION] to RAMBlock.bmap and ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION] is set to zero
3. migration data...
4. migrate_cancel, will stop log dirty
5. migration start:ram_init_bitmaps
- memory_global_dirty_log_start: begin log diry

same as above

Quoted 19 lines

- memory_global_dirty_log_sync: sync dirty bitmap to ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION]
- migration_bitmap_sync_range: sync ram_list. dirty_memory[DIRTY_MEMORY_MIGRATION] to RAMBlock.bmap and ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION] is set to zero

Here RAMBlock.bmap only have new logged dirty pages, don't contain the whole guest pages.

---
migration/ram.c | 15 ++++++++-------

1 file changed, 8 insertions(+), 7 deletions(-)
migration/ram.c +0 -0
index 908517fc2b..bbebaee0c1 100644

migration/ram.c static int ram_state_init(RAMState **rsp) · line 3176

Quoted 4 lines
migration/ram.c +1 -0
@@ -3173,11 +3173,11 @@ static int ram_state_init(RAMState **rsp)
    QSIMPLEQ_INIT(&(*rsp)->src_page_requests);
 
    /*
+     * Count the total number of pages used by ram blocks not including

any

migration/ram.c static int ram_state_init(RAMState **rsp)

Quoted 7 lines
migration/ram.c +2 -3
+     * gaps due to alignment or unplugs.
     * This must match with the initial values of dirty bitmap.
-     * Currently we initialize the dirty bitmap to all zeros so
-     * here the total dirty page count is zero.
     */
-    (*rsp)->migration_dirty_pages = 0;
+    (*rsp)->migration_dirty_pages = ram_bytes_total() >>

TARGET_PAGE_BITS;

migration/ram.c static void ram_list_init_bitmaps(void) · line 3196

Quoted 5 lines
migration/ram.c +0 -0
    ram_state_reset(*rsp);
 
    return 0;
@@ -3196,12 +3196,13 @@ static void ram_list_init_bitmaps(void)
             * The initial dirty bitmap for migration must be set with

all

migration/ram.c static void ram_list_init_bitmaps(void)

Quoted 3 lines
migration/ram.c +0 -1
             * ones to make sure we'll migrate every guest RAM page to
             * destination.
-             * Here we didn't set RAMBlock.bmap simply because it is

already

migration/ram.c static void ram_list_init_bitmaps(void) · line 3201

Quoted 2 lines
migration/ram.c +0 -2
-             * set in ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION] in
-             * ram_block_add, and that's where we'll sync the dirty

bitmaps.

migration/ram.c static void ram_list_init_bitmaps(void) · line 3202

Quoted 1 line
migration/ram.c +0 -1
-             * Here setting RAMBlock.bmap would be fine too but not

necessary.

migration/ram.c static void ram_list_init_bitmaps(void) · line 3200

Quoted 2 lines
migration/ram.c +2 -0
+             * Here we set RAMBlock.bmap all to 1 because when rebegin a
+             * new migration after a failed migration, ram_list.

It is after failure or cancel?

migration/ram.c static void ram_list_init_bitmaps(void) · line 3201

Quoted 1 line
migration/ram.c +1 -0
+             * dirty_memory[DIRTY_MEMORY_MIGRATION] don't include the

whole

Quoted 10 lines
migration/ram.c +2 -1
+             * guest memory.
             */
            block->bmap = bitmap_new(pages);
+            bitmap_set(block->bmap, 0, pages);
            if (migrate_postcopy_ram()) {
                block->unsentmap = bitmap_new(pages);
                bitmap_set(block->unsentmap, 0, pages);
--

2.17.2 (Apple Git-113)

--
Wei Yang
Help you, Help me

#6 lore raw
Quoted 5 lines · Ivan Ren
Quoted 1 line
Quoted 1 line

- * Here we didn't set RAMBlock.bmap simply because it is

already

Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +0 -2
-             * set in ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION] in
-             * ram_block_add, and that's where we'll sync the dirty

bitmaps.

Quoted 9 lines
Quoted 1 line
Quoted 1 line

- * Here setting RAMBlock.bmap would be fine too but not

necessary.

Quoted 4 lines

migration/ram.c static void ram_list_init_bitmaps(void) · line 3200

Quoted 2 lines
migration/ram.c +2 -0
+             * Here we set RAMBlock.bmap all to 1 because when rebegin a
+             * new migration after a failed migration, ram_list.

It is after failure or cancel?

Here we can treat cancel as a special fail.

Well, I am not sure this is officially documented. Would this lead to confusion?

Quoted 2 lines

Thanks.

Signature · 2 lines
Wei Yang
Help you, Help me