]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mds: avoid evaluating stray dentry multiple times
authorYan, Zheng <zyan@redhat.com>
Thu, 14 Feb 2019 07:33:35 +0000 (15:33 +0800)
committerYan, Zheng <zyan@redhat.com>
Thu, 14 Feb 2019 09:52:27 +0000 (17:52 +0800)
If we call eval_stray(delay=true) for a dentry, the dentry will
get evaluated twice. We can avoid the extra evaluation by directly
put dentry into the delayed_eval_stray list.

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

index aa46c17cc59874013eef5b16a4df55f00c0a69c0..7f410d89b4bdf46a46632f0d1ba2a22f150863f8 100644 (file)
@@ -7510,7 +7510,7 @@ void MDCache::dentry_remove_replica(CDentry *dn, mds_rank_t from, set<SimpleLock
     gather_locks.insert(&dn->lock);
 
   // Replicated strays might now be elegible for purge
-  CDentry::linkage_t *dnl = dn->get_linkage();
+  CDentry::linkage_t *dnl = dn->get_projected_linkage();
   if (dnl->is_primary()) {
     maybe_eval_stray(dnl->get_inode());
   }
@@ -12900,9 +12900,11 @@ void MDCache::maybe_eval_stray(CInode *in, bool delay) {
     return;
   }
 
-  if (dn->get_projected_linkage()->is_primary() &&
-      dn->get_dir()->get_inode()->is_stray()) {
-    stray_manager.eval_stray(dn, delay);
+  if (dn->get_dir()->get_inode()->is_stray()) {
+    if (delay)
+      stray_manager.queue_delayed(dn);
+    else
+      stray_manager.eval_stray(dn);
   }
 }
 
index dbf8a0073eb45633e2ade3c9080b6d1b24786d5c..5e666857b65e2b853fee9111063abb7b3d206844 100644 (file)
@@ -1078,7 +1078,6 @@ protected:
   void scan_stray_dir(dirfrag_t next=dirfrag_t());
   StrayManager stray_manager;
   friend struct C_MDC_RetryScanStray;
-  friend class C_IO_MDC_FetchedBacktrace;
 
   // == messages ==
  public:
index 786ca51ab507fb33a2489e859e30dcd142441e7a..ffbbc7ded8c28fba2ab33ed9717e517be1aa7a93 100644 (file)
@@ -338,15 +338,28 @@ void StrayManager::_enqueue(CDentry *dn, bool trunc)
   }
 }
 
+void StrayManager::queue_delayed(CDentry *dn)
+{
+  if (!started)
+    return;
+
+  if (dn->state_test(CDentry::STATE_EVALUATINGSTRAY))
+    return;
+
+  if (!dn->item_stray.is_on_list()) {
+    delayed_eval_stray.push_back(&dn->item_stray);
+    num_strays_delayed++;
+    logger->set(l_mdc_num_strays_delayed, num_strays_delayed);
+  }
+}
 
 void StrayManager::advance_delayed()
 {
   if (!started)
     return;
 
-  for (elist<CDentry*>::iterator p = delayed_eval_stray.begin(); !p.end(); ) {
-    CDentry *dn = *p;
-    ++p;
+  while (!delayed_eval_stray.empty()) {
+    CDentry *dn = delayed_eval_stray.front();
     dn->item_stray.remove_myself();
     num_strays_delayed--;
 
@@ -408,7 +421,7 @@ struct C_MDC_EvalStray : public StrayManagerContext {
   }
 };
 
-bool StrayManager::_eval_stray(CDentry *dn, bool delay)
+bool StrayManager::_eval_stray(CDentry *dn)
 {
   dout(10) << "eval_stray " << *dn << dendl;
   CDentry::linkage_t *dnl = dn->get_projected_linkage();
@@ -427,17 +440,13 @@ bool StrayManager::_eval_stray(CDentry *dn, bool delay)
   // call eval_stray() after purge()
   ceph_assert(!dn->state_test(CDentry::STATE_PURGING));
 
-  if (!dn->is_auth()) {
+  if (!dn->is_auth())
     return false;
-  }
 
   if (!started)
-    delay = true;
+    return false;
 
   if (dn->item_stray.is_on_list()) {
-    if (delay)
-      return false;
-
     dn->item_stray.remove_myself();
     num_strays_delayed--;
     logger->set(l_mdc_num_strays_delayed, num_strays_delayed);
@@ -501,14 +510,8 @@ bool StrayManager::_eval_stray(CDentry *dn, bool delay)
       dout(20) << " too many dn refs" << dendl;
       return false;
     }
-    if (delay) {
-      if (!dn->item_stray.is_on_list()) {
-       delayed_eval_stray.push_back(&dn->item_stray);
-       num_strays_delayed++;
-       logger->set(l_mdc_num_strays_delayed, num_strays_delayed);
-      }
     // don't purge multiversion inode with snap data
-    } else if (in->snaprealm && in->snaprealm->has_past_parents() &&
+    if (in->snaprealm && in->snaprealm->has_past_parents() &&
               !in->old_inodes.empty()) {
       // A file with snapshots: we will truncate the HEAD revision
       // but leave the metadata intact.
@@ -546,14 +549,14 @@ void StrayManager::activate()
   purge_queue.activate();
 }
 
-bool StrayManager::eval_stray(CDentry *dn, bool delay)
+bool StrayManager::eval_stray(CDentry *dn)
 {
   // avoid nested eval_stray
   if (dn->state_test(CDentry::STATE_EVALUATINGSTRAY))
       return false;
 
   dn->state_set(CDentry::STATE_EVALUATINGSTRAY);
-  bool ret = _eval_stray(dn, delay);
+  bool ret = _eval_stray(dn);
   dn->state_clear(CDentry::STATE_EVALUATINGSTRAY);
   return ret;
 }
index c0842de878ee90d6aef58b2eb4337b872069d092..53e4211031245bdd3c990b376b00f05ac92d796a 100644 (file)
@@ -117,7 +117,7 @@ class StrayManager
    * @returns true if the dentry will be purged (caller should never
    *          take more refs after this happens), else false.
    */
-  bool _eval_stray(CDentry *dn, bool delay=false);
+  bool _eval_stray(CDentry *dn);
 
   void _eval_stray_remote(CDentry *stray_dn, CDentry *remote_dn);
 
@@ -127,21 +127,19 @@ class StrayManager
   void set_logger(PerfCounters *l) {logger = l;}
   void activate();
 
-  bool eval_stray(CDentry *dn, bool delay=false);
+  bool eval_stray(CDentry *dn);
 
   void set_num_strays(uint64_t num);
   uint64_t get_num_strays() const { return num_strays; }
 
   /**
-   * Where eval_stray was previously invoked with delay=true, call
-   * eval_stray again for any dentries that were put on the
-   * delayed_eval_stray list as a result of the original call.
-   *
-   * Used so that various places can call eval_stray(delay=true) during
-   * an operation to identify dentries of interest, and then call
-   * this function later during trim in order to do the final
-   * evaluation (and resulting actions) while not in the middle of another
-   * metadata operation.
+   * Queue dentry for later evaluation. (evaluate it while not in the
+   * middle of another metadata operation)
+   */
+  void queue_delayed(CDentry *dn);
+
+  /**
+   * Eval strays in the delayed_eval_stray list
    */
   void advance_delayed();