Project

General

Profile

Actions

Bug #80443

closed
AL LS

mgr/balancer: upmap-read mode aborts every ceph-mgr — ceph_assert(fabs(distribution_sum_desired - pool->get_pg_num()) < 0.01) is unsatisfiable at large pg_num

Bug #80443: mgr/balancer: upmap-read mode aborts every ceph-mgr — ceph_assert(fabs(distribution_sum_desired - pool->get_pg_num()) < 0.01) is unsatisfiable at large pg_num

Added by Armsby Li 3 months ago. Updated about 1 month ago.

Status:
Resolved
Priority:
Normal
Assignee:
Category:
-
Target version:
-
Due date:
% Done:

0%

Source:
Backport:
squid,tentacle,umbrella
Regression:
No
Severity:
2 - major
Reviewed:
Affected Versions:
ceph-qa-suite:
Component(RADOS):
Pull request ID:
Tags (freeform):
Fixed In:
v21.3.0-3588-g5735681856
Released In:
Upkeep Timestamp:
2026-10-29T01:14:57+00:00

Description

With the balancer in upmap-read mode, the active ceph-mgr aborts in the balancer thread inside OSDMap::calc_desired_primary_distribution_simple(). Standby mgrs take over and abort in turn on their next balancer tick (mgr/balancer/sleep_interval, default 60s), so the cluster loses all mgr daemons in a rotating crash loop until the balancer mode is changed.

The cluster was fully healthy at the time — do_read() returns EALREADY if any PG is not active+clean, so this is not an edge-case recovery state. All OSDs have primary_affinity exactly 1.

Environment

- ceph 20.2.4 (7f793731f1b39eb4f465e960113d2363c311b964) tentacle, RelWithDebInfo, cephadm/containerized, python3.9
- 192 OSDs
- mgr/balancer/mode = upmap-read, mgr/balancer/active = true
- All OSDs primary_affinity = 1 ([.osds[] | select(.primary_affinity != 1)] | length → 0)
- Pools: 8 replicated + 1 EC (default.rgw.buckets.data, size 9, skipped by the read balancer)
- Offending pool (by elimination, see below): default.rgw.buckets.index, pool id 7, pg_num 8192, size 3, read_balance.score_acting 1.03 vs optimal_score 1

Crash

/ceph/rpmbuild/BUILD/ceph-20.2.4/src/osd/OSDMap.cc: 5520: FAILED ceph_assert(fabs(distribution_sum_desired - pool->get_pg_num()) < 0.01)
in function 'int OSDMap::calc_desired_primary_distribution_simple(ceph::common::CephContext*, int64_t,
const std::vector<long unsigned int>&, std::map<long unsigned int, float>&) const'
thread 7cb9615b9640 thread_name:balancer

1: (ceph::__ceph_assert_fail(char const*, char const*, int, char const*)+0x12f)
2: /usr/lib64/ceph/libceph-common.so.2(+0x20c994)
3: (OSDMap::balance_primaries(ceph::common::CephContext*, long, OSDMap::Incremental*, OSDMap&,
std::optional&lt;OSDMap::rb_policy&gt; const&) const+0x6b7)
4: /usr/bin/ceph-mgr(+0x1c250b)
...
18: (PyModuleRunner::serve()+0x66)
19: (PyModuleRunner::PyModuleRunnerThread::entry()+0x139)

systemd: ceph-<fsid>@mgr.<host>.<id>.service: Main process exited, code=exited, status=134/n/a

Preceded one log line earlier by 0 [balancer INFO balancer] pools ['.mgr', 'rbd', 'default.rgw.meta', 'default.rgw.control', 'default.rgw.buckets.non-ec', 'default.rgw.log', 'default.rgw.buckets.index', 'default.rgw.buckets.data', '.rgw.root'] — the unshuffled pool list logged by do_read() (do_upmap() shuffles), confirming the read-balancer path. Full crash dump available at /var/lib/ceph/crash/2026-09-10T09:10:35.329781Z_dfc82ffb-8bab-420a-9e30-dc1f7f403a96/.

Analysis

The assert cannot fail for any reason related to cluster state. In calc_desired_primary_distribution_simple():

