Repository navigation
umbrella: OSDMap::calc_pg_maps: fix balancing for some (important) corner cases - #71916
Merged
Merged
Conversation
In some cases the balancer can stall out, unable to find any changes that will help overfull or underfull OSDs get closer to their target num PGs. Here's an example from the wild. These changes are not accepted because the overall stddev does not appear to be decreasing: will try dropping existing remapping pair 264 -> 137 which remapped 24.f9d into overfull osd.137 existing pg_upmap_items [766,799,264,137] remapped 24.f9d into overfull osd.137, new_pg_upmap_items now [766,799] stddev 138085.453125 -> 138085.453125 will try dropping existing remapping pair 496 -> 637 which remapped 24.5ca out from underfull osd.496 existing pg_upmap_items [729,790,496,637] remapped 24.5ca out from underfull osd.496, new_pg_upmap_items now [729,790] stddev 138085.453125 -> 138085.453125 Those changes will now be accepted, which is good because those OSDs will improve, even though the sum of squared deviations does not. Note that a change scoring exactly equal still moves data, so this trades some churn for the ability to escape a plateau. The two following patches make the score both more meaningful and precise enough to tell many of these cases apart on their own merits. Signed-off-by: Dan van der Ster <[email protected]> (cherry picked from commit 181ec6f)
Currently we score how balanced we are using a sum of the absolute deviations, treating small and large OSDs equally. This strongly under values relatively small PGs, which we really need to be accurately balancing with priority to avoid them getting overfull. Consider this scenario: osd.0 weight 100.0 pgs 100 target 100 -> deviation 0 osd.1 weight 1.0 pgs 2 target 1 -> deviation 1 The tiny OSD osd.1 is 2x overfull -- we should prioritize moving one of its PGs to osd.0, which would only go 1% overfull. The new values would become: osd.0 weight 100.0 pgs 101 target 100 -> deviation 1 osd.1 weight 1.0 pgs 1 target 1 -> deviation 0 With the "stddev" calculation, we have these before/after scores: stddev = 0*0 + 1*1 = 1 new_stddev = 1*1 + 0*0 = 1 (Until recently, that change would be rejected because it does not decrease the stddev). To improve things, we calculate a bal_score which incorporates the relative deviation and OSD weights. Here's the new scores for the example change above: bal_score = (100/100 - 1)^2 * 100 + (2/1 - 1)^2 * 1 = 1 new_bal_score = (101/100 - 1)^2 * 100 + (1/1 - 1)^2 * 1 = 0.01 With this new approach the change is highly favourable, as it should be. Note that this changes only how an already proposed change is scored. Deciding whether to run at all, which OSDs are overfull or underfull, and which remap to propose are all still done in absolute PG deviations against max_deviation, so a small OSD like osd.1 above only gets this attention once some OSD in the tree is more than max_deviation PGs away from its target. Signed-off-by: Dan van der Ster <[email protected]> (cherry picked from commit 0c43a01)
bal_score is a sum taken over every OSD in the crush tree, while a proposed change modifies just two of its terms. In float the delta can land below the ULP of the total, so two genuinely different mappings compare equal and we cannot tell an improvement from a regression. That is what the stalled balancer in "accept more proposed changes" was really hitting. try_drop_remap_overfull only proposes a drop when osd_deviation[um_from] + 1 < osd_deviation[osd], and for a sum of squared deviations that gives delta = 2 * (dev_from - dev_to + 1) < 0 so the change was strictly improving; it printed as unchanged only because float at a magnitude of 138085 has a ULP of ~0.016. The weighted score reduces the magnitude of the sum considerably, but it does not remove the failure mode. Simulating a 3000 OSD tree with ~100 PGs per OSD and a drop which satisfies the guard above: float 595.903381 -> 595.903381 delta +0 tie double 595.902895 -> 595.902893 delta -1.98364e-06 accepted While here: - Derive the relative deviation from the absolute one rather than computing pgs / target - 1, which loses precision to cancellation when pgs is close to target. - Log the delta next to the two totals. The totals are printed with the stream's default 6 significant digits, which is exactly enough to hide the improvements of interest here. - Assert target > 0 in calc_deviations, which now divides by it. Both callers already assert this before their own use. - Rename the parameter in the header declaration to match the definition. Signed-off-by: Dan van der Ster <[email protected]> Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> (cherry picked from commit 6aecf7b)
dvanders
approved these changes
Sep 21, 2026
Member
|
This PR has been added to umbrella integration testing by pdonnell started 2026-09-29-17:26. |
Member
|
jenkins test windows |
1 similar comment
Member
|
jenkins test windows |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
backport tracker: https://tracker.ceph.com/issues/80632
backport of #65191
parent tracker: https://tracker.ceph.com/issues/78314
this backport was staged using ceph-backport.sh version 16.0.0.6848
find the latest version at https://github.com/ceph/ceph/blob/main/src/script/ceph-backport.sh