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

gh-112532: Isolate abandoned segments by interpreter #113717

Merged
merged 2 commits into from Jan 4, 2024

Conversation

colesbury
Copy link
Contributor

@colesbury colesbury commented Jan 4, 2024

Mimalloc segments are data structures that contain memory allocations along with metadata. Each segment is "owned" by a thread. When a thread exits, it abandons its segments to a global pool to be later reclaimed by other threads. This changes the pool to be per-interpreter instead of process-wide.

This will be important for when we use mimalloc to find GC objects in the --disable-gil builds. We want heaps to only store Python objects from a single interpreter. Absent this change, the abandoning and reclaiming process could break this isolation.

Mimalloc segments are data structures that contain memory allocations along
with metadata. Each segment is "owned" by a thread. When a thread exits,
it abandons its segments to a global pool to be later reclaimed by other
threads. This changes the pool to be per-interpreter instead of process-wide.

This will be important for when we use mimalloc to find GC objects in the
`--disable-gil` builds. We want heaps to only store Python objects from a
single interpreter. Absent this change, the abandoning and reclaiming process
could break this isolation.
Copy link
Contributor

@DinoV DinoV left a comment

Choose a reason for hiding this comment

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

This probably doesn't matter for the actual Python usage because we use _mi_heap_init_ex, but do we need to initialize some value for tld_empty or set it in _mi_heap_init when we're off the main thread? I would think it just needs to be &_mi_abandoned_default to preserve the existing behavior.

@colesbury
Copy link
Contributor Author

@DinoV - yeah, that's right. I added the missing &_mi_abandoned_default to tld_empty.

@DinoV DinoV enabled auto-merge (squash) January 4, 2024 21:59
@DinoV DinoV merged commit fcb3c2a into python:main Jan 4, 2024
32 checks passed
@colesbury colesbury deleted the gh-112532-abandoned-segments branch January 4, 2024 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 new features, bugs and security fixes skip news topic-free-threading
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants