@@ -1129,9 +1129,10 @@ class ZRelocateTask : public ZRestartableTask {
11291129 ZRelocateWork<ZRelocateMediumAllocator> medium (&_medium_allocator, _medium_targets->addr (), _generation);
11301130
11311131 const uint32_t num_nodes = ZNUMA::count ();
1132- const uint32_t start_node_id = ZNUMA::id ();
1133- uint32_t current_node_id = start_node_id;
1134- int current_node_affinity = -1 ;
1132+ const uint32_t start_node = ZNUMA::id ();
1133+ uint32_t current_node = start_node;
1134+ bool has_affinity = false ;
1135+ bool has_affinity_current_node = false ;
11351136
11361137 const auto do_forwarding = [&](ZForwarding* forwarding) {
11371138 ZPage* const page = forwarding->page ();
@@ -1163,27 +1164,33 @@ class ZRelocateTask : public ZRestartableTask {
11631164
11641165 const auto do_forwarding_one_from_iter = [&]() {
11651166 ZForwarding* forwarding;
1166- if (_iters->get (current_node_id).next_if (&forwarding, check_numa_local, current_node_id)) {
1167- if (UseNUMA) {
1168- // Set thread affinity for NUMA-local processing (if needed)
1169- const int current_node = ZNUMA::numa_id_to_node (current_node_id);
11701167
1171- if (current_node_affinity != current_node) {
1172- os::numa_set_thread_affinity (Thread::current (), current_node);
1173- current_node_affinity = current_node;
1168+ while (true ) {
1169+ if (_iters->get (current_node).next_if (&forwarding, check_numa_local, current_node)) {
1170+ // Set thread affinity for NUMA-local processing (if needed)
1171+ if (UseNUMA && !has_affinity_current_node) {
1172+ os::numa_set_thread_affinity (Thread::current (), ZNUMA::numa_id_to_node (current_node));
1173+ has_affinity = true ;
1174+ has_affinity_current_node = true ;
11741175 }
1176+
1177+ // Perform the forwarding task
1178+ claim_and_do_forwarding (forwarding);
1179+ return true ;
11751180 }
11761181
1177- // Perform the forwarding task
1178- claim_and_do_forwarding (forwarding);
1179- return true ;
1180- }
1182+ // No work found on the current node, move to the next node
1183+ current_node = (current_node + 1 ) % num_nodes;
1184+ has_affinity_current_node = false ;
11811185
1182- // No work found on the current node, move to the next node
1183- current_node_id = (current_node_id + 1 ) % num_nodes;
1186+ // If we've looped back to the starting node there's no more work to do
1187+ if (current_node == start_node) {
1188+ return false ;
1189+ }
1190+ }
11841191
1185- // If we wrapped around to the start node there is no more work
1186- return current_node_id != start_node_id ;
1192+ // No more work
1193+ return false ;
11871194 };
11881195
11891196 for (;;) {
@@ -1208,8 +1215,7 @@ class ZRelocateTask : public ZRestartableTask {
12081215
12091216 _queue->leave ();
12101217
1211- if (current_node_affinity != -1 ) {
1212- assert (UseNUMA, " Should only happen with NUMA" );
1218+ if (UseNUMA && has_affinity) {
12131219 // Restore the affinity of the thread so that it isn't bound to a specific
12141220 // node any more
12151221 os::numa_set_thread_affinity (Thread::current (), -1 );
0 commit comments