]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common: TokenBucketThrottle should use perfect forwarding for item
authorJason Dillaman <dillaman@redhat.com>
Wed, 29 Apr 2020 16:27:46 +0000 (12:27 -0400)
committerJason Dillaman <dillaman@redhat.com>
Thu, 14 May 2020 15:56:45 +0000 (11:56 -0400)
This will allow more than just a pointer to an item to be passed to
the callback.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/common/Throttle.h
src/librbd/io/ImageRequestWQ.cc
src/librbd/io/ImageRequestWQ.h

index e38886de06d33061a84384aa2cd22df496d2bd36..d4bb77025af095619dc524bb97fe53e5c83f6d0b 100644 (file)
@@ -414,16 +414,17 @@ public:
     return m_name;
   }
 
-  template <typename T, typename I, void(T::*MF)(int, I*, uint64_t)>
-  void add_blocker(uint64_t c, T *handler, I *item, uint64_t flag) {
-    Context *ctx = new LambdaContext([handler, item, flag](int r) {
-      (handler->*MF)(r, item, flag);
+  template <typename T, typename MF, typename I>
+  void add_blocker(uint64_t c, T&& t, MF&& mf, I&& item, uint64_t flag) {
+    auto ctx = new LambdaContext(
+      [t, mf, item=std::forward<I>(item), flag](int) mutable {
+        (t->*mf)(std::forward<I>(item), flag);
       });
     m_blockers.emplace_back(c, ctx);
   }
 
-  template <typename T, typename I, void(T::*MF)(int, I*, uint64_t)>
-  bool get(uint64_t c, T *handler, I *item, uint64_t flag) {
+  template <typename T, typename MF, typename I>
+  bool get(uint64_t c, T&& t, MF&& mf, I&& item, uint64_t flag) {
     bool wait = false;
     uint64_t got = 0;
     std::lock_guard lock(m_lock);
@@ -441,8 +442,10 @@ public:
       }
     }
 
-    if (wait)
-      add_blocker<T, I, MF>(c - got, handler, item, flag);
+    if (wait) {
+      add_blocker(c - got, std::forward<T>(t), std::forward<MF>(mf),
+                  std::forward<I>(item), flag);
+    }
 
     return wait;
   }
index 2d21418428196da2d04046c8fa9996bfcd447b04..c8677d0a8c7a15afea51b459ee8a0aef80af9749 100644 (file)
@@ -789,9 +789,10 @@ void ImageRequestWQ<I>::apply_qos_limit(const uint64_t flag,
 }
 
 template <typename I>
-void ImageRequestWQ<I>::handle_throttle_ready(int r, ImageDispatchSpec<I> *item, uint64_t flag) {
+void ImageRequestWQ<I>::handle_throttle_ready(
+    ImageDispatchSpec<I> *item, uint64_t flag) {
   CephContext *cct = m_image_ctx.cct;
-  ldout(cct, 15) << "r=" << r << ", " << "req=" << item << dendl;
+  ldout(cct, 15) << "req=" << item << dendl;
 
   ceph_assert(m_io_throttled.load() > 0);
   item->set_throttled(flag);
@@ -821,9 +822,8 @@ bool ImageRequestWQ<I>::needs_throttle(ImageDispatchSpec<I> *item) {
 
     throttle = t.second;
     if (item->tokens_requested(flag, &tokens) &&
-        throttle->get<ImageRequestWQ<I>, ImageDispatchSpec<I>,
-             &ImageRequestWQ<I>::handle_throttle_ready>(
-               tokens, this, item, flag)) {
+        throttle->get(tokens, this, &ImageRequestWQ<I>::handle_throttle_ready,
+                      item, flag)) {
       blocked = true;
     } else {
       item->set_throttled(flag);
index ecbf33f3d20a8794381cd397498134a7f7d555a2..40acfa52390711ee1ca2a482846e0296956dc813 100644 (file)
@@ -158,7 +158,7 @@ private:
   void handle_refreshed(int r, ImageDispatchSpec<ImageCtxT> *req);
   void handle_blocked_writes(int r);
 
-  void handle_throttle_ready(int r, ImageDispatchSpec<ImageCtxT> *item, uint64_t flag);
+  void handle_throttle_ready(ImageDispatchSpec<ImageCtxT> *item, uint64_t flag);
 };
 
 } // namespace io