Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34k
gh-143057: Use atomics for _PyRuntime.tracemalloc.config.tracing#143066
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
early in `PyTraceMalloc_Track` and `PyTraceMalloc_Untrack` if tracemallocisn't enabled. This avoids a significant scaling issue when tracemallocisn't enabled, in extension modules that properly use thePyTraceMalloc_Track API (like numpy).
| /* everything is ready: start tracing Python memory allocations */ | ||
| TABLES_LOCK(); | ||
| tracemalloc_config.tracing=1; | ||
| _Py_atomic_store_int_release(&tracemalloc_config.tracing,1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I think release is stronger than necessary because there are no data dependencies. The actual functions are called with the lock held anyways so only atomicity oftracing matters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I think thereis a hidden data dependency: we don't want tracing to be enabled, an allocation to be tracked, and then another thread deallocating that tracked data without untracking.
Uh oh!
There was an error while loading.Please reload this page.
Use atomics for the _PyRuntime.tracemalloc.config.tracing so we can bail early in
PyTraceMalloc_TrackandPyTraceMalloc_Untrackif tracemalloc isn't enabled. This avoids a significant scaling issue when tracemalloc isn't enabled, in extension modules that properly use the PyTraceMalloc_Track API (like numpy).