]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: optimize CDir::is_{freezing,frozen}_tree()
authorYan, Zheng <zyan@redhat.com>
Sat, 24 Jan 2015 22:08:10 +0000 (06:08 +0800)
committerYan, Zheng <zyan@redhat.com>
Wed, 25 Feb 2015 12:51:19 +0000 (20:51 +0800)
avoid checking ancestor CDir(s) when there is no freezing/frozen tree

Signed-off-by: Yan, Zheng <zyan@redhat.com>
src/mds/CDir.cc
src/mds/CDir.h

index 50e645ed2ae9d2adf7759ae7da057ad4419e4d72..2389e9b684fc0eb94e711a2890148df9438173a7 100644 (file)
@@ -40,7 +40,8 @@
 #undef dout_prefix
 #define dout_prefix *_dout << "mds." << cache->mds->get_nodeid() << ".cache.dir(" << this->dirfrag() << ") "
 
-
+int CDir::num_frozen_trees = 0;
+int CDir::num_freezing_trees = 0;
 
 class CDirContext : public MDSInternalContextBase
 {
@@ -2511,6 +2512,7 @@ bool CDir::freeze_tree()
     return true;
   } else {
     state_set(STATE_FREEZINGTREE);
+    ++num_freezing_trees;
     dout(10) << "freeze_tree waiting " << *this << dendl;
     return false;
   }
@@ -2522,8 +2524,12 @@ void CDir::_freeze_tree()
   assert(is_freezeable(true));
 
   // twiddle state
-  state_clear(STATE_FREEZINGTREE);   // actually, this may get set again by next context?
+  if (state_test(STATE_FREEZINGTREE)) {
+    state_clear(STATE_FREEZINGTREE);   // actually, this may get set again by next context?
+    --num_freezing_trees;
+  }
   state_set(STATE_FROZENTREE);
+  ++num_frozen_trees;
   get(PIN_FROZEN);
 
   // auth_pin inode for duration of freeze, if we are not a subtree root.
@@ -2538,6 +2544,8 @@ void CDir::unfreeze_tree()
   if (state_test(STATE_FROZENTREE)) {
     // frozen.  unfreeze.
     state_clear(STATE_FROZENTREE);
+    --num_frozen_trees;
+
     put(PIN_FROZEN);
 
     // unpin  (may => FREEZEABLE)   FIXME: is this order good?
@@ -2552,6 +2560,7 @@ void CDir::unfreeze_tree()
     // freezing.  stop it.
     assert(state_test(STATE_FREEZINGTREE));
     state_clear(STATE_FREEZINGTREE);
+    --num_freezing_trees;
     auth_unpin(this);
     
     finish_waiting(WAIT_UNFREEZE);
@@ -2560,6 +2569,8 @@ void CDir::unfreeze_tree()
 
 bool CDir::is_freezing_tree() const
 {
+  if (num_freezing_trees == 0)
+    return false;
   const CDir *dir = this;
   while (1) {
     if (dir->is_freezing_tree_root()) return true;
@@ -2573,6 +2584,8 @@ bool CDir::is_freezing_tree() const
 
 bool CDir::is_frozen_tree() const
 {
+  if (num_frozen_trees == 0)
+    return false;
   const CDir *dir = this;
   while (1) {
     if (dir->is_frozen_tree_root()) return true;
index b25ea2ab65fc5e90556aaac5d750d272653762b1..dbec210c04447ae4c644b24e3f9b78d4ac445fb0 100644 (file)
@@ -249,6 +249,9 @@ protected:
 
 
   // lock nesting, freeze
+  static int num_frozen_trees;
+  static int num_freezing_trees;
+
   int auth_pins;
 #ifdef MDS_AUTHPIN_SET
   multiset<void*> auth_pin_set;