@samitouri / QOSamiQemu / commits / ba92642400

migration/multifd: cache channel count in multifd_send_sync_main

multifd_send_sync_main() is called once per RAM synchronization round during live migration. It iterates over all multifd channels twice (signal loop + wait loop), calling migrate_multifd_channels() independently in each loop header. Cache migrate_multifd_channels() in a local thread_count variable at function entry, matching the pattern already used in multifd_send_setup() and multifd_recv_setup(). This eliminates 2 redundant config lookups per sync call. Signed-off-by: Bin Guo <guobin@linux.alibaba.com> Reviewed-by: Fabiano Rosas <farosas@suse.de> Link: https://lore.kernel.org/r/20260518110112.21395-9-guobin@linux.alibaba.com Signed-off-by: Peter Xu <peterx@redhat.com>

Bin Guo committed May 18, 2026 at 19:01 UTC ba9264240073c2bc4b0c1b3c1e65668122fb8f66
1 file changed +4 -2
migration/multifd.c
+4 -2
@@ -611,13 +611,15 @@ static int multifd_zero_copy_flush(QIOChannel *c)
611 int multifd_send_sync_main(MultiFDSyncReq req)
612 {
613 int i;
614 + int thread_count;
615 bool flush_zero_copy;
616
617 assert(req != MULTIFD_SYNC_NONE);
618
619 + thread_count = migrate_multifd_channels();
620 flush_zero_copy = migrate_zero_copy_send();
621
620 - for (i = 0; i < migrate_multifd_channels(); i++) {
622 + for (i = 0; i < thread_count; i++) {
623 MultiFDSendParams *p = &multifd_send_state->params[i];
624
625 if (multifd_send_should_exit()) {
@@ -634,7 +636,7 @@ int multifd_send_sync_main(MultiFDSyncReq req)
636 qatomic_set(&p->pending_sync, req);
637 qemu_sem_post(&p->sem);
638 }
637 - for (i = 0; i < migrate_multifd_channels(); i++) {
639 + for (i = 0; i < thread_count; i++) {
640 MultiFDSendParams *p = &multifd_send_state->params[i];
641
642 if (multifd_send_should_exit()) {