From 8900606baead1a6ef3a592a9acfce700c5851b34 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 2 Nov 2026 16:19:51 +0000 Subject: [PATCH] fix(shmem): wake the region ack sender when acks stop - the ack sender waited up to 500 ms for a full ack batch, also after StopAcks(), so each region destruction took at least 500 ms - wait with a predicate that includes the stop flag - set the stop flag under the ack mutex, so that the sender cannot miss the notification Co-Authored-By: Claude Opus 5.5 --- fairmq/shmem/UnmanagedRegion.h | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/fairmq/shmem/UnmanagedRegion.h b/fairmq/shmem/UnmanagedRegion.h index 0cd12453..b688e276 100644 --- a/fairmq/shmem/UnmanagedRegion.h +++ b/fairmq/shmem/UnmanagedRegion.h @@ -205,10 +205,9 @@ struct UnmanagedRegion ~UnmanagedRegion() { LOG(debug) << "~UnmanagedRegion(): " << fName << " (" << (fControlling ? "controller" : "viewer") << ")"; - fStopAcks = true; + SetStopAcks(); if (fAcksSender.joinable()) { - fBlockSendCV.notify_one(); fAcksSender.join(); } @@ -357,10 +356,8 @@ struct UnmanagedRegion { std::unique_lock lock(fBlockMtx); - // try to get blocks - if (fBlocksToFree.size() < fAckBunchSize) { - fBlockSendCV.wait_for(lock, std::chrono::milliseconds(500)); - } + // try to get blocks, but do not wait when stopping + fBlockSendCV.wait_for(lock, std::chrono::milliseconds(500), [&] { return fBlocksToFree.size() >= fAckBunchSize || fStopAcks; }); // send whatever blocks we have blocksToSend = std::min(fBlocksToFree.size(), fAckBunchSize); @@ -445,12 +442,21 @@ struct UnmanagedRegion } } + void SetStopAcks() + { + { + // set under the lock, so that the ack sender cannot miss the notification + std::lock_guard lock(fBlockMtx); + fStopAcks = true; + } + fBlockSendCV.notify_one(); + } + void StopAcks() { - fStopAcks = true; + SetStopAcks(); if (fAcksSender.joinable()) { - fBlockSendCV.notify_one(); fAcksSender.join(); }