-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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-123022: Fix crash with Py_Initialize
in background thread
#123052
gh-123022: Fix crash with Py_Initialize
in background thread
#123052
Conversation
Check that the current default heap is initialized in `_mi_os_get_aligned_hint` and `mi_os_claim_huge_pages`. The mimalloc function `_mi_os_get_aligned_hint` assumes that there is an initialized default heap. This is true for our main thread, but not for background threads. The problematic code path is usually called during initialization (i.e., `Py_Initialize`), but it may also be called if the program allocates large amounts of memory in total. The crash only affected the free-threaded build.
We may want to consider setting the default heap in the future, but that would be a more involved change because CPython's thread destruction process doesn't line up perfectly with mimalloc's model. In particular, The approach in this PR -- guarding the call to |
@Yhg1s - I think it's worth considering this for 3.13rc2. Let me know what you think. |
Yeah, this should go into rc2. |
Thanks @colesbury for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13. |
…ythonGH-123052) Check that the current default heap is initialized in `_mi_os_get_aligned_hint` and `mi_os_claim_huge_pages`. The mimalloc function `_mi_os_get_aligned_hint` assumes that there is an initialized default heap. This is true for our main thread, but not for background threads. The problematic code path is usually called during initialization (i.e., `Py_Initialize`), but it may also be called if the program allocates large amounts of memory in total. The crash only affected the free-threaded build. (cherry picked from commit d061ffe) Co-authored-by: Sam Gross <[email protected]>
GH-123114 is a backport of this pull request to the 3.13 branch. |
…GH-123052) (#123114) Check that the current default heap is initialized in `_mi_os_get_aligned_hint` and `mi_os_claim_huge_pages`. The mimalloc function `_mi_os_get_aligned_hint` assumes that there is an initialized default heap. This is true for our main thread, but not for background threads. The problematic code path is usually called during initialization (i.e., `Py_Initialize`), but it may also be called if the program allocates large amounts of memory in total. The crash only affected the free-threaded build. (cherry picked from commit d061ffe) Co-authored-by: Sam Gross <[email protected]>
…ython#123052) Check that the current default heap is initialized in `_mi_os_get_aligned_hint` and `mi_os_claim_huge_pages`. The mimalloc function `_mi_os_get_aligned_hint` assumes that there is an initialized default heap. This is true for our main thread, but not for background threads. The problematic code path is usually called during initialization (i.e., `Py_Initialize`), but it may also be called if the program allocates large amounts of memory in total. The crash only affected the free-threaded build.
…ython#123052) Check that the current default heap is initialized in `_mi_os_get_aligned_hint` and `mi_os_claim_huge_pages`. The mimalloc function `_mi_os_get_aligned_hint` assumes that there is an initialized default heap. This is true for our main thread, but not for background threads. The problematic code path is usually called during initialization (i.e., `Py_Initialize`), but it may also be called if the program allocates large amounts of memory in total. The crash only affected the free-threaded build.
Check that the current default heap is initialized in
_mi_os_get_aligned_hint
andmi_os_claim_huge_pages
.The mimalloc function
_mi_os_get_aligned_hint
assumes that there is an initialized default heap. This is true for our main thread, but not for background threads. The problematic code path is usually called during initialization (i.e.,Py_Initialize
), but it may also be called if the program allocates large amounts of memory in total.The crash only affected the free-threaded build.
Py_Initialize
in non-main thread in free-threading build #123022