]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
osd/OSDMap: maybe_remove_pg_upmaps - avoid do_crush twice
authorxie xingguo <xie.xingguo@zte.com.cn>
Sat, 1 Jun 2019 06:22:39 +0000 (14:22 +0800)
committerNathan Cutler <ncutler@suse.com>
Wed, 26 Jun 2019 15:24:57 +0000 (17:24 +0200)
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 <xie.xingguo@zte.com.cn>
(cherry picked from commit 02e5499b350bcd7d9eac98b2072052a9a4a1f535)

Conflicts:
src/osd/OSDMap.h
- nautilus has "vector" where master has "std::vector"

src/osd/OSDMap.cc
src/osd/OSDMap.h

index 2a8995948eb086464042ac68f0359becacf263f7..e5c19a605fb4869f2ecb77dd3e7ff6b06ea2de20 100644 (file)
@@ -1812,8 +1812,46 @@ void OSDMap::maybe_remove_pg_upmaps(CephContext *cct,
       to_cancel.insert(pg);
       continue;
     }
-    vector<int> up;
-    nextmap.pg_to_raw_upmap(pg, &up);
+    vector<int> 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<pair<int,int>> 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<int> *raw, int *primary) const
   *primary = _pick_primary(*raw);
 }
 
-void OSDMap::pg_to_raw_upmap(pg_t pg, vector<int> *raw_upmap) const
+void OSDMap::pg_to_raw_upmap(pg_t pg, vector<int>*raw,
+                             vector<int> *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<int> orig, out;
-        tmp.pg_to_raw_upmap(pg, &orig); // including existing upmaps too
+        vector<int> 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;
        }
index 0361771e927abb2ceb2b0a97c1703ab1deb7d245..ac7348be424bea417b4612ea8447fe8254a3220f 100644 (file)
@@ -1174,7 +1174,8 @@ public:
    * raw and primary must be non-NULL
    */
   void pg_to_raw_osds(pg_t pg, vector<int> *raw, int *primary) const;
-  void pg_to_raw_upmap(pg_t pg, vector<int> *raw_upmap) const;
+  void pg_to_raw_upmap(pg_t pg, vector<int> *raw,
+                       vector<int> *raw_upmap) const;
   /// map a pg to its acting set. @return acting set size
   void pg_to_acting_osds(const pg_t& pg, vector<int> *acting,
                         int *acting_primary) const {