Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep ob_tid, ob_ref_local, and ob_ref_shared fields valid across allocations in free-threaded build #115491

Closed
Tracked by #108219
colesbury opened this issue Feb 14, 2024 · 1 comment
Assignees
Labels
topic-free-threading type-feature A feature request or enhancement

Comments

@colesbury
Copy link
Contributor

colesbury commented Feb 14, 2024

Feature or enhancement

The free-threaded implementation of dict and list try avoid acquiring locks during read operations. To support this, we need to be able to access the reference count fields of Python objects after they are deallocated (and possibly reallocated). Some of this support is provided by #115103. Additionally, we need to ensure that the debug allocators do not overwrite these fields with "dead" bytes 0xDD, which might make the object look "alive" by having a non-zero reference count.

We still would like to overwrite the rest of the allocation (i.e., from ob_type onwards) to detect use-after-frees in debug builds.

See also: https://peps.python.org/pep-0703/#optimistically-avoiding-locking

Linked PRs

@colesbury colesbury added type-feature A feature request or enhancement topic-free-threading labels Feb 14, 2024
@colesbury colesbury self-assigned this Feb 15, 2024
colesbury added a commit to colesbury/cpython that referenced this issue Feb 16, 2024
…ading)

This avoids filling the memory occupied by ob_tid, ob_ref_local, and
ob_ref_shared with debug bytes (e.g., 0xDD) in mimalloc in the
free-threaded build.
colesbury added a commit to colesbury/cpython that referenced this issue Feb 16, 2024
colesbury added a commit that referenced this issue Feb 20, 2024
…#115573)

This avoids filling the memory occupied by ob_tid, ob_ref_local, and
ob_ref_shared with debug bytes (e.g., 0xDD) in mimalloc in the
free-threaded build.
colesbury added a commit to colesbury/cpython that referenced this issue Feb 20, 2024
@colesbury
Copy link
Contributor Author

This still needs the mimalloc support in #115103 to fully preserve the fields, but the changes to filling debug bytes is done now.

colesbury added a commit to colesbury/cpython that referenced this issue Feb 29, 2024
DinoV pushed a commit that referenced this issue Mar 1, 2024
woodruffw pushed a commit to woodruffw-forks/cpython that referenced this issue Mar 4, 2024
…ading) (python#115573)

This avoids filling the memory occupied by ob_tid, ob_ref_local, and
ob_ref_shared with debug bytes (e.g., 0xDD) in mimalloc in the
free-threaded build.
woodruffw pushed a commit to woodruffw-forks/cpython that referenced this issue Mar 4, 2024
woodruffw pushed a commit to woodruffw-forks/cpython that referenced this issue Mar 4, 2024
adorilson pushed a commit to adorilson/cpython that referenced this issue Mar 25, 2024
diegorusso pushed a commit to diegorusso/cpython that referenced this issue Apr 17, 2024
…ading) (python#115573)

This avoids filling the memory occupied by ob_tid, ob_ref_local, and
ob_ref_shared with debug bytes (e.g., 0xDD) in mimalloc in the
free-threaded build.
diegorusso pushed a commit to diegorusso/cpython that referenced this issue Apr 17, 2024
diegorusso pushed a commit to diegorusso/cpython that referenced this issue Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-free-threading type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant