Skip to contentSkip to conversation

Multifd v4

PATCH In review Juan Quintela 5 participants 28 messages Feb 13, 2017 – Feb 15, 2017

lore
Share & tools
lore
#0 lore raw

cover Multifd v4

Hi

[v4]

- Address reviews
- move synchronization to semaphores (faster). Paolo suggestion
- improvements overall (see invidiual patches)
- fix all the checkpatch warnings
- fix all [HACKS] except for one

Please review.

[v3]

This is the 3rd version of multifd. Changes:
- comments for previous verion addressed
- lots of bugs fixed
- remove DPRINTF from ram.c

- add multifd-group parameter, it gives how many pages we sent each time to the worker threads. I am open to better names.
- Better flush support.
- with migration_set_speed 2G it is able to migrate "stress -vm 2 -vm-bytes 512M" over loopback.

Please review.

Thanks, Juan.

[v2]

This is a version against current code. It is based on top of QIO work. It improves the thread synchronization and fixes the problem when we could have two threads handing the same page.

Please comment, Juan.

The following changes since commit df96bfab49dab2d0373e49b51bbb51ce72e1601e:

Merge remote-tracking branch 'remotes/kraxel/tags/pull-vga-20170213-1' into staging (2017-02-13 10:54:49 +0000)

are available in the git repository at:

git://github.com/juanquintela/qemu.git tags/multifd/20170213

for you to fetch changes up to 733be4d2d815c6331b86364f68f6980699e9bb48:

migration: Test new fd infrastructure (2017-02-13 18:14:06 +0100)

----------------------------------------------------------------
multifd/next for 20170213

----------------------------------------------------------------
Juan Quintela (12):
migration: Test for disabled features on reception
migration: Don't create decompression threads if not enabled
migration: Add multifd capability
migration: Create x-multifd-threads parameter
migration: Create x-multifd-group parameter
migration: Create multifd migration threads
migration: Start of multiple fd work
migration: Create ram_multifd_page
migration: Create thread infrastructure for multifd send side
migration: Really use multiple pages at a time
migration: Send the fd number which we are going to use for this page
migration: Test new fd infrastructure

 hmp.c                         |  18 ++
 include/migration/migration.h |  17 ++
 migration/migration.c         |  77 ++++++-
 migration/ram.c               | 499 +++++++++++++++++++++++++++++++++++++++++-
 migration/socket.c            |  64 +++++-
 qapi-schema.json              |  29 ++-
 6 files changed, 690 insertions(+), 14 deletions(-)
#1 lore raw

[Qemu-devel] [PULL 01/12] migration: Test for disabled features on reception

Right now, if we receive a compressed page while this features are disabled, Bad Things (TM) can happen. Just add a test for them.

--

I had XBZRLE here also, but it don't need extra resources on destination, only on source. Additionally libvirt don't enable it on destination, so don't put it here.

---
 migration/ram.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
