From: Max Kellermann Date: Mon, 7 Oct 2024 19:11:55 +0000 (+0200) Subject: common/Finisher: call logger without holding the lock X-Git-Tag: v20.0.0~789^2~11 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2a19a27040ea1fd86953388a5392de2001265370;p=ceph.git common/Finisher: call logger without holding the lock The `PerfCounters::inc()` method acquires another lock which can block the calling thread while holding the `finisher_lock` which can cause a lot of lock contention. This can be avoided easily by moving the `PerfCounters::inc()` call out of the protected code block. Signed-off-by: Max Kellermann --- diff --git a/src/common/Finisher.h b/src/common/Finisher.h index 46a4599b8d0..81211c82269 100644 --- a/src/common/Finisher.h +++ b/src/common/Finisher.h @@ -65,12 +65,15 @@ class Finisher { public: /// Add a context to complete, optionally specifying a parameter for the complete function. void queue(Context *c, int r = 0) { - const std::lock_guard l{finisher_lock}; - bool was_empty = finisher_queue.empty(); - finisher_queue.push_back(std::make_pair(c, r)); - if (was_empty) { - finisher_cond.notify_one(); + { + const std::lock_guard l{finisher_lock}; + const bool was_empty = finisher_queue.empty(); + finisher_queue.push_back(std::make_pair(c, r)); + if (was_empty) { + finisher_cond.notify_one(); + } } + if (logger) logger->inc(l_finisher_queue_len); } @@ -86,9 +89,9 @@ class Finisher { for (Context *i : ls) { finisher_queue.push_back(std::make_pair(i, 0)); } - if (logger) - logger->inc(l_finisher_queue_len, ls.size()); } + if (logger) + logger->inc(l_finisher_queue_len, ls.size()); ls.clear(); }