auto distribution_sum = 0.0; // double
for (const auto & osd : osds) {
float osd_primary_count = ((float)pgs_by_osd[osd].size() / (float)replica_count) * get_primary_affinityf(osd);
desired_primary_distribution.insert({osd, osd_primary_count});
distribution_sum += osd_primary_count;
}
float factor = (float)pool->get_pg_num() / (float)distribution_sum;
float distribution_sum_desired = 0.0; // float32 accumulator
ceph_assert(factor >= 1.0);
for (const auto & [osd, osd_primary_count] : desired_primary_distribution) {
desired_primary_distribution[osd] *= factor;
distribution_sum_desired += desired_primary_distribution[osd];
}
ceph_assert(fabs(distribution_sum_desired - pool->get_pg_num()) < 0.01);

Every element is scaled by factor = pg_num / distribution_sum and then re-summed, so distribution_sum_desired == pg_num identically in exact arithmetic, for any OSD set, any PG distribution, any primary affinity, any pool size. The assert is a tautology guarded by a fixed absolute epsilon, and the only thing that can break it is rounding in the float accumulator.

That rounding is not marginal at realistic pool sizes:

┌────────┬────────────────────────────────┬────────────────────────┐
│ pg_num │ float32 ULP at accumulator top │ 0.01 tolerance, in ULP │
├────────┼────────────────────────────────┼────────────────────────┤
│ 4096   │ 0.000488                       │ 20.5                   │
├────────┼────────────────────────────────┼────────────────────────┤
│ 8192   │ 0.000977                       │ 10.2                   │
├────────┼────────────────────────────────┼────────────────────────┤
│ 16384  │ 0.00195                        │ 5.1                    │
├────────┼────────────────────────────────┼────────────────────────┤
│ 65536  │ 0.00781                        │ 1.3                    │
└────────┴────────────────────────────────┴────────────────────────┘

The loop performs one rounding per OSD in osds_to_check — 192 here — each up to 0.5 ULP, i.e. up to 0.094 total at pg_num 8192, roughly 9x the tolerance. The error scales with both pg_num and OSD count while the tolerance stays constant, so the check becomes progressively unsatisfiable as clusters grow, and at pg_num ≥ 65536 a single rounding step nearly breaches it regardless of OSD count.

Note also that on this cluster all primary_affinity values are exactly 1, so factor is mathematically exactly 1.0 and the stretch loop — which exists only to handle primary_affinity < 1 — is a no-op that does nothing but accumulate rounding error before aborting the mgr.

The sibling ceph_assert(factor >= 1.0) two lines earlier is fragile in the same way: with uniform primary_affinity = 1 the exact factor is 1.0, and per-term rounding of pgs_by_osd[osd].size() / replica_count can push distribution_sum a fraction above pg_num, yielding factor = 0.99999994 and a second abort path. Independent evidence of this drift is visible in the pool dump — read_balance.primary_affinity_weighted reports 0.99999690055847168 on pools where every OSD's affinity is exactly 1.

Affected code

Identical in all current branches:

- tentacle — src/osd/OSDMap.cc:5520
- squid — src/osd/OSDMap.cc:5380
- main — src/osd/OSDMap.cc:5538

Introduced with the read balancer in PR #48010.

Steps to reproduce

1. Cluster with ~200 OSDs and a replicated pool with pg_num 8192, size 3, all primary_affinity = 1, all PGs active+clean.
2. ceph osd set-require-min-compat-client reef
3. ceph balancer mode upmap-read and ceph balancer on
4. Within one sleep_interval (60s) the active mgr aborts at the assert above; each standby aborts in turn on its own next tick.

Deterministic for a given osdmap. Setting debug_osd 20/20 on the mgr will log calculating simple distribution for replicated pool <name> immediately before the abort, identifying the pool.

Impact

All mgr daemons crash-loop for as long as read or upmap-read is set. No data-path impact (mgr is not in the I/O path), but the cluster loses the dashboard, prometheus metrics, cephadm orchestration and pg_autoscaler, and ceph -s reporting flaps.

Workaround

