From be49866a150e04438cef971dec7948eaf34852fc Mon Sep 17 00:00:00 2001 From: Patrick Donnelly Date: Fri, 2 Aug 2019 13:22:51 -0700 Subject: [PATCH] mds: add explicit trim flag So that the intent of the caller is clear to trim due to the cache being too full. Signed-off-by: Patrick Donnelly --- src/mds/MDCache.cc | 2 +- src/mds/Server.cc | 11 ++++++----- src/mds/Server.h | 22 ++++++++++++++++++++-- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/mds/MDCache.cc b/src/mds/MDCache.cc index 722bb6d065c..df699f32b8d 100644 --- a/src/mds/MDCache.cc +++ b/src/mds/MDCache.cc @@ -7593,7 +7593,7 @@ void MDCache::check_memory_usage() mds->mlogger->set(l_mdm_heap, last.get_heap()); if (cache_toofull()) { - mds->server->recall_client_state(nullptr); + mds->server->recall_client_state(nullptr, Server::RecallFlags::TRIM); } // If the cache size had exceeded its limit, but we're back in bounds diff --git a/src/mds/Server.cc b/src/mds/Server.cc index 07b95260111..a75811a2399 100644 --- a/src/mds/Server.cc +++ b/src/mds/Server.cc @@ -1566,8 +1566,9 @@ void Server::recover_filelocks(CInode *in, bufferlist locks, int64_t client) std::pair Server::recall_client_state(MDSGatherBuilder* gather, RecallFlags flags) { const auto now = clock::now(); - const bool steady = flags&RecallFlags::STEADY; - const bool enforce_max = flags&RecallFlags::ENFORCE_MAX; + const bool steady = !!(flags&RecallFlags::STEADY); + const bool enforce_max = !!(flags&RecallFlags::ENFORCE_MAX); + const bool trim = !!(flags&RecallFlags::TRIM); const auto max_caps_per_client = g_conf().get_val("mds_max_caps_per_client"); const auto min_caps_per_client = g_conf().get_val("mds_min_caps_per_client"); @@ -1579,14 +1580,14 @@ std::pair Server::recall_client_state(MDSGatherBuilder* gather, << " min=" << min_caps_per_client << " max=" << max_caps_per_client << " total=" << Capability::count() - << " flags=0x" << std::hex << flags + << " flags=" << flags << dendl; /* trim caps of sessions with the most caps first */ std::multimap caps_session; - auto f = [&caps_session, enforce_max, max_caps_per_client](auto& s) { + auto f = [&caps_session, enforce_max, trim, max_caps_per_client](auto& s) { auto num_caps = s->caps.size(); - if (!enforce_max || num_caps > max_caps_per_client) { + if (trim || (enforce_max && num_caps > max_caps_per_client)) { caps_session.emplace(std::piecewise_construct, std::forward_as_tuple(num_caps), std::forward_as_tuple(s)); } }; diff --git a/src/mds/Server.h b/src/mds/Server.h index a5296a0a430..5a3aec0b1ca 100644 --- a/src/mds/Server.h +++ b/src/mds/Server.h @@ -169,12 +169,13 @@ public: void reconnect_tick(); void recover_filelocks(CInode *in, bufferlist locks, int64_t client); - enum RecallFlags { + enum class RecallFlags : uint64_t { NONE = 0, STEADY = (1<<0), ENFORCE_MAX = (1<<1), + TRIM = (1<<2), }; - std::pair recall_client_state(MDSGatherBuilder* gather, enum RecallFlags=RecallFlags::NONE); + std::pair recall_client_state(MDSGatherBuilder* gather, RecallFlags=RecallFlags::NONE); void force_clients_readonly(); // -- requests -- @@ -353,4 +354,21 @@ private: time last_recall_state; }; +static inline constexpr auto operator|(Server::RecallFlags a, Server::RecallFlags b) { + using T = std::underlying_type::type; + return static_cast(static_cast(a) | static_cast(b)); +} +static inline constexpr auto operator&(Server::RecallFlags a, Server::RecallFlags b) { + using T = std::underlying_type::type; + return static_cast(static_cast(a) & static_cast(b)); +} +static inline std::ostream& operator<<(std::ostream& os, const Server::RecallFlags& f) { + using T = std::underlying_type::type; + return os << "0x" << std::hex << static_cast(f) << std::dec; +} +static inline constexpr bool operator!(const Server::RecallFlags& f) { + using T = std::underlying_type::type; + return static_cast(f) == static_cast(0); +} + #endif -- 2.39.5