All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fabiano Rosas <farosas@suse.de>
To: qemu-devel@nongnu.org
Cc: berrange@redhat.com, armbru@redhat.com,
	Peter Xu <peterx@redhat.com>, Claudio Fontana <cfontana@suse.de>
Subject: [PATCH v5 21/23] migration/multifd: Support incoming mapped-ram stream format
Date: Wed, 28 Feb 2024 12:21:25 -0300	[thread overview]
Message-ID: <20240228152127.18769-22-farosas@suse.de> (raw)
In-Reply-To: <20240228152127.18769-1-farosas@suse.de>

For the incoming mapped-ram migration we need to read the ramblock
headers, get the pages bitmap and send the host address of each
non-zero page to the multifd channel thread for writing.

Usage on HMP is:

(qemu) migrate_set_capability multifd on
(qemu) migrate_set_capability mapped-ram on
(qemu) migrate_incoming file:migfile

(the ram.h include needs to move because we've been previously relying
on it being included from migration.c. Now file.h will start including
multifd.h before migration.o is processed)

Signed-off-by: Fabiano Rosas <farosas@suse.de>
---
- dropped NOCOMP flag handling
- dropped comment and newline
- dropped duplicate LOAD_BUF_SIZE
---
 migration/file.c    | 18 +++++++++++++++++-
 migration/file.h    |  2 ++
 migration/multifd.c | 31 ++++++++++++++++++++++++++++---
 migration/multifd.h |  2 ++
 migration/ram.c     | 26 ++++++++++++++++++++++++--
 5 files changed, 73 insertions(+), 6 deletions(-)

diff --git a/migration/file.c b/migration/file.c
index 2188774a9d..44b73bf9e5 100644
--- a/migration/file.c
+++ b/migration/file.c
@@ -13,7 +13,6 @@
 #include "channel.h"
 #include "file.h"
 #include "migration.h"
-#include "multifd.h"
 #include "io/channel-file.h"
 #include "io/channel-util.h"
 #include "options.h"
@@ -204,3 +203,20 @@ int file_write_ramblock_iov(QIOChannel *ioc, const struct iovec *iov,
 
     return (ret < 0) ? ret : 0;
 }
+
+int multifd_file_recv_data(MultiFDRecvParams *p, Error **errp)
+{
+    MultiFDRecvData *data = p->data;
+    size_t ret;
+
+    ret = qio_channel_pread(p->c, (char *) data->opaque,
+                            data->size, data->file_offset, errp);
+    if (ret != data->size) {
+        error_prepend(errp,
+                      "multifd recv (%u): read 0x%zx, expected 0x%zx",
+                      p->id, ret, data->size);
+        return -1;
+    }
+
+    return 0;
+}
diff --git a/migration/file.h b/migration/file.h
index 01a338cac7..9f71e87f74 100644
--- a/migration/file.h
+++ b/migration/file.h
@@ -11,6 +11,7 @@
 #include "qapi/qapi-types-migration.h"
 #include "io/task.h"
 #include "channel.h"
+#include "multifd.h"
 
 void file_start_incoming_migration(FileMigrationArgs *file_args, Error **errp);
 
@@ -21,4 +22,5 @@ void file_cleanup_outgoing_migration(void);
 bool file_send_channel_create(gpointer opaque, Error **errp);
 int file_write_ramblock_iov(QIOChannel *ioc, const struct iovec *iov,
                             int niov, RAMBlock *block, Error **errp);
+int multifd_file_recv_data(MultiFDRecvParams *p, Error **errp);
 #endif
diff --git a/migration/multifd.c b/migration/multifd.c
index e31d2934cc..7a3977fc34 100644
--- a/migration/multifd.c
+++ b/migration/multifd.c
@@ -18,7 +18,6 @@
 #include "qemu/error-report.h"
 #include "qapi/error.h"
 #include "file.h"
-#include "ram.h"
 #include "migration.h"
 #include "migration-stats.h"
 #include "socket.h"