migration/ram.c +15 -1
index ef8fadf..5817f8c 100644
@@ -2455,7 +2455,7 @@ static int ram_load_postcopy(QEMUFile *f)
 
 static int ram_load(QEMUFile *f, void *opaque, int version_id)
 {
-    int flags = 0, ret = 0;
+    int flags = 0, ret = 0, invalid_flags;
     static uint64_t seq_iter;
     int len = 0;
     /*
@@ -2470,6 +2470,11 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
         ret = -EINVAL;
     }
 
+    invalid_flags = 0;
+
+    if (!migrate_use_compression()) {
+        invalid_flags |= RAM_SAVE_FLAG_COMPRESS_PAGE;
+    }
     /* This RCU critical section can be very long running.
      * When RCU reclaims in the code start to become numerous,
      * it will be necessary to reduce the granularity of this
@@ -2490,6 +2495,15 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
         flags = addr & ~TARGET_PAGE_MASK;
         addr &= TARGET_PAGE_MASK;
 
+        if (flags & invalid_flags) {
+            if (flags & invalid_flags  & RAM_SAVE_FLAG_COMPRESS_PAGE) {
+                error_report("Received an unexpected compressed page");
+            }
+
+            ret = -EINVAL;
+            break;
+        }
+
         if (flags & (RAM_SAVE_FLAG_COMPRESS | RAM_SAVE_FLAG_PAGE |
                      RAM_SAVE_FLAG_COMPRESS_PAGE | RAM_SAVE_FLAG_XBZRLE)) {
             RAMBlock *block = ram_block_from_stream(f, flags);
Signature · 1 line
2.7.4
#2 lore raw

Re: [Qemu-devel] [PULL 01/12] migration: Test for disabled features on reception

Quoted 4 lines · * Juan Quintela ([email protected]) wrote:

Right now, if we receive a compressed page while this features are disabled, Bad Things (TM) can happen. Just add a test for them.

This could go in separately.

Dave

Quoted 54 lines

--

I had XBZRLE here also, but it don't need extra resources on destination, only on source. Additionally libvirt don't enable it on destination, so don't put it here.

---
 migration/ram.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
migration/ram.c +15 -1
index ef8fadf..5817f8c 100644
@@ -2455,7 +2455,7 @@ static int ram_load_postcopy(QEMUFile *f)
 
 static int ram_load(QEMUFile *f, void *opaque, int version_id)
 {
-    int flags = 0, ret = 0;
+    int flags = 0, ret = 0, invalid_flags;
     static uint64_t seq_iter;
     int len = 0;
     /*
@@ -2470,6 +2470,11 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
         ret = -EINVAL;
     }
 
+    invalid_flags = 0;
+
+    if (!migrate_use_compression()) {
+        invalid_flags |= RAM_SAVE_FLAG_COMPRESS_PAGE;
+    }
     /* This RCU critical section can be very long running.
      * When RCU reclaims in the code start to become numerous,
      * it will be necessary to reduce the granularity of this
@@ -2490,6 +2495,15 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
         flags = addr & ~TARGET_PAGE_MASK;
         addr &= TARGET_PAGE_MASK;
 
+        if (flags & invalid_flags) {
+            if (flags & invalid_flags  & RAM_SAVE_FLAG_COMPRESS_PAGE) {
+                error_report("Received an unexpected compressed page");
+            }
+
+            ret = -EINVAL;
+            break;
+        }
+
         if (flags & (RAM_SAVE_FLAG_COMPRESS | RAM_SAVE_FLAG_PAGE |
                      RAM_SAVE_FLAG_COMPRESS_PAGE | RAM_SAVE_FLAG_XBZRLE)) {
             RAMBlock *block = ram_block_from_stream(f, flags);
Signature · 1 line
2.7.4

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

#3 lore raw

[Qemu-devel] [PULL 02/12] migration: Don't create decompression threads if not enabled

In reply to Juan Quintela

--

I removed the [HACK] part because previous patch just check that compression pages are not received.

---
 migration/ram.c | 6 ++++++
 1 file changed, 6 insertions(+)
migration/ram.c +6 -0
index 5817f8c..4422ee8 100644
@@ -2251,6 +2251,9 @@ void migrate_decompress_threads_create(void)
 {
     int i, thread_count;
 
+    if (!migrate_use_compression()) {
+        return;
+    }
     thread_count = migrate_decompress_threads();
     decompress_threads = g_new0(QemuThread, thread_count);
     decomp_param = g_new0(DecompressParam, thread_count);
@@ -2272,6 +2275,9 @@ void migrate_decompress_threads_join(void)
 {
     int i, thread_count;
 
+    if (!migrate_use_compression()) {
+        return;
+    }
     thread_count = migrate_decompress_threads();
     for (i = 0; i < thread_count; i++) {
         qemu_mutex_lock(&decomp_param[i].mutex);
Signature · 1 line
2.7.4
#4 lore raw

Re: [Qemu-devel] [PULL 02/12] migration: Don't create decompression threads if not enabled

Quoted 1 line · * Juan Quintela ([email protected]) wrote:

This can go in separately.

Quoted 35 lines

--

I removed the [HACK] part because previous patch just check that compression pages are not received.

---
 migration/ram.c | 6 ++++++
 1 file changed, 6 insertions(+)
migration/ram.c +6 -0
index 5817f8c..4422ee8 100644
@@ -2251,6 +2251,9 @@ void migrate_decompress_threads_create(void)
 {
     int i, thread_count;
 
+    if (!migrate_use_compression()) {
+        return;
+    }
     thread_count = migrate_decompress_threads();
     decompress_threads = g_new0(QemuThread, thread_count);
     decomp_param = g_new0(DecompressParam, thread_count);
@@ -2272,6 +2275,9 @@ void migrate_decompress_threads_join(void)
 {
     int i, thread_count;
 
+    if (!migrate_use_compression()) {
+        return;
+    }
     thread_count = migrate_decompress_threads();
     for (i = 0; i < thread_count; i++) {
         qemu_mutex_lock(&decomp_param[i].mutex);
Signature · 1 line
2.7.4

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

#5 lore raw

[Qemu-devel] [PULL 03/12] migration: Add multifd capability

In reply to Juan Quintela
---
 include/migration/migration.h | 1 +
 migration/migration.c         | 9 +++++++++
 qapi-schema.json              | 5 +++--
 3 files changed, 13 insertions(+), 2 deletions(-)
include/migration/migration.h +1 -0
index 7528cc2..e8bba55 100644
@@ -308,6 +308,7 @@ bool migrate_postcopy_ram(void);
 bool migrate_zero_blocks(void);
 
 bool migrate_auto_converge(void);
+bool migrate_use_multifd(void);
 
 int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *new_buf, int slen,
                          uint8_t *dst, int dlen);
migration/migration.c +9 -0
index 2b179c6..37af7a4 100644
@@ -1369,6 +1369,15 @@ bool migrate_use_events(void)
     return s->enabled_capabilities[MIGRATION_CAPABILITY_EVENTS];
 }
 
+bool migrate_use_multifd(void)
+{
+    MigrationState *s;
+
+    s = migrate_get_current();
+
+    return s->enabled_capabilities[MIGRATION_CAPABILITY_X_MULTIFD];
+}
+
 int migrate_use_xbzrle(void)
 {
     MigrationState *s;
qapi-schema.json +3 -2
index 61151f3..ff7579e 100644
@@ -865,12 +865,13 @@
 #        side, this process is called COarse-Grain LOck Stepping (COLO) for
 #        Non-stop Service. (since 2.8)
 #
+# @x-multifd: Use more than one fd for migration (since 2.9)
+#
 # Since: 1.2
 ##
 { 'enum': 'MigrationCapability',
   'data': ['xbzrle', 'rdma-pin-all', 'auto-converge', 'zero-blocks',
-           'compress', 'events', 'postcopy-ram', 'x-colo'] }
-
+           'compress', 'events', 'postcopy-ram', 'x-colo', 'x-multifd'] }
 ##
 # @MigrationCapabilityStatus:
 #
Signature · 1 line
2.7.4
#6 lore raw

Re: [Qemu-devel] [PULL 03/12] migration: Add multifd capability

Quoted 47 lines · * Juan Quintela ([email protected]) wrote:
---
 include/migration/migration.h | 1 +
 migration/migration.c         | 9 +++++++++
 qapi-schema.json              | 5 +++--
 3 files changed, 13 insertions(+), 2 deletions(-)
include/migration/migration.h +1 -0
index 7528cc2..e8bba55 100644
@@ -308,6 +308,7 @@ bool migrate_postcopy_ram(void);
 bool migrate_zero_blocks(void);
 
 bool migrate_auto_converge(void);
+bool migrate_use_multifd(void);
 
 int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *new_buf, int slen,
                          uint8_t *dst, int dlen);
migration/migration.c +9 -0
index 2b179c6..37af7a4 100644
@@ -1369,6 +1369,15 @@ bool migrate_use_events(void)
     return s->enabled_capabilities[MIGRATION_CAPABILITY_EVENTS];
 }
 
+bool migrate_use_multifd(void)
+{
+    MigrationState *s;
+
+    s = migrate_get_current();
+
+    return s->enabled_capabilities[MIGRATION_CAPABILITY_X_MULTIFD];
+}
+
 int migrate_use_xbzrle(void)
 {
     MigrationState *s;
qapi-schema.json +0 -0
index 61151f3..ff7579e 100644
@@ -865,12 +865,13 @@
 #        side, this process is called COarse-Grain LOck Stepping (COLO) for
 #        Non-stop Service. (since 2.8)

qapi-schema.json line 874

Quoted 10 lines
qapi-schema.json +3 -2
 #
+# @x-multifd: Use more than one fd for migration (since 2.9)
+#
 # Since: 1.2
 ##
 { 'enum': 'MigrationCapability',
   'data': ['xbzrle', 'rdma-pin-all', 'auto-converge', 'zero-blocks',
-           'compress', 'events', 'postcopy-ram', 'x-colo'] }
-
+           'compress', 'events', 'postcopy-ram', 'x-colo', 'x-multifd'] }

That needs a minor remerge after 'release-ram' just went in.

Dave

Quoted 6 lines
qapi-schema.json +0 -0
 ##
 # @MigrationCapabilityStatus:
 #
Signature · 1 line
2.7.4

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

#7 lore raw

[Qemu-devel] [PULL 04/12] migration: Create x-multifd-threads parameter

In reply to Juan Quintela

Indicates the number of threads that we would create. By default we create 2 threads.

--

Catch inconsistent defaults.
Thanks Eric

---
 hmp.c                         |  8 ++++++++
 include/migration/migration.h |  2 ++
 migration/migration.c         | 23 +++++++++++++++++++++++
 qapi-schema.json              | 13 +++++++++++--
 4 files changed, 44 insertions(+), 2 deletions(-)
hmp.c +8 -0
index 2bc4f06..71e3d8c 100644
@@ -323,6 +323,9 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
         monitor_printf(mon, " %s: %" PRId64,
             MigrationParameter_lookup[MIGRATION_PARAMETER_X_CHECKPOINT_DELAY],
             params->x_checkpoint_delay);
+        monitor_printf(mon, " %s: %" PRId64,
+            MigrationParameter_lookup[MIGRATION_PARAMETER_X_MULTIFD_THREADS],
+            params->x_multifd_threads);
         monitor_printf(mon, "\n");
     }
 
@@ -1395,6 +1398,10 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
                 p.has_x_checkpoint_delay = true;
                 use_int_value = true;
                 break;
+            case MIGRATION_PARAMETER_X_MULTIFD_THREADS:
+                p.has_x_multifd_threads = true;
+                use_int_value = true;
+                break;
             }
 
             if (use_int_value) {
@@ -1412,6 +1419,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
                 p.cpu_throttle_increment = valueint;
                 p.downtime_limit = valueint;
                 p.x_checkpoint_delay = valueint;
+                p.x_multifd_threads = valueint;
             }
 
             qmp_migrate_set_parameters(&p, &err);
include/migration/migration.h +2 -0
index e8bba55..de987da 100644
@@ -254,6 +254,8 @@ bool migration_in_postcopy(MigrationState *);
 bool migration_in_postcopy_after_devices(MigrationState *);
 MigrationState *migrate_get_current(void);
 
+int migrate_multifd_threads(void);
+
 void migrate_compress_threads_create(void);
 void migrate_compress_threads_join(void);
 void migrate_decompress_threads_create(void);
migration/migration.c +23 -0
index 37af7a4..141eac6 100644
@@ -67,6 +67,7 @@
  * Note: Please change this default value to 10000 when we support hybrid mode.
  */
 #define DEFAULT_MIGRATE_X_CHECKPOINT_DELAY 200
+#define DEFAULT_MIGRATE_MULTIFD_THREADS 2
 
 static NotifierList migration_state_notifiers =
     NOTIFIER_LIST_INITIALIZER(migration_state_notifiers);
@@ -101,6 +102,7 @@ MigrationState *migrate_get_current(void)
             .max_bandwidth = MAX_THROTTLE,
             .downtime_limit = DEFAULT_MIGRATE_SET_DOWNTIME,
             .x_checkpoint_delay = DEFAULT_MIGRATE_X_CHECKPOINT_DELAY,
+            .x_multifd_threads = DEFAULT_MIGRATE_MULTIFD_THREADS,
         },
     };
 
@@ -591,6 +593,8 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)
     params->downtime_limit = s->parameters.downtime_limit;
     params->has_x_checkpoint_delay = true;
     params->x_checkpoint_delay = s->parameters.x_checkpoint_delay;
+    params->has_x_multifd_threads = true;
+    params->x_multifd_threads = s->parameters.x_multifd_threads;
 
     return params;
 }
@@ -854,6 +858,13 @@ void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp)
                     "x_checkpoint_delay",
                     "is invalid, it should be positive");
     }
+    if (params->has_x_multifd_threads &&
+        (params->x_multifd_threads < 1 || params->x_multifd_threads > 255)) {
+        error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
+                   "multifd_threads",
+                   "is invalid, it should be in the range of 1 to 255");
+        return;
+    }
 
     if (params->has_compress_level) {
         s->parameters.compress_level = params->compress_level;
@@ -892,6 +903,9 @@ void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp)
     if (params->has_x_checkpoint_delay) {
         s->parameters.x_checkpoint_delay = params->x_checkpoint_delay;
     }
+    if (params->has_x_multifd_threads) {
+        s->parameters.x_multifd_threads = params->x_multifd_threads;
+    }
 }
 
 
@@ -1378,6 +1392,15 @@ bool migrate_use_multifd(void)
     return s->enabled_capabilities[MIGRATION_CAPABILITY_X_MULTIFD];
 }
 
+int migrate_multifd_threads(void)
+{
+    MigrationState *s;
+
+    s = migrate_get_current();
+
+    return s->parameters.x_multifd_threads;
+}
+
 int migrate_use_xbzrle(void)
 {
     MigrationState *s;
qapi-schema.json +11 -2
index ff7579e..5c18d54 100644
@@ -981,13 +981,17 @@
 # @x-checkpoint-delay: The delay time (in ms) between two COLO checkpoints in
 #          periodic mode. (Since 2.8)
 #
+# @x-multifd-threads: Number of threads used to migrate data in parallel
+#                     The default value is 2 (since 2.9)
+#
 # Since: 2.4
 ##
 { 'enum': 'MigrationParameter',
   'data': ['compress-level', 'compress-threads', 'decompress-threads',
            'cpu-throttle-initial', 'cpu-throttle-increment',
            'tls-creds', 'tls-hostname', 'max-bandwidth',
-           'downtime-limit', 'x-checkpoint-delay' ] }
+           'downtime-limit', 'x-checkpoint-delay',
+           'x-multifd-threads'] }
 
 ##
 # @migrate-set-parameters:
@@ -1050,6 +1054,10 @@
 #
 # @x-checkpoint-delay: the delay time between two COLO checkpoints. (Since 2.8)
 #
