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.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -850,7 +850,7 @@ _PyTraceMalloc_Start(int max_nframe) | ||
| /* everything is ready: start tracing Python memory allocations */ | ||
| TABLES_LOCK(); | ||
| _Py_atomic_store_int_release(&tracemalloc_config.tracing, 1); | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 of MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
| TABLES_UNLOCK(); | ||
| return 0; | ||
| @@ -867,7 +867,7 @@ _PyTraceMalloc_Stop(void) | ||
| } | ||
| /* stop tracing Python memory allocations */ | ||
| _Py_atomic_store_int_release(&tracemalloc_config.tracing, 0); | ||
| /* unregister the hook on memory allocators */ | ||
| PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &allocators.raw); | ||
| @@ -1207,6 +1207,12 @@ int | ||
| PyTraceMalloc_Track(unsigned int domain, uintptr_t ptr, | ||
| size_t size) | ||
| { | ||
| if (!_Py_atomic_load_int_relaxed(&tracemalloc_config.tracing)) { | ||
| // Exit early without attempting to lock if it doesn't look like | ||
| // we're tracing. | ||
| return -2; | ||
| } | ||
| PyGILState_STATE gil_state = PyGILState_Ensure(); | ||
| TABLES_LOCK(); | ||
| @@ -1215,7 +1221,7 @@ PyTraceMalloc_Track(unsigned int domain, uintptr_t ptr, | ||
| result = tracemalloc_add_trace_unlocked(domain, ptr, size); | ||
| } | ||
| else { | ||
| /* tracemallocwas disabled before we locked tables;do nothing. */ | ||
| result = -2; | ||
| } | ||
| @@ -1228,6 +1234,11 @@ PyTraceMalloc_Track(unsigned int domain, uintptr_t ptr, | ||
| int | ||
| PyTraceMalloc_Untrack(unsigned int domain, uintptr_t ptr) | ||
| { | ||
| if (!_Py_atomic_load_int_relaxed(&tracemalloc_config.tracing)) { | ||
| // Exit early without attempting to lock if it doesn't look like | ||
| // we're tracing. | ||
| return -2; | ||
| } | ||
| TABLES_LOCK(); | ||
| int result; | ||
| @@ -1236,7 +1247,7 @@ PyTraceMalloc_Untrack(unsigned int domain, uintptr_t ptr) | ||
| result = 0; | ||
| } | ||
| else { | ||
| /* tracemallocwas disabled before we locked tables;do nothing. */ | ||
| result = -2; | ||
| } | ||
Uh oh!
There was an error while loading.Please reload this page.