From fce0f7c1dfe040033a146c8ec0b2a433c1b51a0d Mon Sep 17 00:00:00 2001 From: xie xingguo Date: Sat, 1 Jun 2019 14:22:39 +0800 Subject: [PATCH] osd/OSDMap: maybe_remove_pg_upmaps - avoid do_crush twice which is extremely time-consuming. Half of the amount of time of calling maybe_remove_pg_upmaps has been saved by applying this patch as a result.. Was: maybe_remove_pg_upmaps (~10000 pg_upmap_items) latency:104s Now: maybe_remove_pg_upmaps (~10000 pg_upmap_items) latency:56s Signed-off-by: xie xingguo (cherry picked from commit 02e5499b350bcd7d9eac98b2072052a9a4a1f535) Conflicts: src/osd/OSDMap.h - nautilus has "vector" where master has "std::vector" --- src/osd/OSDMap.cc | 53 ++++++++++++++++++++++++++++++++++++++++------- src/osd/OSDMap.h | 3 ++- 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/osd/OSDMap.cc b/src/osd/OSDMap.cc index 2a8995948eb0..e5c19a605fb4 100644 --- a/src/osd/OSDMap.cc +++ b/src/osd/OSDMap.cc @@ -1812,8 +1812,46 @@ void OSDMap::maybe_remove_pg_upmaps(CephContext *cct, to_cancel.insert(pg); continue; } - vector up; - nextmap.pg_to_raw_upmap(pg, &up); + vector raw, up; + nextmap.pg_to_raw_upmap(pg, &raw, &up); + auto i = nextmap.pg_upmap.find(pg); + if (i != nextmap.pg_upmap.end() && raw == i->second) { + ldout(cct, 10) << " removing redundant pg_upmap " + << i->first << " " << i->second + << dendl; + to_cancel.insert(pg); + continue; + } + auto j = nextmap.pg_upmap_items.find(pg); + if (j != nextmap.pg_upmap_items.end()) { + mempool::osdmap::vector> newmap; + for (auto& p : j->second) { + if (std::find(raw.begin(), raw.end(), p.first) == raw.end()) { + // cancel mapping if source osd does not exist anymore + continue; + } + if (p.second != CRUSH_ITEM_NONE && p.second < max_osd && + p.second >= 0 && osd_weight[p.second] == 0) { + // cancel mapping if target osd is out + continue; + } + newmap.push_back(p); + } + if (newmap.empty()) { + ldout(cct, 10) << " removing no-op pg_upmap_items " + << j->first << " " << j->second + << dendl; + to_cancel.insert(pg); + continue; + } else if (newmap != j->second) { + ldout(cct, 10) << " simplifying partially no-op pg_upmap_items " + << j->first << " " << j->second + << " -> " << newmap + << dendl; + pending_inc->new_pg_upmap_items[pg] = newmap; + continue; + } + } auto crush_rule = nextmap.get_pg_pool_crush_rule(pg); auto r = nextmap.crush->verify_upmap(cct, crush_rule, @@ -1895,7 +1933,6 @@ void OSDMap::maybe_remove_pg_upmaps(CephContext *cct, } } } - nextmap.clean_pg_upmaps(cct, pending_inc); } int OSDMap::apply_incremental(const Incremental &inc) @@ -2465,14 +2502,16 @@ void OSDMap::pg_to_raw_osds(pg_t pg, vector *raw, int *primary) const *primary = _pick_primary(*raw); } -void OSDMap::pg_to_raw_upmap(pg_t pg, vector *raw_upmap) const +void OSDMap::pg_to_raw_upmap(pg_t pg, vector*raw, + vector *raw_upmap) const { auto pool = get_pg_pool(pg.pool()); if (!pool) { raw_upmap->clear(); return; } - _pg_to_raw_osds(*pool, pg, raw_upmap, NULL); + _pg_to_raw_osds(*pool, pg, raw, NULL); + *raw_upmap = *raw; _apply_upmap(*pool, pg, raw_upmap); } @@ -4700,8 +4739,8 @@ int OSDMap::calc_pg_upmaps( // to see if we can append more remapping pairs } ldout(cct, 10) << " trying " << pg << dendl; - vector orig, out; - tmp.pg_to_raw_upmap(pg, &orig); // including existing upmaps too + vector raw, orig, out; + tmp.pg_to_raw_upmap(pg, &raw, &orig); // including existing upmaps too if (!try_pg_upmap(cct, pg, overfull, underfull, &orig, &out)) { continue; } diff --git a/src/osd/OSDMap.h b/src/osd/OSDMap.h index 0361771e927a..ac7348be424b 100644 --- a/src/osd/OSDMap.h +++ b/src/osd/OSDMap.h @@ -1174,7 +1174,8 @@ public: * raw and primary must be non-NULL */ void pg_to_raw_osds(pg_t pg, vector *raw, int *primary) const; - void pg_to_raw_upmap(pg_t pg, vector *raw_upmap) const; + void pg_to_raw_upmap(pg_t pg, vector *raw, + vector *raw_upmap) const; /// map a pg to its acting set. @return acting set size void pg_to_acting_osds(const pg_t& pg, vector *acting, int *acting_primary) const { -- 2.47.3