From: Max Kellermann Date: Mon, 7 Oct 2024 19:11:31 +0000 (+0200) Subject: common/Finisher: wake up after pushing to the queue X-Git-Tag: v20.0.0~789^2~9 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=0abad594d85f5ab9a5577810d2cd59dcf9a3d2ef;p=ceph.git common/Finisher: wake up after pushing to the queue Pushing to the queue may take a long time when the `std::vector` needs to allocate more memory. We should wake up the `Finisher` thread only right before unlocking the `finisher_mutex` to reduce lock contention, because it is the more likely that the mutex can really be acquired when the thread really wakes up. This imitates how commit cc7ec3e18d191575c did it - it refactored only one of the `queue()` overloads, leaving less-than-optimal copies of this piece code in all other overloads. Signed-off-by: Max Kellermann --- diff --git a/src/common/Finisher.h b/src/common/Finisher.h index 215930116d3..732ed746d56 100644 --- a/src/common/Finisher.h +++ b/src/common/Finisher.h @@ -83,12 +83,13 @@ class Finisher { auto queue(T &ls) -> decltype(std::distance(ls.begin(), ls.end()), void()) { { const std::lock_guard l{finisher_lock}; - if (finisher_queue.empty() && !finisher_running) { - finisher_cond.notify_all(); - } + const bool should_notify = finisher_queue.empty() && !finisher_running; for (Context *i : ls) { finisher_queue.push_back(std::make_pair(i, 0)); } + if (should_notify) { + finisher_cond.notify_all(); + } } if (logger) logger->inc(l_finisher_queue_len, ls.size());