Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-123022: Fix crash withPy_Initialize in background thread#123052

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

Merged

Conversation

colesbury
Copy link
Contributor

@colesburycolesbury commentedAug 15, 2024
edited by bedevere-appbot
Loading

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.

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 aninitialized default heap. This is true for our main thread, but not forbackground threads. The problematic code path is usually called duringinitialization (i.e., `Py_Initialize`), but it may also be called if theprogram allocates large amounts of memory in total.The crash only affected the free-threaded build.
@colesbury
Copy link
ContributorAuthor

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,PyThreadState instances may be destroyed by different threads, while mimalloc assumes that the thread's default heap is destroyed when the OS thread exits.

The approach in this PR -- guarding the call to_mi_heap_random -- seemed like it would have the least risk of complications.

@colesburycolesbury marked this pull request as ready for reviewAugust 15, 2024 20:19
@colesbury
Copy link
ContributorAuthor

@Yhg1s - I think it's worth considering this for 3.13rc2. Let me know what you think.

@Yhg1s
Copy link
Member

@Yhg1s - I think it's worth considering this for 3.13rc2. Let me know what you think.

Yeah, this should go into rc2.

@colesburycolesbury merged commitd061ffe intopython:mainAug 17, 2024
42 checks passed
@colesburycolesbury deleted the gh-123022-mi-prim_get_default branchAugust 17, 2024 20:04
@miss-islington-app
Copy link

Thanks@colesbury for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestAug 17, 2024
…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 aninitialized default heap. This is true for our main thread, but not forbackground threads. The problematic code path is usually called duringinitialization (i.e., `Py_Initialize`), but it may also be called if theprogram allocates large amounts of memory in total.The crash only affected the free-threaded build.(cherry picked from commitd061ffe)Co-authored-by: Sam Gross <colesbury@gmail.com>
@bedevere-app
Copy link

GH-123114 is a backport of this pull request to the3.13 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.13bugs and security fixes labelAug 17, 2024
colesbury added a commit that referenced this pull requestAug 17, 2024
…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 aninitialized default heap. This is true for our main thread, but not forbackground threads. The problematic code path is usually called duringinitialization (i.e., `Py_Initialize`), but it may also be called if theprogram allocates large amounts of memory in total.The crash only affected the free-threaded build.(cherry picked from commitd061ffe)Co-authored-by: Sam Gross <colesbury@gmail.com>
jeremyhylton pushed a commit to jeremyhylton/cpython that referenced this pull requestAug 19, 2024
…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 aninitialized default heap. This is true for our main thread, but not forbackground threads. The problematic code path is usually called duringinitialization (i.e., `Py_Initialize`), but it may also be called if theprogram allocates large amounts of memory in total.The crash only affected the free-threaded build.
blhsing pushed a commit to blhsing/cpython that referenced this pull requestAug 22, 2024
…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 aninitialized default heap. This is true for our main thread, but not forbackground threads. The problematic code path is usually called duringinitialization (i.e., `Py_Initialize`), but it may also be called if theprogram allocates large amounts of memory in total.The crash only affected the free-threaded build.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@Yhg1sYhg1sYhg1s approved these changes

@vstinnervstinnerAwaiting requested review from vstinner

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@colesbury@Yhg1s

[8]ページ先頭

©2009-2025 Movatter.jp