Skip to content

mgr: erase daemon_connections ref on reset for all peer types - #70367

Merged
NitzanMordhai merged 1 commit into
ceph:mainfrom
Nordix:Sunnatillo/fix-mgr-memory-leak
Aug 12, 2026
Merged

NitzanMordhai merged 1 commit into
ceph:mainfrom
Nordix:Sunnatillo/fix-mgr-memory-leak

Conversation

@Sunnatillo

@Sunnatillo Sunnatillo commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

This PR fixes the problem below:

ceph-mgr exhibits a slow, roughly linear RSS increase (~1–2 MiB/hour) that never
plateaus. On a long-running cluster this grows without bound until the mgr is
restarted or OOM-killed.

How we tracked it down

We approached this as an elimination-based investigation rather than guessing at a
fix, narrowing the cause step by step:

  1. Confirmed it's real live-heap growth, not fragmentation. tcmalloc heap-profile
    totals tracked RSS closely over many hours.
  2. Identified the growing object type. pprof --base diffs across profiles
    attributed ~100% of the growth to AsyncConnection objects allocated on the
    inbound-accept path (AsyncMessenger::add_accept) of the mgr server messenger.
  3. Ruled out the messenger tracking sets. conns, anon_conns, accepting_conns,
    and deleted_conns were all dumped and shown to be bounded and oscillating — they
    drain, so they can't explain monotonic growth. (deleted_conns is reap-threshold
    gated; the accepting_conns anon double-membership is a separate bounded smell.)
  4. Traced the object lifecycle with bpftrace. Over a multi-hour window, _stop(),
    cleanup(), and the destructors were probed. cleanup() ran 1:1 with _stop() for
    the leaked cohort, yet those connections were never destroyed — ruling out lost
    clean-up events and the handler refs themselves.
  5. Narrowed to a surviving strong reference held after cleanup(). The leaked
    AsyncConnections were stopped, cleaned, and removed from every messenger set, but
    still alive — so a ConnectionRef was outliving teardown somewhere above the
    messenger layer.
  6. Audited the mgr-side ConnectionRef owners and found the asymmetry below.

Root cause

handle_open() stores a strong ConnectionRef in daemon_connections for every
non-client daemon (mon, mds, osd), but ms_handle_reset() erased it only for OSD peers.

Any non-OSD daemon connection that ended without an explicit MMgrClose (idle timeout,
network drop, daemon crash) left a permanent ConnectionRef behind. That leaked one
AsyncConnection per reconnect cycle and caused unbounded ceph-mgr RSS growth.

The reset handler delivers for lossy connections (which is every connection this
messenger accepts), so once the no-op-for-non-OSD reset returns, the stale
daemon_connections entry becomes the sole surviving owner — exactly matching the
bpftrace observation (cleaned but never destroyed).

Fix

Erase daemon_connections unconditionally on reset while keeping osd_cons cleanup
under the OSD peer-type guard.

Fixes: https://tracker.ceph.com/issues/78408

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

@Sunnatillo
Sunnatillo requested a review from a team as a code owner July 21, 2026 08:29
@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

16 similar comments
@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ifed01

ifed01 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

ok to test

@SrinivasaBharath

Copy link
Copy Markdown
Contributor

This PR has been added to wip-bharath8-testing-20260721.232151-main.

@vshankar
vshankar requested a review from NitzanMordhai July 22, 2026 04:17
@NitzanMordhai

Copy link
Copy Markdown
Contributor

@Sunnatillo

Copy link
Copy Markdown
Contributor Author

I can confirm this has fixed the issue for us.

bazaah added a commit to bazaah/aur-ceph that referenced this pull request Aug 8, 2026
Fixes a slow memory leak that didn't make it's way into the .3 release

References: ceph/ceph#70367
Upstream-ref: ceph/ceph@e1edb48
@SrinivasaBharath

Copy link
Copy Markdown
Contributor

@Sunnatillo @NitzanMordhai -Testing is complete. Once the review is finished, feel free to merge. If a rerun is needed, add the needs-qa label.

@NitzanMordhai NitzanMordhai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sunnatillo, other than the debugging message request, all looks good

Comment thread src/mgr/DaemonServer.cc Resolved
…types

handle_open() stores a strong ConnectionRef in daemon_connections for
every non-client daemon (mon, mds, osd), but ms_handle_reset() erased
it only for OSD peers.

Any non-OSD daemon connection that ended without an explicit MMgrClose
(idle timeout, network drop, daemon crash) left a permanent
ConnectionRef behind. That leaked one AsyncConnection per reconnect
cycle and caused unbounded ceph-mgr RSS growth.

Erase daemon_connections unconditionally on reset while keeping
osd_cons cleanup under the OSD peer-type guard.

Fixes: https://tracker.ceph.com/issues/78408

Signed-off-by: Sunnatillo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants