Introduce multifd zero page checking.
Subsystems (2)
PATCH v5 1/7 migration/multifd: Allow zero pages in file migration
In reply to Hao XiangFrom: Fabiano Rosas <[email protected]>
Currently, it's an error to have no data pages in the multifd file migration because zero page detection is done in the migration thread and zero pages don't reach multifd. This is enforced with the pages->num assert.
We're about to add zero page detection on the multifd thread. Fix the file_write_ramblock_iov() to stop considering p->iovs_num=0 an error.
--- migration/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
migration/file.c +1 -1
@@ -159,7 +159,7 @@ void file_start_incoming_migration(FileMigrationArgs *file_args, Error **errp)int file_write_ramblock_iov (QIOChannel *ioc,const struct iovec *iov,int niov,RAMBlock *block,Error **errp) { -ssize_t ret =-1 ; +ssize_t ret =0 ;int i, slice_idx, slice_num;uintptr_t base, next, offset;size_t len;
Signature · 1 line
2.30.2
PATCH v5 2/7 migration/multifd: Allow clearing of the file_bmap from multifd
In reply to Hao XiangFrom: Fabiano Rosas <[email protected]>
We currently only need to clear the mapped-ram file bitmap from the migration thread during save_zero_page.
We're about to add support for zero page detection on the multifd thread, so allow ramblock_set_file_bmap_atomic() to also clear the bits.
--- migration/multifd.c | 2 +- migration/ram.c | 8 ++++++-- migration/ram.h | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-)
migration/multifd.c +1 -1
@@ -115,7 +115,7 @@ static void multifd_set_file_bitmap(MultiFDSendParams *p)assert (pages->block);for (int i =0 ; i < p->pages->num; i++) { -ramblock_set_file_bmap_atomic (pages->block, pages->offset[i]); +ramblock_set_file_bmap_atomic (pages->block, pages->offset[i], true); } }
migration/ram.c +6 -2
@@ -3150,9 +3150,13 @@ static void ram_save_file_bmap(QEMUFile *f) } } -void ramblock_set_file_bmap_atomic (RAMBlock *block,ram_addr_t offset) +void ramblock_set_file_bmap_atomic (RAMBlock *block,ram_addr_t offset,bool set) { -set_bit_atomic (offset >>TARGET_PAGE_BITS , block->file_bmap); +if (set) { +set_bit_atomic (offset >>TARGET_PAGE_BITS , block->file_bmap); + }else { +clear_bit_atomic (offset >>TARGET_PAGE_BITS , block->file_bmap); + } }/**
migration/ram.h +2 -1
@@ -75,7 +75,8 @@ bool ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *rb, Error **errp);bool ramblock_page_is_discarded (RAMBlock *rb,ram_addr_t start);void postcopy_preempt_shutdown_file (MigrationState *s);void *postcopy_preempt_thread (void *opaque); -void ramblock_set_file_bmap_atomic (RAMBlock *block,ram_addr_t offset); +void ramblock_set_file_bmap_atomic (RAMBlock *block,ram_addr_t offset, +bool set);/* ram cache */ int colo_init_ram_cache (void );
Signature · 1 line
2.30.2
PATCH v5 7/7 migration/multifd: Add new migration test cases for legacy zero page checking.
In reply to Hao XiangFrom: Hao Xiang <[email protected]>
Now that zero page checking is done on the multifd sender threads by default, we still provide an option for backward compatibility. This change adds a qtest migration test case to set the zero-page-detection option to "legacy" and run multifd migration with zero page checking on the migration main thread.
Message-Id: <[email protected]>
--- tests/qtest/migration-test.c | 52 ++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)
tests/qtest/migration-test.c +52 -0
@@ -2771,6 +2771,24 @@ test_migrate_precopy_tcp_multifd_start(QTestState *from,return test_migrate_precopy_tcp_multifd_start_common (from, to,"none" ); } +static void * +test_migrate_precopy_tcp_multifd_start_zero_page_legacy (QTestState *from, +QTestState *to) +{ +test_migrate_precopy_tcp_multifd_start_common (from, to,"none" ); +migrate_set_parameter_str (from,"zero-page-detection" ,"legacy" ); +return NULL ; +} + +static void * +test_migration_precopy_tcp_multifd_start_no_zero_page (QTestState *from, +QTestState *to) +{ +test_migrate_precopy_tcp_multifd_start_common (from, to,"none" ); +migrate_set_parameter_str (from,"zero-page-detection" ,"none" ); +return NULL ; +} +static void *test_migrate_precopy_tcp_multifd_zlib_start (QTestState *from,QTestState *to)
@@ -2812,6 +2830,36 @@ static void test_multifd_tcp_none(void)test_precopy_common (&args); } +static void test_multifd_tcp_zero_page_legacy (void ) +{ +MigrateCommon args = { + .listen_uri ="defer" , + .start_hook = test_migrate_precopy_tcp_multifd_start_zero_page_legacy, +/* +* Multifd is more complicated than most of the features, it +* directly takes guest page buffers when sending, make sure +* everything will work alright even if guest page is changing. +*/ + .live = true, + }; +test_precopy_common (&args); +} + +static void test_multifd_tcp_no_zero_page (void ) +{ +MigrateCommon args = { + .listen_uri ="defer" , + .start_hook = test_migration_precopy_tcp_multifd_start_no_zero_page, +/* +* Multifd is more complicated than most of the features, it +* directly takes guest page buffers when sending, make sure +* everything will work alright even if guest page is changing. +*/ + .live = true, + }; +test_precopy_common (&args); +} +static void test_multifd_tcp_zlib (void ) {MigrateCommon args = {
@@ -3729,6 +3777,10 @@ int main(int argc, char **argv) }migration_test_add ("/migration/multifd/tcp/plain/none" , test_multifd_tcp_none); +migration_test_add ("/migration/multifd/tcp/plain/zero-page/legacy" , + test_multifd_tcp_zero_page_legacy); +migration_test_add ("/migration/multifd/tcp/plain/zero-page/none" , + test_multifd_tcp_no_zero_page);migration_test_add ("/migration/multifd/tcp/plain/cancel" , test_multifd_tcp_cancel); migration_test_add("/migration/multifd/tcp/plain/zlib",
Signature · 1 line
2.30.2
PATCH v5 4/7 migration/multifd: Implement zero page transmission on the multifd thread.
In reply to Hao XiangFrom: Hao Xiang <[email protected]>
1. Add zero_pages field in MultiFDPacket_t.
2. Implements the zero page detection and handling on the multifd threads for non-compression, zlib and zstd compression backends.
3. Added a new value 'multifd' in ZeroPageDetection enumeration.
4. Adds zero page counters and updates multifd send/receive tracing format to track the newly added counters.
--- hw/core/qdev-properties-system.c | 2 +- migration/meson.build | 1 + migration/multifd-zero-page.c | 87 ++++++++++++++++++++++++++++++ migration/multifd-zlib.c | 21 ++++++-- migration/multifd-zstd.c | 20 +++++-- migration/multifd.c | 90 +++++++++++++++++++++++++++----- migration/multifd.h | 23 +++++++- migration/ram.c | 1 - migration/trace-events | 8 +-- qapi/migration.json | 7 ++- 10 files changed, 228 insertions(+), 32 deletions(-) create mode 100644 migration/multifd-zero-page.c
hw/core/qdev-properties-system.c +1 -1
@@ -682,7 +682,7 @@ const PropertyInfo qdev_prop_mig_mode = {const PropertyInfo qdev_prop_zero_page_detection = { .name ="ZeroPageDetection" , .description ="zero_page_detection values, " -"none,legacy" , +"none,legacy,multifd" , .enum_table = &ZeroPageDetection_lookup, .get = qdev_propinfo_get_enum, .set = qdev_propinfo_set_enum,
migration/meson.build +1 -0
@@ -22,6 +22,7 @@ system_ss.add(files( 'migration.c', 'multifd.c', 'multifd-zlib.c', + 'multifd-zero-page.c', 'ram-compress.c', 'options.c', 'postcopy-ram.c',
migration/multifd-zero-page.c new file +87 -0
87 lines not on this page · raw message
migration/multifd-zlib.c +16 -5
@@ -123,13 +123,15 @@ static int zlib_send_prepare(MultiFDSendParams *p, Error **errp)int ret;uint32_t i; -multifd_send_prepare_header (p); +if (!multifd_send_prepare_common (p)) { + goto out; + } -for (i =0 ; i < pages->num; i++) { +for (i =0 ; i < pages->normal_num; i++) {uint32_t available = z->zbuff_len - out_size;int flush =Z_NO_FLUSH ; -if (i == pages->num -1 ) { +if (i == pages->normal_num -1 ) { flush =Z_SYNC_FLUSH ; }
@@ -172,10 +174,10 @@ static int zlib_send_prepare(MultiFDSendParams *p, Error **errp) p->iov[p->iovs_num].iov_len = out_size; p->iovs_num++; p->next_packet_size = out_size; - p->flags |=MULTIFD_FLAG_ZLIB ; +out: + p->flags |=MULTIFD_FLAG_ZLIB ;multifd_send_fill_packet (p); -return 0 ; }
@@ -261,6 +263,14 @@ static int zlib_recv(MultiFDRecvParams *p, Error **errp) p->id, flags, MULTIFD_FLAG_ZLIB);return -1 ; } + +multifd_recv_zero_page_process (p); + +if (!p->normal_num) { +assert (in_size ==0 ); +return 0 ; + } + ret =qio_channel_read_all (p->c, (void *)z->zbuff, in_size, errp);if (ret !=0 ) {
@@ -310,6 +320,7 @@ static int zlib_recv(MultiFDRecvParams *p, Error **errp) p->id, out_size, expected_size);return -1 ; } +return 0 ; }
migration/multifd-zstd.c +15 -5
@@ -118,16 +118,18 @@ static int zstd_send_prepare(MultiFDSendParams *p, Error **errp)int ret;uint32_t i; -multifd_send_prepare_header (p); +if (!multifd_send_prepare_common (p)) { + goto out; + } z->out.dst = z->zbuff; z->out.size = z->zbuff_len; z->out.pos =0 ; -for (i =0 ; i < pages->num; i++) { +for (i =0 ; i < pages->normal_num; i++) {ZSTD_EndDirective flush = ZSTD_e_continue; -if (i == pages->num -1 ) { +if (i == pages->normal_num -1 ) { flush = ZSTD_e_flush; } z->in.src = p->pages->block->host + pages->offset[i];
@@ -161,10 +163,10 @@ static int zstd_send_prepare(MultiFDSendParams *p, Error **errp) p->iov[p->iovs_num].iov_len = z->out.pos; p->iovs_num++; p->next_packet_size = z->out.pos; - p->flags |=MULTIFD_FLAG_ZSTD ; +out: + p->flags |=MULTIFD_FLAG_ZSTD ;multifd_send_fill_packet (p); -return 0 ; }
@@ -257,6 +259,14 @@ static int zstd_recv(MultiFDRecvParams *p, Error **errp) p->id, flags, MULTIFD_FLAG_ZSTD);return -1 ; } + +multifd_recv_zero_page_process (p); + +if (!p->normal_num) { +assert (in_size ==0 ); +return 0 ; + } + ret =qio_channel_read_all (p->c, (void *)z->zbuff, in_size, errp);if (ret !=0 ) {
migration/multifd.c +76 -14
214 lines not on this page · raw message
migration/multifd.h +22 -1
@@ -55,14 +55,24 @@ typedef struct {/* size of the next packet that contains pages */ uint32_t next_packet_size;uint64_t packet_num; -uint64_t unused[4 ];/* Reserved for future use */ +/* zero pages */ +uint32_t zero_pages; +uint32_t unused32[1 ];/* Reserved for future use */ +uint64_t unused64[3 ];/* Reserved for future use */ char ramblock[256 ]; +/* +* This array contains the pointers to: +* - normal pages (initial normal_pages entries) +* - zero pages (following zero_pages entries) +*/ uint64_t offset[]; } __attribute__((packed)) MultiFDPacket_t; typedef struct { /* number of used pages */ uint32_t num; + /* number of normal pages */ + uint32_t normal_num; /* number of allocated pages */ uint32_t allocated; /* offset of each page */
@@ -136,6 +146,8 @@ typedef struct {uint64_t packets_sent;/* non zero pages sent through this channel */ uint64_t total_normal_pages; +/* zero pages sent through this channel */ +uint64_t total_zero_pages;/* buffers to send */ struct iovec *iov;/* number of iovs used */
@@ -194,12 +206,18 @@ typedef struct {uint8_t *host;/* non zero pages recv through this channel */ uint64_t total_normal_pages; +/* zero pages recv through this channel */ +uint64_t total_zero_pages;/* buffers to recv */ struct iovec *iov;/* Pages that are not zero */ ram_addr_t *normal;/* num of non zero pages */ uint32_t normal_num; +/* Pages that are zero */ +ram_addr_t *zero; +/* num of zero pages */ +uint32_t zero_num;/* used for de-compression methods */ void *compress_data; } MultiFDRecvParams;
@@ -221,6 +239,9 @@ typedef struct {void multifd_register_ops (int method,MultiFDMethods *ops);void multifd_send_fill_packet (MultiFDSendParams *p); +bool multifd_send_prepare_common (MultiFDSendParams *p); +void multifd_send_zero_page_detect (MultiFDSendParams *p); +void multifd_recv_zero_page_process (MultiFDRecvParams *p);static inline void multifd_send_prepare_header (MultiFDSendParams *p) {
migration/ram.c +0 -1
@@ -1288,7 +1288,6 @@ static int ram_save_multifd_page(RAMBlock *block, ram_addr_t offset)if (!multifd_queue_page (block, offset)) {return -1 ; } -stat64_add (&mig_stats.normal_pages,1 );return 1 ; }
migration/trace-events +4 -4
@@ -128,21 +128,21 @@ postcopy_preempt_reset_channel(void) "" # multifd.c multifd_new_send_channel_async(uint8_t id) "channel %u" multifd_new_send_channel_async_error(uint8_t id, void *err) "channel=%u err=%p" -multifd_recv(uint8_t id, uint64_t packet_num, uint32_t used, uint32_t flags, uint32_t next_packet_size) "channel %u packet_num %" PRIu64 " pages %u flags 0x%x next packet size %u" +multifd_recv(uint8_t id, uint64_t packet_num, uint32_t normal, uint32_t zero, uint32_t flags, uint32_t next_packet_size) "channel %u packet_num %" PRIu64 " normal pages %u zero pages %u flags 0x%x next packet size %u" multifd_recv_new_channel(uint8_t id) "channel %u" multifd_recv_sync_main(long packet_num) "packet num %ld" multifd_recv_sync_main_signal(uint8_t id) "channel %u" multifd_recv_sync_main_wait(uint8_t id) "iter %u" multifd_recv_terminate_threads(bool error) "error %d" -multifd_recv_thread_end(uint8_t id, uint64_t packets, uint64_t pages) "channel %u packets %" PRIu64 " pages %" PRIu64 +multifd_recv_thread_end(uint8_t id, uint64_t packets, uint64_t normal_pages, uint64_t zero_pages) "channel %u packets %" PRIu64 " normal pages %" PRIu64 " zero pages %" PRIu64 multifd_recv_thread_start(uint8_t id) "%u" -multifd_send(uint8_t id, uint64_t packet_num, uint32_t normal, uint32_t flags, uint32_t next_packet_size) "channel %u packet_num %" PRIu64 " normal pages %u flags 0x%x next packet size %u" +multifd_send(uint8_t id, uint64_t packet_num, uint32_t normal_pages, uint32_t zero_pages, uint32_t flags, uint32_t next_packet_size) "channel %u packet_num %" PRIu64 " normal pages %u zero pages %u flags 0x%x next packet size %u" multifd_send_error(uint8_t id) "channel %u" multifd_send_sync_main(long packet_num) "packet num %ld" multifd_send_sync_main_signal(uint8_t id) "channel %u" multifd_send_sync_main_wait(uint8_t id) "channel %u" multifd_send_terminate_threads(void) "" -multifd_send_thread_end(uint8_t id, uint64_t packets, uint64_t normal_pages) "channel %u packets %" PRIu64 " normal pages %" PRIu64 +multifd_send_thread_end(uint8_t id, uint64_t packets, uint64_t normal_pages, uint64_t zero_pages) "channel %u packets %" PRIu64 " normal pages %" PRIu64 " zero pages %" PRIu64 multifd_send_thread_start(uint8_t id) "%u" multifd_tls_outgoing_handshake_start(void *ioc, void *tioc, const char *hostname) "ioc=%p tioc=%p hostname=%s" multifd_tls_outgoing_handshake_error(void *ioc, const char *err) "ioc=%p err=%s"
qapi/migration.json +6 -1
@@ -677,10 +677,15 @@ # # @legacy: Perform zero page checking in main migration thread. # +# @multifd: Perform zero page checking in multifd sender thread if +# multifd migration is enabled, else in the main migration +# thread as for @legacy. +# # Since: 9.0 +# ## { 'enum': 'ZeroPageDetection', - 'data': [ 'none', 'legacy' ] } + 'data': [ 'none', 'legacy', 'multifd' ] } ## # @BitmapMigrationBitmapAliasTransform:
Signature · 1 line
2.30.2
PATCH v5 6/7 migration/multifd: Enable multifd zero page checking by default.
In reply to Hao XiangFrom: Hao Xiang <[email protected]>
1. Set default "zero-page-detection" option to "multifd". Now zero page checking can be done in the multifd threads and this becomes the default configuration.
2. Handle migration QEMU9.0 -> QEMU8.2 compatibility. We provide backward compatibility where zero page checking is done from the migration main thread.
--- hw/core/machine.c | 4 +++- migration/options.c | 2 +- qapi/migration.json | 6 +++--- 3 files changed, 7 insertions(+), 5 deletions(-)
hw/core/machine.c +3 -1
@@ -32,7 +32,9 @@#include "hw/virtio/virtio-net.h" #include "audio/audio.h" -GlobalProperty hw_compat_8_2[] = {}; +GlobalProperty hw_compat_8_2[] = { + {"migration" ,"zero-page-detection" ,"legacy" }, +};const size_t hw_compat_8_2_len =G_N_ELEMENTS (hw_compat_8_2);GlobalProperty hw_compat_8_1[] = {
migration/options.c +1 -1
@@ -181,7 +181,7 @@ Property migration_properties[] = { MIG_MODE_NORMAL),DEFINE_PROP_ZERO_PAGE_DETECTION ("zero-page-detection" , MigrationState, parameters.zero_page_detection, -ZERO_PAGE_DETECTION_LEGACY ), +ZERO_PAGE_DETECTION_MULTIFD ),/* Migration capabilities */ DEFINE_PROP_MIG_CAP("x-xbzrle", MIGRATION_CAPABILITY_XBZRLE),
qapi/migration.json +3 -3
@@ -909,7 +909,7 @@ # (Since 8.2) # # @zero-page-detection: Whether and how to detect zero pages. -# See description in @ZeroPageDetection. Default is 'legacy'. +# See description in @ZeroPageDetection. Default is 'multifd'. # (since 9.0) # # Features:
@@ -1106,7 +1106,7 @@ # (Since 8.2) # # @zero-page-detection: Whether and how to detect zero pages. -# See description in @ZeroPageDetection. Default is 'legacy'. +# See description in @ZeroPageDetection. Default is 'multifd'. # (since 9.0) # # Features:
@@ -1339,7 +1339,7 @@ # (Since 8.2) # # @zero-page-detection: Whether and how to detect zero pages. -# See description in @ZeroPageDetection. Default is 'legacy'. +# See description in @ZeroPageDetection. Default is 'multifd'. # (since 9.0) # # Features:
Signature · 1 line
2.30.2
PATCH v5 5/7 migration/multifd: Implement ram_save_target_page_multifd to handle multifd version of MigrationOps::ram_save_target_page.
In reply to Hao XiangFrom: Hao Xiang <[email protected]>
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.
Message-Id: <[email protected]>
--- migration/ram.c | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-)
migration/ram.c +29 -13
@@ -1140,10 +1140,6 @@ static int save_zero_page(RAMState *rs, PageSearchStatus *pss,QEMUFile *file = pss->pss_channel;int len =0 ; -if (migrate_zero_page_detection () ==ZERO_PAGE_DETECTION_NONE ) { -return 0 ; - } -if (!buffer_is_zero (p,TARGET_PAGE_SIZE )) {return 0 ; }
@@ -2079,7 +2075,6 @@ static bool save_compress_page(RAMState *rs, PageSearchStatus *pss,*/ static int ram_save_target_page_legacy (RAMState *rs,PageSearchStatus *pss) { -RAMBlock *block = pss->block;ram_addr_t offset = ((ram_addr_t )pss->page) <<TARGET_PAGE_BITS ;int res;
@@ -2095,17 +2090,33 @@ static int ram_save_target_page_legacy(RAMState *rs, PageSearchStatus *pss)return 1 ; } +return ram_save_page (rs, pss); +} + +/** +* ram_save_target_page_multifd: send one target page to multifd workers +* +* Returns 1 if the page was queued, -1 otherwise. +* +* @rs: current RAM state +* @pss: data about the page we want to send +*/ +static int ram_save_target_page_multifd (RAMState *rs,PageSearchStatus *pss) +{ +RAMBlock *block = pss->block; +ram_addr_t offset = ((ram_addr_t )pss->page) <<TARGET_PAGE_BITS ; +/* -* Do not use multifd in postcopy as one whole host page should be -* placed. Meanwhile postcopy requires atomic update of pages, so even -* if host page size == guest page size the dest guest during run may -* still see partially copied pages which is data corruption. +* While using multifd live migration, we still need to handle zero +* page checking on the migration main thread. */ -if (migrate_multifd () && !migration_in_postcopy ()) { -return ram_save_multifd_page (block, offset); +if (migrate_zero_page_detection () ==ZERO_PAGE_DETECTION_LEGACY ) { +if (save_zero_page (rs, pss, offset)) { +return 1 ; + } } -return ram_save_page (rs, pss); +return ram_save_multifd_page (block, offset); }/* Should be called before sending a host page */
@@ -3113,7 +3124,12 @@ static int ram_save_setup(QEMUFile *f, void *opaque) } migration_ops =g_malloc0 (sizeof (MigrationOps)); - migration_ops->ram_save_target_page = ram_save_target_page_legacy; + +if (migrate_multifd ()) { + migration_ops->ram_save_target_page = ram_save_target_page_multifd; + }else { + migration_ops->ram_save_target_page = ram_save_target_page_legacy; + }bql_unlock (); ret =multifd_send_sync_main ();
Signature · 1 line
2.30.2
v5 cover Introduce multifd zero page checking.
From: Hao Xiang <[email protected]>
v5 update:
* Move QEMU9.0 -> QEMU8.2 migration backward compatibility handling into the patch where "multifd" zero page checking becomes the default option.
* A few function renaming according to feedback.
* Fix bug in multifd_send_zero_page_detect.
* Rebase on the new mapped-ram feature.
* Pulled in 2 commits from Fabiano.
v4 update:
* Fix documentation for interface ZeroPageDetection.
* Fix implementation in multifd_send_zero_page_check.
* Rebase on top of c0c6a0e3528b88aaad0b9d333e295707a195587b.
v3 update:
* Change "zero" to "zero-pages" and use type size for "zero-bytes".
* Fixed ZeroPageDetection interface description.
* Move zero page unit tests to its own path.
* Removed some asserts.
* Added backward compatibility support for migration 9.0 -> 8.2.
* Removed fields "zero" and "normal" page address arrays from v2. Now multifd_zero_page_check_send sorts normal/zero pages in the "offset" array.
v2 update:
* Implement zero-page-detection switch with enumeration "legacy", "none" and "multifd".
* Move normal/zero pages from MultiFDSendParams to MultiFDPages_t.
* Add zeros and zero_bytes accounting.
This patchset is based on Juan Quintela's old series here
https://lore.kernel.org/all/[email protected]/
In the multifd live migration model, there is a single migration main thread scanning the page map, queuing the pages to multiple multifd sender threads. The migration main thread runs zero page checking on every page before queuing the page to the sender threads. Zero page checking is a CPU intensive task and hence having a single thread doing all that doesn't scale well. This change introduces a new function to run the zero page checking on the multifd sender threads. This patchset also lays the ground work for future changes to offload zero page checking task to accelerator hardwares.
Use two Intel 4th generation Xeon servers for testing.
Architecture: x86_64 CPU(s): 192 Thread(s) per core: 2 Core(s) per socket: 48 Socket(s): 2 NUMA node(s): 2 Vendor ID: GenuineIntel CPU family: 6 Model: 143 Model name: Intel(R) Xeon(R) Platinum 8457C Stepping: 8 CPU MHz: 2538.624 CPU max MHz: 3800.0000 CPU min MHz: 800.0000
Perform multifd live migration with below setup:
1. VM has 100GB memory. All pages in the VM are zero pages.
2. Use tcp socket for live migration.
3. Use 4 multifd channels and zero page checking on migration main thread.
4. Use 1/2/4 multifd channels and zero page checking on multifd sender threads.
5. Record migration total time from sender QEMU console's "info migrate" command.
+------------------------------------+ |zero-page-checking | total-time(ms) | +------------------------------------+ |main-thread | 9629 | +------------------------------------+ |multifd-1-threads | 6182 | +------------------------------------+ |multifd-2-threads | 4643 | +------------------------------------+ |multifd-4-threads | 4143 | +------------------------------------+
Apply this patchset on top of commitcbccded4a2b5d685a426a437e25f67d3a375b292
Fabiano Rosas (2):
migration/multifd: Allow zero pages in file migration migration/multifd: Allow clearing of the file_bmap from multifd
Hao Xiang (5):
migration/multifd: Add new migration option zero-page-detection. migration/multifd: Implement zero page transmission on the multifd
thread.
migration/multifd: Implement ram_save_target_page_multifd to handle
multifd version of MigrationOps::ram_save_target_page.
migration/multifd: Enable multifd zero page checking by default. migration/multifd: Add new migration test cases for legacy zero page
checking.
hw/core/machine.c | 4 +- hw/core/qdev-properties-system.c | 10 ++++ include/hw/qdev-properties-system.h | 4 ++ migration/file.c | 2 +- migration/meson.build | 1 + migration/migration-hmp-cmds.c | 9 +++ migration/multifd-zero-page.c | 87 +++++++++++++++++++++++++++ migration/multifd-zlib.c | 21 +++++-- migration/multifd-zstd.c | 20 +++++-- migration/multifd.c | 92 ++++++++++++++++++++++++----- migration/multifd.h | 23 +++++++- migration/options.c | 21 +++++++ migration/options.h | 1 + migration/ram.c | 47 +++++++++++---- migration/ram.h | 3 +- migration/trace-events | 8 +-- qapi/migration.json | 38 +++++++++++- tests/qtest/migration-test.c | 52 ++++++++++++++++ 18 files changed, 395 insertions(+), 48 deletions(-) create mode 100644 migration/multifd-zero-page.c
Signature · 1 line
2.30.2
PATCH v5 3/7 migration/multifd: Add new migration option zero-page-detection.
From: Hao Xiang <[email protected]>
This new parameter controls where the zero page checking is running.
1. If this parameter is set to 'legacy', zero page checking is done in the migration main thread.
2. If this parameter is set to 'none', zero page checking is disabled.
Message-Id: <[email protected]>
--- hw/core/qdev-properties-system.c | 10 +++++++++ include/hw/qdev-properties-system.h | 4 ++++ migration/migration-hmp-cmds.c | 9 ++++++++ migration/options.c | 21 ++++++++++++++++++ migration/options.h | 1 + migration/ram.c | 4 ++++ qapi/migration.json | 33 ++++++++++++++++++++++++++--- 7 files changed, 79 insertions(+), 3 deletions(-)
hw/core/qdev-properties-system.c +10 -0
@@ -679,6 +679,16 @@ const PropertyInfo qdev_prop_mig_mode = { .set_default_value = qdev_propinfo_set_default_value_enum, }; +const PropertyInfo qdev_prop_zero_page_detection = { + .name ="ZeroPageDetection" , + .description ="zero_page_detection values, " +"none,legacy" , + .enum_table = &ZeroPageDetection_lookup, + .get = qdev_propinfo_get_enum, + .set = qdev_propinfo_set_enum, + .set_default_value = qdev_propinfo_set_default_value_enum, +}; +/* --- Reserved Region --- */ /*
include/hw/qdev-properties-system.h +4 -0
@@ -8,6 +8,7 @@ extern const PropertyInfo qdev_prop_macaddr;extern const PropertyInfo qdev_prop_reserved_region;extern const PropertyInfo qdev_prop_multifd_compression;extern const PropertyInfo qdev_prop_mig_mode; +extern const PropertyInfo qdev_prop_zero_page_detection;extern const PropertyInfo qdev_prop_losttickpolicy;extern const PropertyInfo qdev_prop_blockdev_on_error;extern const PropertyInfo qdev_prop_bios_chs_trans;
@@ -47,6 +48,9 @@ extern const PropertyInfo qdev_prop_iothread_vq_mapping_list;#define DEFINE_PROP_MIG_MODE (_n, _s, _f, _d) \ DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_mig_mode, \ MigMode) +#define DEFINE_PROP_ZERO_PAGE_DETECTION (_n, _s, _f, _d) \ + DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_zero_page_detection, \ + ZeroPageDetection)#define DEFINE_PROP_LOSTTICKPOLICY (_n, _s, _f, _d) \ DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_losttickpolicy, \ LostTickPolicy)
migration/migration-hmp-cmds.c +9 -0
@@ -344,6 +344,11 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)monitor_printf (mon,"%s: %s\n" ,MigrationParameter_str (MIGRATION_PARAMETER_MULTIFD_COMPRESSION ),MultiFDCompression_str (params->multifd_compression)); +assert (params->has_zero_page_detection); +monitor_printf (mon,"%s: %s\n" , +MigrationParameter_str (MIGRATION_PARAMETER_ZERO_PAGE_DETECTION ), +qapi_enum_lookup (&ZeroPageDetection_lookup, + params->zero_page_detection));monitor_printf (mon,"%s: %" PRIu64" bytes\n" ,MigrationParameter_str (MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE ), params->xbzrle_cache_size);
@@ -634,6 +639,10 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict) p->has_multifd_zstd_level = true;visit_type_uint8 (v, param, &p->multifd_zstd_level, &err);break ; +case MIGRATION_PARAMETER_ZERO_PAGE_DETECTION : + p->has_zero_page_detection = true; +visit_type_ZeroPageDetection (v, param, &p->zero_page_detection, &err); +break ;case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE : p->has_xbzrle_cache_size = true;if (!visit_type_size (v, param, &cache_size, &err)) {
migration/options.c +21 -0
@@ -179,6 +179,9 @@ Property migration_properties[] = {DEFINE_PROP_MIG_MODE ("mode" , MigrationState, parameters.mode,MIG_MODE_NORMAL ), +DEFINE_PROP_ZERO_PAGE_DETECTION ("zero-page-detection" , MigrationState, + parameters.zero_page_detection, +ZERO_PAGE_DETECTION_LEGACY ),/* Migration capabilities */ DEFINE_PROP_MIG_CAP("x-xbzrle", MIGRATION_CAPABILITY_XBZRLE),
@@ -931,6 +934,13 @@ uint64_t migrate_xbzrle_cache_size(void)return s->parameters.xbzrle_cache_size; } +ZeroPageDetection migrate_zero_page_detection (void ) +{ +MigrationState *s =migrate_get_current (); + +return s->parameters.zero_page_detection; +} +/* parameter setters */ void migrate_set_block_incremental (bool value)
@@ -1041,6 +1051,8 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp) params->vcpu_dirty_limit = s->parameters.vcpu_dirty_limit; params->has_mode = true; params->mode = s->parameters.mode; + params->has_zero_page_detection = true; + params->zero_page_detection = s->parameters.zero_page_detection;return params; }
@@ -1077,6 +1089,7 @@ void migrate_params_init(MigrationParameters *params) params->has_x_vcpu_dirty_limit_period = true; params->has_vcpu_dirty_limit = true; params->has_mode = true; + params->has_zero_page_detection = true; }/*
@@ -1391,6 +1404,10 @@ static void migrate_params_test_apply(MigrateSetParameters *params,if (params->has_mode) { dest->mode = params->mode; } + +if (params->has_zero_page_detection) { + dest->zero_page_detection = params->zero_page_detection; + } }static void migrate_params_apply (MigrateSetParameters *params,Error **errp)
@@ -1541,6 +1558,10 @@ static void migrate_params_apply(MigrateSetParameters *params, Error **errp)if (params->has_mode) { s->parameters.mode = params->mode; } + +if (params->has_zero_page_detection) { + s->parameters.zero_page_detection = params->zero_page_detection; + } }void qmp_migrate_set_parameters (MigrateSetParameters *params,Error **errp)
migration/options.h +1 -0
@@ -94,6 +94,7 @@ const char *migrate_tls_authz(void);const char *migrate_tls_creds (void );const char *migrate_tls_hostname (void );uint64_t migrate_xbzrle_cache_size (void ); +ZeroPageDetection migrate_zero_page_detection (void );/* parameters setters */
migration/ram.c +4 -0
@@ -1140,6 +1140,10 @@ static int save_zero_page(RAMState *rs, PageSearchStatus *pss,QEMUFile *file = pss->pss_channel;int len =0 ; +if (migrate_zero_page_detection () ==ZERO_PAGE_DETECTION_NONE ) { +return 0 ; + } +if (!buffer_is_zero (p,TARGET_PAGE_SIZE )) {return 0 ; }
qapi/migration.json +30 -3
@@ -670,6 +670,18 @@ { 'enum': 'MigMode', 'data': [ 'normal', 'cpr-reboot' ] } +## +# @ZeroPageDetection: +# +# @none: Do not perform zero page checking. +# +# @legacy: Perform zero page checking in main migration thread. +# +# Since: 9.0 +## +{ 'enum': 'ZeroPageDetection', + 'data': [ 'none', 'legacy' ] } + ## # @BitmapMigrationBitmapAliasTransform: #
@@ -891,6 +903,10 @@ # @mode: Migration mode. See description in @MigMode. Default is 'normal'. # (Since 8.2) # +# @zero-page-detection: Whether and how to detect zero pages. +# See description in @ZeroPageDetection. Default is 'legacy'. +# (since 9.0) +# # Features: # # @deprecated: Member @block-incremental is deprecated. Use
@@ -924,7 +940,8 @@ 'block-bitmap-mapping', { 'name': 'x-vcpu-dirty-limit-period', 'features': ['unstable'] }, 'vcpu-dirty-limit', - 'mode'] } + 'mode', + 'zero-page-detection'] } ## # @MigrateSetParameters:
@@ -1083,6 +1100,10 @@ # @mode: Migration mode. See description in @MigMode. Default is 'normal'. # (Since 8.2) # +# @zero-page-detection: Whether and how to detect zero pages. +# See description in @ZeroPageDetection. Default is 'legacy'. +# (since 9.0) +# # Features: # # @deprecated: Member @block-incremental is deprecated. Use
@@ -1136,7 +1157,8 @@ '*x-vcpu-dirty-limit-period': { 'type': 'uint64', 'features': [ 'unstable' ] }, '*vcpu-dirty-limit': 'uint64', - '*mode': 'MigMode'} } + '*mode': 'MigMode', + '*zero-page-detection': 'ZeroPageDetection'} } ## # @migrate-set-parameters:
@@ -1311,6 +1333,10 @@ # @mode: Migration mode. See description in @MigMode. Default is 'normal'. # (Since 8.2) # +# @zero-page-detection: Whether and how to detect zero pages. +# See description in @ZeroPageDetection. Default is 'legacy'. +# (since 9.0) +# # Features: # # @deprecated: Member @block-incremental is deprecated. Use
@@ -1361,7 +1387,8 @@ '*x-vcpu-dirty-limit-period': { 'type': 'uint64', 'features': [ 'unstable' ] }, '*vcpu-dirty-limit': 'uint64', - '*mode': 'MigMode'} } + '*mode': 'MigMode', + '*zero-page-detection': 'ZeroPageDetection'} } ## # @query-migrate-parameters:
Signature · 1 line
2.30.2