Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9ae90f7

Browse files
haoxiangbdxzpeter
authored andcommittedMar 11, 2024
migration/multifd: Implement ram_save_target_page_multifd to handle multifd version of MigrationOps::ram_save_target_page.
1. Add a dedicated handler for MigrationOps::ram_save_target_page in multifd live migration. 2. Refactor ram_save_target_page_legacy so that the legacy and multifd handlers don't have internal functions calling into each other. Signed-off-by: Hao Xiang <[email protected]> Reviewed-by: Fabiano Rosas <[email protected]> Message-Id: <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Peter Xu <[email protected]>
1 parent 303e6f5 commit 9ae90f7

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed
 

‎migration/ram.c

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,7 +2079,6 @@ static bool save_compress_page(RAMState *rs, PageSearchStatus *pss,
20792079
*/
20802080
static int ram_save_target_page_legacy(RAMState *rs, PageSearchStatus *pss)
20812081
{
2082-
RAMBlock *block = pss->block;
20832082
ram_addr_t offset = ((ram_addr_t)pss->page) << TARGET_PAGE_BITS;
20842083
int res;
20852084

@@ -2095,17 +2094,33 @@ static int ram_save_target_page_legacy(RAMState *rs, PageSearchStatus *pss)
20952094
return 1;
20962095
}
20972096

2097+
return ram_save_page(rs, pss);
2098+
}
2099+
2100+
/**
2101+
* ram_save_target_page_multifd: send one target page to multifd workers
2102+
*
2103+
* Returns 1 if the page was queued, -1 otherwise.
2104+
*
2105+
* @rs: current RAM state
2106+
* @pss: data about the page we want to send
2107+
*/
2108+
static int ram_save_target_page_multifd(RAMState *rs, PageSearchStatus *pss)
2109+
{
2110+
RAMBlock *block = pss->block;
2111+
ram_addr_t offset = ((ram_addr_t)pss->page) << TARGET_PAGE_BITS;
2112+
20982113
/*
2099-
* Do not use multifd in postcopy as one whole host page should be
2100-
* placed. Meanwhile postcopy requires atomic update of pages, so even
2101-
* if host page size == guest page size the dest guest during run may
2102-
* still see partially copied pages which is data corruption.
2114+
* While using multifd live migration, we still need to handle zero
2115+
* page checking on the migration main thread.
21032116
*/
2104-
if (migrate_multifd() && !migration_in_postcopy()) {
2105-
return ram_save_multifd_page(block, offset);
2117+
if (migrate_zero_page_detection() == ZERO_PAGE_DETECTION_LEGACY) {
2118+
if (save_zero_page(rs, pss, offset)) {
2119+
return 1;
2120+
}
21062121
}
21072122

2108-
return ram_save_page(rs, pss);
2123+
return ram_save_multifd_page(block, offset);
21092124
}
21102125

21112126
/* Should be called before sending a host page */
@@ -3112,7 +3127,12 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
31123127
}
31133128

31143129
migration_ops = g_malloc0(sizeof(MigrationOps));
3115-
migration_ops->ram_save_target_page = ram_save_target_page_legacy;
3130+
3131+
if (migrate_multifd()) {
3132+
migration_ops->ram_save_target_page = ram_save_target_page_multifd;
3133+
} else {
3134+
migration_ops->ram_save_target_page = ram_save_target_page_legacy;
3135+
}
31163136

31173137
bql_unlock();
31183138
ret = multifd_send_sync_main();

0 commit comments

Comments
 (0)
Please sign in to comment.