+#
+# @x-multifd-threads: Number of threads used to migrate data in parallel
+#                     The default value is 2 (since 2.9)
+#
 # Since: 2.4
 ##
 { 'struct': 'MigrationParameters',
@@ -1062,7 +1070,8 @@
             '*tls-hostname': 'str',
             '*max-bandwidth': 'int',
             '*downtime-limit': 'int',
-            '*x-checkpoint-delay': 'int'} }
+            '*x-checkpoint-delay': 'int',
+            '*x-multifd-threads': 'int'} }
 
 ##
 # @query-migrate-parameters:
Signature · 1 line
2.7.4
#8 lore raw

[Qemu-devel] [PULL 05/12] migration: Create x-multifd-group parameter

In reply to Juan Quintela

Indicates how many pages we are going to send in each batch to a multifd thread.

--

Be consistent with defaults and documentation

---
 hmp.c                         |  8 ++++++++
 include/migration/migration.h |  1 +
 migration/migration.c         | 23 +++++++++++++++++++++++
 qapi-schema.json              | 11 +++++++++--
 4 files changed, 41 insertions(+), 2 deletions(-)
hmp.c +8 -0
index 71e3d8c..fc24dad 100644
@@ -326,6 +326,9 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
         monitor_printf(mon, " %s: %" PRId64,
             MigrationParameter_lookup[MIGRATION_PARAMETER_X_MULTIFD_THREADS],
             params->x_multifd_threads);
+        monitor_printf(mon, " %s: %" PRId64,
+            MigrationParameter_lookup[MIGRATION_PARAMETER_X_MULTIFD_GROUP],
+            params->x_multifd_group);
         monitor_printf(mon, "\n");
     }
 
@@ -1402,6 +1405,10 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
                 p.has_x_multifd_threads = true;
                 use_int_value = true;
                 break;
+            case MIGRATION_PARAMETER_X_MULTIFD_GROUP:
+                p.has_x_multifd_group = true;
+                use_int_value = true;
+                break;
             }
 
             if (use_int_value) {
@@ -1420,6 +1427,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
                 p.downtime_limit = valueint;
                 p.x_checkpoint_delay = valueint;
                 p.x_multifd_threads = valueint;
+                p.x_multifd_group = valueint;
             }
 
             qmp_migrate_set_parameters(&p, &err);
include/migration/migration.h +1 -0
index de987da..3c7f165 100644
@@ -255,6 +255,7 @@ bool migration_in_postcopy_after_devices(MigrationState *);
 MigrationState *migrate_get_current(void);
 
 int migrate_multifd_threads(void);
+int migrate_multifd_group(void);
 
 void migrate_compress_threads_create(void);
 void migrate_compress_threads_join(void);
migration/migration.c +23 -0
index 141eac6..2b2d0a8 100644
@@ -68,6 +68,7 @@
  */
 #define DEFAULT_MIGRATE_X_CHECKPOINT_DELAY 200
 #define DEFAULT_MIGRATE_MULTIFD_THREADS 2
+#define DEFAULT_MIGRATE_MULTIFD_GROUP 16
 
 static NotifierList migration_state_notifiers =
     NOTIFIER_LIST_INITIALIZER(migration_state_notifiers);
@@ -103,6 +104,7 @@ MigrationState *migrate_get_current(void)
             .downtime_limit = DEFAULT_MIGRATE_SET_DOWNTIME,
             .x_checkpoint_delay = DEFAULT_MIGRATE_X_CHECKPOINT_DELAY,
             .x_multifd_threads = DEFAULT_MIGRATE_MULTIFD_THREADS,
+            .x_multifd_group = DEFAULT_MIGRATE_MULTIFD_GROUP,
         },
     };
 
@@ -595,6 +597,8 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)
     params->x_checkpoint_delay = s->parameters.x_checkpoint_delay;
     params->has_x_multifd_threads = true;
     params->x_multifd_threads = s->parameters.x_multifd_threads;
+    params->has_x_multifd_group = true;
+    params->x_multifd_group = s->parameters.x_multifd_group;
 
     return params;
 }
@@ -865,6 +869,13 @@ void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp)
                    "is invalid, it should be in the range of 1 to 255");
         return;
     }
+    if (params->has_x_multifd_group &&
+            (params->x_multifd_group < 1 || params->x_multifd_group > 10000)) {
+        error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
+                   "multifd_group",
+                   "is invalid, it should be in the range of 1 to 10000");
+        return;
+    }
 
     if (params->has_compress_level) {
         s->parameters.compress_level = params->compress_level;
@@ -906,6 +917,9 @@ void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp)
     if (params->has_x_multifd_threads) {
         s->parameters.x_multifd_threads = params->x_multifd_threads;
     }
+    if (params->has_x_multifd_group) {
+        s->parameters.x_multifd_group = params->x_multifd_group;
+    }
 }
 
 
@@ -1401,6 +1415,15 @@ int migrate_multifd_threads(void)
     return s->parameters.x_multifd_threads;
 }
 
+int migrate_multifd_group(void)
+{
+    MigrationState *s;
+
+    s = migrate_get_current();
+
+    return s->parameters.x_multifd_group;
+}
+
 int migrate_use_xbzrle(void)
 {
     MigrationState *s;
qapi-schema.json +9 -2
index 5c18d54..4fdea1a 100644
@@ -984,6 +984,9 @@
 # @x-multifd-threads: Number of threads used to migrate data in parallel
 #                     The default value is 2 (since 2.9)
 #
+# @x-multifd-group: Number of pages sent together to a thread
+#                     The default value is 16 (since 2.9)
+#
 # Since: 2.4
 ##
 { 'enum': 'MigrationParameter',
@@ -991,7 +994,7 @@
            'cpu-throttle-initial', 'cpu-throttle-increment',
            'tls-creds', 'tls-hostname', 'max-bandwidth',
            'downtime-limit', 'x-checkpoint-delay',
-           'x-multifd-threads'] }
+           'x-multifd-threads', 'x-multifd-group'] }
 
 ##
 # @migrate-set-parameters:
@@ -1058,6 +1061,9 @@
 # @x-multifd-threads: Number of threads used to migrate data in parallel
 #                     The default value is 2 (since 2.9)
 #
+# @x-multifd-group: Number of pages sent together in a bunch
+#                     The default value is 16 (since 2.9)
+#
 # Since: 2.4
 ##
 { 'struct': 'MigrationParameters',
@@ -1071,7 +1077,8 @@
             '*max-bandwidth': 'int',
             '*downtime-limit': 'int',
             '*x-checkpoint-delay': 'int',
-            '*x-multifd-threads': 'int'} }
+            '*x-multifd-threads': 'int',
+            '*x-multifd-group': 'int'} }
 
 ##
 # @query-migrate-parameters:
Signature · 1 line
2.7.4
#9 lore raw

[Qemu-devel] [PULL 06/12] migration: Create multifd migration threads

In reply to Juan Quintela

Creation of the threads, nothing inside yet.

--

Use pointers instead of long array names
Move to use semaphores instead of conditions as paolo suggestion

---
 include/migration/migration.h |   4 +
 migration/migration.c         |   6 ++
 migration/ram.c               | 168 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 178 insertions(+)
include/migration/migration.h +4 -0
index 3c7f165..13fac75 100644
@@ -256,6 +256,10 @@ MigrationState *migrate_get_current(void);
 
 int migrate_multifd_threads(void);
 int migrate_multifd_group(void);
+void migrate_multifd_send_threads_create(void);
+void migrate_multifd_send_threads_join(void);
+void migrate_multifd_recv_threads_create(void);
+void migrate_multifd_recv_threads_join(void);
 
 void migrate_compress_threads_create(void);
 void migrate_compress_threads_join(void);
migration/migration.c +6 -0
index 2b2d0a8..d2705d7 100644
@@ -344,6 +344,7 @@ static void process_incoming_migration_bh(void *opaque)
                           MIGRATION_STATUS_FAILED);
         error_report_err(local_err);
         migrate_decompress_threads_join();
+        migrate_multifd_recv_threads_join();
         exit(EXIT_FAILURE);
     }
 
@@ -368,6 +369,7 @@ static void process_incoming_migration_bh(void *opaque)
         runstate_set(global_state_get_runstate());
     }
     migrate_decompress_threads_join();
