From 9c2dcfdf4b4bc2da1421467cad0533339f1b720f Mon Sep 17 00:00:00 2001 From: Dongsheng Yang Date: Tue, 24 Apr 2018 22:23:40 -0400 Subject: [PATCH 1/4] librbd: support bps throttle and throttle read and write seperately. Signed-off-by: Dongsheng Yang --- src/common/Throttle.h | 8 +- src/common/options.cc | 20 ++++ src/librbd/ImageCtx.cc | 19 +++- src/librbd/ImageCtx.h | 5 + src/librbd/io/ImageDispatchSpec.cc | 55 +++++++++++ src/librbd/io/ImageDispatchSpec.h | 20 ++-- src/librbd/io/ImageRequestWQ.cc | 93 +++++++++++++++---- src/librbd/io/ImageRequestWQ.h | 15 ++- src/librbd/io/Types.h | 14 +++ .../librbd/io/test_mock_ImageRequestWQ.cc | 18 ++-- 10 files changed, 223 insertions(+), 44 deletions(-) diff --git a/src/common/Throttle.h b/src/common/Throttle.h index 0c03e60569a..a9715f4c9b1 100644 --- a/src/common/Throttle.h +++ b/src/common/Throttle.h @@ -373,8 +373,8 @@ public: ~TokenBucketThrottle(); - template - bool get(uint64_t c, T *handler, I *item) { + template + bool get(uint64_t c, T *handler, I *item, uint64_t flag) { if (0 == m_throttle.max) return false; @@ -384,8 +384,8 @@ public: uint64_t got = m_throttle.get(c); if (got < c) { // Not enough tokens, add a blocker for it. - Context *ctx = new FunctionContext([handler, item](int r) { - (handler->*MF)(r, item); + Context *ctx = new FunctionContext([handler, item, flag](int r) { + (handler->*MF)(r, item, flag); }); m_blockers.emplace_back(c - got, ctx); waited = true; diff --git a/src/common/options.cc b/src/common/options.cc index fd4652362ae..6069d4a6b80 100644 --- a/src/common/options.cc +++ b/src/common/options.cc @@ -6420,6 +6420,26 @@ static std::vector