Multifd v2
cover Multifd v2
Hi
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.
Juan Quintela (13):
migration: create Migration Incoming State at init time
migration: [HACK] Don't create decompression threads if not enabled
migration: Add multifd capability
migration: Create x-multifd-threads 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: Send the fd number which we are going to use for this page
migration: Create thread infrastructure for multifd recv side
migration: Test new fd infrastructure
migration: [HACK]Transfer pages over new channels
migration: flush receive queue
hmp.c | 9 + include/migration/migration.h | 16 +- migration/migration.c | 93 +++++++--- migration/ram.c | 420 +++++++++++++++++++++++++++++++++++++++++- migration/savevm.c | 4 +- migration/socket.c | 53 +++++- qapi-schema.json | 20 +- 7 files changed, 580 insertions(+), 35 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/13 migration: create Migration Incoming State at init time
--- include/migration/migration.h | 1 - migration/migration.c | 38 +++++++++++++++++--------------------- migration/savevm.c | 4 ++-- 3 files changed, 19 insertions(+), 24 deletions(-)
include/migration/migration.h +0 -1
@@ -112,7 +112,6 @@ struct MigrationIncomingState { };MigrationIncomingState *migration_incoming_get_current (void ); -MigrationIncomingState *migration_incoming_state_new (QEMUFile *f);void migration_incoming_state_destroy (void );/*
migration/migration.c +17 -21
@@ -104,32 +104,28 @@ MigrationState *migrate_get_current(void)return ¤t_migration; } -/* For incoming */ -static MigrationIncomingState *mis_current; -MigrationIncomingState *migration_incoming_get_current (void ) { -return mis_current; -} +static bool once; +static MigrationIncomingState mis_current; -MigrationIncomingState *migration_incoming_state_new (QEMUFile * f) -{ - mis_current =g_new0 (MigrationIncomingState,1 ); - mis_current->from_src_file = f; - mis_current->state =MIGRATION_STATUS_NONE ; -QLIST_INIT (&mis_current->loadvm_handlers); -qemu_mutex_init (&mis_current->rp_mutex); -qemu_event_init (&mis_current->main_thread_load_event, false); - -return mis_current; +if (!once) { + mis_current.state =MIGRATION_STATUS_NONE ; +memset (&mis_current,0 ,sizeof (MigrationIncomingState)); +QLIST_INIT (&mis_current.loadvm_handlers); +qemu_mutex_init (&mis_current.rp_mutex); +qemu_event_init (&mis_current.main_thread_load_event, false); + once = true; + } +return &mis_current; }void migration_incoming_state_destroy (void ) { -qemu_event_destroy (&mis_current->main_thread_load_event); -loadvm_free_handlers (mis_current); -g_free (mis_current); - mis_current =NULL ; +struct MigrationIncomingState *mis =migration_incoming_get_current (); + +qemu_event_destroy (&mis->main_thread_load_event); +loadvm_free_handlers (mis); }
@@ -375,11 +371,11 @@ static void process_incoming_migration_bh(void *opaque)static void process_incoming_migration_co (void *opaque) {QEMUFile *f = opaque; -MigrationIncomingState *mis; +MigrationIncomingState *mis =migration_incoming_get_current ();PostcopyState ps;int ret; - mis =migration_incoming_state_new (f); + mis->from_src_file = f;postcopy_state_set (POSTCOPY_INCOMING_NONE );migrate_set_state (&mis->state,MIGRATION_STATUS_NONE ,MIGRATION_STATUS_ACTIVE );
migration/savevm.c +2 -2
@@ -2107,7 +2107,6 @@ void qmp_xen_load_devices_state(const char *filename, Error **errp) } f =qemu_fopen_channel_input (QIO_CHANNEL (ioc)); -migration_incoming_state_new (f); ret =qemu_loadvm_state (f);qemu_fclose (f);if (ret <0 ) {
@@ -2123,6 +2122,7 @@ int load_vmstate(const char *name)QEMUFile *f;int ret;AioContext *aio_context; +MigrationIncomingState *mis =migration_incoming_get_current ();if (!bdrv_all_can_snapshot (&bs)) { error_report("Device '%s' is writable but does not support snapshots.",
@@ -2173,7 +2173,7 @@ int load_vmstate(const char *name) }qemu_system_reset (VMRESET_SILENT ); -migration_incoming_state_new (f); + mis->from_src_file = f;aio_context_acquire (aio_context); ret =qemu_loadvm_state (f);
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 01/13] migration: create Migration Incoming State at init time
Quoted 90 lines · * Juan Quintela ([email protected]) wrote:
Signed-off-by Juan Quintela <[email protected]>--- include/migration/migration.h | 1 - migration/migration.c | 38 +++++++++++++++++--------------------- migration/savevm.c | 4 ++-- 3 files changed, 19 insertions(+), 24 deletions(-)include/migration/migration.h +0
-1@@ -112,7 +112,6 @@ struct MigrationIncomingState { };MigrationIncomingState *migration_incoming_get_current (void ); -MigrationIncomingState *migration_incoming_state_new (QEMUFile *f);void migration_incoming_state_destroy (void );/* migration/migration.c +17
-21@@ -104,32 +104,28 @@ MigrationState *migrate_get_current(void)return ¤t_migration; } -/* For incoming */ -static MigrationIncomingState *mis_current; -MigrationIncomingState *migration_incoming_get_current (void ) { -return mis_current; -} +static bool once; +static MigrationIncomingState mis_current; -MigrationIncomingState *migration_incoming_state_new (QEMUFile * f) -{ - mis_current =g_new0 (MigrationIncomingState,1 ); - mis_current->from_src_file = f; - mis_current->state =MIGRATION_STATUS_NONE ; -QLIST_INIT (&mis_current->loadvm_handlers); -qemu_mutex_init (&mis_current->rp_mutex); -qemu_event_init (&mis_current->main_thread_load_event, false); - -return mis_current; +if (!once) { + mis_current.state =MIGRATION_STATUS_NONE ; +memset (&mis_current,0 ,sizeof (MigrationIncomingState)); +QLIST_INIT (&mis_current.loadvm_handlers); +qemu_mutex_init (&mis_current.rp_mutex); +qemu_event_init (&mis_current.main_thread_load_event, false); + once = true; + } +return &mis_current; }void migration_incoming_state_destroy (void ) { -qemu_event_destroy (&mis_current->main_thread_load_event); -loadvm_free_handlers (mis_current); -g_free (mis_current); - mis_current =NULL ; +struct MigrationIncomingState *mis =migration_incoming_get_current (); + +qemu_event_destroy (&mis->main_thread_load_event); +loadvm_free_handlers (mis); }@@ -375,11 +371,11 @@ static void process_incoming_migration_bh(void *opaque)static void process_incoming_migration_co (void *opaque) {QEMUFile *f = opaque; -MigrationIncomingState *mis; +MigrationIncomingState *mis =migration_incoming_get_current ();PostcopyState ps;int ret; - mis =migration_incoming_state_new (f); + mis->from_src_file = f;postcopy_state_set (POSTCOPY_INCOMING_NONE );migrate_set_state (&mis->state,MIGRATION_STATUS_NONE ,MIGRATION_STATUS_ACTIVE );migration/savevm.c +0
-0
migration/savevm.c void qmp_xen_load_devices_state(const char *filename, Error **errp) · line 2110
Quoted 4 lines
migration/savevm.c +0
-1@@ -2107,7 +2107,6 @@ void qmp_xen_load_devices_state(const char *filename, Error **errp) } f =qemu_fopen_channel_input (QIO_CHANNEL (ioc)); -migration_incoming_state_new (f);
It's curious that this one is the odd case of not setting mis->from_src_file.
Anyway, I think it's OK but please test it with -incoming defer.
Quoted 23 lines
migration/savevm.c +2
-1ret =qemu_loadvm_state (f);qemu_fclose (f);if (ret <0 ) {@@ -2123,6 +2122,7 @@ int load_vmstate(const char *name)QEMUFile *f;int ret;AioContext *aio_context; +MigrationIncomingState *mis =migration_incoming_get_current ();if (!bdrv_all_can_snapshot (&bs)) { error_report("Device '%s' is writable but does not support snapshots.",@@ -2173,7 +2173,7 @@ int load_vmstate(const char *name) }qemu_system_reset (VMRESET_SILENT ); -migration_incoming_state_new (f); + mis->from_src_file = f;aio_context_acquire (aio_context); ret =qemu_loadvm_state (f);Signature · 1 line
2.7.4
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
PATCH 2/13 migration: [HACK] Don't create decompression threads if not enabled
In reply to Juan QuintelaThis is a partial fix, we also need to not allow reception of compression packages if not enabled.
--- migration/ram.c | 6 ++++++ 1 file changed, 6 insertions(+)
migration/ram.c +6 -0
@@ -2241,6 +2241,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);
@@ -2262,6 +2265,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
PATCH 3/13 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
@@ -290,6 +290,7 @@ bool migrate_postcopy_ram(void);bool migrate_zero_blocks (void );bool migrate_auto_converge (void ); +bool migrate_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
@@ -1273,6 +1273,15 @@ bool migrate_use_events(void)return s->enabled_capabilities[MIGRATION_CAPABILITY_EVENTS ]; } +bool migrate_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
@@ -574,12 +574,13 @@ # been migrated, pulling the remaining pages along as needed. NOTE: If # the migration fails during postcopy the VM will fail. (since 2.6) # +# @x-multifd: Use more than one fd for migration (since 2.8) +# # Since: 1.2 ## { 'enum': 'MigrationCapability', 'data': ['xbzrle', 'rdma-pin-all', 'auto-converge', 'zero-blocks', - 'compress', 'events', 'postcopy-ram'] } - + 'compress', 'events', 'postcopy-ram', 'x-multifd'] } ## # @MigrationCapabilityStatus #
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 03/13] migration: Add multifd capability
Quoted 1 line · * Juan Quintela ([email protected]) wrote:
Signed-off-by Juan Quintela <[email protected]>
Quoted 61 lines
--- 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@@ -290,6 +290,7 @@ bool migrate_postcopy_ram(void);bool migrate_zero_blocks (void );bool migrate_auto_converge (void ); +bool migrate_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@@ -1273,6 +1273,15 @@ bool migrate_use_events(void)return s->enabled_capabilities[MIGRATION_CAPABILITY_EVENTS ]; } +bool migrate_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@@ -574,12 +574,13 @@ # been migrated, pulling the remaining pages along as needed. NOTE: If # the migration fails during postcopy the VM will fail. (since 2.6) # +# @x-multifd: Use more than one fd for migration (since 2.8) +# # Since: 1.2 ## { 'enum': 'MigrationCapability', 'data': ['xbzrle', 'rdma-pin-all', 'auto-converge', 'zero-blocks', - 'compress', 'events', 'postcopy-ram'] } - + 'compress', 'events', 'postcopy-ram', 'x-multifd'] } ## # @MigrationCapabilityStatus #Signature · 1 line
2.7.4
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
PATCH 4/13 migration: Create x-multifd-threads parameter
In reply to Juan QuintelaIndicates the number of threads that we would create. By default we create 2 threads.
--- hmp.c | 7 +++++++ include/migration/migration.h | 2 ++ migration/migration.c | 24 ++++++++++++++++++++++++ qapi-schema.json | 11 +++++++++-- 4 files changed, 42 insertions(+), 2 deletions(-)
hmp.c +7 -0
@@ -318,6 +318,9 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)monitor_printf (mon," %s: %" PRId64" milliseconds" , MigrationParameter_lookup[MIGRATION_PARAMETER_DOWNTIME_LIMIT ], params->downtime_limit); +monitor_printf (mon," %s: %" PRId64, + MigrationParameter_lookup[MIGRATION_PARAMETER_X_MULTIFD_THREADS ], + params->x_multifd_threads);monitor_printf (mon,"\n" ); }
@@ -1386,6 +1389,9 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) p.has_downtime_limit = true; use_int_value = true;break ; +case MIGRATION_PARAMETER_X_MULTIFD_THREADS : + p.has_x_multifd_threads = true; +break ; }if (use_int_value) {
@@ -1402,6 +1408,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) p.cpu_throttle_initial = valueint; p.cpu_throttle_increment = valueint; p.downtime_limit = valueint; + p.x_multifd_threads = valueint; }qmp_migrate_set_parameters (&p, &err);
include/migration/migration.h +2 -0
@@ -240,6 +240,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 +24 -0
@@ -62,6 +62,8 @@/* Migration XBZRLE default cache size */ #define DEFAULT_MIGRATE_CACHE_SIZE (64 * 1024 * 1024) +#define DEFAULT_MIGRATE_MULTIFD_THREADS 2 +static NotifierList migration_state_notifiers =NOTIFIER_LIST_INITIALIZER (migration_state_notifiers);
@@ -94,6 +96,7 @@ MigrationState *migrate_get_current(void) .cpu_throttle_increment = DEFAULT_MIGRATE_CPU_THROTTLE_INCREMENT, .max_bandwidth = MAX_THROTTLE, .downtime_limit = DEFAULT_MIGRATE_SET_DOWNTIME, + .x_multifd_threads = DEFAULT_MIGRATE_MULTIFD_THREADS, }, };
@@ -567,6 +570,8 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp) params->max_bandwidth = s->parameters.max_bandwidth; params->has_downtime_limit = true; params->downtime_limit = s->parameters.downtime_limit; + params->has_x_multifd_threads = true; + params->x_multifd_threads = s->parameters.x_multifd_threads;return params; }
@@ -813,6 +818,13 @@ void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp) "an integer in the range of 0 to 2000000 milliseconds");return ; } +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;
@@ -847,6 +859,9 @@ void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp)if (params->has_downtime_limit) { s->parameters.downtime_limit = params->downtime_limit; } +if (params->has_x_multifd_threads) { + s->parameters.x_multifd_threads = params->x_multifd_threads; + } }
@@ -1282,6 +1297,15 @@ bool migrate_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 +9 -2
@@ -665,13 +665,16 @@ # @downtime-limit: set maximum tolerated downtime for migration. maximum # downtime in milliseconds (Since 2.8) # +# @x-multifd-threads: Number of threads used to migrate data in parallel +# The default value is 1 (since 2.8) +# # 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'] } + 'downtime-limit', 'x-multifd-threads'] } # # @migrate-set-parameters
@@ -726,6 +729,9 @@ # @downtime-limit: set maximum tolerated downtime for migration. maximum # downtime in milliseconds (Since 2.8) # +# @x-multifd-threads: Number of threads used to migrate data in parallel +# The default value is 1 (since 2.8) +# # Since: 2.4 ## { 'struct': 'MigrationParameters',
@@ -737,7 +743,8 @@ '*tls-creds': 'str', '*tls-hostname': 'str', '*max-bandwidth': 'int', - '*downtime-limit': 'int'} } + '*downtime-limit': 'int', + '*x-multifd-threads': 'int'} } ## # @query-migrate-parameters #
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 04/13] migration: Create x-multifd-threads parameter
Quoted 4 lines · * Juan Quintela ([email protected]) wrote:
Indicates the number of threads that we would create. By default we create 2 threads.
Signed-off-by Juan Quintela <[email protected]>
Quoted 167 lines
--- hmp.c | 7 +++++++ include/migration/migration.h | 2 ++ migration/migration.c | 24 ++++++++++++++++++++++++ qapi-schema.json | 11 +++++++++-- 4 files changed, 42 insertions(+), 2 deletions(-)hmp.c +7
-0@@ -318,6 +318,9 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)monitor_printf (mon," %s: %" PRId64" milliseconds" , MigrationParameter_lookup[MIGRATION_PARAMETER_DOWNTIME_LIMIT ], params->downtime_limit); +monitor_printf (mon," %s: %" PRId64, + MigrationParameter_lookup[MIGRATION_PARAMETER_X_MULTIFD_THREADS ], + params->x_multifd_threads);monitor_printf (mon,"\n" ); }@@ -1386,6 +1389,9 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) p.has_downtime_limit = true; use_int_value = true;break ; +case MIGRATION_PARAMETER_X_MULTIFD_THREADS : + p.has_x_multifd_threads = true; +break ; }if (use_int_value) {@@ -1402,6 +1408,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) p.cpu_throttle_initial = valueint; p.cpu_throttle_increment = valueint; p.downtime_limit = valueint; + p.x_multifd_threads = valueint; }qmp_migrate_set_parameters (&p, &err);include/migration/migration.h +2
-0@@ -240,6 +240,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 +24
-0@@ -62,6 +62,8 @@/* Migration XBZRLE default cache size */ #define DEFAULT_MIGRATE_CACHE_SIZE (64 * 1024 * 1024) +#define DEFAULT_MIGRATE_MULTIFD_THREADS 2 +static NotifierList migration_state_notifiers =NOTIFIER_LIST_INITIALIZER (migration_state_notifiers);@@ -94,6 +96,7 @@ MigrationState *migrate_get_current(void) .cpu_throttle_increment = DEFAULT_MIGRATE_CPU_THROTTLE_INCREMENT, .max_bandwidth = MAX_THROTTLE, .downtime_limit = DEFAULT_MIGRATE_SET_DOWNTIME, + .x_multifd_threads = DEFAULT_MIGRATE_MULTIFD_THREADS, }, };@@ -567,6 +570,8 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp) params->max_bandwidth = s->parameters.max_bandwidth; params->has_downtime_limit = true; params->downtime_limit = s->parameters.downtime_limit; + params->has_x_multifd_threads = true; + params->x_multifd_threads = s->parameters.x_multifd_threads;return params; }@@ -813,6 +818,13 @@ void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp) "an integer in the range of 0 to 2000000 milliseconds");return ; } +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;@@ -847,6 +859,9 @@ void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp)if (params->has_downtime_limit) { s->parameters.downtime_limit = params->downtime_limit; } +if (params->has_x_multifd_threads) { + s->parameters.x_multifd_threads = params->x_multifd_threads; + } }@@ -1282,6 +1297,15 @@ bool migrate_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 +9
-2@@ -665,13 +665,16 @@ # @downtime-limit: set maximum tolerated downtime for migration. maximum # downtime in milliseconds (Since 2.8) # +# @x-multifd-threads: Number of threads used to migrate data in parallel +# The default value is 1 (since 2.8) +# # 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'] } + 'downtime-limit', 'x-multifd-threads'] } # # @migrate-set-parameters@@ -726,6 +729,9 @@ # @downtime-limit: set maximum tolerated downtime for migration. maximum # downtime in milliseconds (Since 2.8) # +# @x-multifd-threads: Number of threads used to migrate data in parallel +# The default value is 1 (since 2.8) +# # Since: 2.4 ## { 'struct': 'MigrationParameters',@@ -737,7 +743,8 @@ '*tls-creds': 'str', '*tls-hostname': 'str', '*max-bandwidth': 'int', - '*downtime-limit': 'int'} } + '*downtime-limit': 'int', + '*x-multifd-threads': 'int'} } ## # @query-migrate-parameters #Signature · 1 line
2.7.4
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH 04/13] migration: Create x-multifd-threads parameter
In reply to Juan Quintelahmp.c void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) · line 1394
Quoted 13 lines · Juan Quintela
Indicates the number of threads that we would create. By default we create 2 threads.
Signed-off-by Juan Quintela <[email protected]>---
hmp.c +3
-0@@ -1386,6 +1389,9 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) p.has_downtime_limit = true; use_int_value = true;break ; +case MIGRATION_PARAMETER_X_MULTIFD_THREADS : + p.has_x_multifd_threads = true; +break ;
Won't work unless you add a line 'use_int_value = true;'
hmp.c void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) · line 1412
Quoted 9 lines
hmp.c +1
-0}if (use_int_value) {@@ -1402,6 +1408,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) p.cpu_throttle_initial = valueint; p.cpu_throttle_increment = valueint; p.downtime_limit = valueint; + p.x_multifd_threads = valueint; }
See also commit bb2b777 as a regression fix for a missing use_int_value.
Quoted 20 lines
qapi-schema.json +5
-1+++ b/qapi-schema.json@@ -665,13 +665,16 @@ # @downtime-limit: set maximum tolerated downtime for migration. maximum # downtime in milliseconds (Since 2.8) # +# @x-multifd-threads: Number of threads used to migrate data in parallel +# The default value is 1 (since 2.8) +# # 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'] } + 'downtime-limit', 'x-multifd-threads'] } # # @migrate-set-parameters
qapi-schema.json line 733
Quoted 5 lines
qapi-schema.json +2
-0@@ -726,6 +729,9 @@ # @downtime-limit: set maximum tolerated downtime for migration. maximum # downtime in milliseconds (Since 2.8) # +# @x-multifd-threads: Number of threads used to migrate data in parallel +# The default value is 1 (since 2.8)
Pre-existing in the other parameters, but we have an inconsistent use of #optional markers here.
Quoted 15 lines
qapi-schema.json +3
-1+# # Since: 2.4 ## { 'struct': 'MigrationParameters',@@ -737,7 +743,8 @@ '*tls-creds': 'str', '*tls-hostname': 'str', '*max-bandwidth': 'int', - '*downtime-limit': 'int'} } + '*downtime-limit': 'int', + '*x-multifd-threads': 'int'} } ## # @query-migrate-parameters #
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 5/13 migration: create multifd migration threads
In reply to Juan QuintelaCreation of the threads, nothing inside yet.
--- include/migration/migration.h | 4 ++ migration/migration.c | 6 ++ migration/ram.c | 148 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 158 insertions(+)
include/migration/migration.h +4 -0
@@ -241,6 +241,10 @@ bool migration_in_postcopy_after_devices(MigrationState *);MigrationState *migrate_get_current (void );int migrate_multifd_threads (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
@@ -336,6 +336,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 ); }
@@ -360,6 +361,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
@@ -413,6 +415,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 ); }
@@ -425,6 +428,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); }
@@ -916,6 +920,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 ; }
@@ -1922,6 +1927,7 @@ void migrate_fd_connect(MigrationState *s) }migrate_compress_threads_create (); +migrate_multifd_send_threads_create ();qemu_thread_create (&s->thread,"migration" , migration_thread, s,QEMU_THREAD_JOINABLE ); s->migration_thread_running = true;
migration/ram.c +148 -0
154 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 05/13] migration: create multifd migration threads
Quoted 117 lines · * Juan Quintela ([email protected]) wrote:
Creation of the threads, nothing inside yet.
Signed-off-by Juan Quintela <[email protected]>--- include/migration/migration.h | 4 ++ migration/migration.c | 6 ++ migration/ram.c | 148 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 158 insertions(+)include/migration/migration.h +4
-0@@ -241,6 +241,10 @@ bool migration_in_postcopy_after_devices(MigrationState *);MigrationState *migrate_get_current (void );int migrate_multifd_threads (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@@ -336,6 +336,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 ); }@@ -360,6 +361,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 @@ -413,6 +415,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 ); }@@ -425,6 +428,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); }@@ -916,6 +920,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 ; }@@ -1922,6 +1927,7 @@ void migrate_fd_connect(MigrationState *s) }migrate_compress_threads_create (); +migrate_multifd_send_threads_create ();qemu_thread_create (&s->thread,"migration" , migration_thread, s,QEMU_THREAD_JOINABLE ); s->migration_thread_running = true;migration/ram.c +33
-0@@ -389,6 +389,154 @@ void migrate_compress_threads_create(void) } } +/* Multiple fd's */ + +struct MultiFDSendParams { +QemuThread thread; +QemuCond cond; +QemuMutex mutex; +bool quit; +}; +typedef struct MultiFDSendParams MultiFDSendParams ; + +static MultiFDSendParams *multifd_send; + +static void *multifd_send_thread (void *opaque) +{ +MultiFDSendParams *params = opaque; + +qemu_mutex_lock (¶ms->mutex); +while (!params->quit){ +qemu_cond_wait (¶ms->cond, ¶ms->mutex); + } +qemu_mutex_unlock (¶ms->mutex); + +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++) { +qemu_mutex_lock (&multifd_send[i].mutex); + multifd_send[i].quit = true;
migration/ram.c void migrate_compress_threads_create(void) · line 434
Quoted 10 lines
migration/ram.c +10
-0+qemu_cond_signal (&multifd_send[i].cond); +qemu_mutex_unlock (&multifd_send[i].mutex); + } +} + +void migrate_multifd_send_threads_join (void ) +{ +int i, thread_count; + +if (!migrate_multifd ()){
You've missed the space prior to the { (and then copied it everywhere in this patch).
Quoted 17 lines
migration/ram.c +17
-0+return ; + } +terminate_multifd_send_threads (); + thread_count =migrate_multifd_threads (); +for (i =0 ; i < thread_count; i++) { +qemu_thread_join (&multifd_send[i].thread); +qemu_mutex_destroy (&multifd_send[i].mutex); +qemu_cond_destroy (&multifd_send[i].cond); + } +g_free (multifd_send); + multifd_send =NULL ; +} + +void migrate_multifd_send_threads_create (void ) +{ +int i, thread_count; +
migration/ram.c void migrate_compress_threads_create(void) · line 461
Quoted 10 lines
migration/ram.c +10
-0+if (!migrate_multifd ()){ +return ; + } + thread_count =migrate_multifd_threads (); + multifd_send =g_new0 (MultiFDSendParams, thread_count); +for (i =0 ; i < thread_count; i++) { +qemu_mutex_init (&multifd_send[i].mutex); +qemu_cond_init (&multifd_send[i].cond); + multifd_send[i].quit = false; + qemu_thread_create(&multifd_send[i].thread, "multifd_send",
You could make the name of the thread include the thread number, that way you could easily see in top if any one of the threads was getting particularly busy (although be careful with the length I think linux will ignore the name if it's over 14 characters).
Quoted 84 lines
migration/ram.c +78
-0+ multifd_send_thread, &multifd_send[i], + QEMU_THREAD_JOINABLE); + } +} + +struct MultiFDRecvParams { +QemuThread thread; +QemuCond cond; +QemuMutex mutex; +bool quit; +}; +typedef struct MultiFDRecvParams MultiFDRecvParams ; + +static MultiFDRecvParams *multifd_recv; + +static void *multifd_recv_thread (void *opaque) +{ +MultiFDRecvParams *params = opaque; + +qemu_mutex_lock (¶ms->mutex); +while (!params->quit){ +qemu_cond_wait (¶ms->cond, ¶ms->mutex); + } +qemu_mutex_unlock (¶ms->mutex); + +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++) { +qemu_mutex_lock (&multifd_recv[i].mutex); + multifd_recv[i].quit = true; +qemu_cond_signal (&multifd_recv[i].cond); +qemu_mutex_unlock (&multifd_recv[i].mutex); + } +} + +void migrate_multifd_recv_threads_join (void ) +{ +int i, thread_count; + +if (!migrate_multifd ()){ +return ; + } +terminate_multifd_recv_threads (); + thread_count =migrate_multifd_threads (); +for (i =0 ; i < thread_count; i++) { +qemu_thread_join (&multifd_recv[i].thread); +qemu_mutex_destroy (&multifd_recv[i].mutex); +qemu_cond_destroy (&multifd_recv[i].cond); + } +g_free (multifd_recv); + multifd_recv =NULL ; +} + +void migrate_multifd_recv_threads_create (void ) +{ +int i, thread_count; + +if (!migrate_multifd ()){ +return ; + } + thread_count =migrate_multifd_threads (); + multifd_recv =g_new0 (MultiFDRecvParams, thread_count); +for (i =0 ; i < thread_count; i++) { +qemu_mutex_init (&multifd_recv[i].mutex); +qemu_cond_init (&multifd_recv[i].cond); + multifd_recv[i].quit = false; +qemu_thread_create (&multifd_recv[i].thread,"multifd_recv" , + multifd_recv_thread, &multifd_recv[i], +QEMU_THREAD_JOINABLE ); + } +} +/** * save_page_header: Write page header to wire * Signature · 1 line
2.7.4
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH 05/13] migration: create multifd migration threads
Quoted 5 lines · Dr. David Alan Gilbert
Quoted 3 lines · * Juan Quintela ([email protected]) wrote:
Creation of the threads, nothing inside yet.
Signed-off-by Juan Quintela <[email protected]>
Quoted 8 lines
migration/ram.c void migrate_compress_threads_create(void) · line 434
Quoted 5 lines
migration/ram.c +5
-0+void migrate_multifd_send_threads_join (void ) +{ +int i, thread_count; + +if (!migrate_multifd ()){You've missed the space prior to the { (and then copied it everywhere in this patch).
Fixed. As guessed, copy & paste O:-)
Quoted 8 lines
migration/ram.c void migrate_compress_threads_create(void) · line 461
Quoted 7 lines
migration/ram.c +7
-0+ thread_count =migrate_multifd_threads (); + multifd_send =g_new0 (MultiFDSendParams, thread_count); +for (i =0 ; i < thread_count; i++) { +qemu_mutex_init (&multifd_send[i].mutex); +qemu_cond_init (&multifd_send[i].cond); + multifd_send[i].quit = false; + qemu_thread_create(&multifd_send[i].thread, "multifd_send",
Quoted 4 lines
You could make the name of the thread include the thread number, that way you could easily see in top if any one of the threads was getting particularly busy (although be careful with the length I think linux will ignore the name if it's over 14 characters).
Until 99 thread will be show correctly :p
PATCH 6/13 migration: Start of multiple fd work
In reply to Juan QuintelaWe 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.
Note: Reference count/freeing of channels is not done
--- include/migration/migration.h | 6 +++++ migration/ram.c | 45 +++++++++++++++++++++++++++++++++++- migration/socket.c | 53 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 102 insertions(+), 2 deletions(-)
include/migration/migration.h +6 -0
@@ -21,6 +21,7 @@#include "migration/vmstate.h" #include "qapi-types.h" #include "exec/cpu-common.h" +#include "io/channel.h" #define QEMU_VM_FILE_MAGIC 0x5145564d#define QEMU_VM_FILE_VERSION_COMPAT 0x00000002
@@ -211,6 +212,11 @@ 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); +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 +44 -1
99 lines not on this page · raw message
migration/socket.c +52 -1
84 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 7/13 migration: create ram_multifd_page
In reply to Juan QuintelaThe 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 | 44 ++++++++++++++++++++++++++++++++++++++++++- qapi-schema.json | 4 +++- 5 files changed, 50 insertions(+), 2 deletions(-)
hmp.c +2 -0
@@ -222,6 +222,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
@@ -274,6 +274,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
@@ -625,6 +625,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 +43 -1
86 lines not on this page · raw message
qapi-schema.json +3 -1
@@ -405,6 +405,7 @@ # # @postcopy-requests: The number of page requests received from the destination # (since 2.7) +# @multifd: number of pages sent with multifd (since 2.8) # # Since: 0.14.0 ##
@@ -413,7 +414,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
Re: [Qemu-devel] [PATCH 07/13] migration: create ram_multifd_page
Quoted 98 lines · * Juan Quintela ([email protected]) wrote:
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.Signed-off-by Juan Quintela <[email protected]>--- hmp.c | 2 ++ include/migration/migration.h | 1 + migration/migration.c | 1 + migration/ram.c | 44 ++++++++++++++++++++++++++++++++++++++++++- qapi-schema.json | 4 +++- 5 files changed, 50 insertions(+), 2 deletions(-)hmp.c +2
-0@@ -222,6 +222,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@@ -274,6 +274,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@@ -625,6 +625,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 +19
-0@@ -68,6 +68,7 @@ static uint64_t bitmap_sync_count;#define RAM_SAVE_FLAG_XBZRLE 0x40/* 0x80 is reserved in migration.h start with 0x100 next */ #define RAM_SAVE_FLAG_COMPRESS_PAGE 0x100 +#define RAM_SAVE_FLAG_MULTIFD_PAGE 0x200static const uint8_t ZERO_TARGET_PAGE [TARGET_PAGE_SIZE ];@@ -148,6 +149,7 @@ typedef struct AccountingInfo {uint64_t dup_pages;uint64_t skipped_pages;uint64_t norm_pages; +uint64_t multifd_pages;uint64_t iterations;uint64_t xbzrle_bytes;uint64_t xbzrle_pages;@@ -218,6 +220,11 @@ uint64_t xbzrle_mig_pages_overflow(void)return acct_info.xbzrle_overflows; } +uint64_t multifd_mig_pages_transferred (void ) +{ +return acct_info.multifd_pages; +} +/* This is the last block that we have visited serching for dirty pages */ static RAMBlock *last_seen_block;@@ -995,6 +1002,33 @@ static int ram_save_page(QEMUFile *f, PageSearchStatus *pss,return pages; } +static int ram_multifd_page (QEMUFile *f,PageSearchStatus *pss, +bool last_stage,uint64_t *bytes_transferred) +{ +int pages; +uint8_t *p; +RAMBlock *block = pss->block; +ram_addr_t offset = pss->offset; + + p = block->host + offset; + +if (block == last_sent_block) { + offset |=RAM_SAVE_FLAG_CONTINUE ;
migration/ram.c static int ram_save_page(QEMUFile *f, PageSearchStatus *pss, · line 1026
Quoted 10 lines
migration/ram.c +10
-0+ } + pages =save_zero_page (f, block, offset, p, bytes_transferred); +if (pages ==-1 ) { + *bytes_transferred += +save_page_header (f, block, offset |RAM_SAVE_FLAG_MULTIFD_PAGE ); +qemu_put_buffer (f, p,TARGET_PAGE_SIZE ); + *bytes_transferred +=TARGET_PAGE_SIZE ; + pages =1 ; + acct_info.norm_pages++; + acct_info.multifd_pages++;
The acct_info is now updated simultaneously from multiple threads?
Dave
Quoted 64 lines
migration/ram.c +14
-1+ } + +return pages; +} +static int do_compress_ram_page (QEMUFile *f,RAMBlock *block,ram_addr_t offset) {@@ -1432,6 +1466,8 @@ static int ram_save_target_page(MigrationState *ms, QEMUFile *f, res =ram_save_compressed_page (f, pss, last_stage, bytes_transferred); + }else if (migrate_multifd ()) { + res =ram_multifd_page (f, pss, last_stage, bytes_transferred); }else { res =ram_save_page (f, pss, last_stage, bytes_transferred);@@ -2678,7 +2714,8 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) addr &=TARGET_PAGE_MASK ;if (flags & (RAM_SAVE_FLAG_COMPRESS |RAM_SAVE_FLAG_PAGE | -RAM_SAVE_FLAG_COMPRESS_PAGE |RAM_SAVE_FLAG_XBZRLE )) { +RAM_SAVE_FLAG_COMPRESS_PAGE |RAM_SAVE_FLAG_XBZRLE | +RAM_SAVE_FLAG_MULTIFD_PAGE )) {RAMBlock *block =ram_block_from_stream (f, flags); host =host_from_ram_block_offset (block, addr);@@ -2753,6 +2790,11 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)break ; }break ; + +case RAM_SAVE_FLAG_MULTIFD_PAGE : +qemu_get_buffer (f, host,TARGET_PAGE_SIZE ); +break ; +case RAM_SAVE_FLAG_EOS :/* normal exit */ break ;qapi-schema.json +3
-1@@ -405,6 +405,7 @@ # # @postcopy-requests: The number of page requests received from the destination # (since 2.7) +# @multifd: number of pages sent with multifd (since 2.8) # # Since: 0.14.0 ##@@ -413,7 +414,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'} } ## # @XBZRLECacheStatsSignature · 1 line
2.7.4
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [Qemu-devel] [PATCH 07/13] migration: create ram_multifd_page
Quoted 24 lines · Dr. David Alan Gilbert
Quoted 23 lines · * Juan Quintela ([email protected]) wrote:
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.Signed-off-by Juan Quintela <[email protected]>migration/ram.c +17
-0+static int ram_multifd_page (QEMUFile *f,PageSearchStatus *pss, +bool last_stage,uint64_t *bytes_transferred) +{ +int pages; +uint8_t *p; +RAMBlock *block = pss->block; +ram_addr_t offset = pss->offset; + + p = block->host + offset; + +if (block == last_sent_block) { + offset |=RAM_SAVE_FLAG_CONTINUE ; + } + pages =save_zero_page (f, block, offset, p, bytes_transferred); +if (pages ==-1 ) { + *bytes_transferred += +save_page_header (f, block, offset |RAM_SAVE_FLAG_MULTIFD_PAGE );
Quoted 8 lines
migration/ram.c static int ram_save_page(QEMUFile *f, PageSearchStatus *pss, · line 1026
Quoted 5 lines
migration/ram.c +5
-0+qemu_put_buffer (f, p,TARGET_PAGE_SIZE ); + *bytes_transferred +=TARGET_PAGE_SIZE ; + pages =1 ; + acct_info.norm_pages++; + acct_info.multifd_pages++;The
acct_infois now updated simultaneously from multiple threads?
No. This is still done from the migration thread.
Later, Juan.
PATCH 8/13 migration: Create thread infrastructure for multifd send side
In reply to Juan QuintelaWe make the locking and the transfer of information specific, even if we are still transmiting things through the main thread.
--- migration/ram.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-)
migration/ram.c +53 -2
@@ -399,17 +399,25 @@ void migrate_compress_threads_create(void)/* Multiple fd's */ struct MultiFDSendParams { +/* not changed */ QemuThread thread; +QIOChannel *c;QemuCond cond;QemuMutex mutex; +/* protected by param mutex */ bool quit;bool started; -QIOChannel *c; +uint8_t *address; +/* protected by multifd mutex */ +bool done; };typedef struct MultiFDSendParams MultiFDSendParams ;static MultiFDSendParams *multifd_send; +QemuMutex multifd_send_mutex; +QemuCond multifd_send_cond; +static void *multifd_send_thread (void *opaque) {MultiFDSendParams *params = opaque;
@@ -423,7 +431,17 @@ static void *multifd_send_thread(void *opaque)qemu_mutex_lock (¶ms->mutex);while (!params->quit){ -qemu_cond_wait (¶ms->cond, ¶ms->mutex); +if (params->address) { + params->address =0 ; +qemu_mutex_unlock (¶ms->mutex); +qemu_mutex_lock (&multifd_send_mutex); + params->done = true; +qemu_cond_signal (&multifd_send_cond); +qemu_mutex_unlock (&multifd_send_mutex); +qemu_mutex_lock (¶ms->mutex); + }else { +qemu_cond_wait (¶ms->cond, ¶ms->mutex); + } }qemu_mutex_unlock (¶ms->mutex);
@@ -471,11 +489,15 @@ 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_cond_init (&multifd_send_cond);for (i =0 ; i < thread_count; i++) {qemu_mutex_init (&multifd_send[i].mutex);qemu_cond_init (&multifd_send[i].cond); multifd_send[i].quit = false; multifd_send[i].started = false; + multifd_send[i].done = true; + multifd_send[i].address =0 ; multifd_send[i].c =socket_send_channel_create ();if (!multifd_send[i].c) {printf ("Error creating a send channel" );
@@ -492,6 +514,34 @@ void migrate_multifd_send_threads_create(void) } } +static int multifd_send_page (uint8_t *address) +{ +int i, thread_count; +bool found = false; + + thread_count =migrate_multifd_threads (); +qemu_mutex_lock (&multifd_send_mutex); +while (!found) { +for (i =0 ; i < thread_count; i++) { +if (multifd_send[i].done) { + multifd_send[i].done = false; + found = true; +break ; + } + } +if (!found) { +qemu_cond_wait (&multifd_send_cond, &multifd_send_mutex); + } + } +qemu_mutex_unlock (&multifd_send_mutex); +qemu_mutex_lock (&multifd_send[i].mutex); + multifd_send[i].address = address; +qemu_cond_signal (&multifd_send[i].cond); +qemu_mutex_unlock (&multifd_send[i].mutex); + +return 0 ; +} +struct MultiFDRecvParams {QemuThread thread;QemuCond cond;
@@ -1020,6 +1070,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
PATCH 9/13 migration: Send the fd number which we are going to use for this page
In reply to Juan QuintelaWe are still sending the page through the main channel, that would change later in the series
--- migration/ram.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
migration/ram.c +11 -2
@@ -539,7 +539,7 @@ static int multifd_send_page(uint8_t *address)qemu_cond_signal (&multifd_send[i].cond);qemu_mutex_unlock (&multifd_send[i].mutex); -return 0 ; +return i; }struct MultiFDRecvParams {
@@ -1056,6 +1056,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;
@@ -1069,8 +1070,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); +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++;
@@ -2758,6 +2761,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);
@@ -2843,6 +2847,11 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)break ;case RAM_SAVE_FLAG_MULTIFD_PAGE : + fd_num =qemu_get_be16 (f); +if (fd_num !=0 ) { +/* this is yet an unused variable, changed later */ + fd_num =0 ; + }qemu_get_buffer (f, host,TARGET_PAGE_SIZE );break ;
Signature · 1 line
2.7.4
PATCH 10/13 migration: Create thread infrastructure for multifd recv side
In reply to Juan QuintelaWe make the locking and the transfer of information specific, even if we are still receiving things through the main thread.
--- migration/ram.c | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-)
migration/ram.c +44 -3
@@ -543,17 +543,25 @@ static int multifd_send_page(uint8_t *address) }struct MultiFDRecvParams { +/* not changed */ QemuThread thread; +QIOChannel *c;QemuCond cond;QemuMutex mutex; +/* proteced by param mutex */ bool quit;bool started; -QIOChannel *c; +uint8_t *address; +/* proteced by multifd mutex */ +bool done; };typedef struct MultiFDRecvParams MultiFDRecvParams ;static MultiFDRecvParams *multifd_recv; +QemuMutex multifd_recv_mutex; +QemuCond multifd_recv_cond; +static void *multifd_recv_thread (void *opaque) {MultiFDRecvParams *params = opaque;
@@ -567,7 +575,17 @@ static void *multifd_recv_thread(void *opaque)qemu_mutex_lock (¶ms->mutex);while (!params->quit){ -qemu_cond_wait (¶ms->cond, ¶ms->mutex); +if (params->address) { + params->address =0 ; +qemu_mutex_unlock (¶ms->mutex); +qemu_mutex_lock (&multifd_recv_mutex); + params->done = true; +qemu_cond_signal (&multifd_recv_cond); +qemu_mutex_unlock (&multifd_recv_mutex); +qemu_mutex_lock (¶ms->mutex); + }else { +qemu_cond_wait (¶ms->cond, ¶ms->mutex); + } }qemu_mutex_unlock (¶ms->mutex);
@@ -620,8 +638,9 @@ void migrate_multifd_recv_threads_create(void)qemu_cond_init (&multifd_recv[i].cond); multifd_recv[i].quit = false; multifd_recv[i].started = false; + multifd_recv[i].done = true; + multifd_recv[i].address =0 ; multifd_recv[i].c =socket_recv_channel_create (); -if (!multifd_recv[i].c) {printf ("Error creating a recv channel" );exit (0 );
@@ -637,6 +656,27 @@ void migrate_multifd_recv_threads_create(void) } } +static void multifd_recv_page (uint8_t *address,int fd_num) +{ +int thread_count; +MultiFDRecvParams *params; + + thread_count =migrate_multifd_threads (); +assert (fd_num < thread_count); + params = &multifd_recv[fd_num]; + +qemu_mutex_lock (&multifd_recv_mutex); +while (!params->done) { +qemu_cond_wait (&multifd_recv_cond, &multifd_recv_mutex); + } + params->done = false; +qemu_mutex_unlock (&multifd_recv_mutex); +qemu_mutex_lock (¶ms->mutex); + params->address = address; +qemu_cond_signal (¶ms->cond); +qemu_mutex_unlock (¶ms->mutex); +} +/** * save_page_header: Write page header to wire *
@@ -2852,6 +2892,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)/* this is yet an unused variable, changed later */ fd_num =0 ; } +multifd_recv_page (host, fd_num);qemu_get_buffer (f, host,TARGET_PAGE_SIZE );break ;
Signature · 1 line
2.7.4
PATCH 11/13 migration: Test new fd infrastructure
In reply to Juan QuintelaWe just send the address through the alternate channels and test that it is ok.
--- migration/ram.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-)
migration/ram.c +26 -4
@@ -421,6 +421,7 @@ QemuCond multifd_send_cond;static void *multifd_send_thread (void *opaque) {MultiFDSendParams *params = opaque; +uint8_t *address;char start ='s' ;qio_channel_write (params->c, &start,1 , &error_abort);
@@ -432,8 +433,16 @@ static void *multifd_send_thread(void *opaque)qemu_mutex_lock (¶ms->mutex);while (!params->quit){if (params->address) { + address = params->address; params->address =0 ;qemu_mutex_unlock (¶ms->mutex); + +if (qio_channel_write (params->c, (const char *)&address, +sizeof (uint8_t *), &error_abort) + !=sizeof (uint8_t *)) { +/* Shuoudn't ever happen */ +exit (-1 ); + }qemu_mutex_lock (&multifd_send_mutex); params->done = true;qemu_cond_signal (&multifd_send_cond);
@@ -565,6 +574,8 @@ QemuCond multifd_recv_cond;static void *multifd_recv_thread (void *opaque) {MultiFDRecvParams *params = opaque; +uint8_t *address; +uint8_t *recv_address;char start;qio_channel_read (params->c, &start,1 , &error_abort);
@@ -576,8 +587,23 @@ static void *multifd_recv_thread(void *opaque)qemu_mutex_lock (¶ms->mutex);while (!params->quit){if (params->address) { + address = params->address; params->address =0 ;qemu_mutex_unlock (¶ms->mutex); + +if (qio_channel_read (params->c, (char *)&recv_address, +sizeof (uint8_t *), &error_abort) + !=sizeof (uint8_t *)) { +/* shouldn't ever happen */ +exit (-1 ); + } + +if (address != recv_address) { +printf ("We received %p what we were expecting %p\n" , + recv_address, address); +exit (-1 ); + } +qemu_mutex_lock (&multifd_recv_mutex); params->done = true;qemu_cond_signal (&multifd_recv_cond);
@@ -2888,10 +2914,6 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)case RAM_SAVE_FLAG_MULTIFD_PAGE : fd_num =qemu_get_be16 (f); -if (fd_num !=0 ) { -/* this is yet an unused variable, changed later */ - fd_num =0 ; - }multifd_recv_page (host, fd_num);qemu_get_buffer (f, host,TARGET_PAGE_SIZE );break ;
Signature · 1 line
2.7.4
PATCH 12/13 migration: [HACK]Transfer pages over new channels
In reply to Juan QuintelaWe switch for sending the page number to send real pages.
[HACK]
How we calculate the bandwidth is beyond repair, there is a hack there that would work for x86 and archs that have 4kb pages.
If you are having a nice day just go to migration/ram.c and look at acct_update_position(). Now you are depressed, right?
--- migration/migration.c | 15 +++++++++++---- migration/ram.c | 46 +++++++++++++++++++++++++++++++--------------- 2 files changed, 42 insertions(+), 19 deletions(-)
migration/migration.c +11 -4
@@ -1757,7 +1757,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;
@@ -1840,9 +1841,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;
@@ -1859,7 +1865,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 +31 -15
100 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 12/13] migration: [HACK]Transfer pages over new channels
Quoted 5 lines · * Juan Quintela ([email protected]) wrote:
We switch for sending the page number to send real pages.
[HACK]
How we calculate the bandwidth is beyond repair, there is a hack there that would work for x86 and archs that have 4kb pages.
Is that a problem? Isn't it always TARGET_PAGE_SIZE?
But it does add an interesting question about what size chunks to hand out to each fd, do you bother with 4kB chunks or go for something larger?
Quoted 2 lines
If you are having a nice day just go to
migration/ram.cand look atacct_update_position(). Now you are depressed, right?
Been there, then saw the interaction with RDMA.
Dave
Quoted 162 lines
Signed-off-by Juan Quintela <[email protected]>--- migration/migration.c | 15 +++++++++++---- migration/ram.c | 46 +++++++++++++++++++++++++++++++--------------- 2 files changed, 42 insertions(+), 19 deletions(-)migration/migration.c +11
-4@@ -1757,7 +1757,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;@@ -1840,9 +1841,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;@@ -1859,7 +1865,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 +31
-15@@ -437,9 +437,9 @@ static void *multifd_send_thread(void *opaque) params->address =0 ;qemu_mutex_unlock (¶ms->mutex); -if (qio_channel_write (params->c, (const char *)&address, -sizeof (uint8_t *), &error_abort) - !=sizeof (uint8_t *)) { +if (qio_channel_write (params->c, (const char *)address, +TARGET_PAGE_SIZE , &error_abort) + !=TARGET_PAGE_SIZE ) {/* Shuoudn't ever happen */ exit (-1 ); }@@ -551,6 +551,23 @@ static int multifd_send_page(uint8_t *address)return i; } +static void flush_multifd_send_data (QEMUFile *f) +{ +int i, thread_count; + +if (!migrate_multifd ()) { +return ; + } +qemu_fflush (f); + thread_count =migrate_multifd_threads (); +qemu_mutex_lock (&multifd_send_mutex); +for (i =0 ; i < thread_count; i++) { +while (!multifd_send[i].done) { +qemu_cond_wait (&multifd_send_cond, &multifd_send_mutex); + } + } +} +struct MultiFDRecvParams {/* not changed */ QemuThread thread;@@ -575,7 +592,6 @@ static void *multifd_recv_thread(void *opaque) {MultiFDRecvParams *params = opaque;uint8_t *address; -uint8_t *recv_address;char start;qio_channel_read (params->c, &start,1 , &error_abort);@@ -591,19 +607,13 @@ static void *multifd_recv_thread(void *opaque) params->address =0 ;qemu_mutex_unlock (¶ms->mutex); -if (qio_channel_read (params->c, (char *)&recv_address, -sizeof (uint8_t *), &error_abort) - !=sizeof (uint8_t *)) { +if (qio_channel_read (params->c, (char *)address, +TARGET_PAGE_SIZE , &error_abort) + !=TARGET_PAGE_SIZE ) {/* shouldn't ever happen */ exit (-1 ); } -if (address != recv_address) { -printf ("We received %p what we were expecting %p\n" , - recv_address, address); -exit (-1 ); - } -qemu_mutex_lock (&multifd_recv_mutex); params->done = true;qemu_cond_signal (&multifd_recv_cond);@@ -1126,6 +1136,7 @@ static int ram_multifd_page(QEMUFile *f, PageSearchStatus *pss,uint8_t *p;RAMBlock *block = pss->block;ram_addr_t offset = pss->offset; +static int count =32 ; p = block->host + offset;@@ -1137,9 +1148,14 @@ static int ram_multifd_page(QEMUFile *f, PageSearchStatus *pss, *bytes_transferred +=save_page_header (f, block, offset |RAM_SAVE_FLAG_MULTIFD_PAGE ); fd_num =multifd_send_page (p); + count--; +if (!count) { +qemu_fflush (f); + count =32 ; + } +qemu_put_be16 (f, fd_num); *bytes_transferred +=2 ;/* size of fd_num */ -qemu_put_buffer (f, p,TARGET_PAGE_SIZE ); *bytes_transferred +=TARGET_PAGE_SIZE ; pages =1 ; acct_info.norm_pages++;@@ -2401,6 +2417,7 @@ static int ram_save_complete(QEMUFile *f, void *opaque) }flush_compressed_data (f); +flush_multifd_send_data (f);ram_control_after_iterate (f,RAM_CONTROL_FINISH );rcu_read_unlock ();@@ -2915,7 +2932,6 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)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 ;case RAM_SAVE_FLAG_EOS :Signature · 1 line
2.7.4
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
PATCH 13/13 migration: flush receive queue
In reply to Juan QuintelaFrom: Juan Quintela <[email protected]>
Each time that we sync the bitmap, it is a possiblity that we receive a page that is being processed by a different thread. We fix this problem just making sure that we wait for all receiving threads to finish its work before we procedeed with the next stage.
I tried to make a migration command for it, but it don't work because we sync the bitmap sometimes when we have already sent the beggining of the section, so I just added a new page flag.
--- include/migration/migration.h | 1 + migration/ram.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+)
include/migration/migration.h +1 -0
@@ -251,6 +251,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/ram.c +40 -0
@@ -69,6 +69,7 @@ static uint64_t bitmap_sync_count;/* 0x80 is reserved in migration.h start with 0x100 next */ #define RAM_SAVE_FLAG_COMPRESS_PAGE 0x100#define RAM_SAVE_FLAG_MULTIFD_PAGE 0x200 +#define RAM_SAVE_FLAG_MULTIFD_FLUSH 0x400static const uint8_t ZERO_TARGET_PAGE [TARGET_PAGE_SIZE ];
@@ -398,6 +399,11 @@ void migrate_compress_threads_create(void)/* Multiple fd's */ + +/* Indicates if we have synced the bitmap and we need to assure that +target has processeed all previous pages */ +bool multifd_needs_flush = false; +struct MultiFDSendParams {/* not changed */ QemuThread thread;
@@ -713,6 +719,25 @@ static void multifd_recv_page(uint8_t *address, int fd_num)qemu_mutex_unlock (¶ms->mutex); } + +static int multifd_flush (void ) +{ +int i, thread_count; + +if (!migrate_multifd ()) { +return 0 ; + } + thread_count =migrate_multifd_threads (); +qemu_mutex_lock (&multifd_recv_mutex); +for (i =0 ; i < thread_count; i++) { +while (!multifd_recv[i].done) { +qemu_cond_wait (&multifd_recv_cond, &multifd_recv_mutex); + } + } +qemu_mutex_unlock (&multifd_recv_mutex); +return 0 ; +} +/** * save_page_header: Write page header to wire *
@@ -729,6 +754,11 @@ static size_t save_page_header(QEMUFile *f, RAMBlock *block, ram_addr_t offset) {size_t size, len; +if (multifd_needs_flush) { + offset |=RAM_SAVE_FLAG_MULTIFD_FLUSH ; + multifd_needs_flush = false; + } +qemu_put_be64 (f, offset); size =8 ;
@@ -2399,6 +2429,9 @@ static int ram_save_complete(QEMUFile *f, void *opaque)if (!migration_in_postcopy (migrate_get_current ())) {migration_bitmap_sync (); +if (migrate_multifd ()) { + multifd_needs_flush = true; + } }ram_control_before_iterate (f,RAM_CONTROL_FINISH );
@@ -2440,6 +2473,9 @@ static void ram_save_pending(QEMUFile *f, void *opaque, uint64_t max_size,qemu_mutex_lock_iothread ();rcu_read_lock ();migration_bitmap_sync (); +if (migrate_multifd ()) { + multifd_needs_flush = true; + }rcu_read_unlock ();qemu_mutex_unlock_iothread (); remaining_size =ram_save_remaining () *TARGET_PAGE_SIZE ;
@@ -2851,6 +2887,10 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) flags = addr & ~TARGET_PAGE_MASK ; addr &=TARGET_PAGE_MASK ; +if (flags &RAM_SAVE_FLAG_MULTIFD_FLUSH ) { +multifd_flush (); + flags = flags & (~RAM_SAVE_FLAG_MULTIFD_FLUSH ); + }if (flags & (RAM_SAVE_FLAG_COMPRESS |RAM_SAVE_FLAG_PAGE |RAM_SAVE_FLAG_COMPRESS_PAGE |RAM_SAVE_FLAG_XBZRLE |RAM_SAVE_FLAG_MULTIFD_PAGE )) {
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 13/13] migration: flush receive queue
Quoted 34 lines · * Juan Quintela ([email protected]) wrote:
From: Juan Quintela <[email protected]>
Each time that we sync the bitmap, it is a possiblity that we receive a page that is being processed by a different thread. We fix this problem just making sure that we wait for all receiving threads to finish its work before we procedeed with the next stage.
I tried to make a migration command for it, but it don't work because we sync the bitmap sometimes when we have already sent the beggining of the section, so I just added a new page flag.
Signed-off-by Juan Quintela <[email protected]>--- include/migration/migration.h | 1 + migration/ram.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+)include/migration/migration.h +1
-0@@ -251,6 +251,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/ram.c +0
-0
migration/ram.c static uint64_t bitmap_sync_count; · line 72
Quoted 4 lines
migration/ram.c +1
-0@@ -69,6 +69,7 @@ static uint64_t bitmap_sync_count;/* 0x80 is reserved in migration.h start with 0x100 next */ #define RAM_SAVE_FLAG_COMPRESS_PAGE 0x100#define RAM_SAVE_FLAG_MULTIFD_PAGE 0x200 +#define RAM_SAVE_FLAG_MULTIFD_FLUSH 0x400
Now you really have run out of flags; there are architectures with 1kB target pages.
However, we really just shouldn't be gobbling these flags up; the flush could be MULTIFD_PAGE | one of the other flags.
Dave
Quoted 86 lines
migration/ram.c +39
-0static const uint8_t ZERO_TARGET_PAGE [TARGET_PAGE_SIZE ];@@ -398,6 +399,11 @@ void migrate_compress_threads_create(void)/* Multiple fd's */ + +/* Indicates if we have synced the bitmap and we need to assure that +target has processeed all previous pages */ +bool multifd_needs_flush = false; +struct MultiFDSendParams {/* not changed */ QemuThread thread;@@ -713,6 +719,25 @@ static void multifd_recv_page(uint8_t *address, int fd_num)qemu_mutex_unlock (¶ms->mutex); } + +static int multifd_flush (void ) +{ +int i, thread_count; + +if (!migrate_multifd ()) { +return 0 ; + } + thread_count =migrate_multifd_threads (); +qemu_mutex_lock (&multifd_recv_mutex); +for (i =0 ; i < thread_count; i++) { +while (!multifd_recv[i].done) { +qemu_cond_wait (&multifd_recv_cond, &multifd_recv_mutex); + } + } +qemu_mutex_unlock (&multifd_recv_mutex); +return 0 ; +} +/** * save_page_header: Write page header to wire * @@ -729,6 +754,11 @@ static size_t save_page_header(QEMUFile *f, RAMBlock *block, ram_addr_t offset) {size_t size, len; +if (multifd_needs_flush) { + offset |=RAM_SAVE_FLAG_MULTIFD_FLUSH ; + multifd_needs_flush = false; + } +qemu_put_be64 (f, offset); size =8 ;@@ -2399,6 +2429,9 @@ static int ram_save_complete(QEMUFile *f, void *opaque)if (!migration_in_postcopy (migrate_get_current ())) {migration_bitmap_sync (); +if (migrate_multifd ()) { + multifd_needs_flush = true; + } }ram_control_before_iterate (f,RAM_CONTROL_FINISH );@@ -2440,6 +2473,9 @@ static void ram_save_pending(QEMUFile *f, void *opaque, uint64_t max_size,qemu_mutex_lock_iothread ();rcu_read_lock ();migration_bitmap_sync (); +if (migrate_multifd ()) { + multifd_needs_flush = true; + }rcu_read_unlock ();qemu_mutex_unlock_iothread (); remaining_size =ram_save_remaining () *TARGET_PAGE_SIZE ;@@ -2851,6 +2887,10 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) flags = addr & ~TARGET_PAGE_MASK ; addr &=TARGET_PAGE_MASK ; +if (flags &RAM_SAVE_FLAG_MULTIFD_FLUSH ) { +multifd_flush (); + flags = flags & (~RAM_SAVE_FLAG_MULTIFD_FLUSH ); + }if (flags & (RAM_SAVE_FLAG_COMPRESS |RAM_SAVE_FLAG_PAGE |RAM_SAVE_FLAG_COMPRESS_PAGE |RAM_SAVE_FLAG_XBZRLE |RAM_SAVE_FLAG_MULTIFD_PAGE )) {Signature · 1 line
2.7.4
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Your series seems to have some coding style problems. See output below for more information:
Hi,
Your series seems to have some coding style problems. See output below for more information:
Type: series
Message-id: [email protected]
Subject: [Qemu-devel] [RFC 00/13] Multifd v2
=== TEST SCRIPT BEGIN ===
#!/bin/bash
BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0
# Useful git options
git config --local diff.renamelimit 0
git config --local diff.renames True
commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do
echo "Checking PATCH $n/$total: $(git show --no-patch --format=%s $c)..."
if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
failed=1
echo
fi
n=$((n+1))done
exit $failed
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
- [tag update] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
ee17fab migration: flush receive queue
27a9800 migration: [HACK]Transfer pages over new channels
25f1b86 migration: Test new fd infrastructure
d48dd5e migration: Create thread infrastructure for multifd recv side e7a5acd migration: Send the fd number which we are going to use for this page b2ace91 migration: Create thread infrastructure for multifd send side bdfb79f migration: create ram_multifd_page
8209364 migration: Start of multiple fd work
eeb3b70 migration: create multifd migration threads
a6d8287 migration: Create x-multifd-threads parameter
8cc47c1 migration: Add multifd capability
287498c migration: [HACK] Don't create decompression threads if not enabled 4dc8431 migration: create Migration Incoming State at init time
=== OUTPUT BEGIN ===
Checking PATCH 1/13: migration: create Migration Incoming State at init time... Checking PATCH 2/13: migration: [HACK] Don't create decompression threads if not enabled... Checking PATCH 3/13: migration: Add multifd capability...
Checking PATCH 4/13: migration: Create x-multifd-threads parameter...
WARNING: line over 80 characters
#92: FILE: migration/migration.c:822:
+ (params->x_multifd_threads < 1 || params->x_multifd_threads > 255)) {
total: 0 errors, 1 warnings, 128 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 5/13: migration: create multifd migration threads...
ERROR: space required before the open brace '{'
#103: FILE: migration/ram.c:409:
+ while (!params->quit){
ERROR: space required before the open brace '{'
#128: FILE: migration/ram.c:434:
+ if (!migrate_multifd()){
ERROR: space required before the open brace '{'
#146: FILE: migration/ram.c:452:
+ if (!migrate_multifd()){
ERROR: trailing whitespace
#174: FILE: migration/ram.c:480:
+ $
ERROR: space required before the open brace '{'
#176: FILE: migration/ram.c:482:
+ while (!params->quit){
ERROR: space required before the open brace '{'
#201: FILE: migration/ram.c:507:
+ if (!migrate_multifd()){
ERROR: space required before the open brace '{'
#219: FILE: migration/ram.c:525:
+ if (!migrate_multifd()){
total: 7 errors, 0 warnings, 206 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 6/13: migration: Start of multiple fd work...
ERROR: space required before the open parenthesis '(' #80: FILE: migration/ram.c:473:
+ if(!multifd_send[i].c) {
ERROR: space required before the open parenthesis '(' #135: FILE: migration/ram.c:568:
+ if(!multifd_recv[i].c) {
ERROR: do not use C99 // comments
#181: FILE: migration/socket.c:50:
+ // Remove channel here
ERROR: do not use C99 // comments
#197: FILE: migration/socket.c:66:
+ // Remove channel here
ERROR: do not use C99 // comments
#231: FILE: migration/socket.c:205:
+// qio_channel_close(ioc, NULL);
total: 5 errors, 0 warnings, 201 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 7/13: migration: create ram_multifd_page...
Checking PATCH 8/13: migration: Create thread infrastructure for multifd send side... Checking PATCH 9/13: migration: Send the fd number which we are going to use for this page... Checking PATCH 10/13: migration: Create thread infrastructure for multifd recv side... Checking PATCH 11/13: migration: Test new fd infrastructure...
ERROR: "(foo*)" should be "(foo *)"
#34: FILE: migration/ram.c:442:
+ != sizeof(uint8_t*)) {
ERROR: "(foo*)" should be "(foo *)"
#59: FILE: migration/ram.c:595:
+ sizeof(uint8_t*), &error_abort)
total: 2 errors, 0 warnings, 64 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 12/13: migration: [HACK]Transfer pages over new channels...
ERROR: space required before the open parenthesis '('
#91: FILE: migration/ram.c:565:
+ while(!multifd_send[i].done) {
total: 1 errors, 0 warnings, 134 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
Checking PATCH 13/13: migration: flush receive queue...
ERROR: do not initialise globals to 0 or NULL #49: FILE: migration/ram.c:405:
+bool multifd_needs_flush = false;
ERROR: space required before the open parenthesis '(' #69: FILE: migration/ram.c:733:
+ while(!multifd_recv[i].done) {
total: 2 errors, 0 warnings, 89 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===
Test command exited with code: 1
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]