]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/Finisher: wake up after pushing to the queue
authorMax Kellermann <max.kellermann@ionos.com>
Mon, 7 Oct 2024 19:11:31 +0000 (21:11 +0200)
committerMax Kellermann <max.kellermann@ionos.com>
Thu, 10 Oct 2024 05:31:52 +0000 (07:31 +0200)
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 <max.kellermann@ionos.com>
src/common/Finisher.h

index 215930116d35c1ab13c4dbfa87ace3a950e6c6ec..732ed746d56c40d8150f9a37162a104f9dfd9329 100644 (file)
@@ -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());