Skip to contentSkip to conversation

rdma: core logic and unpin support

PATCH Superseded [email protected] 4 participants 21 messages Jun 27, 2013 – Jun 28, 2013 Kbuild

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#4 lore raw

PATCH 2/6 rdma: introduce ram_handle_compressed()

In reply to [email protected]

From: "Michael R. Hines" <[email protected]>

This gives RDMA shared access to madvise() on the destination side when an entire chunk is found to be zero.

---
 arch_init.c                   |   29 +++++++++++++++++++----------
 include/migration/migration.h |    2 ++
 2 files changed, 21 insertions(+), 10 deletions(-)
arch_init.c +19 -10
index ea9ddad..82657e4 100644
@@ -777,6 +777,24 @@ static inline void *host_from_stream_offset(QEMUFile *f,
     return NULL;
 }
 
+/*
+ * If a page (or a whole RDMA chunk) has been
+ * determined to be zero, then zap it.
+ */
+void ram_handle_compressed(void *host, uint8_t ch, uint64_t size)
+{
+    if (ch != 0 || !is_zero_page(host)) {
+        memset(host, ch, size);
+#ifndef _WIN32
+        if (ch == 0 &&
+            (!kvm_enabled() || kvm_has_sync_mmu()) &&
+            getpagesize() <= TARGET_PAGE_SIZE) {
+            qemu_madvise(host, TARGET_PAGE_SIZE, QEMU_MADV_DONTNEED);
+        }
+#endif
+    }
+}
+
 static int ram_load(QEMUFile *f, void *opaque, int version_id)
 {
     ram_addr_t addr;
@@ -847,16 +865,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
             }
 
             ch = qemu_get_byte(f);
