kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Juan Quintela <quintela@redhat.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	kvm@vger.kernel.org, Juan Quintela <quintela@redhat.com>,
	Thomas Huth <thuth@redhat.com>,
	Richard Henderson <rth@twiddle.net>,
	Laurent Vivier <lvivier@redhat.com>,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	Ivan Ren <renyime@gmail.com>, Ivan Ren <ivanren@tencent.com>,
	Peter Xu <peterx@redhat.com>
Subject: [PULL 21/21] migration: always initial RAMBlock.bmap to 1 for new migration
Date: Mon, 15 Jul 2019 15:51:25 +0200	[thread overview]
Message-ID: <20190715135125.17770-22-quintela@redhat.com> (raw)
In-Reply-To: <20190715135125.17770-1-quintela@redhat.com>

From: Ivan Ren <renyime@gmail.com>

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.

Signed-off-by: Ivan Ren <ivanren@tencent.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Message-Id: <1563115879-2715-1-git-send-email-ivanren@tencent.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 migration/ram.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/migration/ram.c b/migration/ram.c
index 85bc36101c..2b0774c2bf 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -3213,11 +3213,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;
@@ -3249,12 +3249,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);
             block->clear_bmap_shift = shift;
             block->clear_bmap = bitmap_new(clear_bmap_size(pages, shift));
             if (migrate_postcopy_ram()) {
-- 
2.21.0


  parent reply	other threads:[~2019-07-15 13:53 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-15 13:51 [PULL 00/21] Migration pull request Juan Quintela
2019-07-15 13:51 ` [PULL 01/21] migration: fix multifd_recv event typo Juan Quintela
2019-07-15 13:51 ` [PULL 02/21] migration-test: rename parameter to parameter_int Juan Quintela
2019-07-15 13:51 ` [PULL 03/21] migration/multifd: call multifd_send_sync_main when sending RAM_SAVE_FLAG_EOS Juan Quintela
2019-07-15 13:51 ` [PULL 04/21] migration/xbzrle: update cache and current_data in one place Juan Quintela
2019-07-15 13:51 ` [PULL 05/21] cutils: remove one unnecessary pointer operation Juan Quintela
2019-07-15 13:51 ` [PULL 06/21] migration/multifd: sync packet_num after all thread are done Juan Quintela
2019-07-15 13:51 ` [PULL 07/21] migration/ram.c: reset complete_round when we gets a queued page Juan Quintela
2019-07-15 13:51 ` [PULL 08/21] migration: No need to take rcu during sync_dirty_bitmap Juan Quintela
2019-07-15 13:51 ` [PULL 09/21] memory: Don't set migration bitmap when without migration Juan Quintela
2019-07-15 13:51 ` [PULL 10/21] bitmap: Add bitmap_copy_with_{src|dst}_offset() Juan Quintela
2019-07-15 13:51 ` [PULL 11/21] memory: Pass mr into snapshot_and_clear_dirty Juan Quintela
2019-07-15 13:51 ` [PULL 12/21] memory: Introduce memory listener hook log_clear() Juan Quintela
2019-07-15 13:51 ` [PULL 13/21] kvm: Update comments for sync_dirty_bitmap Juan Quintela
2019-07-15 13:51 ` [PULL 14/21] kvm: Persistent per kvmslot dirty bitmap Juan Quintela
2019-07-15 13:51 ` [PULL 15/21] kvm: Introduce slots lock for memory listener Juan Quintela
2019-07-15 13:51 ` [PULL 16/21] kvm: Support KVM_CLEAR_DIRTY_LOG Juan Quintela
2019-07-15 13:51 ` [PULL 17/21] migration: Split log_clear() into smaller chunks Juan Quintela
2019-07-15 13:51 ` [PULL 18/21] migration: allow private destination ram with x-ignore-shared Juan Quintela
2019-07-15 13:51 ` [PULL 19/21] migration/postcopy: fix document of postcopy_send_discard_bm_ram() Juan Quintela
2019-07-15 13:51 ` [PULL 20/21] migration/postcopy: remove redundant cpu_synchronize_all_post_init Juan Quintela
2019-07-15 13:51 ` Juan Quintela [this message]
2019-07-15 15:11 ` [Qemu-devel] [PULL 00/21] Migration pull request Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190715135125.17770-22-quintela@redhat.com \
    --to=quintela@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=ivanren@tencent.com \
    --cc=kvm@vger.kernel.org \
    --cc=lvivier@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=renyime@gmail.com \
    --cc=rth@twiddle.net \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).