Repository navigation
mgr: make map cache ownership explicit - #73426
Conversation
|
@NitzanMordhai and @sseshasa , could you please review this change? While reading #72727, I found the code might be difficult to reason about long term, so I wanted to introduce this refactor modeled after Rust’s memory model. Thanks! |
NitzanMordhai
left a comment
There was a problem hiding this comment.
@tchaikov thanks! looks much better, can you please check my comments?
9a655a2 to
e6c31dd
Compare
|
@NitzanMordhai thanks for your constructive suggestions. all addressed. could you take another look? |
NitzanMordhai
left a comment
There was a problem hiding this comment.
LGTM, thanks for the fixes!
sseshasa
left a comment
There was a problem hiding this comment.
LGTM. I just had a non-blocking comment.
|
jenkins test signed |
|
jenkins test make check |
|
jenkins test make check arm64 |
|
jenkins test submodules |
|
jenkins test api |
|
jenkins test windows |
7681a44 to
79cb942
Compare
MgrMapCache uses raw PyObject pointers with different ownership rules for insertion and lookup. Callers must track reference counts by hand, and cache operations must remember to drain pending releases. Changes to error paths or cache operations can easily miss one of these steps. Use a move-only PyObjectRef to make ownership explicit. Insertion takes ownership; lookup returns a separate reference through clone(). Keep raw reference adoption and transfer at the Python C API boundary. Pass the cache decision to get_python so snapshot formatting and insertion use the same decision. Remove the duplicated predicate and its redundant PyGILState_Check. Notification paths hold manager locks without the GIL, so they cannot safely release Python references. Mark entries stale and keep at most one stale reference per key. The next lookup or replacement releases it with the GIL after dropping the cache lock. Clear, disable and shutdown extract references before destroying them with the GIL. On Python 3.13 and later, use PyThreadState_GetUnchecked to preserve an attached interpreter, and acquire the GIL when no state is attached. On older Python, use PyGILState_Ensure and let subinterpreter callers clear explicitly with their GIL held. Avoid the private unchecked getter, which can return another thread's state before Python 3.12. Finalizers can re-enter the cache safely. Reclamation stays synchronous and no longer needs a pending-release queue. Remove the unused generic MgrMapCache and use LFUCache as a member. Let LFUCache hold move-only values and return removed values for destruction outside its lock. Prefer stale entries for eviction and reject writes when capacity is zero. Track a generation for each cacheable key so a notification during snapshot creation prevents insertion of the stale snapshot. Bump the generation even when the key has no entry, and check it under the same lock as insertion. Clear, disable and erasure also reject snapshots that started before them. This builds on the existing leak fix. Signed-off-by: Kefu Chai <[email protected]>
79cb942 to
5a424f7
Compare
|
jenkins test make check |
|
jenkins test make check arm64 |
|
jenkins test make check |
|
This PR has been added to wip-bharath10-testing-20261109.054620-main. |
MgrMapCacheuses rawPyObjectpointers with different ownership rules for insertion and lookup. Callers must track reference counts by hand, and cache operations must remember to drain pending releases. Changes to error paths or cache operations can easily miss one of these steps.Use a move-only
PyObjectRefto make ownership explicit. Insertion takes ownership; lookup returns a separate reference throughclone(). Keep raw reference adoption and transfer at the Python C API boundary.Notification paths hold manager locks without the GIL, so they cannot safely release Python references. Mark entries stale and keep at most one stale reference per key. The next lookup or replacement releases it with the GIL after dropping the cache lock. Clear, disable and shutdown extract references before destroying them with the GIL, preserving the caller's Python context. Finalizers can then re-enter the cache safely. Reclamation stays synchronous and no longer needs a pending-release queue.
Remove the unused generic
MgrMapCacheand useLFUCacheas a member. Let LFUCache hold move-only values and return removed values for destruction outside its lock. Prefer stale entries for eviction and reject writes when capacity is zero.This is an ownership cleanup on top of the existing leak fix.
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
xbetween the brackets:[x]. Spaces and capitalization matter when checking off items this way.Checklist
Show available Jenkins commands
jenkins test classic perfJenkins Job | Jenkins Job Definitionjenkins test crimson perfJenkins Job | Jenkins Job Definitionjenkins test signedJenkins Job | Jenkins Job Definitionjenkins test make checkJenkins Job | Jenkins Job Definitionjenkins test make check arm64Jenkins Job | Jenkins Job Definitionjenkins test submodulesJenkins Job | Jenkins Job Definitionjenkins test dashboardJenkins Job | Jenkins Job Definitionjenkins test dashboard cephadmJenkins Job | Jenkins Job Definitionjenkins test apiJenkins Job | Jenkins Job Definitionjenkins test docsReadTheDocs | Github Workflow Definitionjenkins test ceph-volume allJenkins Jobs | Jenkins Jobs Definitionjenkins test windowsJenkins Job | Jenkins Job Definitionjenkins test rook e2eJenkins Job | Jenkins Job DefinitionYou must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.