ceph config set mgr mgr/balancer/mode upmap (verified: crash loop stops immediately, mgr stable). Applying it via ceph config set rather than ceph balancer mode avoids needing an mgr that survives long enough to accept the command. Existing pg_upmap_primary entries remain valid and need not be cleared.

Suggested fix

Accumulate in double and make the tolerance relative rather than absolute, e.g. < 0.01 * pg_num or scaled by osds.size(). Better still, drop the assert to a derr/ldout warning: the quantity is an algebraic identity, so a mismatch can never indicate map corruption or a state problem worth killing the mgr over. The same treatment applies to ceph_assert(factor >= 1.0), which should tolerate factor slightly below 1 (factor = std::max(factor, 1.0f) or an epsilon).


Files

osdmap-60osd-65536pg-pgp60800.bin (43.6 KB) osdmap-60osd-65536pg-pgp60800.bin Lumir Sliva, 09/16/2026 12:25 AM
mgr-crash-backtrace.log (2.6 KB) mgr-crash-backtrace.log Lumir Sliva, 09/16/2026 12:25 AM

Related issues 3 (0 open — 3 closed)

Copied to RADOS - Backport #80814: squid: mgr/balancer: upmap-read mode aborts every ceph-mgr — ceph_assert(fabs(distribution_sum_desired - pool->get_pg_num()) < 0.01) is unsatisfiable at large pg_numResolvedLumir Sliva

Actions
Copied to RADOS - Backport #80815: umbrella: mgr/balancer: upmap-read mode aborts every ceph-mgr — ceph_assert(fabs(distribution_sum_desired - pool->get_pg_num()) < 0.01) is unsatisfiable at large pg_numResolvedLumir Sliva

Actions
Copied to RADOS - Backport #80816: tentacle: mgr/balancer: upmap-read mode aborts every ceph-mgr — ceph_assert(fabs(distribution_sum_desired - pool->get_pg_num()) < 0.01) is unsatisfiable at large pg_numResolvedLumir Sliva

Actions

LS Updated by Lumir Sliva 3 months ago Actions #1

  • Status changed from New to In Progress
  • Assignee set to Lumir Sliva

LS Updated by Lumir Sliva 3 months ago Actions #2

Confirmed the analysis and reproduced it on a plain vstart cluster (60 OSDs, one size-3 pool at pg_num 65536): enabling upmap-read aborts the active mgr within one balancer tick at the same assert, and a patched mgr balances the identical osdmap cleanly.

Fix is up at https://github.com/ceph/ceph/pull/71772 — factor and both accumulators computed in double, the factor assert tolerates rounding before clamping back to 1.0, and the sum tolerance scales with pg_num. The PR includes two regression tests at OSD count / pg_num combinations that deterministically trip the old asserts (500/32768 and 100/131072).

Thanks for the unusually thorough report, it made the root cause a straight confirmation.

LS Updated by Lumir Sliva 3 months ago Actions #3

  • Pull request ID set to 71772

LS Updated by Lumir Sliva 3 months ago Actions #4

  • Status changed from In Progress to Fix Under Review

KS Updated by Kamoltat (Junior) Sirivadhna 3 months ago Actions #5

  • Backport set to tentacle

LF Updated by Laura Flores 3 months ago Actions #6

  • Backport changed from tentacle to tentacle,umbrella

Will review the fix.

LS Updated by Lumir Sliva 3 months ago Actions #7

  • Backport changed from tentacle,umbrella to squid,tentacle,umbrella

LF Updated by Laura Flores 3 months ago Actions #8

  • Description updated (diff)

LF Updated by Laura Flores 3 months ago · Edited Actions #9

Thanks for the in-depth explanation Lumir. My understanding of this issue is that it's mathematically correct, but due to the float calculations in this function, some precision is lost when the PG num is very large.

I wrote out a small demo function to show roughly what happened in the cluster specs above. Note that the original function uses "auto" for "distribution_sum", but the small program I wrote needed me to specify a float value:

total_osds = 192
total_pgs = 8192
replica size = 3
all primary affinity = 1
estimate of pgs_per_osd = ((8192 * 3) / 192) = 128