-            if (ch != 0 || !is_zero_page(host)) {
-                memset(host, ch, TARGET_PAGE_SIZE);
-#ifndef _WIN32
-                if (ch == 0 &&
-                    (!kvm_enabled() || kvm_has_sync_mmu()) &&
-                    getpagesize() <= TARGET_PAGE_SIZE) {
-                    qemu_madvise(host, TARGET_PAGE_SIZE, QEMU_MADV_DONTNEED);
-                }
-#endif
-            }
+            ram_handle_compressed(host, ch, TARGET_PAGE_SIZE);
         } else if (flags & RAM_SAVE_FLAG_PAGE) {
             void *host;
 
include/migration/migration.h +2 -0
index f0640e0..9d3cc85 100644
@@ -109,6 +109,8 @@ uint64_t xbzrle_mig_pages_transferred(void);
 uint64_t xbzrle_mig_pages_overflow(void);
 uint64_t xbzrle_mig_pages_cache_miss(void);
 
+void ram_handle_compressed(void *host, uint8_t ch, uint64_t size);
+
 /**
  * @migrate_add_blocker - prevent migration from proceeding
  *
Signature · 1 line
1.7.10.4
#19 lore raw

PATCH 5/6 rdma: introduce MIG_STATE_NONE and change MIG_STATE_SETUP state transition

In reply to [email protected]

From: "Michael R. Hines" <[email protected]>

As described in the previous patch, until now, the MIG_STATE_SETUP state was not really a 'formal' state. It has been used as a 'zero' state (what we're calling 'NONE' here) and QEMU has been unconditionally transitioning into this state when the QMP migration command was called. Instead we want to introduce MIG_STATE_NONE, which is our starting state in the state machine, and then immediately transition into the MIG_STATE_SETUP state when the QMP migrate command is issued.

In order to do this, we must delay the transition into MIG_STATE_ACTIVE until later in the migration_thread(). This is done to be able to timestamp the amount of time spent in the SETUP state for proper accounting to the user during an RDMA migration.

Furthermore, the management software, until now, has never been aware of the existence of the SETUP state whatsoever. This must change, because, timing of this state implies that the state actually exists.

These two patches cannot be separated because the 'query_migrate' QMP switch statement needs to know how to handle this new state transition.

---
 migration.c |   21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
migration.c +14 -7
index cbfdb2c..a199a67 100644
@@ -36,7 +36,8 @@
 #endif
 
 enum {
-    MIG_STATE_ERROR,
+    MIG_STATE_ERROR = -1,
+    MIG_STATE_NONE,
     MIG_STATE_SETUP,
     MIG_STATE_CANCELLED,
     MIG_STATE_ACTIVE,
@@ -63,7 +64,7 @@ static NotifierList migration_state_notifiers =
 MigrationState *migrate_get_current(void)
 {
     static MigrationState current_migration = {
-        .state = MIG_STATE_SETUP,
+        .state = MIG_STATE_NONE,
         .bandwidth_limit = MAX_THROTTLE,
         .xbzrle_cache_size = DEFAULT_MIGRATE_CACHE_SIZE,
         .mbps = -1,
@@ -184,9 +185,13 @@ MigrationInfo *qmp_query_migrate(Error **errp)
     MigrationState *s = migrate_get_current();
 
     switch (s->state) {
-    case MIG_STATE_SETUP:
+    case MIG_STATE_NONE:
         /* no migration has happened ever */
         break;
+    case MIG_STATE_SETUP:
+        info->has_status = true;
+        info->status = g_strdup("setup");
+        break;
     case MIG_STATE_ACTIVE:
         info->has_status = true;
         info->status = g_strdup("active");
@@ -257,7 +262,7 @@ void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params,
     MigrationState *s = migrate_get_current();
     MigrationCapabilityStatusList *cap;
 
-    if (s->state == MIG_STATE_ACTIVE) {
+    if (s->state == MIG_STATE_ACTIVE || s->state == MIG_STATE_SETUP) {
         error_set(errp, QERR_MIGRATION_ACTIVE);
         return;
     }
@@ -393,7 +398,7 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
     params.blk = blk;
     params.shared = inc;
 
-    if (s->state == MIG_STATE_ACTIVE) {
+    if (s->state == MIG_STATE_ACTIVE || s->state == MIG_STATE_SETUP) {
         error_set(errp, QERR_MIGRATION_ACTIVE);
         return;
     }
@@ -525,6 +530,8 @@ static void *migration_thread(void *opaque)
     DPRINTF("beginning savevm\n");
     qemu_savevm_state_begin(s->file, &s->params);
 
+    migrate_set_state(s, MIG_STATE_SETUP, MIG_STATE_ACTIVE);
+
     while (s->state == MIG_STATE_ACTIVE) {
         int64_t current_time;
         uint64_t pending_size;
@@ -604,8 +611,8 @@ static void *migration_thread(void *opaque)
 
 void migrate_fd_connect(MigrationState *s)
 {
-    s->state = MIG_STATE_ACTIVE;
-    trace_migrate_set_state(MIG_STATE_ACTIVE);
+    s->state = MIG_STATE_SETUP;
+    trace_migrate_set_state(MIG_STATE_SETUP);
 
     /* This is a best 1st approximation. ns to ms */
     s->expected_downtime = max_downtime/1000000;
Signature · 1 line
1.7.10.4
#20 lore raw

PATCH 6/6 rdma: account for the time spent in MIG_STATE_SETUP through QMP

In reply to [email protected]

From: "Michael R. Hines" <[email protected]>

Using the previous patches, we're now able to timestamp the SETUP state. Once we have this time, let the user know about it in the schema.

---
 hmp.c                         |    4 ++++
 include/migration/migration.h |    1 +
 migration.c                   |    9 +++++++++
 qapi-schema.json              |    9 ++++++++-
 4 files changed, 22 insertions(+), 1 deletion(-)
hmp.c +4 -0
index 148a3fb..5f52f17 100644
@@ -164,6 +164,10 @@ void hmp_info_migrate(Monitor *mon, const QDict *qdict)
             monitor_printf(mon, "downtime: %" PRIu64 " milliseconds\n",
                            info->downtime);
         }
+        if (info->has_setup_time) {
+            monitor_printf(mon, "setup: %" PRIu64 " milliseconds\n",
+                           info->setup_time);
+        }
     }
 
     if (info->has_ram) {
include/migration/migration.h +1 -0
index b5e413a..71dbe54 100644
@@ -49,6 +49,7 @@ struct MigrationState
     int64_t dirty_bytes_rate;
     bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
     int64_t xbzrle_cache_size;
+    int64_t setup_time;
 };
 
 void process_incoming_migration(QEMUFile *f);
migration.c +9 -0
index a199a67..892302a 100644
@@ -191,6 +191,7 @@ MigrationInfo *qmp_query_migrate(Error **errp)
     case MIG_STATE_SETUP:
         info->has_status = true;
         info->status = g_strdup("setup");
+        info->has_total_time = false;
         break;
     case MIG_STATE_ACTIVE:
         info->has_status = true;
@@ -200,6 +201,8 @@ MigrationInfo *qmp_query_migrate(Error **errp)
             - s->total_time;
         info->has_expected_downtime = true;
         info->expected_downtime = s->expected_downtime;
+        info->has_setup_time = true;
+        info->setup_time = s->setup_time;
 
         info->has_ram = true;
         info->ram = g_malloc0(sizeof(*info->ram));
@@ -231,6 +234,8 @@ MigrationInfo *qmp_query_migrate(Error **errp)
         info->total_time = s->total_time;
         info->has_downtime = true;
         info->downtime = s->downtime;
+        info->has_setup_time = true;
+        info->setup_time = s->setup_time;
 
         info->has_ram = true;
         info->ram = g_malloc0(sizeof(*info->ram));
@@ -522,6 +527,7 @@ static void *migration_thread(void *opaque)
 {
     MigrationState *s = opaque;
     int64_t initial_time = qemu_get_clock_ms(rt_clock);
+    int64_t setup_start = qemu_get_clock_ms(host_clock);
     int64_t initial_bytes = 0;
     int64_t max_size = 0;
     int64_t start_time = initial_time;
@@ -530,8 +536,11 @@ static void *migration_thread(void *opaque)
     DPRINTF("beginning savevm\n");
     qemu_savevm_state_begin(s->file, &s->params);
 
+    s->setup_time = qemu_get_clock_ms(host_clock) - setup_start;
     migrate_set_state(s, MIG_STATE_SETUP, MIG_STATE_ACTIVE);
 
+    DPRINTF("setup complete\n");
+
     while (s->state == MIG_STATE_ACTIVE) {
         int64_t current_time;
         uint64_t pending_size;
qapi-schema.json +8 -1
index a30a728..0ad7257 100644
@@ -578,6 +578,12 @@
 #        expected downtime in milliseconds for the guest in last walk
 #        of the dirty bitmap. (since 1.3)
 #
+# @setup-time: #optional amount of setup time spent _before_ the iterations
+#        begin but _after_ the QMP command is issued. This is designed to
+#        provide an accounting of any activities (such as RDMA pinning) which
+#        may be expensive, but do not actually occur during the iterative
+#        migration rounds themselves. (since 1.6)
+#
 # Since: 0.14.0
 ##
 { 'type': 'MigrationInfo',
@@ -586,7 +592,8 @@
            '*xbzrle-cache': 'XBZRLECacheStats',
            '*total-time': 'int',
            '*expected-downtime': 'int',
-           '*downtime': 'int'} }
+           '*downtime': 'int',
+           '*setup-time' : 'int'} }
 
 ##
 # @query-migrate
Signature · 1 line
1.7.10.4
#7 lore raw

PATCH 3/6 rdma: core logic

In reply to [email protected]

From: "Michael R. Hines" <[email protected]>

Code that does need to be visible is kept well contained inside this file and this is the only new additional file to the entire patch.

This file includes the entire protocol and interfaces required to perform RDMA migration.

Also, the configure and Makefile modifications to link this file are included.

Full documentation is in docs/rdma.txt

---
 Makefile.objs                 |    1 +
 configure                     |   29 +
 include/migration/migration.h |    4 +
 migration-rdma.c              | 2976 +++++++++++++++++++++++++++++++++++++++++
 migration.c                   |    8 +
 5 files changed, 3018 insertions(+)
 create mode 100644 migration-rdma.c
Makefile.objs +1 -0
index 5b288ba..9928542 100644
@@ -51,6 +51,7 @@ common-obj-$(CONFIG_POSIX) += os-posix.o
 common-obj-$(CONFIG_LINUX) += fsdev/
 
 common-obj-y += migration.o migration-tcp.o
+common-obj-$(CONFIG_RDMA) += migration-rdma.o
 common-obj-y += qemu-char.o #aio.o
 common-obj-y += block-migration.o
 common-obj-y += page_cache.o xbzrle.o
configure +29 -0
index 0e0adde..958e7b8 100755
@@ -180,6 +180,7 @@ xfs=""
 vhost_net="no"
 vhost_scsi="no"
 kvm="no"
+rdma=""
 gprof="no"
 debug_tcg="no"
 debug="no"
@@ -936,6 +937,10 @@ for opt do
   ;;
   --enable-gtk) gtk="yes"
   ;;
+  --enable-rdma) rdma="yes"
+  ;;
+  --disable-rdma) rdma="no"
+  ;;
   --with-gtkabi=*) gtkabi="$optarg"
   ;;
   --enable-tpm) tpm="yes"
@@ -1094,6 +1099,8 @@ echo "  --enable-bluez           enable bluez stack connectivity"
 echo "  --disable-slirp          disable SLIRP userspace network connectivity"
 echo "  --disable-kvm            disable KVM acceleration support"
 echo "  --enable-kvm             enable KVM acceleration support"
+echo "  --disable-rdma           disable RDMA-based migration support"
+echo "  --enable-rdma            enable RDMA-based migration support"
 echo "  --enable-tcg-interpreter enable TCG with bytecode interpreter (TCI)"
 echo "  --disable-nptl           disable usermode NPTL support"
 echo "  --enable-nptl            enable usermode NPTL support"
@@ -1796,6 +1803,23 @@ EOF
   libs_softmmu="$sdl_libs $libs_softmmu"
 fi
 
