Bug #81794
closedmgr: MgrMapCache leaks every erased Python object, prometheus causes ~400MB/min growth on large clusters
0%
Description
ceph-mgr memory grows without limit when prometheus is enabled. On a cluster with 10K PGs, mgr RSS grew about 400MB per minute (526MB to 7GB in 17 minutes) and never leveled off. With prometheus disabled it stayed flat at about 278MB.
The growth is Python objects held by C++, not tcmalloc. tcmalloc reported 1.9GB in use while RSS was 7.3GB. tracemalloc showed each prometheus collect leaving one full pg_dump alive (about 90MB, 1.26M objects). After the next collect, the previous pg_dump was still alive with refcount 1 and no Python
referrers.
Root cause:
MgrMapCache<PyObject*>::erase() drops the cache's reference through Py_AddPendingCall(). That call only queues the function for the main thread of the main interpreter. CPython only run pending calls on the main thread, and the ceph-mgr main thread never runs Python, so the queued Py_DECREF
never runs. Once the queue is full the call returns -1, which erase() ignores. Either way every erased entry keeps its reference.
Every cache invalidation of pg_dump (and the other cached keys) leaks the cached object. prometheus fetches pg_dump on every scrape, so the cache is refilled and leaked again each time. The leak scales with PG count, so small test clusters show only a few MB per hour.
Reproduce:
1. vstart with 1 mon, 1 mgr, and about 10 OSDs. We used fake OSDs reporting 10K PGs.
2. Create a pool with 10000 PGs.
3. ceph mgr module enable prometheus
4. Watch the RSS of the ceph-mgr process. It grows steadily.
5. ceph config set mgr mgr_map_cache_enabled false stops the growth.
Workaround: ceph config set mgr mgr_map_cache_enabled false
Fix: queue erased objects in the cache, and drop them on the next get() or insert(), which already hold the GIL. Freeing them directly in erase() isn't safe, because it runs from notify paths that hold ActivePyModules::lock without the GIL. With the fix, the previous pg_dump is freed after every collect and
RSS stays flat at about 546MB at 10K PGs.
NM Updated by Nitzan Mordechai about 2 months ago
- Description updated (diff)
NM Updated by Nitzan Mordechai about 2 months ago
- Status changed from In Progress to Fix Under Review
- Pull request ID set to 72727
NM Updated by Nitzan Mordechai about 1 month ago
- Status changed from Fix Under Review to Pending Backport
UB Updated by Upkeep Bot about 1 month ago
- Copied to Backport #82489: umbrella: mgr: MgrMapCache leaks every erased Python object, prometheus causes ~400MB/min growth on large clusters added
UB Updated by Upkeep Bot about 1 month ago
- Status changed from Pending Backport to Backporting
- Merge Commit set to 4f1994254f247c34dad3b345121cb68dd028aff4
- Fixed In set to v22.0.0-205-g4f1994254f
- Upkeep Timestamp set to 2026-11-01T07:50:32+00:00
NM Updated by Nitzan Mordechai about 1 month ago
- Has duplicate Bug #82397: umbrealla 21.2.0 memory leak after upgrading added
UB Updated by Upkeep Bot 24 days ago
- Status changed from Backporting to Resolved
- Upkeep Timestamp changed from 2026-11-01T07:50:32+00:00 to 2026-11-10T01:00:58+00:00