diff mbox series

[RFC,22/26] migration/multifd: Convert multifd_send_pages::next_channel to atomic

Message ID e519ae20524b4cecb50b3dc29d1b1614f737cb10.1713269378.git.maciej.szmigiero@oracle.com (mailing list archive)
State New
Headers show
Series Multifd | expand

Commit Message

Maciej S. Szmigiero April 16, 2024, 2:43 p.m. UTC
From: "Maciej S. Szmigiero" <maciej.szmigiero@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.szmigiero@oracle.com>
---
 migration/multifd.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
diff mbox series

Patch

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;
         }
     }