From: "Maciej S. Szmigiero" <maciej.szmigi...@oracle.com> This is necessary for multifd_send_pages() to be able to be called from multiple threads.
Signed-off-by: Maciej S. Szmigiero <maciej.szmigi...@oracle.com> --- migration/multifd.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index a26418d87485..878ff7d9f9f0 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -622,8 +622,8 @@ static bool multifd_send_pages(void) * using more channels, so ensure it doesn't overflow if the * limit is lower now. */ - next_channel %= migrate_multifd_channels(); - for (i = next_channel;; i = (i + 1) % migrate_multifd_channels()) { + i = qatomic_load_acquire(&next_channel) % migrate_multifd_channels(); + for (;; i = (i + 1) % migrate_multifd_channels()) { if (multifd_send_should_exit()) { return false; } @@ -633,7 +633,8 @@ static bool multifd_send_pages(void) * sender thread can clear it. */ if (qatomic_read(&p->pending_job) == false) { - next_channel = (i + 1) % migrate_multifd_channels(); + qatomic_store_release(&next_channel, + (i + 1) % migrate_multifd_channels()); break; } }