From d2f1440d7ae4635eaff8c75d38db454ab55f9d22 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 14 Mar 2019 11:29:10 -0500 Subject: [PATCH] crush/CrushWrapper: add update_weight_sets arg to adjust_item_weight_* - Make it optional whether the weight-set weights are adjusted to match the weight. - Fix the adjustment of the parent bucket(s) so that the summations in weight-sets are correctly maintained. Prior to this change, if I adjust any weight, all parent buckets' weight-set weights are reset to the bucket's primary weight. Signed-off-by: Sage Weil --- src/crush/CrushWrapper.cc | 58 +++++++++++++++++++++++++++++++-------- src/crush/CrushWrapper.h | 27 ++++++++++++------ 2 files changed, 65 insertions(+), 20 deletions(-) diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index 81470ac0140..6af6084207c 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -1441,15 +1441,19 @@ int CrushWrapper::get_item_weight_in_loc(int id, const map &loc) return -ENOENT; } -int CrushWrapper::adjust_item_weight(CephContext *cct, int id, int weight) +int CrushWrapper::adjust_item_weight(CephContext *cct, int id, int weight, + bool update_weight_sets) { - ldout(cct, 5) << __func__ << " " << id << " weight " << weight << dendl; + ldout(cct, 5) << __func__ << " " << id << " weight " << weight + << " update_weight_sets=" << (int)update_weight_sets + << dendl; int changed = 0; for (int bidx = 0; bidx < crush->max_buckets; bidx++) { if (!crush->buckets[bidx]) { continue; } - int r = adjust_item_weight_in_bucket(cct, id, weight, -1-bidx); + int r = adjust_item_weight_in_bucket(cct, id, weight, -1-bidx, + update_weight_sets); if (r > 0) { ++changed; } @@ -1462,10 +1466,12 @@ int CrushWrapper::adjust_item_weight(CephContext *cct, int id, int weight) int CrushWrapper::adjust_item_weight_in_bucket( CephContext *cct, int id, int weight, - int bucket_id) + int bucket_id, + bool update_weight_sets) { ldout(cct, 5) << __func__ << " " << id << " weight " << weight << " in bucket " << bucket_id + << " update_weight_sets=" << (int)update_weight_sets << dendl; int changed = 0; if (!bucket_exists(bucket_id)) { @@ -1474,13 +1480,37 @@ int CrushWrapper::adjust_item_weight_in_bucket( crush_bucket *b = get_bucket(bucket_id); for (unsigned int i = 0; i < b->size; i++) { if (b->items[i] == id) { - int diff = bucket_adjust_item_weight(cct, b, id, weight); + int diff = bucket_adjust_item_weight(cct, b, id, weight, + update_weight_sets); ldout(cct, 5) << __func__ << " " << id << " diff " << diff << " in bucket " << bucket_id << dendl; - adjust_item_weight(cct, bucket_id, b->weight); + adjust_item_weight(cct, bucket_id, b->weight, false); changed++; } } + // update weight-sets so they continue to sum + for (auto& p : choose_args) { + auto &cmap = p.second; + if (!cmap.args) { + continue; + } + crush_choose_arg *arg = &cmap.args[-1 - bucket_id]; + if (!arg->weight_set) { + continue; + } + ceph_assert(arg->weight_set_positions > 0); + vector w(arg->weight_set_positions); + for (unsigned i = 0; i < b->size; ++i) { + for (unsigned j = 0; j < arg->weight_set_positions; ++j) { + crush_weight_set *weight_set = &arg->weight_set[j]; + w[j] += weight_set->weights[i]; + } + } + ldout(cct,5) << __func__ << " adjusting bucket " << bucket_id + << " cmap " << p.first << " weights to " << w << dendl; + ostringstream ss; + choose_args_adjust_item_weight(cct, cmap, bucket_id, w, &ss); + } if (!changed) { return -ENOENT; } @@ -1489,16 +1519,20 @@ int CrushWrapper::adjust_item_weight_in_bucket( int CrushWrapper::adjust_item_weight_in_loc( CephContext *cct, int id, int weight, - const map& loc) + const map& loc, + bool update_weight_sets) { ldout(cct, 5) << "adjust_item_weight_in_loc " << id << " weight " << weight - << " in " << loc << dendl; + << " in " << loc + << " update_weight_sets=" << (int)update_weight_sets + << dendl; int changed = 0; for (auto l = loc.begin(); l != loc.end(); ++l) { int bid = get_item_id(l->second); if (!bucket_exists(bid)) continue; - int r = adjust_item_weight_in_bucket(cct, id, weight, bid); + int r = adjust_item_weight_in_bucket(cct, id, weight, bid, + update_weight_sets); if (r > 0) { ++changed; } @@ -2391,9 +2425,11 @@ int CrushWrapper::remove_rule(int ruleno) return rebuild_roots_with_classes(nullptr); } -int CrushWrapper::bucket_adjust_item_weight(CephContext *cct, crush_bucket *bucket, int item, int weight) +int CrushWrapper::bucket_adjust_item_weight( + CephContext *cct, crush_bucket *bucket, int item, int weight, + bool adjust_weight_sets) { - if (cct->_conf->osd_crush_update_weight_set) { + if (adjust_weight_sets) { unsigned position; for (position = 0; position < bucket->size; position++) if (bucket->items[position] == item) diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index e3668729def..9cd19e96397 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -956,25 +956,32 @@ public: } return 0; } - int adjust_item_weight(CephContext *cct, int id, int weight); - int adjust_item_weightf(CephContext *cct, int id, float weight) { + int adjust_item_weight(CephContext *cct, int id, int weight, + bool update_weight_sets=true); + int adjust_item_weightf(CephContext *cct, int id, float weight, + bool update_weight_sets=true) { int r = validate_weightf(weight); if (r < 0) { return r; } - return adjust_item_weight(cct, id, (int)(weight * (float)0x10000)); + return adjust_item_weight(cct, id, (int)(weight * (float)0x10000), + update_weight_sets); } - int adjust_item_weight_in_bucket( - CephContext *cct, int id, int weight, int bucket_id); + int adjust_item_weight_in_bucket(CephContext *cct, int id, int weight, + int bucket_id, + bool update_weight_sets); int adjust_item_weight_in_loc(CephContext *cct, int id, int weight, - const map& loc); + const map& loc, + bool update_weight_sets=true); int adjust_item_weightf_in_loc(CephContext *cct, int id, float weight, - const map& loc) { + const map& loc, + bool update_weight_sets=true) { int r = validate_weightf(weight); if (r < 0) { return r; } - return adjust_item_weight_in_loc(cct, id, (int)(weight * (float)0x10000), loc); + return adjust_item_weight_in_loc(cct, id, (int)(weight * (float)0x10000), + loc, update_weight_sets); } void reweight(CephContext *cct); void reweight_bucket(crush_bucket *b, @@ -1288,7 +1295,9 @@ public: int *items, int *weights, int *idout); int bucket_add_item(crush_bucket *bucket, int item, int weight); int bucket_remove_item(struct crush_bucket *bucket, int item); - int bucket_adjust_item_weight(CephContext *cct, struct crush_bucket *bucket, int item, int weight); + int bucket_adjust_item_weight( + CephContext *cct, struct crush_bucket *bucket, int item, int weight, + bool adjust_weight_sets); void finalize() { ceph_assert(crush); -- 2.39.5