From: Yan, Zheng Date: Fri, 9 May 2014 07:07:45 +0000 (+0800) Subject: mds: try trimming exported objects X-Git-Tag: v0.82~56^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=0bd4fa2ea817ba8d81c8a09b4bae37b8b4fe3c4b;p=ceph.git mds: try trimming exported objects Signed-off-by: Yan, Zheng --- diff --git a/src/mds/MDCache.cc b/src/mds/MDCache.cc index 4c9a1e530e92..1605fe147584 100644 --- a/src/mds/MDCache.cc +++ b/src/mds/MDCache.cc @@ -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; diff --git a/src/mds/MDCache.h b/src/mds/MDCache.h index 225cce0519b4..bd823429f5fa 100644 --- a/src/mds/MDCache.h +++ b/src/mds/MDCache.h @@ -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& expiremap); void trim_dirfrag(CDir *dir, CDir *con, map& 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 ls; diff --git a/src/mds/Migrator.cc b/src/mds/Migrator.cc index 11475846d996..f23ea3bf43f1 100644 --- a/src/mds/Migrator.cc +++ b/src/mds/Migrator.cc @@ -1461,7 +1461,7 @@ int Migrator::encode_export_dir(bufferlist& exportbl, void Migrator::finish_export_dir(CDir *dir, utime_t now, int peer, map >& peer_imported, - list& finished) + list& 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::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 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; diff --git a/src/mds/Migrator.h b/src/mds/Migrator.h index f9cb078e3743..22a4c071961a 100644 --- a/src/mds/Migrator.h +++ b/src/mds/Migrator.h @@ -257,7 +257,7 @@ public: utime_t now); void finish_export_dir(CDir *dir, utime_t now, int target, map >& peer_imported, - list& finished); + list& finished, int *num_dentries); void add_export_finish_waiter(CDir *dir, Context *c) { map::iterator it = export_state.find(dir);