migration: Add precopy initial data capability and VFIO precopy support
v2 cover migration: Add precopy initial data capability and VFIO precopy support
Hello everyone,
This is v2 of the precopy initial data series.
I am still wondering about the name -- maybe "explicit switchover", as suggested by Peter, is better as it's more general?
Anyway,
Changes from v1 [3]:
* Rebased on latest master branch.
* Updated to latest QAPI doc comment conventions and refined QAPI docs and capability error message. (Markus)
* Followed Peter/Juan suggestion and removed the handshake between source and destination.
Now the capability must be set on both source and destination. Compatibility of this feature between different QEMU versions or different host capabilities (i.e., kernel) is achieved in the regular way of device properties and hw_comapt_x_y.
* Replaced is_initial_data_active() and initial_data_loaded() SaveVMHandlers handlers with a notification mechanism. (Peter)
* Set the capability also in destination in the migration test.
* Added VFIO device property x-allow-pre-copy to be able to preserve compatibility between different QEMU versions or different host capabilities (i.e., kernel).
* Changed VFIO precopy initial data implementation according to the above changes.
* Documented VFIO precopy initial data support in VFIO migration documentation.
* Added R-bs.
===
This series adds a new migration capability called "precopy initial data". The purpose of this capability is to reduce migration downtime in cases where loading of migration data in the destination can take a lot of time, such as with VFIO migration data.
The series then moves to add precopy support and precopy initial data support for VFIO migration.
Precopy initial data is used by VFIO migration, but other migration users can add support for it and use it as well.
=== Background ===
Migration downtime estimation is calculated based on bandwidth and remaining migration data. This assumes that loading of migration data in the destination takes a negligible amount of time and that downtime depends only on network speed.
While this may be true for RAM, it's not necessarily true for other migration users. For example, loading the data of a VFIO device in the destination might require from the device to allocate resources and prepare internal data structures which can take a significant amount of time to do.
This poses a problem, as the source may think that the remaining migration data is small enough to meet the downtime limit, so it will stop the VM and complete the migration, but in fact sending and loading the data in the destination may take longer than the downtime limit.
To solve this, VFIO migration uAPI defines "initial bytes" as part of its precopy stream [1]. Initial bytes can be used in various ways to improve VFIO migration performance. For example, it can be used to transfer device metadata to pre-allocate resources in the destination. However, for this to work we need to make sure that all initial bytes are sent and loaded in the destination before the source VM is stopped.
The new precopy initial data migration capability helps us achieve this. It allows the source to send initial precopy data and the destination to ACK that this data has been loaded. Migration will not attempt to stop the source VM and complete the migration until this ACK is received.
Note that this relies on the return path capability to communicate from the destination back to the source.
=== Flow of operation ===
To use precopy initial data, the capability must be enabled in both the source and the destination.
During migration setup, migration code calls the initial_data_advise() SaveVMHandlers handler of the migration users, both in the source and the destination, to notify them that precopy initial data is used. In the destination, an "initial_data_pending_num" counter is increased for each migration user that supports this feature. It will be used later to mark when an ACK should be sent to the source.
Migration starts to send precopy data and as part of it also the initial precopy data. Initial precopy data is just like any other precopy data and as such, migration code is not aware of it. Therefore, it's the responsibility of the migration users (such as VFIO devices) to notify their counterparts in the destination that their initial precopy data has been sent (for example, VFIO migration does it when its initial bytes reach zero).
In the destination, when a migration user finishes to receive and load its initial data, it notifies the migration code about it and the "initial_data_pending_num" counter is decreased. When this counter reaches zero, it means that all initial data has been loaded in the destination and an ACK is sent to the source, which will now be able to complete migration when appropriate.
=== Test results ===
The below table shows the downtime of two identical migrations. In the first migration precopy initial data is disabled and in the second it is enabled. The migrated VM is assigned with a mlx5 VFIO device which has 300MB of device data to be migrated.
+----------------------+-----------------------+----------+ | Precopy initial data | VFIO device data size | Downtime | +----------------------+-----------------------+----------+ | Disabled | 300MB | 1900ms | | Enabled | 300MB | 420ms | +----------------------+-----------------------+----------+
Precopy initial data gives a roughly 4.5 times improvement in downtime. The 1480ms difference is time that is used for resource allocation for the VFIO device in the destination. Without precopy initial data, this time is spent when the source VM is stopped and thus the downtime is much higher. With precopy initial data, the time is spent when the source VM is still running.
=== Patch breakdown ===
- Patches 1-4 add the precopy initial data capability.
- Patches 5-6 add VFIO migration precopy support. Similar version of them was previously sent here [2].
- Patch 7 adds precopy initial data support for VFIO migration.
Thanks for reviewing!
[1]
https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/vfio.h#L1048
[2]
https://lore.kernel.org/qemu-devel/[email protected]/
[3]
https://lore.kernel.org/qemu-devel/[email protected]/
Avihai Horon (7):
migration: Add precopy initial data capability
migration: Implement precopy initial data logic
migration: Enable precopy initial data capability
tests: Add migration precopy initial data capability test vfio/migration: Refactor vfio_save_block() to return saved data size vfio/migration: Add VFIO migration pre-copy support vfio/migration: Add support for precopy initial data capability
docs/devel/vfio-migration.rst | 45 +++++-- qapi/migration.json | 9 +- include/hw/vfio/vfio-common.h | 6 + include/migration/register.h | 6 + migration/migration.h | 14 +++ migration/options.h | 1 + migration/savevm.h | 2 + hw/core/machine.c | 1 + hw/vfio/common.c | 6 +- hw/vfio/migration.c | 220 +++++++++++++++++++++++++++++++--- hw/vfio/pci.c | 2 + migration/migration.c | 40 ++++++- migration/options.c | 17 +++ migration/savevm.c | 65 ++++++++++ tests/qtest/migration-test.c | 26 ++++ hw/vfio/trace-events | 4 +- migration/trace-events | 4 + 17 files changed, 435 insertions(+), 33 deletions(-)
Signature · 1 line
2.26.3
PATCH v2 1/7 migration: Add precopy initial data capability
Migration downtime estimation is calculated based on bandwidth and remaining migration data. This assumes that loading of migration data in the destination takes a negligible amount of time and that downtime depends only on network speed.
While this may be true for RAM, it's not necessarily true for other migration users. For example, loading the data of a VFIO device in the destination might require from the device to allocate resources, prepare internal data structures and so on. These operations can take a significant amount of time which can increase migration downtime.
This patch adds a new capability "precopy initial data" that allows the source to send initial precopy data and the destination to ACK that this data has been loaded. Migration will not attempt to stop the source VM and complete the migration until this ACK is received.
This will allow migration users to send initial precopy data which can be used to reduce downtime (e.g., by pre-allocating resources), while making sure that the source will stop the VM and complete the migration only after this initial precopy data is sent and loaded in the destination so it will have full effect.
This new capability relies on the return path capability to communicate from the destination back to the source.
The actual implementation of the capability will be added in the following patches.
--- qapi/migration.json | 9 ++++++++- migration/options.h | 1 + migration/options.c | 21 +++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-)
qapi/migration.json +8 -1
@@ -487,6 +487,13 @@ # and should not affect the correctness of postcopy migration. # (since 7.1) # +# @precopy-initial-data: If enabled, migration will not attempt to +# stop source VM and complete the migration until an ACK is +# received from the destination that initial precopy data has been +# loaded. This can improve downtime if there are migration users +# that support precopy initial data. 'return-path' capability +# must be enabled to use it. (since 8.1) +# # Features: # # @unstable: Members @x-colo and @x-ignore-shared are experimental.
@@ -502,7 +509,7 @@ 'dirty-bitmaps', 'postcopy-blocktime', 'late-block-activate', { 'name': 'x-ignore-shared', 'features': [ 'unstable' ] }, 'validate-uuid', 'background-snapshot', - 'zero-copy-send', 'postcopy-preempt'] } + 'zero-copy-send', 'postcopy-preempt', 'precopy-initial-data'] } ## # @MigrationCapabilityStatus:
migration/options.h +1 -0
@@ -44,6 +44,7 @@ bool migrate_pause_before_switchover(void);bool migrate_postcopy_blocktime (void );bool migrate_postcopy_preempt (void );bool migrate_postcopy_ram (void ); +bool migrate_precopy_initial_data (void );bool migrate_rdma_pin_all (void );bool migrate_release_ram (void );bool migrate_return_path (void );
migration/options.c +21 -0
@@ -184,6 +184,8 @@ Property migration_properties[] = {DEFINE_PROP_MIG_CAP ("x-zero-copy-send" ,MIGRATION_CAPABILITY_ZERO_COPY_SEND ), #endif +DEFINE_PROP_MIG_CAP ("x-precopy-initial-data" , +MIGRATION_CAPABILITY_PRECOPY_INITIAL_DATA ), DEFINE_PROP_END_OF_LIST(), };
@@ -286,6 +288,13 @@ bool migrate_postcopy_ram(void)return s->capabilities[MIGRATION_CAPABILITY_POSTCOPY_RAM ]; } +bool migrate_precopy_initial_data (void ) +{ +MigrationState *s =migrate_get_current (); + +return s->capabilities[MIGRATION_CAPABILITY_PRECOPY_INITIAL_DATA ]; +} +bool migrate_rdma_pin_all (void ) {MigrationState *s =migrate_get_current ();
@@ -546,6 +555,18 @@ bool migrate_caps_check(bool *old_caps, bool *new_caps, Error **errp) } } +if (new_caps[MIGRATION_CAPABILITY_PRECOPY_INITIAL_DATA ]) { +if (!new_caps[MIGRATION_CAPABILITY_RETURN_PATH ]) { +error_setg (errp,"Capability 'precopy-initial-data' requires " +"capability 'return-path'" ); +return false; + } + +/* Disable this capability until it's implemented */ +error_setg (errp,"'precopy-initial-data' is not implemented yet" ); +return false; + } +return true; }
Signature · 1 line
2.26.3
PATCH v2 2/7 migration: Implement precopy initial data logic
In reply to Avihai HoronImplement precopy initial data logic. This allows migration users in the source to send precopy initial data and the destination to ACK when this data is loaded. Migration will not attempt to stop the source VM and complete the migration until this ACK is received.
To achieve this, a new SaveVMHandlers handler initial_data_advise() and a new return path mesage MIG_RP_MSG_INITIAL_DATA_LOADED_ACK are added.
The initial_data_advise() handler is called during migration setup both in the source and the destination to advise the migration user that precopy initial data is used, and its return value indicates whether precopy initial data is supported by it.
When precopy initial data of all the migration users is loaded in the destination, the MIG_RP_MSG_INITIAL_DATA_LOADED_ACK return path message is sent to the source to notify it.
--- include/migration/register.h | 6 ++++ migration/migration.h | 14 ++++++++ migration/savevm.h | 2 ++ migration/migration.c | 40 ++++++++++++++++++++-- migration/savevm.c | 65 ++++++++++++++++++++++++++++++++++++ migration/trace-events | 4 +++ 6 files changed, 129 insertions(+), 2 deletions(-)
include/migration/register.h +6 -0
@@ -71,6 +71,12 @@ typedef struct SaveVMHandlers {int (*load_cleanup)(void *opaque);/* Called when postcopy migration wants to resume from failure */ int (*resume_prepare)(MigrationState *s,void *opaque); + +/* +* Advises that precopy initial data was requested. Returns true if it's +* supported or false otherwise. Called both in src and dest. +*/ +bool (*initial_data_advise)(void *opaque); } SaveVMHandlers; int register_savevm_live(const char *idstr,
migration/migration.h +14 -0
@@ -202,6 +202,13 @@ struct MigrationIncomingState {* contains valid information. */ QemuMutex page_request_mutex; + +/* +* Number of migration users that are waiting for their initial data to be +* loaded. When this reaches zero an ACK is sent to source. No lock is +* needed as this field is updated serially. +*/ +unsigned int initial_data_pending_num; };MigrationIncomingState *migration_incoming_get_current (void );
@@ -430,6 +437,12 @@ struct MigrationState {/* QEMU_VM_VMDESCRIPTION content filled for all non-iterable devices. */ JSONWriter *vmdesc; + +/* +* Indicates whether an ACK that precopy initial data was loaded in +* destination has been received. +*/ +bool initial_data_loaded_acked; };void migrate_set_state (int *state,int old_state,int new_state);
@@ -470,6 +483,7 @@ int migrate_send_rp_message_req_pages(MigrationIncomingState *mis,void migrate_send_rp_recv_bitmap (MigrationIncomingState *mis,char *block_name);void migrate_send_rp_resume_ack (MigrationIncomingState *mis,uint32_t value); +int migrate_send_rp_initial_data_loaded_ack (MigrationIncomingState *mis);void dirty_bitmap_mig_before_vm_start (void );void dirty_bitmap_mig_cancel_outgoing (void );
migration/savevm.h +2 -0
@@ -32,6 +32,7 @@bool qemu_savevm_state_blocked (Error **errp);void qemu_savevm_non_migratable_list (strList **reasons);void qemu_savevm_state_setup (QEMUFile *f); +void qemu_savevm_state_initial_data_advise (MigrationState *ms);bool qemu_savevm_state_guest_unplug_pending (void );int qemu_savevm_state_resume_prepare (MigrationState *s);void qemu_savevm_state_header (QEMUFile *f);
@@ -65,6 +66,7 @@ int qemu_loadvm_state(QEMUFile *f);void qemu_loadvm_state_cleanup (void );int qemu_loadvm_state_main (QEMUFile *f,MigrationIncomingState *mis);int qemu_load_device_state (QEMUFile *f); +int qemu_loadvm_notify_initial_data_loaded (void );int qemu_savevm_state_complete_precopy_non_iterable (QEMUFile *f,bool in_postcopy,bool inactivate_disks);
migration/migration.c +38 -2
@@ -78,6 +78,7 @@ enum mig_rp_message_type {MIG_RP_MSG_REQ_PAGES ,/* data (start: be64, len: be32) */ MIG_RP_MSG_RECV_BITMAP ,/* send recved_bitmap back to source */ MIG_RP_MSG_RESUME_ACK ,/* tell source that we are ready to resume */ +MIG_RP_MSG_INITIAL_DATA_LOADED_ACK ,/* Tell source initial data is loaded */ MIG_RP_MSG_MAX };
@@ -780,6 +781,12 @@ bool migration_has_all_channels(void)return true; } +int migrate_send_rp_initial_data_loaded_ack (MigrationIncomingState *mis) +{ +return migrate_send_rp_message (mis,MIG_RP_MSG_INITIAL_DATA_LOADED_ACK ,0 , +NULL ); +} +/* * Send a 'SHUT' message on the return channel with the given value * to indicate that we've finished with the RP. Non-0 value indicates
@@ -1425,6 +1432,7 @@ void migrate_init(MigrationState *s) s->vm_was_running = false; s->iteration_initial_bytes =0 ; s->threshold_size =0 ; + s->initial_data_loaded_acked = false; }int migrate_add_blocker_internal (Error *reason,Error **errp)
@@ -1741,6 +1749,9 @@ static struct rp_cmd_args { [MIG_RP_MSG_REQ_PAGES_ID] = { .len = -1, .name = "REQ_PAGES_ID" }, [MIG_RP_MSG_RECV_BITMAP] = { .len = -1, .name = "RECV_BITMAP" }, [MIG_RP_MSG_RESUME_ACK] = { .len = 4, .name = "RESUME_ACK" }, + [MIG_RP_MSG_INITIAL_DATA_LOADED_ACK ] = { .len =0 , + .name = + "INITIAL_DATA_LOADED_ACK" }, [MIG_RP_MSG_MAX] = { .len = -1, .name = "MAX" }, };
@@ -1979,6 +1990,11 @@ retry: }break ; +case MIG_RP_MSG_INITIAL_DATA_LOADED_ACK : + ms->initial_data_loaded_acked = true; +trace_source_return_path_thread_initial_data_loaded_ack (); +break ; +default :break ; }
@@ -2727,6 +2743,20 @@ static void migration_update_counters(MigrationState *s, bandwidth, s->threshold_size); } +static bool initial_data_loaded_acked (MigrationState *s) +{ +if (!migrate_precopy_initial_data ()) { +return true; + } + +/* No reason to wait for precopy initial data loaded ACK if VM is stopped */ +if (!runstate_is_running ()) { +return true; + } + +return s->initial_data_loaded_acked; +} +/* Migration thread iteration status */ typedef enum { MIG_ITERATE_RESUME, /* Resume current iteration */
@@ -2742,6 +2772,7 @@ static MigIterateState migration_iteration_run(MigrationState *s) {uint64_t must_precopy, can_postcopy;bool in_postcopy = s->state ==MIGRATION_STATUS_POSTCOPY_ACTIVE ; +bool initial_data_loaded =initial_data_loaded_acked (s);qemu_savevm_state_pending_estimate (&must_precopy, &can_postcopy);uint64_t pending_size = must_precopy + can_postcopy;
@@ -2754,7 +2785,8 @@ static MigIterateState migration_iteration_run(MigrationState *s)trace_migrate_pending_exact (pending_size, must_precopy, can_postcopy); } -if (!pending_size || pending_size < s->threshold_size) { +if ((!pending_size || pending_size < s->threshold_size) && + initial_data_loaded) {trace_migration_thread_low_pending (pending_size);migration_completion (s);return MIG_ITERATE_BREAK ;
@@ -2762,7 +2794,7 @@ static MigIterateState migration_iteration_run(MigrationState *s)/* Still a significant amount to transfer */ if (!in_postcopy && must_precopy <= s->threshold_size && -qatomic_read (&s->start_postcopy)) { + initial_data_loaded &&qatomic_read (&s->start_postcopy)) {if (postcopy_start (s)) {error_report ("%s: postcopy failed to start" , __func__); }
@@ -2986,6 +3018,10 @@ static void *migration_thread(void *opaque)qemu_savevm_state_setup (s->to_dst_file); +if (migrate_precopy_initial_data ()) { +qemu_savevm_state_initial_data_advise (s); + } +qemu_savevm_wait_unplug (s,MIGRATION_STATUS_SETUP ,MIGRATION_STATUS_ACTIVE );
migration/savevm.c +65 -0
89 lines not on this page · raw message
migration/trace-events +4 -0
@@ -7,6 +7,7 @@ qemu_loadvm_state_section_partend(uint32_t section_id) "%u" qemu_loadvm_state_post_main(int ret) "%d" qemu_loadvm_state_section_startfull(uint32_t section_id, const char *idstr, uint32_t instance_id, uint32_t version_id) "%u(%s) %u %u" qemu_savevm_send_packaged(void) "" +loadvm_state_initial_data_advise(unsigned int initial_data_pending_num) "Initial data pending num=%u" loadvm_state_setup(void) "" loadvm_state_cleanup(void) "" loadvm_handle_cmd_packaged(unsigned int length) "%u"
@@ -23,6 +24,7 @@ loadvm_postcopy_ram_handle_discard_end(void) "" loadvm_postcopy_ram_handle_discard_header(const char *ramid, uint16_t len) "%s: %ud" loadvm_process_command(const char *s, uint16_t len) "com=%s len=%d" loadvm_process_command_ping(uint32_t val) "0x%x" +loadvm_notify_initial_data_loaded(unsigned int initial_data_pending_num) "Initial data pending num=%u" postcopy_ram_listen_thread_exit(void) "" postcopy_ram_listen_thread_start(void) "" qemu_savevm_send_postcopy_advise(void) ""
@@ -39,6 +41,7 @@ savevm_send_postcopy_resume(void) "" savevm_send_colo_enable(void) "" savevm_send_recv_bitmap(char *name) "%s" savevm_state_setup(void) "" +savevm_state_initial_data_advise(unsigned int initial_data_supported_num) "Initial data supported num=%u" savevm_state_resume_prepare(void) "" savevm_state_header(void) "" savevm_state_iterate(void) ""
@@ -180,6 +183,7 @@ source_return_path_thread_loop_top(void) "" source_return_path_thread_pong(uint32_t val) "0x%x" source_return_path_thread_shut(uint32_t val) "0x%x" source_return_path_thread_resume_ack(uint32_t v) "%"PRIu32 +source_return_path_thread_initial_data_loaded_ack(void) "" migration_thread_low_pending(uint64_t pending) "%" PRIu64 migrate_transferred(uint64_t tranferred, uint64_t time_spent, uint64_t bandwidth, uint64_t size) "transferred %" PRIu64 " time_spent %" PRIu64 " bandwidth %" PRIu64 " max_size %" PRId64 process_incoming_migration_co_end(int ret, int ps) "ret=%d postcopy-state=%d"
Signature · 1 line
2.26.3
Re: [PATCH v2 2/7] migration: Implement precopy initial data logic
Quoted 8 lines · Avihai Horon
Implement precopy initial data logic. This allows migration users in the source to send precopy initial data and the destination to ACK when this data is loaded. Migration will not attempt to stop the source VM and complete the migration until this ACK is received.
To achieve this, a new SaveVMHandlers handler
initial_data_advise()and a new return path mesageMIG_RP_MSG_INITIAL_DATA_LOADED_ACKare added.
Quoted 8 lines
The
initial_data_advise()handler is called during migration setup both in the source and the destination to advise the migration user that precopy initial data is used, and its return value indicates whether precopy initial data is supported by it.When precopy initial data of all the migration users is loaded in the destination, the
MIG_RP_MSG_INITIAL_DATA_LOADED_ACKreturn path message is sent to the source to notify it.
This looks much better and easier to digest, thanks a lot.
It does answer one of my question that I wanted to ask on whether both sides would know which device will need this feature enabled. It seems both sides are actually in consensus with it, which is great on reducing the changeset. Then it's less controversial on whether we'll need a more generic handshake because we simply don't need the per-dev handshake for now.
The name is probably prone to change indeed. Firstly, it's not really always on precopy but also for postcopy. If vfio will supports postcopy in the future this feature will also be needed to make sure low downtime during switching to postcopy. I saw that you even changed postcopy for this [1] which is definitely good. So "precopy" in the cap is not proper anymore.
How about "switchover-ack"? Then..
Quoted 16 lines
Signed-off-by Avihai Horon <[email protected]>--- include/migration/register.h | 6 ++++ migration/migration.h | 14 ++++++++ migration/savevm.h | 2 ++ migration/migration.c | 40 ++++++++++++++++++++-- migration/savevm.c | 65 ++++++++++++++++++++++++++++++++++++ migration/trace-events | 4 +++ 6 files changed, 129 insertions(+), 2 deletions(-)include/migration/register.h +0
-0
include/migration/register.h typedef struct SaveVMHandlers { · line 79
Quoted 9 lines
include/migration/register.h +6
-0@@ -71,6 +71,12 @@ typedef struct SaveVMHandlers {int (*load_cleanup)(void *opaque);/* Called when postcopy migration wants to resume from failure */ int (*resume_prepare)(MigrationState *s,void *opaque); + +/* +* Advises that precopy initial data was requested. Returns true if it's +* supported or false otherwise. Called both in src and dest. +*/ +bool (*initial_data_advise)(void *opaque);
.. this can be "switchover_ack_needed()". Ditto below on most of the name of variables.
Quoted 96 lines
include/migration/register.h +0
-0} SaveVMHandlers; int register_savevm_live(const char *idstr,migration/migration.h +14
-0@@ -202,6 +202,13 @@ struct MigrationIncomingState {* contains valid information. */ QemuMutex page_request_mutex; + +/* +* Number of migration users that are waiting for their initial data to be +* loaded. When this reaches zero an ACK is sent to source. No lock is +* needed as this field is updated serially. +*/ +unsigned int initial_data_pending_num; };MigrationIncomingState *migration_incoming_get_current (void );@@ -430,6 +437,12 @@ struct MigrationState {/* QEMU_VM_VMDESCRIPTION content filled for all non-iterable devices. */ JSONWriter *vmdesc; + +/* +* Indicates whether an ACK that precopy initial data was loaded in +* destination has been received. +*/ +bool initial_data_loaded_acked; };void migrate_set_state (int *state,int old_state,int new_state);@@ -470,6 +483,7 @@ int migrate_send_rp_message_req_pages(MigrationIncomingState *mis,void migrate_send_rp_recv_bitmap (MigrationIncomingState *mis,char *block_name);void migrate_send_rp_resume_ack (MigrationIncomingState *mis,uint32_t value); +int migrate_send_rp_initial_data_loaded_ack (MigrationIncomingState *mis);void dirty_bitmap_mig_before_vm_start (void );void dirty_bitmap_mig_cancel_outgoing (void );migration/savevm.h +2
-0@@ -32,6 +32,7 @@bool qemu_savevm_state_blocked (Error **errp);void qemu_savevm_non_migratable_list (strList **reasons);void qemu_savevm_state_setup (QEMUFile *f); +void qemu_savevm_state_initial_data_advise (MigrationState *ms);bool qemu_savevm_state_guest_unplug_pending (void );int qemu_savevm_state_resume_prepare (MigrationState *s);void qemu_savevm_state_header (QEMUFile *f);@@ -65,6 +66,7 @@ int qemu_loadvm_state(QEMUFile *f);void qemu_loadvm_state_cleanup (void );int qemu_loadvm_state_main (QEMUFile *f,MigrationIncomingState *mis);int qemu_load_device_state (QEMUFile *f); +int qemu_loadvm_notify_initial_data_loaded (void );int qemu_savevm_state_complete_precopy_non_iterable (QEMUFile *f,bool in_postcopy,bool inactivate_disks);migration/migration.c +8
-0@@ -78,6 +78,7 @@ enum mig_rp_message_type {MIG_RP_MSG_REQ_PAGES ,/* data (start: be64, len: be32) */ MIG_RP_MSG_RECV_BITMAP ,/* send recved_bitmap back to source */ MIG_RP_MSG_RESUME_ACK ,/* tell source that we are ready to resume */ +MIG_RP_MSG_INITIAL_DATA_LOADED_ACK ,/* Tell source initial data is loaded */ MIG_RP_MSG_MAX };@@ -780,6 +781,12 @@ bool migration_has_all_channels(void)return true; } +int migrate_send_rp_initial_data_loaded_ack (MigrationIncomingState *mis) +{ +return migrate_send_rp_message (mis,MIG_RP_MSG_INITIAL_DATA_LOADED_ACK ,0 , +NULL ); +} +/* * Send a 'SHUT' message on the return channel with the given value * to indicate that we've finished with the RP. Non-0 value indicates @@ -1425,6 +1432,7 @@ void migrate_init(MigrationState *s) s->vm_was_running = false; s->iteration_initial_bytes =0 ; s->threshold_size =0 ; + s->initial_data_loaded_acked = false; }int migrate_add_blocker_internal (Error *reason,Error **errp)
migration/migration.c static struct rp_cmd_args { · line 1754
Quoted 6 lines
migration/migration.c +3
-0@@ -1741,6 +1749,9 @@ static struct rp_cmd_args { [MIG_RP_MSG_REQ_PAGES_ID] = { .len = -1, .name = "REQ_PAGES_ID" }, [MIG_RP_MSG_RECV_BITMAP] = { .len = -1, .name = "RECV_BITMAP" }, [MIG_RP_MSG_RESUME_ACK] = { .len = 4, .name = "RESUME_ACK" }, + [MIG_RP_MSG_INITIAL_DATA_LOADED_ACK] = { .len = 0, + .name = + "INITIAL_DATA_LOADED_ACK" },
Nit: let's just put it in a single line. If it'll be SWITCHOVER_ACK it's even shorter. :)
Quoted 19 lines
migration/migration.c +5
-0[MIG_RP_MSG_MAX] = { .len = -1, .name = "MAX" }, };@@ -1979,6 +1990,11 @@ retry: }break ; +case MIG_RP_MSG_INITIAL_DATA_LOADED_ACK : + ms->initial_data_loaded_acked = true; +trace_source_return_path_thread_initial_data_loaded_ack (); +break ; +default :break ; }@@ -2727,6 +2743,20 @@ static void migration_update_counters(MigrationState *s, bandwidth, s->threshold_size); }
migration/migration.c static void migration_update_counters(MigrationState *s, · line 2755
Quoted 10 lines
migration/migration.c +10
-0+static bool initial_data_loaded_acked (MigrationState *s) +{ +if (!migrate_precopy_initial_data ()) { +return true; + } + +/* No reason to wait for precopy initial data loaded ACK if VM is stopped */ +if (!runstate_is_running ()) { +return true; + }
This check may or may not be a problem, as it can become running right away after the check.
But I think I get your point here and I think it's fine; it at least means the vm stopped for even a while and the user doesn't strictly care super lot about downtime.
Quoted 26 lines
migration/migration.c +7
-1+ +return s->initial_data_loaded_acked; +} +/* Migration thread iteration status */ typedef enum { MIG_ITERATE_RESUME, /* Resume current iteration */@@ -2742,6 +2772,7 @@ static MigIterateState migration_iteration_run(MigrationState *s) {uint64_t must_precopy, can_postcopy;bool in_postcopy = s->state ==MIGRATION_STATUS_POSTCOPY_ACTIVE ; +bool initial_data_loaded =initial_data_loaded_acked (s);qemu_savevm_state_pending_estimate (&must_precopy, &can_postcopy);uint64_t pending_size = must_precopy + can_postcopy;@@ -2754,7 +2785,8 @@ static MigIterateState migration_iteration_run(MigrationState *s)trace_migrate_pending_exact (pending_size, must_precopy, can_postcopy); } -if (!pending_size || pending_size < s->threshold_size) { +if ((!pending_size || pending_size < s->threshold_size) && + initial_data_loaded) {trace_migration_thread_low_pending (pending_size);migration_completion (s);return MIG_ITERATE_BREAK ;
migration/migration.c static MigIterateState migration_iteration_run(MigrationState *s) · line 2797
Quoted 5 lines
migration/migration.c +1
-1@@ -2762,7 +2794,7 @@ static MigIterateState migration_iteration_run(MigrationState *s)/* Still a significant amount to transfer */ if (!in_postcopy && must_precopy <= s->threshold_size && -qatomic_read (&s->start_postcopy)) { + initial_data_loaded &&qatomic_read (&s->start_postcopy)) {
[1]
Quoted 34 lines
migration/migration.c +4
-0if (postcopy_start (s)) {error_report ("%s: postcopy failed to start" , __func__); }@@ -2986,6 +3018,10 @@ static void *migration_thread(void *opaque)qemu_savevm_state_setup (s->to_dst_file); +if (migrate_precopy_initial_data ()) { +qemu_savevm_state_initial_data_advise (s); + } +qemu_savevm_wait_unplug (s,MIGRATION_STATUS_SETUP ,MIGRATION_STATUS_ACTIVE );migration/savevm.c +12
-0@@ -1233,6 +1233,32 @@ bool qemu_savevm_state_guest_unplug_pending(void)return false; } +void qemu_savevm_state_initial_data_advise (MigrationState *ms) +{ +SaveStateEntry *se; +unsigned int supported_num =0 ; + + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { +if (!se->ops || !se->ops->initial_data_advise) { +continue ; + } + +if (se->ops->initial_data_advise (se->opaque)) { + supported_num++;
migration/savevm.c bool qemu_savevm_state_guest_unplug_pending(void) · line 1257
Quoted 10 lines
migration/savevm.c +10
-0+ } + } + +if (!supported_num) { +/* +* There are no migration users that support precopy initial data. Set +* initial data loaded acked to true so migration can be completed. +*/ + ms->initial_data_loaded_acked = true; + }
This is fine but slightly hackish (e.g. someone would assume we received a msg when this var being true, but in this case we just don't need one).
How about remember this "supported_nums" on src too and just check that in initial_data_loaded_acked() above?
PS: we should someday have a common object for both src/dst migration which will be suitable for variables like this, so all common vars in MigrationState and MigrationIncomingState will go there. Another story.
Quoted 106 lines
migration/savevm.c +43
-0+ +trace_savevm_state_initial_data_advise (supported_num); +} +void qemu_savevm_state_setup (QEMUFile *f) {MigrationState *ms =migrate_get_current ();@@ -2586,6 +2612,23 @@ static int qemu_loadvm_state_header(QEMUFile *f)return 0 ; } +static void qemu_loadvm_state_initial_data_advise (MigrationIncomingState *mis) +{ +SaveStateEntry *se; + + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { +if (!se->ops || !se->ops->initial_data_advise) { +continue ; + } + +if (se->ops->initial_data_advise (se->opaque)) { + mis->initial_data_pending_num++; + } + } + +trace_loadvm_state_initial_data_advise (mis->initial_data_pending_num); +} +static int qemu_loadvm_state_setup (QEMUFile *f) {SaveStateEntry *se;@@ -2789,6 +2832,10 @@ int qemu_loadvm_state(QEMUFile *f)return -EINVAL ; } +if (migrate_precopy_initial_data ()) { +qemu_loadvm_state_initial_data_advise (mis); + } +cpu_synchronize_all_pre_loadvm (); ret =qemu_loadvm_state_main (f, mis);@@ -2862,6 +2909,24 @@ int qemu_load_device_state(QEMUFile *f)return 0 ; } +int qemu_loadvm_notify_initial_data_loaded (void ) +{ +MigrationIncomingState *mis =migration_incoming_get_current (); + +if (!mis->initial_data_pending_num) { +return -EINVAL ; + } + + mis->initial_data_pending_num--; +trace_loadvm_notify_initial_data_loaded (mis->initial_data_pending_num); + +if (mis->initial_data_pending_num) { +return 0 ; + } + +return migrate_send_rp_initial_data_loaded_ack (mis); +} +bool save_snapshot (const char *name,bool overwrite,const char *vmstate,bool has_devices,strList *devices,Error **errp) {migration/trace-events +4
-0@@ -7,6 +7,7 @@ qemu_loadvm_state_section_partend(uint32_t section_id) "%u" qemu_loadvm_state_post_main(int ret) "%d" qemu_loadvm_state_section_startfull(uint32_t section_id, const char *idstr, uint32_t instance_id, uint32_t version_id) "%u(%s) %u %u" qemu_savevm_send_packaged(void) "" +loadvm_state_initial_data_advise(unsigned int initial_data_pending_num) "Initial data pending num=%u" loadvm_state_setup(void) "" loadvm_state_cleanup(void) "" loadvm_handle_cmd_packaged(unsigned int length) "%u"@@ -23,6 +24,7 @@ loadvm_postcopy_ram_handle_discard_end(void) "" loadvm_postcopy_ram_handle_discard_header(const char *ramid, uint16_t len) "%s: %ud" loadvm_process_command(const char *s, uint16_t len) "com=%s len=%d" loadvm_process_command_ping(uint32_t val) "0x%x" +loadvm_notify_initial_data_loaded(unsigned int initial_data_pending_num) "Initial data pending num=%u" postcopy_ram_listen_thread_exit(void) "" postcopy_ram_listen_thread_start(void) "" qemu_savevm_send_postcopy_advise(void) ""@@ -39,6 +41,7 @@ savevm_send_postcopy_resume(void) "" savevm_send_colo_enable(void) "" savevm_send_recv_bitmap(char *name) "%s" savevm_state_setup(void) "" +savevm_state_initial_data_advise(unsigned int initial_data_supported_num) "Initial data supported num=%u" savevm_state_resume_prepare(void) "" savevm_state_header(void) "" savevm_state_iterate(void) ""@@ -180,6 +183,7 @@ source_return_path_thread_loop_top(void) "" source_return_path_thread_pong(uint32_t val) "0x%x" source_return_path_thread_shut(uint32_t val) "0x%x" source_return_path_thread_resume_ack(uint32_t v) "%"PRIu32 +source_return_path_thread_initial_data_loaded_ack(void) "" migration_thread_low_pending(uint64_t pending) "%" PRIu64 migrate_transferred(uint64_t tranferred, uint64_t time_spent, uint64_t bandwidth, uint64_t size) "transferred %" PRIu64 " time_spent %" PRIu64 " bandwidth %" PRIu64 " max_size %" PRId64 process_incoming_migration_co_end(int ret, int ps) "ret=%d postcopy-state=%d"Signature · 1 line
2.26.3
Thanks,
Signature · 1 line
Peter Xu
Re: [PATCH v2 2/7] migration: Implement precopy initial data logic
Quoted 29 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 8 lines · Avihai Horon
Implement precopy initial data logic. This allows migration users in the source to send precopy initial data and the destination to ACK when this data is loaded. Migration will not attempt to stop the source VM and complete the migration until this ACK is received.
To achieve this, a new SaveVMHandlers handler
initial_data_advise()and a new return path mesageMIG_RP_MSG_INITIAL_DATA_LOADED_ACKare added.Quoted 8 lines
The
initial_data_advise()handler is called during migration setup both in the source and the destination to advise the migration user that precopy initial data is used, and its return value indicates whether precopy initial data is supported by it.When precopy initial data of all the migration users is loaded in the destination, the
MIG_RP_MSG_INITIAL_DATA_LOADED_ACKreturn path message is sent to the source to notify it.This looks much better and easier to digest, thanks a lot.
It does answer one of my question that I wanted to ask on whether both sides would know which device will need this feature enabled. It seems both sides are actually in consensus with it, which is great on reducing the changeset. Then it's less controversial on whether we'll need a more generic handshake because we simply don't need the per-dev handshake for now.
Quoted 8 lines
The name is probably prone to change indeed. Firstly, it's not really always on precopy but also for postcopy. If vfio will supports postcopy in the future this feature will also be needed to make sure low downtime during switching to postcopy. I saw that you even changed postcopy for this [1] which is definitely good. So "precopy" in the cap is not proper anymore.
How about "switchover-ack"?
Sounds good to me.
It's shorter than "explicit switchover" and maybe more understandable even without context. Plus, the "switchover" terminology is already used in migration, so we're not adding a new term here.
Quoted 12 lines
Then..Quoted 10 lines
Signed-off-by Avihai Horon <[email protected]>--- include/migration/register.h | 6 ++++ migration/migration.h | 14 ++++++++ migration/savevm.h | 2 ++ migration/migration.c | 40 ++++++++++++++++++++-- migration/savevm.c | 65 ++++++++++++++++++++++++++++++++++++ migration/trace-events | 4 +++ 6 files changed, 129 insertions(+), 2 deletions(-)
Quoted 16 lines
Quoted 5 lines
include/migration/register.h +0
-0include/migration/register.h typedef struct SaveVMHandlers { · line 79
Quoted 9 lines
include/migration/register.h +6
-0@@ -71,6 +71,12 @@ typedef struct SaveVMHandlers {int (*load_cleanup)(void *opaque);/* Called when postcopy migration wants to resume from failure */ int (*resume_prepare)(MigrationState *s,void *opaque); + +/* +* Advises that precopy initial data was requested. Returns true if it's +* supported or false otherwise. Called both in src and dest. +*/ +bool (*initial_data_advise)(void *opaque);.. this can be "
switchover_ack_needed()". Ditto below on most of the name of variables.
Sure, will change.
Quoted 95 lines
Quoted 95 lines
include/migration/register.h +0
-0} SaveVMHandlers; int register_savevm_live(const char *idstr,migration/migration.h +14
-0@@ -202,6 +202,13 @@ struct MigrationIncomingState {* contains valid information. */ QemuMutex page_request_mutex; + +/* +* Number of migration users that are waiting for their initial data to be +* loaded. When this reaches zero an ACK is sent to source. No lock is +* needed as this field is updated serially. +*/ +unsigned int initial_data_pending_num; };MigrationIncomingState *migration_incoming_get_current (void );@@ -430,6 +437,12 @@ struct MigrationState {/* QEMU_VM_VMDESCRIPTION content filled for all non-iterable devices. */ JSONWriter *vmdesc; + +/* +* Indicates whether an ACK that precopy initial data was loaded in +* destination has been received. +*/ +bool initial_data_loaded_acked; };void migrate_set_state (int *state,int old_state,int new_state);@@ -470,6 +483,7 @@ int migrate_send_rp_message_req_pages(MigrationIncomingState *mis,void migrate_send_rp_recv_bitmap (MigrationIncomingState *mis,char *block_name);void migrate_send_rp_resume_ack (MigrationIncomingState *mis,uint32_t value); +int migrate_send_rp_initial_data_loaded_ack (MigrationIncomingState *mis);void dirty_bitmap_mig_before_vm_start (void );void dirty_bitmap_mig_cancel_outgoing (void );migration/savevm.h +2
-0@@ -32,6 +32,7 @@bool qemu_savevm_state_blocked (Error **errp);void qemu_savevm_non_migratable_list (strList **reasons);void qemu_savevm_state_setup (QEMUFile *f); +void qemu_savevm_state_initial_data_advise (MigrationState *ms);bool qemu_savevm_state_guest_unplug_pending (void );int qemu_savevm_state_resume_prepare (MigrationState *s);void qemu_savevm_state_header (QEMUFile *f);@@ -65,6 +66,7 @@ int qemu_loadvm_state(QEMUFile *f);void qemu_loadvm_state_cleanup (void );int qemu_loadvm_state_main (QEMUFile *f,MigrationIncomingState *mis);int qemu_load_device_state (QEMUFile *f); +int qemu_loadvm_notify_initial_data_loaded (void );int qemu_savevm_state_complete_precopy_non_iterable (QEMUFile *f,bool in_postcopy,bool inactivate_disks);migration/migration.c +8
-0@@ -78,6 +78,7 @@ enum mig_rp_message_type {MIG_RP_MSG_REQ_PAGES ,/* data (start: be64, len: be32) */ MIG_RP_MSG_RECV_BITMAP ,/* send recved_bitmap back to source */ MIG_RP_MSG_RESUME_ACK ,/* tell source that we are ready to resume */ +MIG_RP_MSG_INITIAL_DATA_LOADED_ACK ,/* Tell source initial data is loaded */ MIG_RP_MSG_MAX };@@ -780,6 +781,12 @@ bool migration_has_all_channels(void)return true; } +int migrate_send_rp_initial_data_loaded_ack (MigrationIncomingState *mis) +{ +return migrate_send_rp_message (mis,MIG_RP_MSG_INITIAL_DATA_LOADED_ACK ,0 , +NULL ); +} +/* * Send a 'SHUT' message on the return channel with the given value * to indicate that we've finished with the RP. Non-0 value indicates @@ -1425,6 +1432,7 @@ void migrate_init(MigrationState *s) s->vm_was_running = false; s->iteration_initial_bytes =0 ; s->threshold_size =0 ; + s->initial_data_loaded_acked = false; }
Quoted 10 lines
migration/migration.c static struct rp_cmd_args { · line 1754
Quoted 8 lines
migration/migration.c +3
-0int migrate_add_blocker_internal (Error *reason,Error **errp)@@ -1741,6 +1749,9 @@ static struct rp_cmd_args { [MIG_RP_MSG_REQ_PAGES_ID] = { .len = -1, .name = "REQ_PAGES_ID" }, [MIG_RP_MSG_RECV_BITMAP] = { .len = -1, .name = "RECV_BITMAP" }, [MIG_RP_MSG_RESUME_ACK] = { .len = 4, .name = "RESUME_ACK" }, + [MIG_RP_MSG_INITIAL_DATA_LOADED_ACK] = { .len = 0, + .name = + "INITIAL_DATA_LOADED_ACK" },Nit: let's just put it in a single line. If it'll be
SWITCHOVER_ACKit's even shorter. :)
Sure.
Quoted 33 lines
Quoted 20 lines
migration/migration.c +5
-0[MIG_RP_MSG_MAX] = { .len = -1, .name = "MAX" }, };@@ -1979,6 +1990,11 @@ retry: }break ; +case MIG_RP_MSG_INITIAL_DATA_LOADED_ACK : + ms->initial_data_loaded_acked = true; +trace_source_return_path_thread_initial_data_loaded_ack (); +break ; +default :break ; }@@ -2727,6 +2743,20 @@ static void migration_update_counters(MigrationState *s, bandwidth, s->threshold_size); }migration/migration.c static void migration_update_counters(MigrationState *s, · line 2755
Quoted 10 lines
migration/migration.c +10
-0+static bool initial_data_loaded_acked (MigrationState *s) +{ +if (!migrate_precopy_initial_data ()) { +return true; + } + +/* No reason to wait for precopy initial data loaded ACK if VM is stopped */ +if (!runstate_is_running ()) { +return true; + }This check may or may not be a problem, as it can become running right away after the check.
Quoted 3 lines
But I think I get your point here and I think it's fine; it at least means the vm stopped for even a while and the user doesn't strictly care super lot about downtime.
Yes, exactly.
Quoted 81 lines
Quoted 27 lines
migration/migration.c +7
-1+ +return s->initial_data_loaded_acked; +} +/* Migration thread iteration status */ typedef enum { MIG_ITERATE_RESUME, /* Resume current iteration */@@ -2742,6 +2772,7 @@ static MigIterateState migration_iteration_run(MigrationState *s) {uint64_t must_precopy, can_postcopy;bool in_postcopy = s->state ==MIGRATION_STATUS_POSTCOPY_ACTIVE ; +bool initial_data_loaded =initial_data_loaded_acked (s);qemu_savevm_state_pending_estimate (&must_precopy, &can_postcopy);uint64_t pending_size = must_precopy + can_postcopy;@@ -2754,7 +2785,8 @@ static MigIterateState migration_iteration_run(MigrationState *s)trace_migrate_pending_exact (pending_size, must_precopy, can_postcopy); } -if (!pending_size || pending_size < s->threshold_size) { +if ((!pending_size || pending_size < s->threshold_size) && + initial_data_loaded) {trace_migration_thread_low_pending (pending_size);migration_completion (s);return MIG_ITERATE_BREAK ;migration/migration.c static MigIterateState migration_iteration_run(MigrationState *s) · line 2797
Quoted 5 lines
migration/migration.c +1
-1@@ -2762,7 +2794,7 @@ static MigIterateState migration_iteration_run(MigrationState *s)/* Still a significant amount to transfer */ if (!in_postcopy && must_precopy <= s->threshold_size && -qatomic_read (&s->start_postcopy)) { + initial_data_loaded &&qatomic_read (&s->start_postcopy)) {[1]
Quoted 34 lines
migration/migration.c +4
-0if (postcopy_start (s)) {error_report ("%s: postcopy failed to start" , __func__); }@@ -2986,6 +3018,10 @@ static void *migration_thread(void *opaque)qemu_savevm_state_setup (s->to_dst_file); +if (migrate_precopy_initial_data ()) { +qemu_savevm_state_initial_data_advise (s); + } +qemu_savevm_wait_unplug (s,MIGRATION_STATUS_SETUP ,MIGRATION_STATUS_ACTIVE );migration/savevm.c +12
-0@@ -1233,6 +1233,32 @@ bool qemu_savevm_state_guest_unplug_pending(void)return false; } +void qemu_savevm_state_initial_data_advise (MigrationState *ms) +{ +SaveStateEntry *se; +unsigned int supported_num =0 ; + + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { +if (!se->ops || !se->ops->initial_data_advise) { +continue ; + } + +if (se->ops->initial_data_advise (se->opaque)) { + supported_num++;migration/savevm.c bool qemu_savevm_state_guest_unplug_pending(void) · line 1257
Quoted 10 lines
migration/savevm.c +10
-0+ } + } + +if (!supported_num) { +/* +* There are no migration users that support precopy initial data. Set +* initial data loaded acked to true so migration can be completed. +*/ + ms->initial_data_loaded_acked = true; + }This is fine but slightly hackish (e.g. someone would assume we received a msg when this var being true, but in this case we just don't need one).
Quoted 2 lines
How about remember this "
supported_nums" on src too and just check that ininitial_data_loaded_acked()above?
I see what you mean.
Yes, I will change it.
Quoted 4 lines
PS: we should someday have a common object for both src/dst migration which will be suitable for variables like this, so all common vars in MigrationState and MigrationIncomingState will go there. Another story.
Oh, cool!
Thanks!
Quoted 112 lines
Quoted 105 lines
migration/savevm.c +43
-0+ +trace_savevm_state_initial_data_advise (supported_num); +} +void qemu_savevm_state_setup (QEMUFile *f) {MigrationState *ms =migrate_get_current ();@@ -2586,6 +2612,23 @@ static int qemu_loadvm_state_header(QEMUFile *f)return 0 ; } +static void qemu_loadvm_state_initial_data_advise (MigrationIncomingState *mis) +{ +SaveStateEntry *se; + + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { +if (!se->ops || !se->ops->initial_data_advise) { +continue ; + } + +if (se->ops->initial_data_advise (se->opaque)) { + mis->initial_data_pending_num++; + } + } + +trace_loadvm_state_initial_data_advise (mis->initial_data_pending_num); +} +static int qemu_loadvm_state_setup (QEMUFile *f) {SaveStateEntry *se;@@ -2789,6 +2832,10 @@ int qemu_loadvm_state(QEMUFile *f)return -EINVAL ; } +if (migrate_precopy_initial_data ()) { +qemu_loadvm_state_initial_data_advise (mis); + } +cpu_synchronize_all_pre_loadvm (); ret =qemu_loadvm_state_main (f, mis);@@ -2862,6 +2909,24 @@ int qemu_load_device_state(QEMUFile *f)return 0 ; } +int qemu_loadvm_notify_initial_data_loaded (void ) +{ +MigrationIncomingState *mis =migration_incoming_get_current (); + +if (!mis->initial_data_pending_num) { +return -EINVAL ; + } + + mis->initial_data_pending_num--; +trace_loadvm_notify_initial_data_loaded (mis->initial_data_pending_num); + +if (mis->initial_data_pending_num) { +return 0 ; + } + +return migrate_send_rp_initial_data_loaded_ack (mis); +} +bool save_snapshot (const char *name,bool overwrite,const char *vmstate,bool has_devices,strList *devices,Error **errp) {migration/trace-events +4
-1@@ -7,6 +7,7 @@ qemu_loadvm_state_section_partend(uint32_t section_id) "%u" qemu_loadvm_state_post_main(int ret) "%d" qemu_loadvm_state_section_startfull(uint32_t section_id, const char *idstr, uint32_t instance_id, uint32_t version_id) "%u(%s) %u %u" qemu_savevm_send_packaged(void) "" +loadvm_state_initial_data_advise(unsigned int initial_data_pending_num) "Initial data pending num=%u" loadvm_state_setup(void) "" loadvm_state_cleanup(void) "" loadvm_handle_cmd_packaged(unsigned int length) "%u"@@ -23,6 +24,7 @@ loadvm_postcopy_ram_handle_discard_end(void) "" loadvm_postcopy_ram_handle_discard_header(const char *ramid, uint16_t len) "%s: %ud" loadvm_process_command(const char *s, uint16_t len) "com=%s len=%d" loadvm_process_command_ping(uint32_t val) "0x%x" +loadvm_notify_initial_data_loaded(unsigned int initial_data_pending_num) "Initial data pending num=%u" postcopy_ram_listen_thread_exit(void) "" postcopy_ram_listen_thread_start(void) "" qemu_savevm_send_postcopy_advise(void) ""@@ -39,6 +41,7 @@ savevm_send_postcopy_resume(void) "" savevm_send_colo_enable(void) "" savevm_send_recv_bitmap(char *name) "%s" savevm_state_setup(void) "" +savevm_state_initial_data_advise(unsigned int initial_data_supported_num) "Initial data supported num=%u" savevm_state_resume_prepare(void) "" savevm_state_header(void) "" savevm_state_iterate(void) ""@@ -180,6 +183,7 @@ source_return_path_thread_loop_top(void) "" source_return_path_thread_pong(uint32_t val) "0x%x" source_return_path_thread_shut(uint32_t val) "0x%x" source_return_path_thread_resume_ack(uint32_t v) "%"PRIu32 +source_return_path_thread_initial_data_loaded_ack(void) "" migration_thread_low_pending(uint64_t pending) "%" PRIu64 migrate_transferred(uint64_t tranferred, uint64_t time_spent, uint64_t bandwidth, uint64_t size) "transferred %" PRIu64 " time_spent %" PRIu64 " bandwidth %" PRIu64 " max_size %" PRId64 process_incoming_migration_co_end(int ret, int ps) "ret=%d postcopy-state=%d" --Quoted 2 lines
2.26.3
Thanks,
--
Peter Xu
PATCH v2 3/7 migration: Enable precopy initial data capability
In reply to Avihai HoronNow that precopy initial data logic has been implemented, enable the capability.
--- migration/options.c | 4 ---- 1 file changed, 4 deletions(-)
migration/options.c +0 -4
@@ -561,10 +561,6 @@ bool migrate_caps_check(bool *old_caps, bool *new_caps, Error **errp) "capability 'return-path'");return false; } - -/* Disable this capability until it's implemented */ -error_setg (errp,"'precopy-initial-data' is not implemented yet" ); -return false; }return true;
Signature · 1 line
2.26.3
Re: [PATCH v2 3/7] migration: Enable precopy initial data capability
Quoted 14 lines · Avihai Horon
Now that precopy initial data logic has been implemented, enable the capability.
Signed-off-by Avihai Horon <[email protected]>Reviewed-by Juan Quintela <[email protected]>--- migration/options.c | 4 ---- 1 file changed, 4 deletions(-)migration/options.c +0
-0
migration/options.c bool migrate_caps_check(bool *old_caps, bool *new_caps, Error **errp) · line 564
Quoted 8 lines
migration/options.c +0
-4@@ -561,10 +561,6 @@ bool migrate_caps_check(bool *old_caps, bool *new_caps, Error **errp) "capability 'return-path'");return false; } - -/* Disable this capability until it's implemented */ -error_setg (errp,"'precopy-initial-data' is not implemented yet" ); -return false; }
I'm always confused why we need this and not having this squashed into patch 1 (or say, never have these lines).
The only thing it matters is when someone backports patch 1 but not backport the rest of the patches. But that's really, really weird already as a backporter doing that, and I doubt its happening.
Neither should we merge patch 1 without merging follow up patches to master, as we should just always merge the whole feature or just keep reworking on the list.
I'd like to know if I missed something else..
PS: sorry to be late on replying to your email for previous version due to travelling last week, I'll reply to your series instead. Actually I was just writting up the reply to your previous version when receiving this one. :)
Thanks,
Signature · 1 line
Peter Xu
Re: [PATCH v2 3/7] migration: Enable precopy initial data capability
Quoted 33 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 14 lines · Avihai Horon
Now that precopy initial data logic has been implemented, enable the capability.
Signed-off-by Avihai Horon <[email protected]>Reviewed-by Juan Quintela <[email protected]>--- migration/options.c | 4 ---- 1 file changed, 4 deletions(-)migration/options.c +0
-0migration/options.c bool migrate_caps_check(bool *old_caps, bool *new_caps, Error **errp) · line 564
Quoted 8 lines
migration/options.c +0
-4@@ -561,10 +561,6 @@ bool migrate_caps_check(bool *old_caps, bool *new_caps, Error **errp) "capability 'return-path'");return false; } - -/* Disable this capability until it's implemented */ -error_setg (errp,"'precopy-initial-data' is not implemented yet" ); -return false; }I'm always confused why we need this and not having this squashed into patch 1 (or say, never have these lines).
The only thing it matters is when someone backports patch 1 but not backport the rest of the patches. But that's really, really weird already as a backporter doing that, and I doubt its happening.
Quoted 5 lines
Neither should we merge patch 1 without merging follow up patches to master, as we should just always merge the whole feature or just keep reworking on the list.
I'd like to know if I missed something else..
There are also git bisect considerations.
This practice is useful for git bisect for features that are enabled by default, so you won't mistakenly run "half a feature" if you do bisect. But here the capability must be manually enabled, so maybe it's not that useful in this case.
I like it for the sake of good order, so this capability can't be enabled before it's fully implemented (even if it's unlikely that someone would do that).
Quoted 5 lines
PS: sorry to be late on replying to your email for previous version due to travelling last week, I'll reply to your series instead. Actually I was just writting up the reply to your previous version when receiving this one. :)
No worries, thanks :)
Peter Xu
Reviewed-byRe: [PATCH v2 3/7] migration: Enable precopy initial data capability
Quoted 47 lines · Avihai Horon
Quoted 33 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 14 lines · Avihai Horon
Now that precopy initial data logic has been implemented, enable the capability.
Signed-off-by Avihai Horon <[email protected]>Reviewed-by Juan Quintela <[email protected]>--- migration/options.c | 4 ---- 1 file changed, 4 deletions(-)migration/options.c +0
-0migration/options.c bool migrate_caps_check(bool *old_caps, bool *new_caps, Error **errp) · line 564
Quoted 8 lines
migration/options.c +0
-4@@ -561,10 +561,6 @@ bool migrate_caps_check(bool *old_caps, bool *new_caps, Error **errp) "capability 'return-path'");return false; } - -/* Disable this capability until it's implemented */ -error_setg (errp,"'precopy-initial-data' is not implemented yet" ); -return false; }I'm always confused why we need this and not having this squashed into patch 1 (or say, never have these lines).
The only thing it matters is when someone backports patch 1 but not backport the rest of the patches. But that's really, really weird already as a backporter doing that, and I doubt its happening.
Quoted 5 lines
Neither should we merge patch 1 without merging follow up patches to master, as we should just always merge the whole feature or just keep reworking on the list.
I'd like to know if I missed something else..
There are also git bisect considerations.
This practice is useful for git bisect for features that are enabled by default, so you won't mistakenly run "half a feature" if you do bisect. But here the capability must be manually enabled, so maybe it's not that useful in this case.
Quoted 3 lines
I like it for the sake of good order, so this capability can't be enabled before it's fully implemented (even if it's unlikely that someone would do that).
Right. I was kind of thinking someone bisecting such feature will always make sure to start from the last commit got merged, but I see your point as a general concept.
One slightly better way to not add something and remove again is, we can introduce migrate_precopy_initial_data() in patch 2, returning constantly false, then we can put patch 1 (qapi interface) to be after current patch 2, where you allow migrate_precopy_initial_data() to start return true. It saves a few lines to remove, and also one specific patch explicitly removing it. But I think fundamentally it's similar indeed.
In case you'd like to keep this as is, feel free to add:
Thanks,
Signature · 1 line
Peter Xu
Re: [PATCH v2 3/7] migration: Enable precopy initial data capability
Quoted 63 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 45 lines · Avihai Horon
Quoted 33 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 14 lines · Avihai Horon
Now that precopy initial data logic has been implemented, enable the capability.
Signed-off-by Avihai Horon <[email protected]>Reviewed-by Juan Quintela <[email protected]>--- migration/options.c | 4 ---- 1 file changed, 4 deletions(-)migration/options.c +0
-0migration/options.c bool migrate_caps_check(bool *old_caps, bool *new_caps, Error **errp) · line 564
Quoted 8 lines
migration/options.c +0
-4@@ -561,10 +561,6 @@ bool migrate_caps_check(bool *old_caps, bool *new_caps, Error **errp) "capability 'return-path'");return false; } - -/* Disable this capability until it's implemented */ -error_setg (errp,"'precopy-initial-data' is not implemented yet" ); -return false; }I'm always confused why we need this and not having this squashed into patch 1 (or say, never have these lines).
The only thing it matters is when someone backports patch 1 but not backport the rest of the patches. But that's really, really weird already as a backporter doing that, and I doubt its happening.
Quoted 5 lines
Neither should we merge patch 1 without merging follow up patches to master, as we should just always merge the whole feature or just keep reworking on the list.
I'd like to know if I missed something else..
There are also git bisect considerations.
This practice is useful for git bisect for features that are enabled by default, so you won't mistakenly run "half a feature" if you do bisect. But here the capability must be manually enabled, so maybe it's not that useful in this case.Quoted 3 lines
I like it for the sake of good order, so this capability can't be enabled before it's fully implemented (even if it's unlikely that someone would do that).
Right. I was kind of thinking someone bisecting such feature will always make sure to start from the last commit got merged, but I see your point as a general concept.
One slightly better way to not add something and remove again is, we can introduce
migrate_precopy_initial_data()in patch 2, returning constantly false, then we can put patch 1 (qapi interface) to be after current patch 2, where you allowmigrate_precopy_initial_data()to start return true. It saves a few lines to remove, and also one specific patch explicitly removing it. But I think fundamentally it's similar indeed.
Quoted 3 lines
In case you'd like to keep this as is, feel free to add:
Reviewed-by Peter Xu <[email protected]>
I think I will keep it as is, it seems more natural to me. However, if someone insists then I don't mind changing it.
Thanks!
PATCH v2 4/7 tests: Add migration precopy initial data capability test
In reply to Avihai HoronAdd migration precopy initial data capability test. The test runs without migration users that support this capability, but is still useful to make sure it didn't break anything.
--- tests/qtest/migration-test.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
tests/qtest/migration-test.c +26 -0
@@ -1648,6 +1648,28 @@ static void test_precopy_tcp_plain(void)test_precopy_common (&args); } +static void *test_migrate_initial_data_start (QTestState *from,QTestState *to) +{ + +migrate_set_capability (from,"return-path" , true); +migrate_set_capability (to,"return-path" , true); + +migrate_set_capability (from,"precopy-initial-data" , true); +migrate_set_capability (to,"precopy-initial-data" , true); + +return NULL ; +} + +static void test_precopy_tcp_initial_data (void ) +{ +MigrateCommon args = { + .listen_uri ="tcp:127.0.0.1:0" , + .start_hook = test_migrate_initial_data_start, + }; + +test_precopy_common (&args); +} +#ifdef CONFIG_GNUTLS static void test_precopy_tcp_tls_psk_match (void ) {
@@ -2695,6 +2717,10 @@ int main(int argc, char **argv)#endif /* CONFIG_GNUTLS */ qtest_add_func ("/migration/precopy/tcp/plain" , test_precopy_tcp_plain); + +qtest_add_func ("/migration/precopy/tcp/plain/precopy-initial-data" , + test_precopy_tcp_initial_data); +#ifdef CONFIG_GNUTLS qtest_add_func ("/migration/precopy/tcp/tls/psk/match" , test_precopy_tcp_tls_psk_match);
Signature · 1 line
2.26.3
Re: [PATCH v2 4/7] tests: Add migration precopy initial data capability test
Quoted 6 lines · Avihai Horon
Add migration precopy initial data capability test. The test runs without migration users that support this capability, but is still useful to make sure it didn't break anything.
Signed-off-by Avihai Horon <[email protected]>Reviewed-by Juan Quintela <[email protected]>
It's a pity that there seems to have no easy way to test the RP msg and notifications into the qtest.. Besides the cap name it looks all fine:
Signature · 1 line
Peter Xu
PATCH v2 5/7 vfio/migration: Refactor vfio_save_block() to return saved data size
In reply to Avihai HoronRefactor vfio_save_block() to return the size of saved data on success and -errno on error.
This will be used in next patch to implement VFIO migration pre-copy support.
--- hw/vfio/migration.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
hw/vfio/migration.c +9 -8
@@ -241,8 +241,8 @@ static int vfio_query_stop_copy_size(VFIODevice *vbasedev,return 0 ; } -/* Returns 1 if end-of-stream is reached, 0 if more data and -errno if error */ -static int vfio_save_block (QEMUFile *f,VFIOMigration *migration) +/* Returns the size of saved data on success and -errno on error */ +static ssize_t vfio_save_block (QEMUFile *f,VFIOMigration *migration) {ssize_t data_size;
@@ -252,7 +252,7 @@ static int vfio_save_block(QEMUFile *f, VFIOMigration *migration)return -errno; }if (data_size ==0 ) { -return 1 ; +return 0 ; }qemu_put_be64 (f,VFIO_MIG_FLAG_DEV_DATA_STATE );
@@ -262,7 +262,7 @@ static int vfio_save_block(QEMUFile *f, VFIOMigration *migration)trace_vfio_save_block (migration->vbasedev->name, data_size); -return qemu_file_get_error (f); +return qemu_file_get_error (f) ?: data_size; }/* ---------------------------------------------------------------------- */
@@ -335,6 +335,7 @@ static void vfio_state_pending_exact(void *opaque, uint64_t *must_precopy,static int vfio_save_complete_precopy (QEMUFile *f,void *opaque) {VFIODevice *vbasedev = opaque; +ssize_t data_size;int ret;/* We reach here with device state STOP only */
@@ -345,11 +346,11 @@ static int vfio_save_complete_precopy(QEMUFile *f, void *opaque) }do { - ret =vfio_save_block (f, vbasedev->migration); -if (ret <0 ) { -return ret; + data_size =vfio_save_block (f, vbasedev->migration); +if (data_size <0 ) { +return data_size; } - }while (!ret); + }while (data_size);qemu_put_be64 (f,VFIO_MIG_FLAG_END_OF_STATE ); ret =qemu_file_get_error (f);
Signature · 1 line
2.26.3
PATCH v2 6/7 vfio/migration: Add VFIO migration pre-copy support
In reply to Avihai HoronPre-copy support allows the VFIO device data to be transferred while the VM is running. This helps to accommodate VFIO devices that have a large amount of data that needs to be transferred, and it can reduce migration downtime.
Pre-copy support is optional in VFIO migration protocol v2. Implement pre-copy of VFIO migration protocol v2 and use it for devices that support it. Full description of it can be found here [1].
In addition, add a new VFIO device property x-allow-pre-copy to keep migration compatibility to/from older QEMU versions that don't have VFIO pre-copy support.
[1]
https://lore.kernel.org/kvm/[email protected]/
--- docs/devel/vfio-migration.rst | 35 +++++--- include/hw/vfio/vfio-common.h | 4 + hw/core/machine.c | 1 + hw/vfio/common.c | 6 +- hw/vfio/migration.c | 163 ++++++++++++++++++++++++++++++++-- hw/vfio/pci.c | 2 + hw/vfio/trace-events | 4 +- 7 files changed, 193 insertions(+), 22 deletions(-)
docs/devel/vfio-migration.rst +25 -10
@@ -7,12 +7,14 @@ the guest is running on source host and restoring this saved state on the destination host. This document details how saving and restoring of VFIO devices is done in QEMU. -Migration of VFIO devices currently consists of a single stop-and-copy phase. -During the stop-and-copy phase the guest is stopped and the entire VFIO device -data is transferred to the destination. - -The pre-copy phase of migration is currently not supported for VFIO devices. -Support for VFIO pre-copy will be added later on. +Migration of VFIO devices consists of two phases: the optional pre-copy phase, +and the stop-and-copy phase. The pre-copy phase is iterative and allows to +accommodate VFIO devices that have a large amount of data that needs to be +transferred. The iterative pre-copy phase of migration allows for the guest to +continue whilst the VFIO device state is transferred to the destination, this +helps to reduce the total downtime of the VM. VFIO devices opt-in to pre-copy +support by reporting the VFIO_MIGRATION_PRE_COPY flag in the +VFIO_DEVICE_FEATURE_MIGRATION ioctl. Note that currently VFIO migration is supported only for a single device. This is due to VFIO migration's lack of P2P support. However, P2P support is planned
@@ -29,10 +31,20 @@ VFIO implements the device hooks for the iterative approach as follows: * A ``load_setup`` function that sets the VFIO device on the destination in _RESUMING state. +* A ``state_pending_estimate`` function that reports an estimate of the + remaining pre-copy data that the vendor driver has yet to save for the VFIO + device. + * A ``state_pending_exact`` function that reads pending_bytes from the vendor driver, which indicates the amount of data that the vendor driver has yet to save for the VFIO device. +* An ``is_active_iterate`` function that indicates ``save_live_iterate`` is + active only when the VFIO device is in pre-copy states. + +* A ``save_live_iterate`` function that reads the VFIO device's data from the + vendor driver during iterative pre-copy phase. + * A ``save_state`` function to save the device config space if it is present. * A ``save_live_complete_precopy`` function that sets the VFIO device in
@@ -111,8 +123,10 @@ Flow of state changes during Live migration =========================================== Below is the flow of state change during live migration. -The values in the brackets represent the VM state, the migration state, and +The values in the parentheses represent the VM state, the migration state, and the VFIO device state, respectively. +The text in the square brackets represents the flow if the VFIO device supports +pre-copy. Live migration save path ------------------------
@@ -124,11 +138,12 @@ Live migration save path | migrate_init spawns migration_thread Migration thread then calls each device's .save_setup() - (RUNNING, _SETUP, _RUNNING) + (RUNNING, _SETUP, _RUNNING [_PRE_COPY]) | - (RUNNING, _ACTIVE, _RUNNING) - If device is active, get pending_bytes by .state_pending_exact() + (RUNNING, _ACTIVE, _RUNNING [_PRE_COPY]) + If device is active, get pending_bytes by .state_pending_{estimate,exact}() If total pending_bytes >= threshold_size, call .save_live_iterate() + [Data of VFIO device for pre-copy phase is copied] Iterate till total pending bytes converge and are less than threshold | On migration completion, vCPU stops and calls .save_live_complete_precopy for
include/hw/vfio/vfio-common.h +4 -0
@@ -66,6 +66,9 @@ typedef struct VFIOMigration {int data_fd;void *data_buffer;size_t data_buffer_size; +uint64_t precopy_init_size; +uint64_t precopy_dirty_size; +uint64_t mig_flags; } VFIOMigration; typedef struct VFIOAddressSpace {
@@ -143,6 +146,7 @@ typedef struct VFIODevice {VFIOMigration *migration;Error *migration_blocker;OnOffAuto pre_copy_dirty_page_tracking; +bool allow_pre_copy;bool dirty_pages_supported;bool dirty_tracking; } VFIODevice;
hw/core/machine.c +1 -0
@@ -41,6 +41,7 @@GlobalProperty hw_compat_8_0[] = { {"migration" ,"multifd-flush-after-each-section" ,"on" }, + {"vfio-pci" ,"x-allow-pre-copy" ,"false" }, };const size_t hw_compat_8_0_len =G_N_ELEMENTS (hw_compat_8_0);
hw/vfio/common.c +4 -2
@@ -492,7 +492,8 @@ static bool vfio_devices_all_dirty_tracking(VFIOContainer *container) }if (vbasedev->pre_copy_dirty_page_tracking ==ON_OFF_AUTO_OFF && - migration->device_state ==VFIO_DEVICE_STATE_RUNNING ) { + (migration->device_state ==VFIO_DEVICE_STATE_RUNNING || + migration->device_state ==VFIO_DEVICE_STATE_PRE_COPY )) {return false; } }
@@ -537,7 +538,8 @@ static bool vfio_devices_all_running_and_mig_active(VFIOContainer *container)return false; } -if (migration->device_state ==VFIO_DEVICE_STATE_RUNNING ) { +if (migration->device_state ==VFIO_DEVICE_STATE_RUNNING || + migration->device_state ==VFIO_DEVICE_STATE_PRE_COPY ) {continue ; }else {return false;
hw/vfio/migration.c +154 -9
247 lines not on this page · raw message
hw/vfio/pci.c +2 -0
@@ -3335,6 +3335,8 @@ static Property vfio_pci_dev_properties[] = {DEFINE_PROP_ON_OFF_AUTO ("x-pre-copy-dirty-page-tracking" , VFIOPCIDevice, vbasedev.pre_copy_dirty_page_tracking,ON_OFF_AUTO_ON ), +DEFINE_PROP_BOOL ("x-allow-pre-copy" , VFIOPCIDevice, + vbasedev.allow_pre_copy, true),DEFINE_PROP_ON_OFF_AUTO ("display" , VFIOPCIDevice, display,ON_OFF_AUTO_OFF ), DEFINE_PROP_UINT32("xres", VFIOPCIDevice, display_xres, 0),
hw/vfio/trace-events +3 -1
@@ -162,6 +162,8 @@ vfio_save_block(const char *name, int data_size) " (%s) data_size %d" vfio_save_cleanup(const char *name) " (%s)" vfio_save_complete_precopy(const char *name, int ret) " (%s) ret %d" vfio_save_device_config_state(const char *name) " (%s)" +vfio_save_iterate(const char *name) " (%s)" vfio_save_setup(const char *name, uint64_t data_buffer_size) " (%s) data buffer size 0x%"PRIx64 -vfio_state_pending_exact(const char *name, uint64_t precopy, uint64_t postcopy, uint64_t stopcopy_size) " (%s) precopy 0x%"PRIx64" postcopy 0x%"PRIx64" stopcopy size 0x%"PRIx64 +vfio_state_pending_estimate(const char *name, uint64_t precopy, uint64_t postcopy, uint64_t precopy_init_size, uint64_t precopy_dirty_size) " (%s) precopy 0x%"PRIx64" postcopy 0x%"PRIx64" precopy initial size 0x%"PRIx64" precopy dirty size 0x%"PRIx64 +vfio_state_pending_exact(const char *name, uint64_t precopy, uint64_t postcopy, uint64_t stopcopy_size, uint64_t precopy_init_size, uint64_t precopy_dirty_size) " (%s) precopy 0x%"PRIx64" postcopy 0x%"PRIx64" stopcopy size 0x%"PRIx64" precopy initial size 0x%"PRIx64" precopy dirty size 0x%"PRIx64 vfio_vmstate_change(const char *name, int running, const char *reason, const char *dev_state) " (%s) running %d reason %s device state %s"
Signature · 1 line
2.26.3
PATCH v2 7/7 vfio/migration: Add support for precopy initial data capability
In reply to Avihai HoronLoading of a VFIO device's data can take a substantial amount of time as the device may need to allocate resources, prepare internal data structures, etc. This can increase migration downtime, especially for VFIO devices with a lot of resources.
To solve this, VFIO migration uAPI defines "initial bytes" as part of its precopy data stream. Initial bytes can be used in various ways to improve VFIO migration performance. For example, it can be used to transfer device metadata to pre-allocate resources in the destination. However, for this to work we need to make sure that all initial bytes are sent and loaded in the destination before the source VM is stopped.
Use migration precopy initial data capability to make sure a VFIO device's initial bytes are sent and loaded in the destination before the source stops the VM and attempts to complete the migration. This can significantly reduce migration downtime for some devices.
As precopy support and precopy initial data support come together in VFIO migration, use x-allow-pre-copy device property to control usage of this feature as well.
--- docs/devel/vfio-migration.rst | 10 +++++++++ include/hw/vfio/vfio-common.h | 2 ++ hw/vfio/migration.c | 42 ++++++++++++++++++++++++++++++++++- 3 files changed, 53 insertions(+), 1 deletion(-)
docs/devel/vfio-migration.rst +10 -0
@@ -16,6 +16,13 @@ helps to reduce the total downtime of the VM. VFIO devices opt-in to pre-copy support by reporting the VFIO_MIGRATION_PRE_COPY flag in the VFIO_DEVICE_FEATURE_MIGRATION ioctl. +When pre-copy is supported, it's possible to further reduce downtime by +enabling "precopy-initial-data" migration capability. +VFIO migration uAPI defines "initial bytes" as part of its pre-copy data stream +and recommends that the initial bytes are sent and loaded in the destination +before stopping the source VM. Enabling this migration capability will +guarantee that and thus, can potentially reduce downtime even further. + Note that currently VFIO migration is supported only for a single device. This is due to VFIO migration's lack of P2P support. However, P2P support is planned to be added later on.
@@ -45,6 +52,9 @@ VFIO implements the device hooks for the iterative approach as follows: * A ``save_live_iterate`` function that reads the VFIO device's data from the vendor driver during iterative pre-copy phase. +* An ``initial_data_advise`` function that advises the VFIO device to use + "precopy-initial-data" migration capability if supported. + * A ``save_state`` function to save the device config space if it is present. * A ``save_live_complete_precopy`` function that sets the VFIO device in
include/hw/vfio/vfio-common.h +2 -0
@@ -69,6 +69,8 @@ typedef struct VFIOMigration {uint64_t precopy_init_size;uint64_t precopy_dirty_size;uint64_t mig_flags; +bool initial_data_active; +bool initial_data_sent; } VFIOMigration; typedef struct VFIOAddressSpace {
hw/vfio/migration.c +41 -1
87 lines not on this page · raw message
Signature · 1 line
2.26.3