gh-143057: Use atomics for _PyRuntime.tracemalloc.config.tracing#143066
Closed
Yhg1s wants to merge 1 commit intopython:mainfrom
Closed
gh-143057: Use atomics for _PyRuntime.tracemalloc.config.tracing#143066Yhg1s wants to merge 1 commit intopython:mainfrom
Yhg1s wants to merge 1 commit intopython:mainfrom
Conversation
early in `PyTraceMalloc_Track` and `PyTraceMalloc_Untrack` if 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).
| /* everything is ready: start tracing Python memory allocations */ | ||
| TABLES_LOCK(); | ||
| tracemalloc_config.tracing = 1; | ||
| _Py_atomic_store_int_release(&tracemalloc_config.tracing, 1); |
Contributor
There was a problem hiding this comment.
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 of tracing matters.
Member
Author
There was a problem hiding this comment.
I think there is 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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).