]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: try trimming exported objects
authorYan, Zheng <zheng.z.yan@intel.com>
Fri, 9 May 2014 07:07:45 +0000 (15:07 +0800)
committerYan, Zheng <zheng.z.yan@intel.com>
Sun, 18 May 2014 05:13:22 +0000 (13:13 +0800)
Signed-off-by: Yan, Zheng <zheng.z.yan@intel.com>
src/mds/MDCache.cc
src/mds/MDCache.h
src/mds/Migrator.cc
src/mds/Migrator.h

index 4c9a1e530e92deac1be17c12bb34caad03be9ff8..1605fe1475841b18b4d97e2946b7a2aa95aa7526 100644 (file)
@@ -6188,12 +6188,17 @@ void MDCache::start_recovered_truncates()
  * however, we may expire a replica whose authority is recovering.
  * 
  */
-bool MDCache::trim(int max
+bool MDCache::trim(int max, int count)
 {
   // trim LRU
-  if (max < 0) {
+  if (count > 0) {
+    max = lru.lru_get_size() - count;
+    if (max <= 0)
+      max = 1;
+  } else if (max < 0) {
     max = g_conf->mds_cache_size;
-    if (!max) return false;
+    if (max <= 0)
+      return false;
   }
   dout(7) << "trim max=" << max << "  cur=" << lru.lru_get_size() << dendl;
 
index 225cce0519b454648cf444aa818617bf106d13aa..bd823429f5faa74fe0a789e2e85d8b177a6c101e 100644 (file)
@@ -565,7 +565,7 @@ public:
   size_t get_cache_size() { return lru.lru_get_size(); }
 
   // trimming
-  bool trim(int max = -1);   // trim cache
+  bool trim(int max=-1, int count=-1);   // trim cache
   bool trim_dentry(CDentry *dn, map<int, MCacheExpire*>& expiremap);
   void trim_dirfrag(CDir *dir, CDir *con,
                    map<int, MCacheExpire*>& expiremap);
@@ -659,7 +659,8 @@ public:
   }
   void touch_dentry_bottom(CDentry *dn) {
     lru.lru_bottouch(dn);
-    if (dn->get_projected_linkage()->is_primary()) {
+    if (dn->get_projected_linkage()->is_primary() &&
+       dn->get_dir()->inode->is_stray()) {
       CInode *in = dn->get_projected_linkage()->get_inode();
       if (in->has_dirfrags()) {
        list<CDir*> ls;
index 11475846d996cb98c6e85d7cbc40058345f17467..f23ea3bf43f1e6394d396c4c6bd212ef7d32d88c 100644 (file)
@@ -1461,7 +1461,7 @@ int Migrator::encode_export_dir(bufferlist& exportbl,
 
 void Migrator::finish_export_dir(CDir *dir, utime_t now, int peer,
                                 map<inodeno_t,map<client_t,Capability::Import> >& peer_imported,
-                                list<Context*>& finished)
+                                list<Context*>& finished, int *num_dentries)
 {
   dout(10) << "finish_export_dir " << *dir << dendl;
 
@@ -1500,11 +1500,14 @@ void Migrator::finish_export_dir(CDir *dir, utime_t now, int peer,
       // subdirs?
       in->get_nested_dirfrags(subdirs);
     }
+
+    cache->touch_dentry_bottom(dn); // move dentry to tail of LRU
+    ++(*num_dentries);
   }
 
   // subdirs
   for (list<CDir*>::iterator it = subdirs.begin(); it != subdirs.end(); ++it) 
-    finish_export_dir(*it, now, peer, peer_imported, finished);
+    finish_export_dir(*it, now, peer, peer_imported, finished, num_dentries);
 }
 
 class C_MDS_ExportFinishLogged : public Context {
@@ -1765,9 +1768,10 @@ void Migrator::export_finish(CDir *dir)
   assert(g_conf->mds_kill_export_at != 13);
   
   // finish export (adjust local cache state)
+  int num_dentries = 0;
   C_Contexts *fin = new C_Contexts(g_ceph_context);
-  finish_export_dir(dir, ceph_clock_now(g_ceph_context),
-                   it->second.peer, it->second.peer_imported, fin->contexts);
+  finish_export_dir(dir, ceph_clock_now(g_ceph_context), it->second.peer,
+                   it->second.peer_imported, fin->contexts, &num_dentries);
   dir->add_waiter(CDir::WAIT_UNFREEZE, fin);
 
   // unfreeze
@@ -1816,6 +1820,8 @@ void Migrator::export_finish(CDir *dir)
   cache->show_subtrees();
   audit();
 
+  cache->trim(-1, num_dentries); // try trimming exported dentries
+
   // send pending import_maps?
   mds->mdcache->maybe_send_pending_resolves();
   
@@ -2329,6 +2335,7 @@ void Migrator::import_reverse(CDir *dir)
       !dir->get_inode()->has_subtree_root_dirfrag(mds->get_nodeid()))
     dir->get_inode()->clear_scatter_dirty();
 
+  int num_dentries = 0;
   // adjust auth bits.
   list<CDir*> q;
   q.push_back(dir);
@@ -2381,6 +2388,9 @@ void Migrator::import_reverse(CDir *dir)
          if (bounds.count(*p) == 0)
            q.push_back(*p);
       }
+
+      cache->touch_dentry_bottom(dn); // move dentry to tail of LRU
+      ++num_dentries;
     }
   }
 
@@ -2414,6 +2424,8 @@ void Migrator::import_reverse(CDir *dir)
 
   cache->try_subtree_merge(dir);  // NOTE: this may journal subtree map as side effect
 
+  cache->trim(-1, num_dentries); // try trimming dentries
+
   // bystanders?
   if (stat.bystanders.empty()) {
     dout(7) << "no bystanders, finishing reverse now" << dendl;
index f9cb078e37433e9112b11cd8bb7e03bc48f33b48..22a4c071961a6d3824c0dd891f1311138e31ea76 100644 (file)
@@ -257,7 +257,7 @@ public:
                        utime_t now);
   void finish_export_dir(CDir *dir, utime_t now, int target,
                         map<inodeno_t,map<client_t,Capability::Import> >& peer_imported,
-                        list<Context*>& finished);
+                        list<Context*>& finished, int *num_dentries);
 
   void add_export_finish_waiter(CDir *dir, Context *c) {
     map<CDir*, export_state_t>::iterator it = export_state.find(dir);