FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-143057: Use atomics for _PyRuntime.tracemalloc.config.tracing by Yhg1s · Pull Request #143066 · python/cpython · GitHub

Repository navigation

gh-143057: Use atomics for _PyRuntime.tracemalloc.config.tracing - #143066

Closed
Yhg1s wants to merge 1 commit into
python:mainfrom
Yhg1s:tracemalloc_atomic_check
Closed

Yhg1s wants to merge 1 commit into
python:mainfrom
Yhg1s:tracemalloc_atomic_check

Conversation

Yhg1s commented Dec 22, 2025 •
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

Use atomics for the _PyRuntime.tracemalloc.config.tracing so we can bail 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).

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).
Comment thread Python/tracemalloc.c
/* everything is ready: start tracing Python memory allocations */
TABLES_LOCK();
tracemalloc_config.tracing = 1;
_Py_atomic_store_int_release(&tracemalloc_config.tracing, 1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Yhg1s closed this Dec 22, 2025
Yhg1s deleted the tracemalloc_atomic_check branch August 13, 2026 12:51
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL