From d55b30105c2d39c4f668789b5962699cfcd0aa23 Mon Sep 17 00:00:00 2001 From: "Yan, Zheng" Date: Tue, 10 Jul 2018 08:25:23 +0800 Subject: [PATCH] mds: convert MDSCacheObject::ref_map to flat_map flat_map is more suitable for small map Signed-off-by: "Yan, Zheng" --- src/mds/CDentry.cc | 13 ++++++++++--- src/mds/CDir.cc | 13 ++++++++++--- src/mds/CInode.cc | 9 ++++++--- src/mds/MDSCacheObject.cc | 5 ++--- src/mds/MDSCacheObject.h | 13 ++++++++----- 5 files changed, 36 insertions(+), 17 deletions(-) diff --git a/src/mds/CDentry.cc b/src/mds/CDentry.cc index 93e07e04c269f..069a4affef309 100644 --- a/src/mds/CDentry.cc +++ b/src/mds/CDentry.cc @@ -83,8 +83,12 @@ ostream& operator<<(ostream& out, const CDentry& dn) out << " pv=" << dn.get_projected_version(); out << " v=" << dn.get_version(); - if (dn.is_auth_pinned()) + if (dn.is_auth_pinned()) { out << " ap=" << dn.get_num_auth_pins() << "+" << dn.get_num_nested_auth_pins(); +#ifdef MDS_AUTHPIN_SET + dn.print_authpin_set(out); +#endif + } { const CInode *inode = dn.get_linkage()->get_inode(); @@ -362,8 +366,11 @@ void CDentry::auth_unpin(void *by) auth_pins--; #ifdef MDS_AUTHPIN_SET - ceph_assert(auth_pin_set.count(by)); - auth_pin_set.erase(auth_pin_set.find(by)); + { + auto it = auth_pin_set.find(by); + ceph_assert(it != auth_pin_set.end()); + auth_pin_set.erase(it); + } #endif if (auth_pins == 0) diff --git a/src/mds/CDir.cc b/src/mds/CDir.cc index 8fe2fbe483614..7efeab7398bbc 100644 --- a/src/mds/CDir.cc +++ b/src/mds/CDir.cc @@ -107,10 +107,14 @@ ostream& operator<<(ostream& out, const CDir& dir) out << " dir_auth=" << dir.get_dir_auth(); } - if (dir.get_cum_auth_pins()) + if (dir.get_cum_auth_pins()) { out << " ap=" << dir.get_auth_pins() << "+" << dir.get_dir_auth_pins() << "+" << dir.get_nested_auth_pins(); +#ifdef MDS_AUTHPIN_SET + dir.print_authpin_set(out); +#endif + } out << " state=" << dir.get_state(); if (dir.state_test(CDir::STATE_COMPLETE)) out << "|complete"; @@ -2759,8 +2763,11 @@ void CDir::auth_unpin(void *by) auth_pins--; #ifdef MDS_AUTHPIN_SET - ceph_assert(auth_pin_set.count(by)); - auth_pin_set.erase(auth_pin_set.find(by)); + { + auto it = auth_pin_set.find(by); + ceph_assert(it != auth_pin_set.end()); + auth_pin_set.erase(it); + } #endif if (auth_pins == 0) put(PIN_AUTHPIN); diff --git a/src/mds/CInode.cc b/src/mds/CInode.cc index 7b7f2bdfaa348..4d26e810a4b72 100644 --- a/src/mds/CInode.cc +++ b/src/mds/CInode.cc @@ -130,7 +130,7 @@ ostream& operator<<(ostream& out, const CInode& in) if (in.is_auth_pinned()) { out << " ap=" << in.get_num_auth_pins() << "+" << in.get_num_nested_auth_pins(); #ifdef MDS_AUTHPIN_SET - out << "(" << in.auth_pin_set << ")"; + in.print_authpin_set(out); #endif } @@ -2572,8 +2572,11 @@ void CInode::auth_unpin(void *by) auth_pins--; #ifdef MDS_AUTHPIN_SET - ceph_assert(auth_pin_set.count(by)); - auth_pin_set.erase(auth_pin_set.find(by)); + { + auto it = auth_pin_set.find(by); + ceph_assert(it != auth_pin_set.end()); + auth_pin_set.erase(it); + } #endif if (auth_pins == 0) diff --git a/src/mds/MDSCacheObject.cc b/src/mds/MDSCacheObject.cc index 6c6a676ba857d..eabcabc7e1ae7 100644 --- a/src/mds/MDSCacheObject.cc +++ b/src/mds/MDSCacheObject.cc @@ -48,9 +48,8 @@ void MDSCacheObject::dump(Formatter *f) const #ifdef MDS_REF_SET f->open_object_section("pins"); - for(std::map::const_iterator it = ref_map.begin(); - it != ref_map.end(); ++it) { - f->dump_int(pin_name(it->first), it->second); + for(const auto& p : ref_map) { + f->dump_int(pin_name(p.first), p.second); } f->close_section(); #endif diff --git a/src/mds/MDSCacheObject.h b/src/mds/MDSCacheObject.h index cbfc89da0a0eb..27f20349476b7 100644 --- a/src/mds/MDSCacheObject.h +++ b/src/mds/MDSCacheObject.h @@ -141,7 +141,7 @@ class MDSCacheObject { protected: __s32 ref = 0; // reference count #ifdef MDS_REF_SET - mempool::mds_co::map ref_map; + mempool::mds_co::flat_map ref_map; #endif public: @@ -208,10 +208,8 @@ protected: void print_pin_set(std::ostream& out) const { #ifdef MDS_REF_SET - std::map::const_iterator it = ref_map.begin(); - while (it != ref_map.end()) { - out << " " << pin_name(it->first) << "=" << it->second; - ++it; + for(auto const &p : ref_map) { + out << " " << pin_name(p.first) << "=" << p.second; } #else out << " nref=" << ref; @@ -229,6 +227,11 @@ protected: bool is_auth_pinned() const { return auth_pins || nested_auth_pins; } int get_num_auth_pins() const { return auth_pins; } int get_num_nested_auth_pins() const { return nested_auth_pins; } +#ifdef MDS_AUTHPIN_SET + void print_authpin_set(std::ostream& out) const { + out << " (" << auth_pin_set << ")"; + } +#endif void dump_states(Formatter *f) const; void dump(Formatter *f) const; -- 2.39.5