@@ -251,7 +250,7 @@ static int nocomp_recv(MultiFDRecvParams *p, Error **errp)
     uint32_t flags;
 
     if (!multifd_use_packets()) {
-        return 0;
+        return multifd_file_recv_data(p, errp);
     }
 
     flags = p->flags & MULTIFD_FLAG_COMPRESSION_MASK;
@@ -1331,22 +1330,48 @@ void multifd_recv_cleanup(void)
 void multifd_recv_sync_main(void)
 {
     int thread_count = migrate_multifd_channels();
+    bool file_based = !multifd_use_packets();
     int i;
 
-    if (!migrate_multifd() || !multifd_use_packets()) {
+    if (!migrate_multifd()) {
         return;
     }
 
+    /*
+     * File-based channels don't use packets and therefore need to
+     * wait for more work. Release them to start the sync.
+     */
+    if (file_based) {
+        for (i = 0; i < thread_count; i++) {
+            MultiFDRecvParams *p = &multifd_recv_state->params[i];
+
+            trace_multifd_recv_sync_main_signal(p->id);
+            qemu_sem_post(&p->sem);
+        }
+    }
+
     /*
      * Initiate the synchronization by waiting for all channels.
+     *
      * For socket-based migration this means each channel has received
      * the SYNC packet on the stream.
+     *
+     * For file-based migration this means each channel is done with
+     * the work (pending_job=false).
      */
     for (i = 0; i < thread_count; i++) {
         trace_multifd_recv_sync_main_wait(i);
         qemu_sem_wait(&multifd_recv_state->sem_sync);
     }
 
+    if (file_based) {
+        /*
+         * For file-based loading is done in one iteration. We're
+         * done.
+         */
+        return;
+    }
+
     /*
      * Sync done. Release the channels for the next iteration.
      */
diff --git a/migration/multifd.h b/migration/multifd.h
index db8887f088..7447c2bea3 100644
--- a/migration/multifd.h
+++ b/migration/multifd.h
@@ -13,6 +13,8 @@
 #ifndef QEMU_MIGRATION_MULTIFD_H
 #define QEMU_MIGRATION_MULTIFD_H
 
+#include "ram.h"
+
 typedef struct MultiFDRecvData MultiFDRecvData;
 
 bool multifd_send_setup(void);
diff --git a/migration/ram.c b/migration/ram.c
index 53643d2046..c8e2372f06 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -3950,6 +3950,22 @@ void colo_flush_ram_cache(void)
     trace_colo_flush_ram_cache_end();
 }
 
+static size_t ram_load_multifd_pages(void *host_addr, size_t size,
+                                     uint64_t offset)
+{
+    MultiFDRecvData *data = multifd_get_recv_data();
+
+    data->opaque = host_addr;
+    data->file_offset = offset;
+    data->size = size;
+
+    if (!multifd_recv()) {
+        return 0;
+    }
+
+    return size;
+}
+
 static bool read_ramblock_mapped_ram(QEMUFile *f, RAMBlock *block,
                                      long num_pages, unsigned long *bitmap,
                                      Error **errp)
@@ -3979,8 +3995,14 @@ static bool read_ramblock_mapped_ram(QEMUFile *f, RAMBlock *block,
 
             size = MIN(unread, MAPPED_RAM_LOAD_BUF_SIZE);
 
-            read = qemu_get_buffer_at(f, host, size,
-                                      block->pages_offset + offset);
+            if (migrate_multifd()) {
+                read = ram_load_multifd_pages(host, size,
+                                              block->pages_offset + offset);
+            } else {
+                read = qemu_get_buffer_at(f, host, size,
+                                          block->pages_offset + offset);
+            }
+
             if (!read) {
                 goto err;
             }
-- 
2.35.3



  parent reply	other threads:[~2024-02-28 15:24 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-28 15:21 [PATCH v5 00/23] migration: File based migration with multifd and mapped-ram Fabiano Rosas
2024-02-28 15:21 ` [PATCH v5 01/23] migration/multifd: Cleanup multifd_recv_sync_main Fabiano Rosas
2024-02-29  1:26   ` Peter Xu
2024-02-28 15:21 ` [PATCH v5 02/23] io: add and implement QIO_CHANNEL_FEATURE_SEEKABLE for channel file Fabiano Rosas
2024-02-28 15:21 ` [PATCH v5 03/23] io: Add generic pwritev/preadv interface Fabiano Rosas
2024-02-28 15:21 ` [PATCH v5 04/23] io: implement io_pwritev/preadv for QIOChannelFile Fabiano Rosas
2024-02-28 15:21 ` [PATCH v5 05/23] io: fsync before closing a file channel Fabiano Rosas
2024-02-28 15:21 ` [PATCH v5 06/23] migration/qemu-file: add utility methods for working with seekable channels Fabiano Rosas
2024-02-28 15:21 ` [PATCH v5 07/23] migration/ram: Introduce 'mapped-ram' migration capability Fabiano Rosas
2024-02-29  2:10   ` Peter Xu
2024-02-28 15:21 ` [PATCH v5 08/23] migration: Add mapped-ram URI compatibility check Fabiano Rosas
2024-02-28 15:21 ` [PATCH v5 09/23] migration/ram: Add outgoing 'mapped-ram' migration Fabiano Rosas
2024-02-28 15:21 ` [PATCH v5 10/23] migration/ram: Add incoming " Fabiano Rosas
2024-02-28 15:21 ` [PATCH v5 11/23] tests/qtest/migration: Add tests for mapped-ram file-based migration Fabiano Rosas
2024-02-28 15:21 ` [PATCH v5 12/23] migration/multifd: Rename MultiFDSend|RecvParams::data to compress_data Fabiano Rosas
2024-02-28 15:21 ` [PATCH v5 13/23] migration/multifd: Decouple recv method from pages Fabiano Rosas
2024-02-28 15:21 ` [PATCH v5 14/23] migration/multifd: Allow multifd without packets Fabiano Rosas
2024-02-29  2:20   ` Peter Xu
2024-02-28 15:21 ` [PATCH v5 15/23] migration/multifd: Allow receiving pages " Fabiano Rosas
2024-02-29  2:28   ` Peter Xu
2024-02-28 15:21 ` [PATCH v5 16/23] migration/multifd: Add a wrapper for channels_created Fabiano Rosas
2024-02-29  2:29   ` Peter Xu
2024-02-28 15:21 ` [PATCH v5 17/23] migration/multifd: Add outgoing QIOChannelFile support Fabiano Rosas
2024-02-29  2:44   ` Peter Xu
2024-02-29  3:33     ` Peter Xu
2024-02-29 14:27       ` Fabiano Rosas
2024-02-29 14:34         ` Daniel P. Berrangé
2024-03-01  0:08           ` Peter Xu
2024-02-28 15:21 ` [PATCH v5 18/23] migration/multifd: Add incoming " Fabiano Rosas
2024-02-29  2:53   ` Peter Xu
2024-02-28 15:21 ` [PATCH v5 19/23] migration/multifd: Prepare multifd sync for mapped-ram migration Fabiano Rosas
2024-02-29  3:16   ` Peter Xu
2024-02-29 13:19     ` Fabiano Rosas
2024-03-01  0:15       ` Peter Xu
2024-02-28 15:21 ` [PATCH v5 20/23] migration/multifd: Support outgoing mapped-ram stream format Fabiano Rosas
2024-02-28 15:21 ` Fabiano Rosas [this message]
2024-02-29  3:23   ` [PATCH v5 21/23] migration/multifd: Support incoming " Peter Xu
2024-02-28 15:21 ` [PATCH v5 22/23] migration/multifd: Add mapped-ram support to fd: URI Fabiano Rosas
2024-02-29  3:31   ` Peter Xu
2024-02-28 15:21 ` [PATCH v5 23/23] tests/qtest/migration: Add a multifd + mapped-ram migration test Fabiano Rosas

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=20240228152127.18769-22-farosas@suse.de \
    --to=farosas@suse.de \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=cfontana@suse.de \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.