+if test "$rdma" != "no" ; then
+  cat > $TMPC <<EOF
+#include <rdma/rdma_cma.h>
+int main(void) { return 0; }
+EOF
+  rdma_libs="-lrdmacm -libverbs"
+  if compile_prog "-Werror" "$rdma_libs" ; then
+    rdma="yes"
+    libs_softmmu="$libs_softmmu $rdma_libs"
+  else
+    if test "$rdma" = "yes" ; then
+      feature_not_found "rdma"
+    fi
+    rdma="no"
+  fi
+fi
+
 ##########################################
 # VNC TLS/WS detection
 if test "$vnc" = "yes" -a \( "$vnc_tls" != "no" -o "$vnc_ws" != "no" \) ; then
@@ -3525,6 +3549,7 @@ echo "Linux AIO support $linux_aio"
 echo "ATTR/XATTR support $attr"
 echo "Install blobs     $blobs"
 echo "KVM support       $kvm"
+echo "RDMA support      $rdma"
 echo "TCG interpreter   $tcg_interpreter"
 echo "fdt support       $fdt"
 echo "preadv support    $preadv"
@@ -4464,6 +4489,10 @@ if [ "$pixman" = "internal" ]; then
   echo "config-host.h: subdir-pixman" >> $config_host_mak
 fi
 
+if test "$rdma" = "yes" ; then
+echo "CONFIG_RDMA=y" >> $config_host_mak
+fi
+
 if [ "$dtc_internal" = "yes" ]; then
   echo "config-host.h: subdir-dtc" >> $config_host_mak
 fi
include/migration/migration.h +4 -0
index 9d3cc85..b5e413a 100644
@@ -77,6 +77,10 @@ void fd_start_incoming_migration(const char *path, Error **errp);
 
 void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **errp);
 
+void rdma_start_outgoing_migration(void *opaque, const char *host_port, Error **errp);
+
+void rdma_start_incoming_migration(const char *host_port, Error **errp);
+
 void migrate_fd_error(MigrationState *s);
 
 void migrate_fd_connect(MigrationState *s);
migration-rdma.c new file +2976 -0

2,918 lines not on this page · raw message

migration.c +8 -0
index a704d48..62c6b85 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.7.10.4

Part of the diff is not shown here. View the raw message.

#1 lore raw

PATCH 1/6 rdma: update documentation to reflect new unpin support

In reply to [email protected]

From: "Michael R. Hines" <[email protected]>

As requested, the protocol now includes memory unpinning support. This has been implemented in a non-optimized manner, in such a way that one could devise an LRU or other workload-specific information on top of the basic mechanism to influence the way unpinning happens during runtime.

The feature is not yet user-facing, and is thus can only be enable at compile-time.

---
 docs/rdma.txt |   23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
docs/rdma.txt +14 -9
index 45a4b1d..c842da4 100644
@@ -204,15 +204,17 @@ observations on the maximum future benefit of simultaneous page registrations.
 
 The 'type' field has 10 different command values:
     1. Unused
-    2. Error              (sent to the source during bad things)
-    3. Ready              (control-channel is available)
-    4. QEMU File          (for sending non-live device state)
-    5. RAM Blocks request (used right after connection setup)
-    6. RAM Blocks result  (used right after connection setup)
-    7. Compress page      (zap zero page and skip registration)
-    8. Register request   (dynamic chunk registration)
-    9. Register result    ('rkey' to be used by sender)
-    10. Register finished  (registration for current iteration finished)
+    2. Error                (sent to the source during bad things)
+    3. Ready                (control-channel is available)
+    4. QEMU File            (for sending non-live device state)
+    5. RAM Blocks request   (used right after connection setup)
+    6. RAM Blocks result    (used right after connection setup)
+    7. Compress page        (zap zero page and skip registration)
+    8. Register request     (dynamic chunk registration)
+    9. Register result      ('rkey' to be used by sender)
+    10. Register finished   (registration for current iteration finished)
+    11. Unregister request  (unpin previously registered memory)
+    12. Unregister finished (confirmation that unpin completed)
 
 A single control message, as hinted above, can contain within the data
 portion an array of many commands of the same type. If there is more than
@@ -413,3 +415,6 @@ TODO:
    the use of KSM and ballooning while using RDMA.
 4. Also, some form of balloon-device usage tracking would also
    help alleviate some issues.
+5. Use LRU or workload-specific information to provide more
+   fine-grained direction of UNREGISTER requests for unpinning
+   memory in an overcommitted environment.
Signature · 1 line
1.7.10.4
#0 lore raw

cover rdma: core logic and unpin support

From: "Michael R. Hines" <[email protected]>

Changes:
- Per request, basic (compile-time-enabled) unpin support is available, but turned off by default.

Michael R. Hines (6):
rdma: update documentation to reflect new unpin support
rdma: introduce ram_handle_compressed()
rdma: core logic
rdma: allow state transitions between other states besides ACTIVE
rdma: introduce MIG_STATE_NONE and change MIG_STATE_SETUP state
transition
rdma: account for the time spent in MIG_STATE_SETUP through QMP

 Makefile.objs                 |    1 +
 arch_init.c                   |   29 +-
 configure                     |   29 +
 docs/rdma.txt                 |   23 +-
 hmp.c                         |    4 +
 include/migration/migration.h |    7 +
 migration-rdma.c              | 2976 +++++++++++++++++++++++++++++++++++++++++
 migration.c                   |   48 +-
 qapi-schema.json              |    9 +-
 9 files changed, 3094 insertions(+), 32 deletions(-)
 create mode 100644 migration-rdma.c
Signature · 1 line
1.7.10.4
#16 lore raw

PATCH 4/6 rdma: allow state transitions between other states besides ACTIVE

From: "Michael R. Hines" <[email protected]>

This patch is in preparation for the next ones: Until now the MIG_STATE_SETUP state was not really a 'formal' state. It has been used as a 'zero' state and QEMU has been unconditionally transitioning into this state when the QMP migrate command was called. In preparation for timing this state, we have to make this state a a 'real' state which actually gets transitioned from later in the migration_thread() from SETUP => ACTIVE, rather than just automatically dropping into this state at the beginninig of the migration.

This means that the state transition function (migration_finish_set_state()) needs to be capable of transitioning from valid states _other_ than just MIG_STATE_ACTIVE.

The function is in fact already capable of doing that, but was not allowing the old state to be a parameter specified as an input.

This patch fixes that and only makes the transition if the current state matches the old state that the caller intended to transition from.

---
 migration.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
migration.c +5 -5
index 62c6b85..cbfdb2c 100644
@@ -295,9 +295,9 @@ static void migrate_fd_cleanup(void *opaque)
     notifier_list_notify(&migration_state_notifiers, s);
 }
 
