From cd6f77c6a08cf0d7f0a995664e7a8981675b1b9c Mon Sep 17 00:00:00 2001 From: "Yan, Zheng" Date: Tue, 3 Apr 2018 11:34:32 +0800 Subject: [PATCH] mds: mds: optimize MDBalancer::try_rebalance() 1. change import_pop_map to multimap because subtrees may have the same popularity. 2. avoid calculating subtrees' popularity multiple times Signed-off-by: "Yan, Zheng" --- src/mds/MDBalancer.cc | 58 +++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/src/mds/MDBalancer.cc b/src/mds/MDBalancer.cc index 229092308eef7..ab20a91e6914f 100644 --- a/src/mds/MDBalancer.cc +++ b/src/mds/MDBalancer.cc @@ -820,8 +820,8 @@ void MDBalancer::try_rebalance(balance_state_t& state) } // make a sorted list of my imports - map import_pop_map; - multimap import_from_map; + multimap import_pop_map; + multimap > import_from_map; set fullauthsubs; mds->mdcache->get_fullauth_subtrees(fullauthsubs); @@ -829,6 +829,8 @@ void MDBalancer::try_rebalance(balance_state_t& state) CInode *diri = dir->get_inode(); if (diri->is_mdsdir()) continue; + if (dir->is_freezing() || dir->is_frozen()) + continue; // export pbly already in progress mds_rank_t from = diri->authority().first; double pop = dir->pop_auth_subtree.meta_load(rebalance_time, mds->mdcache->decayrate); @@ -842,13 +844,11 @@ void MDBalancer::try_rebalance(balance_state_t& state) continue; } - import_pop_map[pop] = dir; dout(15) << " map: i imported " << *dir << " from " << from << dendl; - import_from_map.insert(pair(from, dir)); + import_pop_map.insert(make_pair(pop, dir)); + import_from_map.insert(make_pair(from, make_pair(dir, pop))); } - - // do my exports! set already_exporting; @@ -856,8 +856,10 @@ void MDBalancer::try_rebalance(balance_state_t& state) mds_rank_t target = it.first; double amount = it.second; - if (amount < MIN_OFFLOAD) continue; - if (amount / target_load < .2) continue; + if (amount / target_load < .2) + continue; + if (amount < MIN_OFFLOAD) + continue; dout(5) << "want to send " << amount << " to mds." << target //<< " .. " << (*it).second << " * " << load_fac @@ -865,38 +867,41 @@ void MDBalancer::try_rebalance(balance_state_t& state) << dendl;//" .. fudge is " << fudge << dendl; double have = 0.0; - mds->mdcache->show_subtrees(); // search imports from target if (import_from_map.count(target)) { dout(5) << " aha, looking through imports from target mds." << target << dendl; - pair::iterator, multimap::iterator> p = - import_from_map.equal_range(target); - while (p.first != p.second) { - CDir *dir = (*p.first).second; + for (auto p = import_from_map.equal_range(target); + p.first != p.second; ) { + CDir *dir = p.first->second.first; + double pop = p.first->second.second; dout(5) << "considering " << *dir << " from " << (*p.first).first << dendl; - multimap::iterator plast = p.first++; + auto plast = p.first++; if (dir->inode->is_base()) continue; - if (dir->is_freezing() || dir->is_frozen()) - continue; // export pbly already in progress - double pop = dir->pop_auth_subtree.meta_load(rebalance_time, mds->mdcache->decayrate); assert(dir->inode->authority().first == target); // cuz that's how i put it in the map, dummy if (pop <= amount-have) { - dout(5) << "reexporting " << *dir - << " pop " << pop + dout(5) << "reexporting " << *dir << " pop " << pop << " back to mds." << target << dendl; mds->mdcache->migrator->export_dir_nicely(dir, target); have += pop; import_from_map.erase(plast); - import_pop_map.erase(pop); + for (auto q = import_pop_map.equal_range(pop); + q.first != q.second; ) { + if (q.first->second == dir) { + import_pop_map.erase(q.first); + break; + } + q.first++; + } } else { dout(5) << "can't reexport " << *dir << ", too big " << pop << dendl; } - if (amount-have < MIN_OFFLOAD) break; + if (amount-have < MIN_OFFLOAD) + break; } } if (amount-have < MIN_OFFLOAD) { @@ -906,13 +911,12 @@ void MDBalancer::try_rebalance(balance_state_t& state) // okay, search for fragments of my workload list exports; - for (auto dir : fullauthsubs) { - if (dir->get_inode()->is_mdsdir()) - continue; - if (dir->is_freezing() || dir->is_frozen()) - continue; // export pbly already in progress + for (auto p = import_pop_map.rbegin(); + p != import_pop_map.rend(); + ++p) { + CDir *dir = p->second; find_exports(dir, amount, exports, have, already_exporting); - if (have > amount-MIN_OFFLOAD) + if (amount-have < MIN_OFFLOAD) break; } //fudge = amount - have; -- 2.39.5