int main()
{
    float distribution_sum = 0.0;
    for (int i=0; i<192; i++) {
      float osd_primary_count = (128.0 / 3 * 1);

      std::cout << "osd_primary_count: " << osd_primary_count << std::endl;
      std::cout << " " << std::endl;

      distribution_sum += osd_primary_count;
    }

    std::cout<<"distribution_sum: " << distribution_sum << std::endl;

    return 0;
}

------------- Output ------------------------------------------------------------------------------------

osd_primary_count: 42.6667 // this number is mathematically 42.666.... but the float rounds it up.

osd_primary_count: 42.6667

osd_primary_count: 42.6667

...

distribution_sum: 8191.99 // the value should exactly equal total_pgs (8192), but the number is slightly off.

I'd need the crash dump to see the exact value that was calculated, but I understand the overall problem.

@Lumir Sliva although you already have a fix up, can you please attach the following items?
  1. The coredump
  2. The OSDMap of your cluster

The latter is especially handy since we should be able to verify the fix against the osdmaptool.

LS Updated by Lumir Sliva 3 months ago Actions #10

The latter is especially handy since we should be able to verify the fix against the osdmaptool.

Attached osdmap-60osd-65536pg-pgp60800.bin, the map from my vstart reproduction. 60 OSDs, all up/in, all primary_affinity 1, no upmaps, pool bigpool (id 2) replicated size 3, pg_num 65536, pgp_num 60800. Saved before any fixed binary ran against the cluster, so it carries no pg_upmap_primary entries. It trips the assert offline, deterministically:

osdmaptool osdmap-60osd-65536pg-pgp60800.bin --read /tmp/read.out --read-pool bigpool

Two notes on the map. It was encoded by a main build (21.3.0 dev); a reef ceph-dencoder fails in pg_pool_t::decode on it, so use an osdmaptool built from main or the PR branch. And the abort is deterministic per map but not per pool size: at 60 OSDs / 65536 PGs roughly 15% of settled pgp_num values trip it, at 32768 PGs about 0.4%, so a freshly created pool of the same size will usually pass. This particular map is one that fails.

Note that the original function uses "auto" for "distribution_sum", but the small program I wrote needed me to specify a float value

That's the one place the demo diverges from the real code: auto distribution_sum = 0.0 is a double, so the first sum is close to exact. The float32 that breaches the tolerance is distribution_sum_desired in the second loop, together with factor, which is computed in float from (float)distribution_sum. Those two are exactly what the PR moves to double.

LS Updated by Lumir Sliva 3 months ago Actions #11

I'd need the crash dump to see the exact value that was calculated

I can pull the exact distribution_sum_desired and factor for the attached map, but my only build box is tied up with another build right now, so that'll take a day or so. If you get to a main build of osdmaptool first, one print in calc_desired_primary_distribution_simple() on that map gives the same numbers.

Armsby, could you attach the crash dump from /var/lib/ceph/crash/2026-09-10T09:10:35.329781Z_.../ and the osdmap of the 192-OSD cluster (ceph osd getmap -o osdmap.bin)?

LF Updated by Laura Flores 3 months ago 1Actions #12

Lumir Sliva wrote in #note-10:

The latter is especially handy since we should be able to verify the fix against the osdmaptool.

Attached osdmap-60osd-65536pg-pgp60800.bin, the map from my vstart reproduction. 60 OSDs, all up/in, all primary_affinity 1, no upmaps, pool bigpool (id 2) replicated size 3, pg_num 65536, pgp_num 60800. Saved before any fixed binary ran against the cluster, so it carries no pg_upmap_primary entries. It trips the assert offline, deterministically:

[...]

  • main before the fix: SIGABRT at src/osd/OSDMap.cc:5538, same assert as in the report. The live mgr abort on the same map is in the attached mgr-crash-backtrace.log and matches the field backtrace frame for frame.
  • with https://github.com/ceph/ceph/pull/71772: exit 0. The fixed mgr on this same map produced a plan and applied 952 pg_upmap_primary entries.
    Two notes on the map. It was encoded by a main build (21.3.0 dev); a reef ceph-dencoder fails in pg_pool_t::decode on it, so use an osdmaptool built from main or the PR branch. And the abort is deterministic per map but not per pool size: at 60 OSDs / 65536 PGs roughly 15% of settled pgp_num values trip it, at 32768 PGs about 0.4%, so a freshly created pool of the same size will usually pass. This particular map is one that fails.