-static void migrate_finish_set_state(MigrationState *s, int new_state)
+static void migrate_set_state(MigrationState *s, int old_state, int new_state)
 {
-    if (__sync_val_compare_and_swap(&s->state, MIG_STATE_ACTIVE,
+    if (__sync_val_compare_and_swap(&s->state, old_state,
                                     new_state) == new_state) {
         trace_migrate_set_state(new_state);
     }
@@ -316,7 +316,7 @@ static void migrate_fd_cancel(MigrationState *s)
 {
     DPRINTF("cancelling migration\n");
 
-    migrate_finish_set_state(s, MIG_STATE_CANCELLED);
+    migrate_set_state(s, s->state, MIG_STATE_CANCELLED);
 }
 
 void add_migration_state_change_notifier(Notifier *notify)
@@ -546,14 +546,14 @@ static void *migration_thread(void *opaque)
                 qemu_savevm_state_complete(s->file);
                 qemu_mutex_unlock_iothread();
                 if (!qemu_file_get_error(s->file)) {
-                    migrate_finish_set_state(s, MIG_STATE_COMPLETED);
+                    migrate_set_state(s, MIG_STATE_ACTIVE, MIG_STATE_COMPLETED);
                     break;
                 }
             }
         }
 
         if (qemu_file_get_error(s->file)) {
-            migrate_finish_set_state(s, MIG_STATE_ERROR);
+            migrate_set_state(s, MIG_STATE_ACTIVE, MIG_STATE_ERROR);
             break;
         }
         current_time = qemu_get_clock_ms(rt_clock);
Signature · 1 line
1.7.10.4
#5 lore raw

Re: [Qemu-devel] [PATCH 2/6] rdma: introduce ram_handle_compressed()

In reply to [email protected]
Quoted 2 lines · On 27 June 2013 23:44, <[email protected]> wrote:
 arch_init.c                   |   29 +++++++++++++++++++----------
 include/migration/migration.h |    2 ++

Implementation in arch_init.c but prototype in migration.h? The function pretty clearly has nothing to do with initialization anyway, which suggests it's just in the wrong place (along with a pile of other migration related code there).

thanks
-- PMM

#2 lore raw

Re: [Qemu-devel] [PATCH 1/6] rdma: update documentation to reflect new unpin support

In reply to [email protected]
Quoted 19 lines · On 06/27/2013 04:44 PM, [email protected] wrote:

From: "Michael R. Hines" <[email protected]>

As requested, the protocol now includes memory unpinning support. This has been implemented in a non-optimized manner, in such a way that one could devise an LRU or other workload-specific information on top of the basic mechanism to influence the way unpinning happens during runtime.

The feature is not yet user-facing, and is thus can only be enable at compile-time.

---
 docs/rdma.txt |   23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

+++ b/docs/rdma.txt

docs/rdma.txt observations on the maximum future benefit of simultaneous page registrations. · line 205

Quoted 2 lines
docs/rdma.txt +0 -0
@@ -204,15 +204,17 @@ observations on the maximum future benefit of simultaneous page registrations.
 
 The 'type' field has 10 different command values:

10 != ...

Quoted 11 lines
docs/rdma.txt +1 -9
     1. Unused
-    2. Error              (sent to the source during bad things)
-    3. Ready              (control-channel is available)
-    4. QEMU File          (for sending non-live device state)
-    5. RAM Blocks request (used right after connection setup)
-    6. RAM Blocks result  (used right after connection setup)
-    7. Compress page      (zap zero page and skip registration)
-    8. Register request   (dynamic chunk registration)
-    9. Register result    ('rkey' to be used by sender)
-    10. Register finished  (registration for current iteration finished)
+    2. Error                (sent to the source during bad things)

docs/rdma.txt observations on the maximum future benefit of simultaneous page registrations. · line 217

Quoted 10 lines
docs/rdma.txt +10 -0
+    3. Ready                (control-channel is available)
+    4. QEMU File            (for sending non-live device state)
+    5. RAM Blocks request   (used right after connection setup)
+    6. RAM Blocks result    (used right after connection setup)
+    7. Compress page        (zap zero page and skip registration)
+    8. Register request     (dynamic chunk registration)
+    9. Register result      ('rkey' to be used by sender)
+    10. Register finished   (registration for current iteration finished)
+    11. Unregister request  (unpin previously registered memory)
+    12. Unregister finished (confirmation that unpin completed)

...12.

Also, is it worth indenting things with extra spaces in your original series, so that this series (and even future follow-on series) have more space to use without having to reindent? That is, why not leave room after your current longest command:

12. Unregister finished (confirmation that unpin completed)

and adjust the remaining lines to line up.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#17 lore raw

Re: [Qemu-devel] [PATCH 4/6] rdma: allow state transitions between other states besides ACTIVE

In reply to [email protected]
Quoted 9 lines · On 06/27/2013 04:44 PM, [email protected] wrote:

From: "Michael R. Hines" <[email protected]>

This patch is in preparation for the next ones: Until now the MIG_STATE_SETUP state was not really a 'formal' state. It has been used as a 'zero' state and QEMU has been unconditionally transitioning into this state when the QMP migrate command was called. In preparation for timing this state, we have to make this state a a 'real' state which actually gets transitioned from later in the migration_thread() from SETUP => ACTIVE, rather than just automatically dropping into this state at the beginninig of the migration.

Isn't this a repeat from your earlier series v12?

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#8 lore raw

Re: [Qemu-devel] [PATCH 3/6] rdma: core logic

In reply to [email protected]

configure EOF · line 1812

Quoted 7 lines · On 27 June 2013 23:44, <[email protected]> wrote:
configure +7 -0
+if test "$rdma" != "no" ; then
+  cat > $TMPC <<EOF
+#include <rdma/rdma_cma.h>
+int main(void) { return 0; }
+EOF
+  rdma_libs="-lrdmacm -libverbs"
+  if compile_prog "-Werror" "$rdma_libs" ; then

Do you really need -Werror in your test's CFLAGS? If so, you need a comment explaining why (as with the couple of other tests which do this). If not, just use "" like the majority of our tests.

Also, configure's not totally consistent about it but (especially given where in the file you've put this) you could add in a comment header like the one you can just see for VNC at the bottom of the context:

configure EOF · line 1825

Quoted 13 lines
configure +10 -0
+    rdma="yes"
+    libs_softmmu="$libs_softmmu $rdma_libs"
+  else
+    if test "$rdma" = "yes" ; then
+      feature_not_found "rdma"
+    fi
+    rdma="no"
+  fi
+fi
+
 ##########################################
 # VNC TLS/WS detection
 if test "$vnc" = "yes" -a \( "$vnc_tls" != "no" -o "$vnc_ws" != "no" \) ; then

...there.

Quoted 9 lines
configure +1 -0
@@ -3525,6 +3549,7 @@ echo "Linux AIO support $linux_aio"
 echo "ATTR/XATTR support $attr"
 echo "Install blobs     $blobs"
 echo "KVM support       $kvm"
+echo "RDMA support      $rdma"
 echo "TCG interpreter   $tcg_interpreter"
 echo "fdt support       $fdt"
 echo "preadv support    $preadv"

configure if [ "$pixman" = "internal" ]; then · line 4495

Quoted 7 lines
configure +4 -0
@@ -4464,6 +4489,10 @@ if [ "$pixman" = "internal" ]; then
   echo "config-host.h: subdir-pixman" >> $config_host_mak
 fi
 
+if test "$rdma" = "yes" ; then
+echo "CONFIG_RDMA=y" >> $config_host_mak
+fi
+

