From 33048410c8546c47ea69313656a46e5c025f40c1 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 11 Aug 2014 20:54:38 -0700 Subject: [PATCH] mon/OSDMonitor: respect CRUSH weights for reweight-by-pg Do not assume that all OSDs are weighted equally for reweight-by-pg. Note that reweight-by-utilization already reweights based on the size of the OSD volume; we presume that this is already reflected by the CRUSH weights. Signed-off-by: Sage Weil --- src/mon/OSDMonitor.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 7eb90f13be68a..1b92f06ea7f73 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -459,13 +459,14 @@ int OSDMonitor::reweight_by_utilization(int oload, std::string& out_str, const PGMap &pgm = mon->pgmon()->pg_map; vector pgs_by_osd(osdmap.get_max_osd()); unsigned num_pg_copies = 0; - unsigned num_osds = pgm.osd_stat.size(); // Avoid putting a small number (or 0) in the denominator when calculating // average_util double average_util; if (by_pg) { // by pg mapping + double weight_sum = 0.0; // sum up the crush weights + int num_osds = 0; for (ceph::unordered_map::const_iterator p = pgm.pg_stat.begin(); p != pgm.pg_stat.end(); @@ -477,6 +478,10 @@ int OSDMonitor::reweight_by_utilization(int oload, std::string& out_str, ++q) { if (*q >= (int)pgs_by_osd.size()) pgs_by_osd.resize(*q); + if (pgs_by_osd[*q] == 0) { + weight_sum += osdmap.crush->get_item_weightf(*q); + ++num_osds; + } ++pgs_by_osd[*q]; ++num_pg_copies; } @@ -490,7 +495,7 @@ int OSDMonitor::reweight_by_utilization(int oload, std::string& out_str, return -EDOM; } - average_util = (double)num_pg_copies / (double)num_osds; + average_util = (double)num_pg_copies / weight_sum; } else { // by osd utilization if (pgm.osd_sum.kb < 1024) { @@ -532,7 +537,7 @@ int OSDMonitor::reweight_by_utilization(int oload, std::string& out_str, ++p) { float util; if (by_pg) { - util = pgs_by_osd[p->first]; + util = pgs_by_osd[p->first] / osdmap.crush->get_item_weightf(p->first); } else { util = (double)p->second.kb_used / (double)p->second.kb; } -- 2.39.5