qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: Fabiano Rosas <farosas@suse.de>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	peterx@redhat.com, Prasad Pandit <pjp@fedoraproject.org>
Subject: [PULL 10/14] migration/ram: Implement save_postcopy_prepare()
Date: Fri,  2 May 2025 12:41:37 -0400	[thread overview]
Message-ID: <20250502164141.747202-11-peterx@redhat.com> (raw)
In-Reply-To: <20250502164141.747202-1-peterx@redhat.com>

Implement save_postcopy_prepare(), preparing for the enablement
of both multifd and postcopy.

Signed-off-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Prasad Pandit <pjp@fedoraproject.org>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
Message-ID: <20250411114534.3370816-5-ppandit@redhat.com>
Signed-off-by: Fabiano Rosas <farosas@suse.de>
---
 migration/ram.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/migration/ram.c b/migration/ram.c
index 1181a99cf6..a749e4a421 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -4398,6 +4398,42 @@ static int ram_resume_prepare(MigrationState *s, void *opaque)
     return 0;
 }
 
+static bool ram_save_postcopy_prepare(QEMUFile *f, void *opaque, Error **errp)
+{
+    int ret;
+
+    if (migrate_multifd()) {
+        /*
+         * When multifd is enabled, source QEMU needs to make sure all the
+         * pages queued before postcopy starts have been flushed.
+         *
+         * The load of these pages must happen before switching to postcopy.
+         * It's because loading of guest pages (so far) in multifd recv
+         * threads is still non-atomic, so the load cannot happen with vCPUs
+         * running on the destination side.
+         *
+         * This flush and sync will guarantee that those pages are loaded
+         * _before_ postcopy starts on the destination. The rationale is,
+         * this happens before VM stops (and before source QEMU sends all
+         * the rest of the postcopy messages).  So when the destination QEMU
+         * receives the postcopy messages, it must have received the sync
+         * message on the main channel (either RAM_SAVE_FLAG_MULTIFD_FLUSH,
+         * or RAM_SAVE_FLAG_EOS), and such message would guarantee that
+         * all previous guest pages queued in the multifd channels are
+         * completely loaded.
+         */
+        ret = multifd_ram_flush_and_sync(f);
+        if (ret < 0) {
+            error_setg(errp, "%s: multifd flush and sync failed", __func__);
+            return false;
+        }
+    }
+
+    qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
+
+    return true;
+}
+
 void postcopy_preempt_shutdown_file(MigrationState *s)
 {
     qemu_put_be64(s->postcopy_qemufile_src, RAM_SAVE_FLAG_EOS);
@@ -4417,6 +4453,7 @@ static SaveVMHandlers savevm_ram_handlers = {
     .load_setup = ram_load_setup,
     .load_cleanup = ram_load_cleanup,
     .resume_prepare = ram_resume_prepare,
+    .save_postcopy_prepare = ram_save_postcopy_prepare,
 };
 
 static void ram_mig_ram_block_resized(RAMBlockNotifier *n, void *host,
-- 
2.48.1



  parent reply	other threads:[~2025-05-02 16:43 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-02 16:41 [PULL 00/14] Migration 20250502 patches Peter Xu
2025-05-02 16:41 ` [PULL 01/14] migration: check RDMA and capabilities are compatible on both sides Peter Xu
2025-05-02 16:41 ` [PULL 02/14] migration: disable RDMA + postcopy-ram Peter Xu
2025-05-02 16:41 ` [PULL 03/14] migration/rdma: Remove redundant migration_in_postcopy checks Peter Xu
2025-05-02 16:41 ` [PULL 04/14] migration: Unfold control_save_page() Peter Xu
2025-05-02 16:41 ` [PULL 05/14] migration: Add qtest for migration over RDMA Peter Xu
2025-05-02 16:41 ` [PULL 06/14] migration: Fix latent bug in migrate_params_test_apply() Peter Xu
2025-05-02 16:41 ` [PULL 07/14] migration/multifd: move macros to multifd header Peter Xu
2025-05-02 16:41 ` [PULL 08/14] migration: refactor channel discovery mechanism Peter Xu
2025-05-02 16:41 ` [PULL 09/14] migration: Add save_postcopy_prepare() savevm handler Peter Xu
2025-05-02 16:41 ` Peter Xu [this message]
2025-05-02 16:41 ` [PULL 11/14] tests/qtest/migration: consolidate set capabilities Peter Xu
2025-05-02 16:41 ` [PULL 12/14] migration/postcopy: Spatial locality page hint for preempt mode Peter Xu
2025-05-02 16:41 ` [PULL 13/14] migration/rdma: Remove qemu_rdma_broken_ipv6_kernel Peter Xu
2025-05-02 16:41 ` [PULL 14/14] scripts/vmstate-static-checker.py: Allow new name for ghes_addr_le field Peter Xu
2025-05-06 13:58 ` [PULL 00/14] Migration 20250502 patches Stefan Hajnoczi

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=20250502164141.747202-11-peterx@redhat.com \
    --to=peterx@redhat.com \
    --cc=farosas@suse.de \
    --cc=pjp@fedoraproject.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@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).