This is definitely completely the wrong place for this hunk:
you've put it between the two "here's a submodule directory" stanzas. Put it further up with all the other simple "if thing then echo to $config_host_mak" checks (VNC and so on).

Also, you need to indent the echo line.

migration-rdma.c line 180

Quoted 10 lines
migration-rdma.c new file +6 -0
 if [ "$dtc_internal" = "yes" ]; then
   echo "config-host.h: subdir-dtc" >> $config_host_mak
 fi
 
+const char *wrid_desc[] = {
+        [RDMA_WRID_NONE] = "NONE",
+        [RDMA_WRID_RDMA_WRITE] = "WRITE RDMA",
+        [RDMA_WRID_SEND_CONTROL] = "CONTROL SEND",
+        [RDMA_WRID_RECV_CONTROL] = "CONTROL RECV",
+};

Weird indent (here and elsewhere).

Quoted 4 lines
migration-rdma.c new file +4 -0
+/*
+ * Also represents a RAMblock, but only on the dest.
+ * This gets transmitted by the dest during connection-time
+ * to the source VM and then is used to populate the

migration-rdma.c line 281

Quoted 10 lines
migration-rdma.c new file +10 -0
+ * corresponding RDMALocalBlock with
+ * the information needed to perform the actual RDMA.
+ */
+typedef struct QEMU_PACKED RDMARemoteBlock {
+    uint64_t remote_host_addr;
+    uint64_t offset;
+    uint64_t length;
+    uint32_t remote_rkey;
+    uint32_t padding;
+} QEMU_PACKED RDMARemoteBlock;

I assume from the PACKED annotations (do we really need both, incidentally) that this is shared with either the guest or with another instance of QEMU. Are there definitely no endianness issues to deal with here?

Quoted 1 line