+    migrate_multifd_recv_threads_join();
     /*
      * This must happen after any state changes since as soon as an external
      * observer sees this event they might start to prod at the VM assuming
@@ -433,6 +435,7 @@ static void process_incoming_migration_co(void *opaque)
                           MIGRATION_STATUS_FAILED);
         error_report("load of migration failed: %s", strerror(-ret));
         migrate_decompress_threads_join();
+        migrate_multifd_recv_threads_join();
         exit(EXIT_FAILURE);
     }
 
@@ -445,6 +448,7 @@ void migration_fd_process_incoming(QEMUFile *f)
     Coroutine *co = qemu_coroutine_create(process_incoming_migration_co, f);
 
     migrate_decompress_threads_create();
+    migrate_multifd_recv_threads_create();
     qemu_file_set_blocking(f, false);
     qemu_coroutine_enter(co);
 }
@@ -974,6 +978,7 @@ static void migrate_fd_cleanup(void *opaque)
         qemu_mutex_lock_iothread();
 
         migrate_compress_threads_join();
+        migrate_multifd_send_threads_join();
         qemu_fclose(s->to_dst_file);
         s->to_dst_file = NULL;
     }
@@ -2100,6 +2105,7 @@ void migrate_fd_connect(MigrationState *s)
     }
 
     migrate_compress_threads_create();
+    migrate_multifd_send_threads_create();
     qemu_thread_create(&s->thread, "live_migration", migration_thread, s,
                        QEMU_THREAD_JOINABLE);
     s->migration_thread_running = true;
migration/ram.c +168 -0

174 lines not on this page · raw message

Signature · 1 line
2.7.4
#10 lore raw

Re: [Qemu-devel] [PULL 06/12] migration: Create multifd migration threads

Quoted 105 lines · Juan Quintela

Creation of the threads, nothing inside yet.

--

Use pointers instead of long array names
Move to use semaphores instead of conditions as paolo suggestion

---
 include/migration/migration.h |   4 +
 migration/migration.c         |   6 ++
 migration/ram.c               | 168 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 178 insertions(+)
include/migration/migration.h +4 -0
index 3c7f165..13fac75 100644
@@ -256,6 +256,10 @@ MigrationState *migrate_get_current(void);
 
 int migrate_multifd_threads(void);
 int migrate_multifd_group(void);
+void migrate_multifd_send_threads_create(void);
+void migrate_multifd_send_threads_join(void);
+void migrate_multifd_recv_threads_create(void);
+void migrate_multifd_recv_threads_join(void);
 
 void migrate_compress_threads_create(void);
 void migrate_compress_threads_join(void);
migration/migration.c +6 -0
index 2b2d0a8..d2705d7 100644
@@ -344,6 +344,7 @@ static void process_incoming_migration_bh(void *opaque)
                           MIGRATION_STATUS_FAILED);
         error_report_err(local_err);
         migrate_decompress_threads_join();
+        migrate_multifd_recv_threads_join();
         exit(EXIT_FAILURE);
     }
 
@@ -368,6 +369,7 @@ static void process_incoming_migration_bh(void *opaque)
         runstate_set(global_state_get_runstate());
     }
     migrate_decompress_threads_join();
+    migrate_multifd_recv_threads_join();
     /*
      * This must happen after any state changes since as soon as an external
      * observer sees this event they might start to prod at the VM assuming
@@ -433,6 +435,7 @@ static void process_incoming_migration_co(void *opaque)
                           MIGRATION_STATUS_FAILED);
         error_report("load of migration failed: %s", strerror(-ret));
         migrate_decompress_threads_join();
+        migrate_multifd_recv_threads_join();
         exit(EXIT_FAILURE);
     }
 
@@ -445,6 +448,7 @@ void migration_fd_process_incoming(QEMUFile *f)
     Coroutine *co = qemu_coroutine_create(process_incoming_migration_co, f);
 
     migrate_decompress_threads_create();
+    migrate_multifd_recv_threads_create();
     qemu_file_set_blocking(f, false);
     qemu_coroutine_enter(co);
 }
@@ -974,6 +978,7 @@ static void migrate_fd_cleanup(void *opaque)
         qemu_mutex_lock_iothread();
 
         migrate_compress_threads_join();
+        migrate_multifd_send_threads_join();
         qemu_fclose(s->to_dst_file);
         s->to_dst_file = NULL;
     }
@@ -2100,6 +2105,7 @@ void migrate_fd_connect(MigrationState *s)
     }
 
     migrate_compress_threads_create();
+    migrate_multifd_send_threads_create();
     qemu_thread_create(&s->thread, "live_migration", migration_thread, s,
                        QEMU_THREAD_JOINABLE);
     s->migration_thread_running = true;
migration/ram.c +15 -0
index 4422ee8..0cb19cf 100644
@@ -382,6 +382,174 @@ void migrate_compress_threads_create(void)
     }
 }
 
+/* Multiple fd's */
+
+struct MultiFDSendParams {
+    QemuThread thread;
+    QemuSemaphore sem;
+    QemuMutex mutex;
+    bool quit;
+};
+typedef struct MultiFDSendParams MultiFDSendParams;
+
+static MultiFDSendParams *multifd_send;
+
+static void *multifd_send_thread(void *opaque)
+{
+    MultiFDSendParams *params = opaque;

migration/ram.c void migrate_compress_threads_create(void) · line 409

Quoted 10 lines
migration/ram.c +10 -0
+
+    while (true) {
+        qemu_mutex_lock(&params->mutex);
+        if (params->quit) {
+            qemu_mutex_unlock(&params->mutex);
+            break;
+        }
+        qemu_mutex_unlock(&params->mutex);
+        qemu_sem_wait(&params->sem);
+    }

You can use

    while (true) {
        qemu_sem_wait(&params->sem);
        if (atomic_read(&params->quit)) {
            break;
        }
        if (atomic_read(&params->address)) {
            params->address = 0;
            params->done = true;
            qemu_set_post(&multifd_send_sem);
        }
    }

...

    atomic_set(&p->quit, true);
    qemu_sem_post(&p->sem);

This avoid params->mutex, and it works because wait and post are respectively acquire and release operations: the read certainly happens after wait, the write certainly happens before the post.

Likewise for ->done in patch 9; ->address and later ->pages.num don't even need atomic_read/atomic_set because there are two semaphores involved and they act as the synchronization point.

Paolo

Quoted 147 lines
migration/ram.c +143 -0
+
+    return NULL;
+}
+
+static void terminate_multifd_send_threads(void)
+{
+    int i, thread_count;
+
+    thread_count = migrate_multifd_threads();
+    for (i = 0; i < thread_count; i++) {
+        MultiFDSendParams *p = &multifd_send[i];
+
+        qemu_mutex_lock(&p->mutex);
+        p->quit = true;
+        qemu_sem_post(&p->sem);
+        qemu_mutex_unlock(&p->mutex);
+    }
+}
+
+void migrate_multifd_send_threads_join(void)
+{
+    int i, thread_count;
+
+    if (!migrate_use_multifd()) {
+        return;
+    }
+    terminate_multifd_send_threads();
+    thread_count = migrate_multifd_threads();
+    for (i = 0; i < thread_count; i++) {
+        MultiFDSendParams *p = &multifd_send[i];
+
+        qemu_thread_join(&p->thread);
+        qemu_mutex_destroy(&p->mutex);
+        qemu_sem_destroy(&p->sem);
+    }
+    g_free(multifd_send);
+    multifd_send = NULL;
+}
+
+void migrate_multifd_send_threads_create(void)
+{
+    int i, thread_count;
+
+    if (!migrate_use_multifd()) {
+        return;
+    }
+    thread_count = migrate_multifd_threads();
+    multifd_send = g_new0(MultiFDSendParams, thread_count);
+    for (i = 0; i < thread_count; i++) {
+        char thread_name[15];
+        MultiFDSendParams *p = &multifd_send[i];
+
+        qemu_mutex_init(&p->mutex);
+        qemu_sem_init(&p->sem, 0);
+        p->quit = false;
+        snprintf(thread_name, 15, "multifd_send_%d", i);
+        qemu_thread_create(&p->thread, thread_name, multifd_send_thread, p,
+                           QEMU_THREAD_JOINABLE);
+    }
+}
+
+struct MultiFDRecvParams {
+    QemuThread thread;
+    QemuSemaphore sem;
+    QemuMutex mutex;
+    bool quit;
+};
+typedef struct MultiFDRecvParams MultiFDRecvParams;
+
+static MultiFDRecvParams *multifd_recv;
+
+static void *multifd_recv_thread(void *opaque)
+{
+    MultiFDRecvParams *params = opaque;
+
+    while (true) {
+        qemu_mutex_lock(&params->mutex);
+        if (params->quit) {
+            qemu_mutex_unlock(&params->mutex);
+            break;
+        }
+        qemu_mutex_unlock(&params->mutex);
+        qemu_sem_wait(&params->sem);
+    }
+
+    return NULL;
+}
+
+static void terminate_multifd_recv_threads(void)
+{
+    int i, thread_count;
+
+    thread_count = migrate_multifd_threads();
+    for (i = 0; i < thread_count; i++) {
+        MultiFDRecvParams *p = &multifd_recv[i];
+
+        qemu_mutex_lock(&p->mutex);
+        p->quit = true;
+        qemu_sem_post(&p->sem);
+        qemu_mutex_unlock(&p->mutex);
+    }
+}
+
+void migrate_multifd_recv_threads_join(void)
+{
+    int i, thread_count;
+
+    if (!migrate_use_multifd()) {
+        return;
+    }
+    terminate_multifd_recv_threads();
+    thread_count = migrate_multifd_threads();
+    for (i = 0; i < thread_count; i++) {
+        MultiFDRecvParams *p = &multifd_recv[i];
+
+        qemu_thread_join(&p->thread);
+        qemu_mutex_destroy(&p->mutex);
+        qemu_sem_destroy(&p->sem);
+    }
+    g_free(multifd_recv);
+    multifd_recv = NULL;
+}
+
+void migrate_multifd_recv_threads_create(void)
+{
+    int i, thread_count;
+
+    if (!migrate_use_multifd()) {
+        return;
+    }
+    thread_count = migrate_multifd_threads();
+    multifd_recv = g_new0(MultiFDRecvParams, thread_count);
+    for (i = 0; i < thread_count; i++) {
+        MultiFDRecvParams *p = &multifd_recv[i];
+
+        qemu_mutex_init(&p->mutex);
+        qemu_sem_init(&p->sem, 0);
+        p->quit = false;
+        qemu_thread_create(&p->thread, "multifd_recv", multifd_recv_thread, p,
+                           QEMU_THREAD_JOINABLE);
+    }
+}
+
 /**
  * save_page_header: Write page header to wire
  *
#11 lore raw

[Qemu-devel] [PULL 07/12] migration: Start of multiple fd work

In reply to Juan Quintela

We create new channels for each new thread created. We only send through them a character to be sure that we are creating the channels in the right order.

---
 include/migration/migration.h |  7 +++++
 migration/ram.c               | 33 ++++++++++++++++++++++
 migration/socket.c            | 64 +++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 101 insertions(+), 3 deletions(-)
include/migration/migration.h +7 -0
index 13fac75..ff890b5 100644
@@ -22,6 +22,7 @@
 #include "qapi-types.h"
 #include "exec/cpu-common.h"
 #include "qemu/coroutine_int.h"
+#include "io/channel.h"
 
 #define QEMU_VM_FILE_MAGIC           0x5145564d
 #define QEMU_VM_FILE_VERSION_COMPAT  0x00000002
@@ -224,6 +225,12 @@ void tcp_start_incoming_migration(const char *host_port, Error **errp);
 
 void tcp_start_outgoing_migration(MigrationState *s, const char *host_port, Error **errp);
 
+QIOChannel *socket_recv_channel_create(void);
+int socket_recv_channel_destroy(QIOChannel *recv);
+int socket_recv_channel_close_listening(void);
+QIOChannel *socket_send_channel_create(void);
+int socket_send_channel_destroy(QIOChannel *send);
+
 void unix_start_incoming_migration(const char *path, Error **errp);
 
 void unix_start_outgoing_migration(MigrationState *s, const char *path, Error **errp);
migration/ram.c +33 -0
index 0cb19cf..b101a59 100644
@@ -386,7 +386,9 @@ void migrate_compress_threads_create(void)
 
 struct MultiFDSendParams {
     QemuThread thread;
+    QIOChannel *c;
     QemuSemaphore sem;
+    QemuSemaphore init;
     QemuMutex mutex;
     bool quit;
 };
@@ -397,6 +399,10 @@ static MultiFDSendParams *multifd_send;
 static void *multifd_send_thread(void *opaque)
 {
     MultiFDSendParams *params = opaque;
+    char start = 's';
+
+    qio_channel_write(params->c, &start, 1, &error_abort);
+    qemu_sem_post(&params->init);
 
     while (true) {
         qemu_mutex_lock(&params->mutex);
@@ -441,7 +447,10 @@ void migrate_multifd_send_threads_join(void)
         qemu_thread_join(&p->thread);
         qemu_mutex_destroy(&p->mutex);
         qemu_sem_destroy(&p->sem);
+        qemu_sem_destroy(&p->init);
+        socket_send_channel_destroy(p->c);
     }
+
     g_free(multifd_send);
     multifd_send = NULL;
 }
@@ -461,15 +470,24 @@ void migrate_multifd_send_threads_create(void)
 
         qemu_mutex_init(&p->mutex);
         qemu_sem_init(&p->sem, 0);
+        qemu_sem_init(&p->init, 0);
         p->quit = false;
+        p->c = socket_send_channel_create();
+        if (!p->c) {
+            error_report("Error creating a send channel");
+            exit(0);
+        }
         snprintf(thread_name, 15, "multifd_send_%d", i);
         qemu_thread_create(&p->thread, thread_name, multifd_send_thread, p,
                            QEMU_THREAD_JOINABLE);
+        qemu_sem_wait(&p->init);
     }
 }
 
 struct MultiFDRecvParams {
     QemuThread thread;
+    QIOChannel *c;
+    QemuSemaphore init;
     QemuSemaphore sem;
     QemuMutex mutex;
     bool quit;
@@ -481,6 +499,10 @@ static MultiFDRecvParams *multifd_recv;
 static void *multifd_recv_thread(void *opaque)
 {
     MultiFDRecvParams *params = opaque;
+    char start;
+
+    qio_channel_read(params->c, &start, 1, &error_abort);
+    qemu_sem_post(&params->init);
 
     while (true) {
         qemu_mutex_lock(&params->mutex);
@@ -525,6 +547,8 @@ void migrate_multifd_recv_threads_join(void)
         qemu_thread_join(&p->thread);
         qemu_mutex_destroy(&p->mutex);
         qemu_sem_destroy(&p->sem);
+        qemu_sem_destroy(&p->init);
+        socket_send_channel_destroy(multifd_recv[i].c);
     }
     g_free(multifd_recv);
     multifd_recv = NULL;
@@ -544,10 +568,19 @@ void migrate_multifd_recv_threads_create(void)
 
         qemu_mutex_init(&p->mutex);
         qemu_sem_init(&p->sem, 0);
+        qemu_sem_init(&p->init, 0);
         p->quit = false;
+        p->c = socket_recv_channel_create();
+
+        if (!p->c) {
+            error_report("Error creating a recv channel");
+            exit(0);
+        }
         qemu_thread_create(&p->thread, "multifd_recv", multifd_recv_thread, p,
                            QEMU_THREAD_JOINABLE);
+        qemu_sem_wait(&p->init);
     }
+    socket_recv_channel_close_listening();
 }
 
 /**
migration/socket.c +61 -3

94 lines not on this page · raw message

Signature · 1 line
2.7.4
#12 lore raw

Re: [Qemu-devel] [PULL 07/12] migration: Start of multiple fd work

Quoted 10 lines · Juan Quintela

We create new channels for each new thread created. We only send through them a character to be sure that we are creating the channels in the right order.

---
 include/migration/migration.h |  7 +++++
 migration/ram.c               | 33 ++++++++++++++++++++++
 migration/socket.c            | 64 +++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 101 insertions(+), 3 deletions(-)

[snip]

Quoted 96 lines
migration/socket.c +60 -3
index 13966f1..1c764f1 100644
@@ -24,6 +24,62 @@
 #include "io/channel-socket.h"
 #include "trace.h"
 
+struct SocketArgs {
+    QIOChannelSocket *ioc;
+    SocketAddress *saddr;
+    Error **errp;
+} socket_args;
+
+QIOChannel *socket_recv_channel_create(void)
+{
+    QIOChannelSocket *sioc;
+    Error *err = NULL;
+
+    sioc = qio_channel_socket_accept(QIO_CHANNEL_SOCKET(socket_args.ioc),
+                                     &err);
+    if (!sioc) {
+        error_report("could not accept migration connection (%s)",
+                     error_get_pretty(err));
+        return NULL;
+    }
+    return QIO_CHANNEL(sioc);
+}
+
+int socket_recv_channel_destroy(QIOChannel *recv)
+{
+    /* Remove channel */
+    object_unref(OBJECT(send));
+    return 0;
+}
+
+/* we have created all the recv channels, we can close the main one */
+int socket_recv_channel_close_listening(void)
+{
+    /* Close listening socket as its no longer needed */
+    qio_channel_close(QIO_CHANNEL(socket_args.ioc), NULL);
+    return 0;
+}
+
+QIOChannel *socket_send_channel_create(void)
+{
+    QIOChannelSocket *sioc = qio_channel_socket_new();
+
+    qio_channel_socket_connect_sync(sioc, socket_args.saddr,
+                                    socket_args.errp);
+    qio_channel_set_delay(QIO_CHANNEL(sioc), false);
+    return QIO_CHANNEL(sioc);
+}
+
+int socket_send_channel_destroy(QIOChannel *send)
+{
+    /* Remove channel */
+    object_unref(OBJECT(send));
+    if (socket_args.saddr) {
+        qapi_free_SocketAddress(socket_args.saddr);
+        socket_args.saddr = NULL;
+    }
+    return 0;
+}
 
 static SocketAddress *tcp_build_address(const char *host_port, Error **errp)
 {
@@ -97,6 +153,10 @@ static void socket_start_outgoing_migration(MigrationState *s,
     struct SocketConnectData *data = g_new0(struct SocketConnectData, 1);
 
     data->s = s;
+
+    socket_args.saddr = saddr;
+    socket_args.errp = errp;
+
     if (saddr->type == SOCKET_ADDRESS_KIND_INET) {
         data->hostname = g_strdup(saddr->u.inet.data->host);
     }
@@ -107,7 +167,6 @@ static void socket_start_outgoing_migration(MigrationState *s,
                                      socket_outgoing_migration,
                                      data,
                                      socket_connect_data_free);
-    qapi_free_SocketAddress(saddr);
 }
 
 void tcp_start_outgoing_migration(MigrationState *s,
@@ -154,8 +213,6 @@ static gboolean socket_accept_incoming_migration(QIOChannel *ioc,
     object_unref(OBJECT(sioc));
 
 out:
-    /* Close listening socket as its no longer needed */
-    qio_channel_close(ioc, NULL);
     return FALSE; /* unregister */
 }
 

migration/socket.c static void socket_start_incoming_migration(SocketAddress *saddr, · line 227

Quoted 7 lines
migration/socket.c +1 -0
@@ -164,6 +221,7 @@ static void socket_start_incoming_migration(SocketAddress *saddr,
                                             Error **errp)
 {
     QIOChannelSocket *listen_ioc = qio_channel_socket_new();
+    socket_args.ioc = listen_ioc;
 
     qio_channel_set_name(QIO_CHANNEL(listen_ioc),
                          "migration-socket-listener");

FYI I put some comments against v3 on this patch just as you sent this v4, as I don't think the changes here are desirable in this format.

Regards,
Daniel

Signature · 3 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://entangle-photo.org       -o-    http://search.cpan.org/~danberr/ :|
#13 lore raw

Re: [Qemu-devel] [PULL 07/12] migration: Start of multiple fd work

In reply to Juan Quintela

migration/ram.c void migrate_multifd_send_threads_create(void) · line 483

Quoted 11 lines · Juan Quintela
migration/ram.c +7 -0
+        qemu_sem_init(&p->init, 0);
         p->quit = false;
+        p->c = socket_send_channel_create();
+        if (!p->c) {
+            error_report("Error creating a send channel");
+            exit(0);
+        }
         snprintf(thread_name, 15, "multifd_send_%d", i);
         qemu_thread_create(&p->thread, thread_name, multifd_send_thread, p,
                            QEMU_THREAD_JOINABLE);
+        qemu_sem_wait(&p->init);

Why do you need p->init here? Could initialization proceed in parallel for all the threads?

Paolo

#14 lore raw

Re: [Qemu-devel] [PULL 07/12] migration: Start of multiple fd work

Quoted 13 lines · Paolo Bonzini

migration/ram.c void migrate_multifd_send_threads_create(void) · line 483

Quoted 11 lines · Juan Quintela
migration/ram.c +7 -0
+        qemu_sem_init(&p->init, 0);
         p->quit = false;
+        p->c = socket_send_channel_create();
+        if (!p->c) {
+            error_report("Error creating a send channel");
+            exit(0);
+        }
         snprintf(thread_name, 15, "multifd_send_%d", i);
         qemu_thread_create(&p->thread, thread_name, multifd_send_thread, p,
                            QEMU_THREAD_JOINABLE);
+        qemu_sem_wait(&p->init);
Quoted 2 lines

Why do you need p->init here? Could initialization proceed in parallel for all the threads?

We need to make sure that the send thread number 2 goes to thread number 2 on destination. Yes, we could do a more complicated algorithm, but we really care so much about this initialization time?

Later, Juan.

#15 lore raw

Re: [Qemu-devel] [PULL 07/12] migration: Start of multiple fd work

Quoted 12 lines · Juan Quintela
Quoted 12 lines · Juan Quintela
Quoted 11 lines
migration/ram.c +7 -0
+        qemu_sem_init(&p->init, 0);
         p->quit = false;
+        p->c = socket_send_channel_create();
+        if (!p->c) {
+            error_report("Error creating a send channel");
+            exit(0);
+        }
         snprintf(thread_name, 15, "multifd_send_%d", i);
         qemu_thread_create(&p->thread, thread_name, multifd_send_thread, p,
                            QEMU_THREAD_JOINABLE);
+        qemu_sem_wait(&p->init);
Quoted 6 lines
Quoted 2 lines

Why do you need p->init here? Could initialization proceed in parallel for all the threads?

We need to make sure that the send thread number 2 goes to thread number 2 on destination. Yes, we could do a more complicated algorithm, but we really care so much about this initialization time?

I was wondering if p->init was needed in general, so it would simplify. But without a design document I cannot really understand the logic---as I said, I don't really grok the need for RAM_SAVE_FLAG_MULTIFD_PAGE.

Paolo

#16 lore raw

Re: [Qemu-devel] [PULL 07/12] migration: Start of multiple fd work

Quoted 16 lines · Paolo Bonzini
Quoted 15 lines · Juan Quintela
Quoted 14 lines · Juan Quintela

migration/ram.c void migrate_multifd_send_threads_create(void) · line 483

Quoted 11 lines
migration/ram.c +7 -0
+        qemu_sem_init(&p->init, 0);
         p->quit = false;
+        p->c = socket_send_channel_create();
+        if (!p->c) {
+            error_report("Error creating a send channel");
+            exit(0);
+        }
         snprintf(thread_name, 15, "multifd_send_%d", i);
         qemu_thread_create(&p->thread, thread_name, multifd_send_thread, p,
                            QEMU_THREAD_JOINABLE);
+        qemu_sem_wait(&p->init);

Why do you need p->init here? Could initialization proceed in parallel for all the threads?

Quoted 7 lines
Quoted 3 lines

We need to make sure that the send thread number 2 goes to thread number 2 on destination. Yes, we could do a more complicated algorithm, but we really care so much about this initialization time?

I was wondering if p->init was needed in general, so it would simplify. But without a design document I cannot really understand the logic---as I said, I don't really grok the need for RAM_SAVE_FLAG_MULTIFD_PAGE.

will get some general documentation in /doc/.

Basically what we had on the only stream was:

{[page header][page]}+

And we moved to:

{[page header]+[where to receive]}: on the principal stream

[page]+: on the rest of the multifd

All nicely aligned and so.

My understanding is that we could optimize the receiving with splice to not even touch userspace? (that part is not done). That was the reason why I didn't want to put header's footers there. As the headers are so small compared with the pages payload, the transmission of them should be lost on the noise, no?

Later, Juan.

#17 lore raw

Re: [Qemu-devel] [PULL 07/12] migration: Start of multiple fd work

Quoted 10 lines · Juan Quintela

will get some general documentation in /doc/.

Basically what we had on the only stream was:

{[page header][page]}+

And we moved to:

Quoted 8 lines

{[page header]+[where to receive]}: on the principal stream

[page]+: on the rest of the multifd

All nicely aligned and so.

My understanding is that we could optimize the receiving with splice to not even touch userspace? (that part is not done).

The frames are not going to be aligned (MTU is usually 1500 or 9000), and the extra synchronization cost might nullify any speedup.

Even the send side can in principle be made completely independent, by scanning the bitmap in each thread.

Quoted 4 lines

That was the reason
why I didn't want to put header's footers there. As the headers are so small compared with the pages payload, the transmission of them should be lost on the noise, no?

The transmission may be, but the cost of having one more active socket + possibly the cost of Nagle's algorithm on that one socket + the cost of synchronization can be nontrivial.

Paolo

#18 lore raw

[Qemu-devel] [PULL 08/12] migration: Create ram_multifd_page

In reply to Juan Quintela

The function still don't use multifd, but we have simplified ram_save_page, xbzrle and RDMA stuff is gone. We have added a new counter and a new flag for this type of pages.

---
 hmp.c                         |  2 ++
 include/migration/migration.h |  1 +
 migration/migration.c         |  1 +
 migration/ram.c               | 51 ++++++++++++++++++++++++++++++++++++++++++-
 qapi-schema.json              |  4 +++-
 5 files changed, 57 insertions(+), 2 deletions(-)
hmp.c +2 -0
index fc24dad..eec0ffd 100644
@@ -223,6 +223,8 @@ void hmp_info_migrate(Monitor *mon, const QDict *qdict)
             monitor_printf(mon, "postcopy request count: %" PRIu64 "\n",
                            info->ram->postcopy_requests);
         }
+        monitor_printf(mon, "multifd: %" PRIu64 " pages\n",
+                       info->ram->multifd);
     }
 
     if (info->has_disk) {
include/migration/migration.h +1 -0
index ff890b5..cad03ab 100644
@@ -290,6 +290,7 @@ uint64_t xbzrle_mig_pages_transferred(void);
 uint64_t xbzrle_mig_pages_overflow(void);
 uint64_t xbzrle_mig_pages_cache_miss(void);
 double xbzrle_mig_cache_miss_rate(void);
+uint64_t multifd_mig_pages_transferred(void);
 
 void ram_handle_compressed(void *host, uint8_t ch, uint64_t size);
 void ram_debug_dump_bitmap(unsigned long *todump, bool expected);
migration/migration.c +1 -0
index d2705d7..2e3b357 100644
@@ -652,6 +652,7 @@ static void populate_ram_info(MigrationInfo *info, MigrationState *s)
     info->ram->mbps = s->mbps;
     info->ram->dirty_sync_count = s->dirty_sync_count;
     info->ram->postcopy_requests = s->postcopy_requests;
+    info->ram->multifd = multifd_mig_pages_transferred();
 
     if (s->state != MIGRATION_STATUS_COMPLETED) {
         info->ram->remaining = ram_bytes_remaining();
migration/ram.c +50 -1

105 lines not on this page · raw message

qapi-schema.json +3 -1
index 4fdea1a..03a0383 100644
@@ -574,6 +574,7 @@
 #
 # @postcopy-requests: The number of page requests received from the destination
 #        (since 2.7)
+# @multifd: number of pages sent with multifd (since 2.9)
 #
 # Since: 0.14.0
 ##
@@ -582,7 +583,8 @@
            'duplicate': 'int', 'skipped': 'int', 'normal': 'int',
            'normal-bytes': 'int', 'dirty-pages-rate' : 'int',
            'mbps' : 'number', 'dirty-sync-count' : 'int',
-           'postcopy-requests' : 'int' } }
+           'postcopy-requests' : 'int',
+           'multifd' : 'int'} }
 
 ##
 # @XBZRLECacheStats:
