]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: add mon_reweight_max_osds to limit reweight-by-* commands
authorDan van der Ster <daniel.vanderster@cern.ch>
Fri, 26 Feb 2016 21:29:46 +0000 (22:29 +0100)
committerSage Weil <sage@redhat.com>
Tue, 1 Mar 2016 16:37:58 +0000 (11:37 -0500)
Add configurable mon_reweight_max_osds which limits the number
of OSDs modified each time reweight-by-* is called (by default
to 4 OSDs).

Also change the order in which we look at OSDs to go from most
to least utilized.

Signed-off-by: Dan van der Ster <daniel.vanderster@cern.ch>
src/common/config_opts.h
src/mon/OSDMonitor.cc

index 525861bf41931c19ef59e4ed39c5128d3095b4e3..1eb307f7662634f69ef06b2392aecc300495800e 100644 (file)
@@ -281,6 +281,7 @@ OPTION(mon_daemon_bytes, OPT_U64, 400ul << 20)  // mds, osd message memory cap (
 OPTION(mon_max_log_entries_per_event, OPT_INT, 4096)
 OPTION(mon_reweight_min_pgs_per_osd, OPT_U64, 10)   // min pgs per osd for reweight-by-pg command
 OPTION(mon_reweight_min_bytes_per_osd, OPT_U64, 100*1024*1024)   // min bytes per osd for reweight-by-utilization command
+OPTION(mon_reweight_max_osds, OPT_INT, 4)   // max osds to change per reweight-by-* command
 OPTION(mon_reweight_max_change, OPT_FLOAT, 0.05)   // max change to each osd per reweight-by-* command
 OPTION(mon_health_data_update_interval, OPT_FLOAT, 60.0)
 OPTION(mon_health_to_clog, OPT_BOOL, true)
index 5d42c1757e5e552f4778862f705c01838fb581bc..3bf56bea08aacb8d3cd6ff37931eba0264c7bc28 100644 (file)
@@ -569,16 +569,35 @@ int OSDMonitor::reweight_by_utilization(int oload, std::string& out_str,
   std::string sep;
   oss << "reweighted: ";
   bool changed = false;
+  int num_changed = 0;
+
+  // precompute util for each OSD
+  std::vector<std::pair<int, float> > util_by_osd;
   for (ceph::unordered_map<int,osd_stat_t>::const_iterator p =
-        pgm.osd_stat.begin();
+       pgm.osd_stat.begin();
        p != pgm.osd_stat.end();
        ++p) {
-    float util;
+    std::pair<int, float> osd_util;
+    osd_util.first = p->first;
     if (by_pg) {
-      util = pgs_by_osd[p->first] / osdmap.crush->get_item_weightf(p->first);
+      osd_util.second = pgs_by_osd[p->first] / osdmap.crush->get_item_weightf(p->first);
     } else {
-      util = (double)p->second.kb_used / (double)p->second.kb;
+      osd_util.second = (double)p->second.kb_used / (double)p->second.kb;
     }
+    util_by_osd.push_back(osd_util);
+  }
+
+  // sort and iterate from most to least utilized
+  std::sort(util_by_osd.begin(), util_by_osd.end(), [](std::pair<int, float> l, std::pair<int, float> r) {
+    return l.second > r.second;
+  });
+
+  for (std::vector<std::pair<int, float> >::const_iterator p =
+        util_by_osd.begin();
+       p != util_by_osd.end();
+       ++p) {
+    float util = p->second;
+
     if (util >= overload_util) {
       sep = ", ";
       // Assign a lower weight to overloaded OSDs. The current weight
@@ -596,6 +615,8 @@ int OSDMonitor::reweight_by_utilization(int oload, std::string& out_str,
               (float)weight / (float)0x10000,
               (float)new_weight / (float)0x10000);
       oss << buf << sep;
+      if (++num_changed >= g_conf->mon_reweight_max_osds)
+       break;
     }
     if (!no_increasing && util <= underload_util) {
       // assign a higher weight.. if we can.
@@ -615,6 +636,8 @@ int OSDMonitor::reweight_by_utilization(int oload, std::string& out_str,
                 (float)weight / (float)0x10000,
                 (float)new_weight / (float)0x10000);
        oss << buf << sep;
+       if (++num_changed >= g_conf->mon_reweight_max_osds)
+         break;
       }
     }
   }