Thanks for the map. I was also able to easily reproduce the issue, and I verified that your commit fixes the issue.

Note that the original function uses "auto" for "distribution_sum", but the small program I wrote needed me to specify a float value

That's the one place the demo diverges from the real code: auto distribution_sum = 0.0 is a double, so the first sum is close to exact. The float32 that breaches the tolerance is distribution_sum_desired in the second loop, together with factor, which is computed in float from (float)distribution_sum. Those two are exactly what the PR moves to double.

ACK

LF Updated by Laura Flores 3 months ago Actions #13

As for the coredump, I think we have enough information here already with the osdmap, so that information is just extra if you are able to provide it.

LF Updated by Laura Flores 3 months ago Actions #14

Requested minor changes on the PR.

LS Updated by Lumir Sliva 3 months ago Actions #15

Exact values from osdmap-60osd-65536pg-pgp60800.bin on the pre-fix code, printed right before the asserts in calc_desired_primary_distribution_simple():

  • distribution_sum = 65536.0000000000 and factor = 1.0000000000, both exact
  • distribution_sum_desired (float re-sum) = 65535.9882812500, diff = -0.0117187500

A float at magnitude 65536 has a resolution of 0.0078125, so the fixed 0.01 tolerance was barely one rounding step. That is why the assert trips with every OSD at primary affinity 1.

Per Laura's review on https://github.com/ceph/ceph/pull/71772 the two asserts are now a debug-10 log plus -EINVAL (the caller already skips the pool on a negative rc) instead of an abort. New head is 9425ea22c58; unittest_osdmap 44/44 and the osdmaptool replay on the map above exits 0 with 967 changes.

LF Updated by Laura Flores 3 months ago Actions #16

Approved the PR and sent to testing.

LF Updated by Laura Flores 2 months ago Actions #17

  • Status changed from Fix Under Review to Pending Backport

@Lumir Sliva do you need help with creating backports?

UB Updated by Upkeep Bot 2 months ago Actions #18

  • Copied to Backport #80814: squid: mgr/balancer: upmap-read mode aborts every ceph-mgr — ceph_assert(fabs(distribution_sum_desired - pool->get_pg_num()) < 0.01) is unsatisfiable at large pg_num added

UB Updated by Upkeep Bot 2 months ago Actions #19

  • Copied to Backport #80815: umbrella: mgr/balancer: upmap-read mode aborts every ceph-mgr — ceph_assert(fabs(distribution_sum_desired - pool->get_pg_num()) < 0.01) is unsatisfiable at large pg_num added

UB Updated by Upkeep Bot 2 months ago Actions #20

  • Copied to Backport #80816: tentacle: mgr/balancer: upmap-read mode aborts every ceph-mgr — ceph_assert(fabs(distribution_sum_desired - pool->get_pg_num()) < 0.01) is unsatisfiable at large pg_num added

UB Updated by Upkeep Bot 2 months ago Actions #21

  • Status changed from Pending Backport to Backporting
  • Merge Commit set to 573568185630f176e7cafdea8c66648cf4990746
  • Fixed In set to v21.3.0-3588-g5735681856
  • Upkeep Timestamp set to 2026-09-23T22:04:58+00:00

LS Updated by Lumir Sliva 2 months ago Actions #22

All three are up:

Clean cherry-picks of 9425ea22c58 on all three, hunks byte-identical to main with only the line offsets moving, so no Conflicts: block on any of them. The single production caller of calc_desired_primary_distribution() is identical on every branch, if (rc < 0) block included, so the skip-the-pool return needed no adaptation.

Built and ran unittest_osdmap on each branch: 40/40 squid, 41/41 tentacle, 43/43 umbrella, in every case including the two new regression tests.

UB Updated by Upkeep Bot about 1 month ago Actions #23

  • Status changed from Backporting to Resolved
  • Upkeep Timestamp changed from 2026-09-23T22:04:58+00:00 to 2026-10-29T01:14:57+00:00
Actions

Also available in: PDF Atom