Signature · 1 line
2.7.4
#19 lore raw

[Qemu-devel] [PULL 10/12] migration: Really use multiple pages at a time

In reply to Juan Quintela

We now send several pages at a time each time that we wakeup a thread.

---
 migration/ram.c | 44 ++++++++++++++++++++++++++++++++++++++------
 1 file changed, 38 insertions(+), 6 deletions(-)
migration/ram.c +38 -6
index f7df6cb..8d85c49 100644
@@ -391,6 +391,13 @@ void migrate_compress_threads_create(void)
 
 /* Multiple fd's */
 
+
+typedef struct {
+    int num;
+    int size;
+    uint8_t **address;
+} MultiFDPages;
+
 struct MultiFDSendParams {
     /* not changed */
     QemuThread thread;
@@ -400,7 +407,7 @@ struct MultiFDSendParams {
     QemuMutex mutex;
     /* protected by param mutex */
     bool quit;
-    uint8_t *address;
+    MultiFDPages pages;
     /* protected by multifd mutex */
     bool done;
 };
@@ -426,8 +433,8 @@ static void *multifd_send_thread(void *opaque)
             qemu_mutex_unlock(&params->mutex);
             break;
         }
-        if (params->address) {
-            params->address = 0;
+        if (params->pages.num) {
+            params->pages.num = 0;
             qemu_mutex_unlock(&params->mutex);
             qemu_mutex_lock(&multifd_send_mutex);
             params->done = true;
@@ -480,6 +487,13 @@ void migrate_multifd_send_threads_join(void)
     multifd_send = NULL;
 }
 
+static void multifd_init_group(MultiFDPages *pages)
+{
+    pages->num = 0;
+    pages->size = migrate_multifd_group();
+    pages->address = g_new0(uint8_t *, pages->size);
+}
+
 void migrate_multifd_send_threads_create(void)
 {
     int i, thread_count;
@@ -500,7 +514,7 @@ void migrate_multifd_send_threads_create(void)
         qemu_sem_init(&p->init, 0);
         p->quit = false;
         p->done = true;
-        p->address = 0;
+        multifd_init_group(&multifd_send[i].pages);
         p->c = socket_send_channel_create();
         if (!p->c) {
             error_report("Error creating a send channel");
@@ -515,7 +529,21 @@ void migrate_multifd_send_threads_create(void)
 
 static int multifd_send_page(uint8_t *address)
 {
-    int i, thread_count;
+    int i, j, thread_count;
+    static MultiFDPages pages;
+    static bool once;
+
+    if (!once) {
+        multifd_init_group(&pages);
+        once = true;
+    }
+
+    pages.address[pages.num] = address;
+    pages.num++;
+
+    if (pages.num < (pages.size - 1)) {
+        return UINT16_MAX;
+    }
 
     thread_count = migrate_multifd_threads();
     qemu_sem_wait(&multifd_send_sem);
@@ -528,7 +556,11 @@ static int multifd_send_page(uint8_t *address)
     }
     qemu_mutex_unlock(&multifd_send_mutex);
     qemu_mutex_lock(&multifd_send[i].mutex);
-    multifd_send[i].address = address;
+    multifd_send[i].pages.num = pages.num;
+    for (j = 0; j < pages.size; j++) {
+        multifd_send[i].pages.address[j] = pages.address[j];
+    }
+    pages.num = 0;
     qemu_mutex_unlock(&multifd_send[i].mutex);
     qemu_sem_post(&multifd_send[i].sem);
 
Signature · 1 line
2.7.4
#20 lore raw

[Qemu-devel] [PULL 09/12] migration: Create thread infrastructure for multifd send side

In reply to Juan Quintela

We make the locking and the transfer of information specific, even if we are still transmiting things through the main thread.

--

Move synchronization to use semaphores, as paolo suggestion.

---
 migration/ram.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
migration/ram.c +45 -0
index 45c46cb..f7df6cb 100644
@@ -392,17 +392,25 @@ void migrate_compress_threads_create(void)
 /* Multiple fd's */
 
 struct MultiFDSendParams {
+    /* not changed */
     QemuThread thread;
     QIOChannel *c;
     QemuSemaphore sem;
     QemuSemaphore init;
     QemuMutex mutex;
+    /* protected by param mutex */
     bool quit;
+    uint8_t *address;
+    /* protected by multifd mutex */
+    bool done;
 };
 typedef struct MultiFDSendParams MultiFDSendParams;
 
 static MultiFDSendParams *multifd_send;
 
+QemuMutex multifd_send_mutex;
+QemuSemaphore multifd_send_sem;
+
 static void *multifd_send_thread(void *opaque)
 {
     MultiFDSendParams *params = opaque;
@@ -410,6 +418,7 @@ static void *multifd_send_thread(void *opaque)
 
     qio_channel_write(params->c, &start, 1, &error_abort);
     qemu_sem_post(&params->init);
+    qemu_sem_post(&multifd_send_sem);
 
     while (true) {
         qemu_mutex_lock(&params->mutex);
@@ -417,6 +426,15 @@ static void *multifd_send_thread(void *opaque)
             qemu_mutex_unlock(&params->mutex);
             break;
         }
+        if (params->address) {
+            params->address = 0;
+            qemu_mutex_unlock(&params->mutex);
+            qemu_mutex_lock(&multifd_send_mutex);
+            params->done = true;
+            qemu_mutex_unlock(&multifd_send_mutex);
+            qemu_sem_post(&multifd_send_sem);
+            continue;
+        }
         qemu_mutex_unlock(&params->mutex);
         qemu_sem_wait(&params->sem);
     }
@@ -471,6 +489,8 @@ void migrate_multifd_send_threads_create(void)
     }
     thread_count = migrate_multifd_threads();
     multifd_send = g_new0(MultiFDSendParams, thread_count);
+    qemu_mutex_init(&multifd_send_mutex);
+    qemu_sem_init(&multifd_send_sem, 0);
     for (i = 0; i < thread_count; i++) {
         char thread_name[15];
         MultiFDSendParams *p = &multifd_send[i];
@@ -479,6 +499,8 @@ void migrate_multifd_send_threads_create(void)
         qemu_sem_init(&p->sem, 0);
         qemu_sem_init(&p->init, 0);
         p->quit = false;
+        p->done = true;
+        p->address = 0;
         p->c = socket_send_channel_create();
         if (!p->c) {
             error_report("Error creating a send channel");
@@ -491,6 +513,28 @@ void migrate_multifd_send_threads_create(void)
     }
 }
 
+static int multifd_send_page(uint8_t *address)
+{
+    int i, thread_count;
+
+    thread_count = migrate_multifd_threads();
+    qemu_sem_wait(&multifd_send_sem);
+    qemu_mutex_lock(&multifd_send_mutex);
+    for (i = 0; i < thread_count; i++) {
+        if (multifd_send[i].done) {
+            multifd_send[i].done = false;
+            break;
+        }
+    }
+    qemu_mutex_unlock(&multifd_send_mutex);
+    qemu_mutex_lock(&multifd_send[i].mutex);
+    multifd_send[i].address = address;
+    qemu_mutex_unlock(&multifd_send[i].mutex);
+    qemu_sem_post(&multifd_send[i].sem);
+
+    return 0;
+}
+
 struct MultiFDRecvParams {
     QemuThread thread;
     QIOChannel *c;
@@ -1023,6 +1067,7 @@ static int ram_multifd_page(QEMUFile *f, PageSearchStatus *pss,
         *bytes_transferred +=
             save_page_header(f, block, offset | RAM_SAVE_FLAG_MULTIFD_PAGE);
         qemu_put_buffer(f, p, TARGET_PAGE_SIZE);
+        multifd_send_page(p);
         *bytes_transferred += TARGET_PAGE_SIZE;
         pages = 1;
         acct_info.norm_pages++;
Signature · 1 line
2.7.4
#21 lore raw

[Qemu-devel] [PULL 11/12] migration: Send the fd number which we are going to use for this page

In reply to Juan Quintela

We are still sending the page through the main channel, that would change later in the series

---
 migration/ram.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 66 insertions(+), 5 deletions(-)
migration/ram.c +66 -5
index 8d85c49..38789c8 100644
@@ -527,7 +527,8 @@ void migrate_multifd_send_threads_create(void)
     }
 }
 
-static int multifd_send_page(uint8_t *address)
+
+static uint16_t multifd_send_page(uint8_t *address, bool last_page)
 {
     int i, j, thread_count;
     static MultiFDPages pages;
@@ -541,8 +542,10 @@ static int multifd_send_page(uint8_t *address)
     pages.address[pages.num] = address;
     pages.num++;
 
-    if (pages.num < (pages.size - 1)) {
-        return UINT16_MAX;
+    if (!last_page) {
+        if (pages.num < (pages.size - 1)) {
+            return UINT16_MAX;
+        }
     }
 
     thread_count = migrate_multifd_threads();
@@ -564,16 +567,21 @@ static int multifd_send_page(uint8_t *address)
     qemu_mutex_unlock(&multifd_send[i].mutex);
     qemu_sem_post(&multifd_send[i].sem);
 
-    return 0;
+    return i;
 }
 
 struct MultiFDRecvParams {
+    /* not changed */
     QemuThread thread;
     QIOChannel *c;
     QemuSemaphore init;
+    QemuSemaphore ready;
     QemuSemaphore sem;
     QemuMutex mutex;
+    /* proteced by param mutex */
     bool quit;
+    MultiFDPages pages;
+    bool done;
 };
 typedef struct MultiFDRecvParams MultiFDRecvParams;
 
@@ -586,6 +594,7 @@ static void *multifd_recv_thread(void *opaque)
 
     qio_channel_read(params->c, &start, 1, &error_abort);
     qemu_sem_post(&params->init);
+    qemu_sem_post(&params->ready);
 
     while (true) {
         qemu_mutex_lock(&params->mutex);
@@ -593,6 +602,13 @@ static void *multifd_recv_thread(void *opaque)
             qemu_mutex_unlock(&params->mutex);
             break;
         }
+        if (params->pages.num) {
+            params->pages.num = 0;
+            params->done = true;
+            qemu_mutex_unlock(&params->mutex);
+            qemu_sem_post(&params->ready);
+            continue;
+        }
         qemu_mutex_unlock(&params->mutex);
         qemu_sem_wait(&params->sem);
     }
@@ -652,7 +668,10 @@ void migrate_multifd_recv_threads_create(void)
         qemu_mutex_init(&p->mutex);
         qemu_sem_init(&p->sem, 0);
         qemu_sem_init(&p->init, 0);
+        qemu_sem_init(&p->ready, 0);
         p->quit = false;
+        p->done = false;
+        multifd_init_group(&p->pages);
         p->c = socket_recv_channel_create();
 
         if (!p->c) {
@@ -666,6 +685,42 @@ void migrate_multifd_recv_threads_create(void)
     socket_recv_channel_close_listening();
 }
 
+static void multifd_recv_page(uint8_t *address, uint16_t fd_num)
+{
+    int i, thread_count;
+    MultiFDRecvParams *params;
+    static MultiFDPages pages;
+    static bool once;
+
+    if (!once) {
+        multifd_init_group(&pages);
+        once = true;
+    }
+
+    pages.address[pages.num] = address;
+    pages.num++;
+
+    if (fd_num == UINT16_MAX) {
+        return;
+    }
+
+    thread_count = migrate_multifd_threads();
+    assert(fd_num < thread_count);
+    params = &multifd_recv[fd_num];
+
+    qemu_sem_wait(&params->ready);
+
+    qemu_mutex_lock(&params->mutex);
+    params->done = false;
+    for (i = 0; i < pages.num; i++) {
+        params->pages.address[i] = pages.address[i];
+    }
+    params->pages.num = pages.num;
+    pages.num = 0;
+    qemu_mutex_unlock(&params->mutex);
+    qemu_sem_post(&params->sem);
+}
+
 /**
  * save_page_header: Write page header to wire
  *
@@ -1085,6 +1140,7 @@ static int ram_multifd_page(QEMUFile *f, PageSearchStatus *pss,
                             bool last_stage, uint64_t *bytes_transferred)
 {
     int pages;
+    uint16_t fd_num;
     uint8_t *p;
     RAMBlock *block = pss->block;
     ram_addr_t offset = pss->offset;
@@ -1098,8 +1154,10 @@ static int ram_multifd_page(QEMUFile *f, PageSearchStatus *pss,
     if (pages == -1) {
         *bytes_transferred +=
             save_page_header(f, block, offset | RAM_SAVE_FLAG_MULTIFD_PAGE);
+        fd_num = multifd_send_page(p, migration_dirty_pages == 1);
+        qemu_put_be16(f, fd_num);
+        *bytes_transferred += 2; /* size of fd_num */
         qemu_put_buffer(f, p, TARGET_PAGE_SIZE);
-        multifd_send_page(p);
         *bytes_transferred += TARGET_PAGE_SIZE;
         pages = 1;
         acct_info.norm_pages++;
@@ -2813,6 +2871,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
     while (!postcopy_running && !ret && !(flags & RAM_SAVE_FLAG_EOS)) {
         ram_addr_t addr, total_ram_bytes;
         void *host = NULL;
+        uint16_t fd_num;
         uint8_t ch;
 
         addr = qemu_get_be64(f);
@@ -2910,6 +2969,8 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
             break;
 
         case RAM_SAVE_FLAG_MULTIFD_PAGE:
+            fd_num = qemu_get_be16(f);
+            multifd_recv_page(host, fd_num);
             qemu_get_buffer(f, host, TARGET_PAGE_SIZE);
             break;
 
Signature · 1 line
2.7.4
#22 lore raw

Re: [Qemu-devel] [PULL 11/12] migration: Send the fd number which we are going to use for this page

migration/ram.c static int ram_load(QEMUFile *f, void *opaque, int version_id) · line 2975

Quoted 5 lines · Juan Quintela

case RAM_SAVE_FLAG_MULTIFD_PAGE:

migration/ram.c +2 -0
+            fd_num = qemu_get_be16(f);
+            multifd_recv_page(host, fd_num);
             qemu_get_buffer(f, host, TARGET_PAGE_SIZE);
             break;

Why do you need RAM_SAVE_FLAG_MULTIFD_PAGE? I understand the orchestration of sent pages from a single thread, but could the receive threads proceed independently, each reading its own socket? They do not even need to tell the central thread "I'm done" (they can do so just by exiting, and the central thread does qemu_thread_join when it sees the marker for end of live data).

Paolo

#23 lore raw

Re: [Qemu-devel] [PULL 11/12] migration: Send the fd number which we are going to use for this page

Quoted 7 lines · Paolo Bonzini

migration/ram.c static int ram_load(QEMUFile *f, void *opaque, int version_id) · line 2975

Quoted 5 lines · Juan Quintela

case RAM_SAVE_FLAG_MULTIFD_PAGE:

migration/ram.c +2 -0
+            fd_num = qemu_get_be16(f);
+            multifd_recv_page(host, fd_num);
             qemu_get_buffer(f, host, TARGET_PAGE_SIZE);
             break;
Quoted 6 lines

Why do you need RAM_SAVE_FLAG_MULTIFD_PAGE? I understand the orchestration of sent pages from a single thread, but could the receive threads proceed independently, each reading its own socket? They do not even need to tell the central thread "I'm done" (they can do so just by exiting, and the central thread does qemu_thread_join when it sees the marker for end of live data).

We can send multiple sends in one go, the whole idea was to send the pages "aligned", and being able to read also in place on destination.

But this showed that we still have bottlenecks on the code that search for pages :-(

Later, Juan.

#24 lore raw

[Qemu-devel] [PULL 12/12] migration: Test new fd infrastructure

In reply to Juan Quintela

We just send the address through the alternate channels and test that it is ok.

---
 include/migration/migration.h |  1 +
 migration/migration.c         | 15 +++++--
 migration/ram.c               | 91 ++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 101 insertions(+), 6 deletions(-)
include/migration/migration.h +1 -0
index cad03ab..5ec5c62 100644
@@ -267,6 +267,7 @@ void migrate_multifd_send_threads_create(void);
 void migrate_multifd_send_threads_join(void);
 void migrate_multifd_recv_threads_create(void);
 void migrate_multifd_recv_threads_join(void);
+void qemu_savevm_send_multifd_flush(QEMUFile *f);
 
 void migrate_compress_threads_create(void);
 void migrate_compress_threads_join(void);
migration/migration.c +11 -4
index 2e3b357..10ed934 100644
@@ -1919,7 +1919,8 @@ static void *migration_thread(void *opaque)
     /* Used by the bandwidth calcs, updated later */
     int64_t initial_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
     int64_t setup_start = qemu_clock_get_ms(QEMU_CLOCK_HOST);
-    int64_t initial_bytes = 0;
+    int64_t qemu_file_bytes = 0;
+    int64_t multifd_pages = 0;
     int64_t max_size = 0;
     int64_t start_time = initial_time;
     int64_t end_time;
@@ -2003,9 +2004,14 @@ static void *migration_thread(void *opaque)
         }
         current_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
         if (current_time >= initial_time + BUFFER_DELAY) {
-            uint64_t transferred_bytes = qemu_ftell(s->to_dst_file) -
-                                         initial_bytes;
             uint64_t time_spent = current_time - initial_time;
+            uint64_t qemu_file_bytes_now = qemu_ftell(s->to_dst_file);
+            uint64_t multifd_pages_now = multifd_mig_pages_transferred();
+            /* Hack ahead.  Why the hell we don't have a function to now the
+               target_page_size.  Hard coding it to 4096 */
+            uint64_t transferred_bytes =
+                (qemu_file_bytes_now - qemu_file_bytes) +
+                (multifd_pages_now - multifd_pages) * 4096;
             double bandwidth = (double)transferred_bytes / time_spent;
             max_size = bandwidth * s->parameters.downtime_limit;
 
@@ -2022,7 +2028,8 @@ static void *migration_thread(void *opaque)
 
             qemu_file_reset_rate_limit(s->to_dst_file);
             initial_time = current_time;
-            initial_bytes = qemu_ftell(s->to_dst_file);
+            qemu_file_bytes = qemu_file_bytes_now;
+            multifd_pages = multifd_pages_now;
         }
         if (qemu_file_rate_limit(s->to_dst_file)) {
             /* usleep expects microseconds */
migration/ram.c +89 -2

185 lines not on this page · raw message

Signature · 1 line
2.7.4
#25 lore raw
In reply to Juan Quintela
Quoted 10 lines · Juan Quintela

Hi

[v4]

- Address reviews
- move synchronization to semaphores (faster). Paolo suggestion
- improvements overall (see invidiual patches)
- fix all the checkpatch warnings
- fix all [HACKS] except for one
Please review.

Is this a patch series or a pull request? The subject line says "PATCH" and the body says 'please review' but it's in the form of a pull request email...

thanks
-- PMM

#26 lore raw
Quoted 13 lines · Peter Maydell
Quoted 10 lines · Juan Quintela

Hi

[v4]

- Address reviews
- move synchronization to semaphores (faster). Paolo suggestion
- improvements overall (see invidiual patches)
- fix all the checkpatch warnings
- fix all [HACKS] except for one
Please review.

Quoted 3 lines

Is this a patch series or a pull request? The subject line says "PATCH" and the body says 'please review' but it's in the form of a pull request email...

patch, sorry.

I have to upgrade my scripts.

Sorry again, Juan.

#27 lore raw
In reply to Juan Quintela
Quoted 9 lines · Juan Quintela

[v4]

- Address reviews
- move synchronization to semaphores (faster). Paolo suggestion
- improvements overall (see invidiual patches)
- fix all the checkpatch warnings
- fix all [HACKS] except for one

Please review.

I think you can simplify the receive threads much more. I left comments on patch 11.

Paolo