+ DDPRINTF("Ungegistration request (%d): "

Typo.

Quoted 14 lines
migration.c +4 -0
@@ -78,6 +78,10 @@ void qemu_start_incoming_migration(const char *uri, Error **errp)
 
     if (strstart(uri, "tcp:", &p))
         tcp_start_incoming_migration(p, errp);
+#ifdef CONFIG_RDMA
+    else if (strstart(uri, "x-rdma:", &p))
+        rdma_start_incoming_migration(p, errp);
+#endif
 #if !defined(WIN32)
     else if (strstart(uri, "exec:", &p))
         exec_start_incoming_migration(p, errp);

migration.c void qmp_migrate(const char *uri, bool has_blk, bool blk, · line 420

Quoted 10 lines
migration.c +4 -0
@@ -407,6 +411,10 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
 
     if (strstart(uri, "tcp:", &p)) {
         tcp_start_outgoing_migration(s, p, &local_err);
+#ifdef CONFIG_RDMA
+    } else if (strstart(uri, "x-rdma:", &p)) {
+        rdma_start_outgoing_migration(s, p, &local_err);
+#endif
 #if !defined(WIN32)
     } else if (strstart(uri, "exec:", &p)) {
         exec_start_outgoing_migration(s, p, &local_err);

This code is begging to be refactored into something table driven.

-- PMM

#6 lore raw

Re: [Qemu-devel] [PATCH 2/6] rdma: introduce ram_handle_compressed()

In reply to Peter Maydell

Il 28/06/2013 00:56, Peter Maydell ha scritto:

Quoted 8 lines · On 27 June 2013 23:44, <[email protected]> wrote:
Quoted 2 lines
 arch_init.c                   |   29 +++++++++++++++++++----------
 include/migration/migration.h |    2 ++

Implementation in arch_init.c but prototype in migration.h? The function pretty clearly has nothing to do with initialization anyway, which suggests it's just in the wrong place (along with a pile of other migration related code there).

Yes, this used to be in vl.c, and was moved here by Blue Swirl. We can create a new savevm-ram.c file, but it is not really the fault of this patch.

Paolo

#14 lore raw

Re: [Qemu-devel] [PATCH 3/6] rdma: core logic

In reply to [email protected]

Il 28/06/2013 00:44, [email protected] ha scritto:

Quoted 6 lines

+ *
+ * This will have a terrible impact on migration performance, so until future
+ * workload information or LRU information is available, do not attempt to use
+ * this feature except for basic testing.
+ */
+//#define RDMA_ALLOW_REGISTRATION_WINDOW

Out of curiosity, how terrible is the terrible impact?

migration-rdma.c line 1013

Quoted 5 lines

+ * Perform a non-optimized memory registration after every transfer
+ * for demonsration purposes, only if pin-all is not requested.
+ */

migration-rdma.c new file +2 -0
+static int qemu_rdma_unregister_waiting(RDMAContext *rdma) {
+#ifdef RDMA_ALLOW_REGISTRATION_WINDOW

IIRC function can be always enabled, it will just do nothing if no one registers anything. It is just this bit that needs the #ifdef:

+
+ if (!rdma->pin_all) {
+ /*

+             * FYI: If one wanted to signal a specific chunk to be unregistered
+             * using LRU or workload-specific information, this is the function
+             * you would call to do so. That chunk would then get asynchronously
+             * unregistered later.
+             */
Quoted 1 line
Quoted 1 line

#ifdef RDMA_ALLOW_REGISTRATION_WINDOW

+ qemu_rdma_signal_unregister(rdma, index, chunk, wc.wr_id);

Quoted 1 line
Quoted 1 line

#endif

+ }

Then qemu_rdma_signal_unregister would be unused for !RDMA_ALLOW_REGISTRATION_WINDOW, so you would need to put that function within an #ifdef (the whole function, not just the body).

At this point RDMA_ALLOW_REGISTRATION_WINDOW becomes a slightly wrong name. What about RDMA_UNREGISTRATION_EXAMPLE?

migration-rdma.c line 1047

Quoted 5 lines
migration-rdma.c new file +4 -0
+        if(test_bit(chunk, block->transit_bitmap)) {
+            DDPRINTF("Cannot unregister inflight chunk: %" PRIu64 "\n", chunk);
+            continue;
+        }

Nobody will process this unregistration after this. Should you move this

+ // perhaps test_and_clear_bit here? and exit if the bit is zero
+ clear_bit(chunk, block->unregister_bitmap);
+

+        ret = ibv_dereg_mr(block->pmr[chunk]);
+        block->pmr[chunk] = NULL;
+        block->remote_keys[chunk] = 0;

+
+ if(ret != 0) {
+ perror("unregistration chunk failed");
+ return -ret;
+ }
+ rdma->total_registrations--;
+
+ reg.key.chunk = chunk;
+ ret = qemu_rdma_exchange_send(rdma, &head, (uint8_t *) &reg,
+ &resp, &resp_idx, NULL);
+ if (ret < 0) {
+ return ret;
+ }
+
+ DDPRINTF("Unregister for chunk: %" PRIu64 " complete.\n", chunk);

to a separate function and check the unregister_bitmap when you get a transfer completed message from IB?

Also, you do not need to receive the unregistration completed response now, do you? You can have another bitmap for "unregistration in progress" and only wait for completion before re-pinning. This way, the impact of unregistration is low if the page is not going to be changed soon.

_However_, please make this new functionality a separate patch so that we can discuss it better.

Paolo

#18 lore raw

Re: [Qemu-devel] [PATCH 4/6] rdma: allow state transitions between other states besides ACTIVE

In reply to Eric Blake

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Il 28/06/2013 01:10, Eric Blake ha scritto:

Quoted 1 line

Isn't this a repeat from your earlier series v12?

Juan didn't apply all the patches because he had some issues with the later ones.

Paolo
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.19 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBAgAGBQJRzTxuAAoJEBvWZb6bTYbySDAP/juOl4y2lzl3z6GBUVtZ5HbF vC/a9PSl7RM4COMw1nOCsXHR4P+WfdnnBlENnYy/IqYEWlS/uISQLXWFZTxYnB2R 04pzkHVE5YRw/6ZIxDT9nFFOyOtSeNtCI2P0FWJ4Ef2ssshZEqZaRGhIKeHonzN5 QMzcVPZAqWn4C9Z+lIdb/g/ebMilLbyVnADVI9ThcamzifxDRUC/eF5e4ja4HWkq uf+QhtXMLDgv/+YCdOfjQMGBYwbbhxI8xp86gMUOLjzoz7XCy1HlQQwwb7b470l4 +eK5JZEHW9teRJeHftBAjopQaUS27y0RXpyBHcFl0FXpRoW+iwhxAJg7oFxqnPv2 Fejp1yvMja9/IpqGsjOQGsaxUn+CqowJZuagNYkIeD6gh9L/Cd5IwChbPFwqG7xb +ux5Bl3eyZG1f4JaxcgBf8drroxKkFdVhKCsal+L+0l6VKOP0K28r/nGFMfQQXBr KT1hjIngBXVY1mWGPhbmRvO+69VD1gx2xRKs3j/1J6EmR8350YuTjKBzMmAd+e1D lZq6e8dJLqMq5EkD3hNyRFMNCWctfuu5NGRji3r843xgu/dffAaIFeVuDRJDh1cD Dc1law/NO+k3jqfAvIHiZOjFY+Yy/kSL3wWi+7b27TDxnCl2VR4cvJaYcFD5eMEF q9/3/Ebn2/xho1xl5M2R
=XxMh
-----END PGP SIGNATURE-----

#3 lore raw

Re: [Qemu-devel] [PATCH 1/6] rdma: update documentation to reflect new unpin support

In reply to Eric Blake
Quoted 46 lines · Eric Blake
Quoted 18 lines · On 06/27/2013 04:44 PM, [email protected] wrote:

From: "Michael R. Hines" <[email protected]>

As requested, the protocol now includes memory unpinning support. This has been implemented in a non-optimized manner, in such a way that one could devise an LRU or other workload-specific information on top of the basic mechanism to influence the way unpinning happens during runtime.

The feature is not yet user-facing, and is thus can only be enable at compile-time.

---
  docs/rdma.txt |   23 ++++++++++++++---------
  1 file changed, 14 insertions(+), 9 deletions(-)

+++ b/docs/rdma.txt

docs/rdma.txt observations on the maximum future benefit of simultaneous page registrations. · line 205

Quoted 2 lines
docs/rdma.txt +0 -0
@@ -204,15 +204,17 @@ observations on the maximum future benefit of simultaneous page registrations.
 
  The 'type' field has 10 different command values:

10 != ...

Quoted 11 lines
docs/rdma.txt +1 -9
      1. Unused
-    2. Error              (sent to the source during bad things)
-    3. Ready              (control-channel is available)
-    4. QEMU File          (for sending non-live device state)
-    5. RAM Blocks request (used right after connection setup)
-    6. RAM Blocks result  (used right after connection setup)
-    7. Compress page      (zap zero page and skip registration)
-    8. Register request   (dynamic chunk registration)
-    9. Register result    ('rkey' to be used by sender)
-    10. Register finished  (registration for current iteration finished)
+    2. Error                (sent to the source during bad things)

docs/rdma.txt observations on the maximum future benefit of simultaneous page registrations. · line 217

Quoted 10 lines
docs/rdma.txt +10 -0
+    3. Ready                (control-channel is available)
+    4. QEMU File            (for sending non-live device state)
+    5. RAM Blocks request   (used right after connection setup)
+    6. RAM Blocks result    (used right after connection setup)
+    7. Compress page        (zap zero page and skip registration)
+    8. Register request     (dynamic chunk registration)
+    9. Register result      ('rkey' to be used by sender)
+    10. Register finished   (registration for current iteration finished)
+    11. Unregister request  (unpin previously registered memory)
+    12. Unregister finished (confirmation that unpin completed)

...12.

Quoted 9 lines

Also, is it worth indenting things with extra spaces in your original series, so that this series (and even future follow-on series) have more space to use without having to reindent? That is, why not leave room after your current longest command:

12. Unregister finished (confirmation that unpin completed)

and adjust the remaining lines to line up.

Understood. (I got your other corrections in as well - just sent this series out too fast before I read your other emails.)

#9 lore raw

Re: [Qemu-devel] [PATCH 3/6] rdma: core logic

In reply to Peter Maydell
Quoted 13 lines · Peter Maydell

configure EOF · line 1812

Quoted 7 lines · On 27 June 2013 23:44, <[email protected]> wrote:
configure +7 -0
+if test "$rdma" != "no" ; then
+  cat > $TMPC <<EOF
+#include <rdma/rdma_cma.h>
+int main(void) { return 0; }
+EOF
+  rdma_libs="-lrdmacm -libverbs"
+  if compile_prog "-Werror" "$rdma_libs" ; then

Do you really need -Werror in your test's CFLAGS? If so, you need a comment explaining why (as with the couple of other tests which do this). If not, just use "" like the majority of our tests.

Quoted 4 lines

Also, configure's not totally consistent about it but (especially given where in the file you've put this) you could add in a comment header like the one you can just see for VNC at the bottom of the context:

Will drop the -Werror, no problem. (I think I copied and pasted 99% of the configure changes), can't even remember why I added it in the first place. Perhaps I was debugging something and forgot to remove it....

Quoted 6 lines
Quoted 6 lines
configure +6 -0
+    rdma="yes"
+    libs_softmmu="$libs_softmmu $rdma_libs"
+  else
+    if test "$rdma" = "yes" ; then
+      feature_not_found "rdma"
+    fi
Quoted 9 lines

configure EOF · line 1825

Quoted 7 lines
configure +4 -0
+    rdma="no"
+  fi
+fi
+
  ##########################################
  # VNC TLS/WS detection
  if test "$vnc" = "yes" -a \( "$vnc_tls" != "no" -o "$vnc_ws" != "no" \) ; then

...there.

Acknowledged.

Quoted 21 lines
Quoted 9 lines
configure +1 -0
@@ -3525,6 +3549,7 @@ echo "Linux AIO support $linux_aio"
  echo "ATTR/XATTR support $attr"
  echo "Install blobs     $blobs"
  echo "KVM support       $kvm"
+echo "RDMA support      $rdma"
  echo "TCG interpreter   $tcg_interpreter"
  echo "fdt support       $fdt"
  echo "preadv support    $preadv"

configure if [ "$pixman" = "internal" ]; then · line 4495

Quoted 7 lines
configure +4 -0
@@ -4464,6 +4489,10 @@ if [ "$pixman" = "internal" ]; then
    echo "config-host.h: subdir-pixman" >> $config_host_mak
  fi
 
+if test "$rdma" = "yes" ; then
+echo "CONFIG_RDMA=y" >> $config_host_mak
+fi
+

This is definitely completely the wrong place for this hunk:
you've put it between the two "here's a submodule directory" stanzas. Put it further up with all the other simple "if thing then echo to $config_host_mak" checks (VNC and so on).

Quoted 1 line

Also, you need to indent the echo line.

Acknowledged.

Quoted 10 lines

migration-rdma.c line 180

Quoted 9 lines
migration-rdma.c new file +6 -0
  if [ "$dtc_internal" = "yes" ]; then
    echo "config-host.h: subdir-dtc" >> $config_host_mak
  fi
+const char *wrid_desc[] = {
+        [RDMA_WRID_NONE] = "NONE",
+        [RDMA_WRID_RDMA_WRITE] = "WRITE RDMA",
+        [RDMA_WRID_SEND_CONTROL] = "CONTROL SEND",
+        [RDMA_WRID_RECV_CONTROL] = "CONTROL RECV",
+};

Weird indent (here and elsewhere).

Acknowledged.

Quoted 10 lines
Quoted 10 lines
migration-rdma.c new file +10 -0
+/*
+ * Also represents a RAMblock, but only on the dest.
+ * This gets transmitted by the dest during connection-time
+ * to the source VM and then is used to populate the
+ * corresponding RDMALocalBlock with
+ * the information needed to perform the actual RDMA.
+ */
+typedef struct QEMU_PACKED RDMARemoteBlock {
+    uint64_t remote_host_addr;
+    uint64_t offset;
Quoted 8 lines

migration-rdma.c line 281

Quoted 4 lines
migration-rdma.c new file +4 -0
+    uint64_t length;
+    uint32_t remote_rkey;
+    uint32_t padding;
+} QEMU_PACKED RDMARemoteBlock;

I assume from the PACKED annotations (do we really need both, incidentally) that this is shared with either the guest or with another instance of QEMU. Are there definitely no endianness issues to deal with here?

I have ntohl()/htonl() on the protocol headers, but I did not add them for the data portions of the protocol.

Is endianess for the data a big issue when you are assume the migration is happening across identical CPU architectures?

Quoted 2 lines
Quoted 1 line

+ DDPRINTF("Ungegistration request (%d): "

Typo.

I have ntohl()/htonl() on the protocol headers, but I did not add them for the data portions of the protocol.

Quoted 29 lines
Quoted 14 lines
migration.c +4 -0
@@ -78,6 +78,10 @@ void qemu_start_incoming_migration(const char *uri, Error **errp)
 
      if (strstart(uri, "tcp:", &p))
          tcp_start_incoming_migration(p, errp);
+#ifdef CONFIG_RDMA
+    else if (strstart(uri, "x-rdma:", &p))
+        rdma_start_incoming_migration(p, errp);
+#endif
  #if !defined(WIN32)
      else if (strstart(uri, "exec:", &p))
          exec_start_incoming_migration(p, errp);

migration.c void qmp_migrate(const char *uri, bool has_blk, bool blk, · line 420

Quoted 10 lines
migration.c +4 -0
@@ -407,6 +411,10 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
 
      if (strstart(uri, "tcp:", &p)) {
          tcp_start_outgoing_migration(s, p, &local_err);
+#ifdef CONFIG_RDMA
+    } else if (strstart(uri, "x-rdma:", &p)) {
+        rdma_start_outgoing_migration(s, p, &local_err);
+#endif
  #if !defined(WIN32)
      } else if (strstart(uri, "exec:", &p)) {
          exec_start_outgoing_migration(s, p, &local_err);

This code is begging to be refactored into something table driven.

-- PMM

#10 lore raw

Re: [Qemu-devel] [PATCH 3/6] rdma: core logic

Quoted 6 lines · Michael R. Hines
Quoted 4 lines

I assume from the PACKED annotations (do we really need both, incidentally) that this is shared with either the guest or with another instance of QEMU. Are there definitely no endianness issues to deal with here?

Quoted 6 lines

I have ntohl()/htonl() on the protocol headers, but I did not add them for the data portions of the protocol.

Is endianess for the data a big issue when you are assume the migration is happening across identical CPU architectures?

Well:
* is that a reasonable assumption? (why?)
* if you try this on some setup where it's not true, do we fail helpfully or obscurely?

This is really just my usual "all the world is not an x86" nudge; I don't know enough about rdma to be able to say what the right thing in this particular case is.

-- PMM

#12 lore raw

Re: [Qemu-devel] [PATCH 3/6] rdma: core logic

In reply to Michael R. Hines
Quoted 4 lines · Michael R. Hines
Quoted 3 lines · Peter Maydell
Quoted 2 lines

Is endianess for the data a big issue when you are assume the migration is happening across identical CPU architectures?

Quoted 8 lines
Quoted 2 lines

Well:
* is that a reasonable assumption? (why?)

I would yes, because we're dealing raw guest RAM. Migration of memory would not work across a different architecture (particularly page tables - which would need to be canonicalized and de-canonicalized).

Raw guest RAM is fine, because the VM at the destination will (by definition) be running a guest of the same endianness. However it looks like in this code you have host (QEMU) code looking into the guest RAM, and the guest and host might not have the same endianness. (The easy way for them to be different is if you're using TCG rather than KVM; alternatively you might be running a big-endian VM inside KVM with a little-endian QEMU controlling it, if your architecture supports that.)

Quoted 5 lines
Quoted 2 lines

* if you try this on some setup where it's not true, do we fail helpfully or obscurely?

Shouldn't a check like that occur before the migration actually begins? Is this specific to RDMA?

Normal migration works fine for TCG because it doesn't depend on the endianness of the host vs the guest -- everything on the wire is in big-endian format and we byteswap field values as we marshall them. Guest RAM itself is just sent as a bag of bytes (conceptually speaking, anyway).

thanks
-- PMM

#11 lore raw

Re: [Qemu-devel] [PATCH 3/6] rdma: core logic

In reply to Peter Maydell
Quoted 6 lines · Peter Maydell
Quoted 5 lines · Michael R. Hines
Quoted 4 lines

I assume from the PACKED annotations (do we really need both, incidentally) that this is shared with either the guest or with another instance of QEMU. Are there definitely no endianness issues to deal with here?

Quoted 8 lines
Quoted 6 lines

I have ntohl()/htonl() on the protocol headers, but I did not add them for the data portions of the protocol.

Is endianess for the data a big issue when you are assume the migration is happening across identical CPU architectures?

Well:
* is that a reasonable assumption? (why?)

I would yes, because we're dealing raw guest RAM. Migration of memory would not work across a different architecture (particularly page tables - which would need to be canonicalized and de-canonicalized).

Quoted 2 lines

* if you try this on some setup where it's not true, do we fail helpfully or obscurely?

Shouldn't a check like that occur before the migration actually begins? Is this specific to RDMA?

#15 lore raw

Re: [Qemu-devel] [PATCH 3/6] rdma: core logic

In reply to Paolo Bonzini
Quoted 8 lines · Paolo Bonzini

Il 28/06/2013 00:44, [email protected] ha scritto:

Quoted 6 lines

+ *
+ * This will have a terrible impact on migration performance, so until future
+ * workload information or LRU information is available, do not attempt to use
+ * this feature except for basic testing.
+ */
+//#define RDMA_ALLOW_REGISTRATION_WINDOW

Out of curiosity, how terrible is the terrible impact?

(I'll be sure to put this in the cover letter next time - sorry about that).

Here's the breakdown for a 14 GB (proprietary) memory intensive micro-benchmark that was use here in IBM. (14 is the largest I can create on my older hardware):

These numbers are *after* the bulk phase:

1. x-rdma-pin-all enabled: ~26 gbps (PCI limit, hardware is a few years old).
2. x-rdma-pin-all disabled, unpin disabled: ~15 gbps (fluctuates as high as 20, but usually 15)
3. x-rdma-pin-all disabled, unpin enabled: ~13 gbps (very stable at 13, little or no deviation)

I have to admit that the difference between #2 and #3 is much smaller than I expected.

I suspect this is because of the very large chunk sizes (1MB).

The larger the chunk size, the less of a difference in unpinning costs.

Quoted 8 lines

migration-rdma.c line 1013

Quoted 5 lines

+ * Perform a non-optimized memory registration after every transfer
+ * for demonsration purposes, only if pin-all is not requested.
+ */

migration-rdma.c new file +2 -0
+static int qemu_rdma_unregister_waiting(RDMAContext *rdma) {
+#ifdef RDMA_ALLOW_REGISTRATION_WINDOW

IIRC function can be always enabled, it will just do nothing if no one registers anything. It is just this bit that needs the #ifdef:

No, this is an entirely different unpinning function. It only has one user, which is the new RDMA_ALLOW_REGISTRATION_WINDOW.

But adding an extra #ifdef doesn't hurt anyway.

Quoted 13 lines
migration-rdma.c new file +10 -0
+
+        if (!rdma->pin_all) {
+            /*
+             * FYI: If one wanted to signal a specific chunk to be unregistered
+             * using LRU or workload-specific information, this is the function
+             * you would call to do so. That chunk would then get asynchronously
+             * unregistered later.
+             */
    >> #ifdef RDMA_ALLOW_REGISTRATION_WINDOW
+            qemu_rdma_signal_unregister(rdma, index, chunk, wc.wr_id);
    >> #endif
+        }
Quoted 7 lines

Then qemu_rdma_signal_unregister would be unused for !RDMA_ALLOW_REGISTRATION_WINDOW, so you would need to put that function within an #ifdef (the whole function, not just the body).

At this point RDMA_ALLOW_REGISTRATION_WINDOW becomes a slightly wrong name. What about RDMA_UNREGISTRATION_EXAMPLE?

Sounds fine to me. Will change it.

Quoted 6 lines

migration-rdma.c line 1047

Quoted 4 lines
migration-rdma.c new file +4 -0
+        if(test_bit(chunk, block->transit_bitmap)) {
+            DDPRINTF("Cannot unregister inflight chunk: %" PRIu64 "\n", chunk);
+            continue;
+        }

Nobody will process this unregistration after this.

Good catch - the clear_bit() was too late.

Quoted 25 lines

Should you move this

migration-rdma.c new file +21 -0
+        // perhaps test_and_clear_bit here?  and exit if the bit is zero
+        clear_bit(chunk, block->unregister_bitmap);
+
+        ret = ibv_dereg_mr(block->pmr[chunk]);
+        block->pmr[chunk] = NULL;
+        block->remote_keys[chunk] = 0;
+
+        if(ret != 0) {
+            perror("unregistration chunk failed");
+            return -ret;
+        }
+        rdma->total_registrations--;
+
+        reg.key.chunk = chunk;
+        ret = qemu_rdma_exchange_send(rdma, &head, (uint8_t *) &reg,
+                                &resp, &resp_idx, NULL);
+        if (ret < 0) {
+            return ret;
+        }
+
+        DDPRINTF("Unregister for chunk: %" PRIu64 " complete.\n", chunk);
Quoted 2 lines

to a separate function and check the unregister_bitmap when you get a transfer completed message from IB?

We would need a new thread for that. The migration is currently single threaded. The new thread would listen asynchronously for the unregistration complete messages. Based on the last couple years of emails I've seen, introducing a new thread is not a simple review task.

With respect, now that the implementation is available, I'd like to move on, as we do not have an LRU for this migration and I do not have the authorized manpower to implementing one.

There is a sufficient body of (compile-time-enabled) code here for anyone to take up should overcommitment become a problem for someone in the middle of an RDMA migration.

Quoted 5 lines

Also, you do not need to receive the unregistration completed response now, do you? You can have another bitmap for "unregistration in progress" and only wait for completion before re-pinning. This way, the impact of unregistration is low if the page is not going to be changed soon.

Same answer above applies to this question.

Quoted 2 lines

_However_, please make this new functionality a separate patch so that we can discuss it better.

Will do.

- Michael

#13 lore raw

Re: [Qemu-devel] [PATCH 3/6] rdma: core logic

In reply to Peter Maydell
Quoted 11 lines · Peter Maydell
Quoted 10 lines · Michael R. Hines
Quoted 4 lines · Peter Maydell
Quoted 2 lines

Is endianess for the data a big issue when you are assume the migration is happening across identical CPU architectures?

Well:
* is that a reasonable assumption? (why?)

I would yes, because we're dealing raw guest RAM. Migration of memory would not work across a different architecture (particularly page tables - which would need to be canonicalized and de-canonicalized).

Quoted 9 lines

Raw guest RAM is fine, because the VM at the destination will (by definition) be running a guest of the same endianness. However it looks like in this code you have host (QEMU) code looking into the guest RAM, and the guest and host might not have the same endianness. (The easy way for them to be different is if you're using TCG rather than KVM; alternatively you might be running a big-endian VM inside KVM with a little-endian QEMU controlling it, if your architecture supports that.)

Alright, I see. I guess the moral of the story is that I should not make any architecture assumptions about *any* part of QEMU, then.

I'll add the remaining byte-swap routines for safety to the patch before I sent out the next patch series.

Quoted 9 lines
Quoted 4 lines
Quoted 2 lines

* if you try this on some setup where it's not true, do we fail helpfully or obscurely?

Shouldn't a check like that occur before the migration actually begins? Is this specific to RDMA?

Normal migration works fine for TCG because it doesn't depend on the endianness of the host vs the guest -- everything on the wire is in big-endian format and we byteswap field values as we marshall them. Guest RAM itself is just sent as a bag of bytes (conceptually speaking, anyway).

Understood.

- Michael