Skip to content

umbrella: OSDMap::calc_pg_maps: fix balancing for some (important) corner cases - #71916

Merged
batrick merged 3 commits into
ceph:umbrellafrom
ljflores:wip-80632-umbrella
Oct 7, 2026
Merged

batrick merged 3 commits into
ceph:umbrellafrom
ljflores:wip-80632-umbrella

Conversation

@ljflores

Copy link
Copy Markdown
Member

dvanders and others added 3 commits September 18, 2026 15:36
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)
@ljflores
ljflores requested a review from a team as a code owner September 18, 2026 20:36
@ljflores ljflores added this to the umbrella milestone Sep 18, 2026
@ljflores ljflores added the core label Sep 18, 2026
@ljflores
ljflores requested a review from dvanders September 18, 2026 20:37
@github-actions github-actions Bot added the releng-audit-pass Release engineering: passed backport verification audit. label Sep 18, 2026
@batrick

batrick commented Sep 29, 2026

Copy link
Copy Markdown
Member

@batrick

batrick commented Oct 1, 2026

Copy link
Copy Markdown
Member

jenkins test windows

1 similar comment
@batrick

batrick commented Oct 7, 2026

Copy link
Copy Markdown
Member

jenkins test windows

@batrick
batrick merged commit 095846e into ceph:umbrella Oct 7, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core releng-audit-pass Release engineering: passed backport verification audit. wip-pdonnell-testing3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants