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-112529: Make the GC scheduling thread-safe#114880

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
colesbury merged 5 commits intopython:mainfromcolesbury:gh-112529-gc-schedule
Feb 16, 2024

Conversation

@colesbury
Copy link
Contributor

@colesburycolesbury commentedFeb 1, 2024
edited by bedevere-appbot
Loading

The GC keeps track of the number of allocations (less deallocations) since the last GC. This change buffers the allocation count in thread-local state and uses atomic operations to modify the per-interpreter count. The thread-local buffering avoids contention on shared state.

A consequence is that the GC scheduling is not as precise, so "test_sneaky_frame_object" is skipped because it requires that the GC be run exactly after allocating a frame object.

The GC keeps track of the number of allocations (less deallocations)since the last GC. This buffers the count in thread-local state and usesatomic operations to modify the per-interpreter count. The thread-localbuffering avoids contention on shared state.A consequence is that the GC scheduling is not as precise, so"test_sneaky_frame_object" is skipped because it requires that the GC berun exactly after allocating a frame object.
Copy link
Member

@ericsnowcurrentlyericsnowcurrently left a comment

Choose a reason for hiding this comment

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

The GC is one of the runtime components with which I am least familiar, so I mostly have questions for you. 😄

Otherwise, the PR mostly makes sense.

@ericsnowcurrently
Copy link
Member

The change here seems okay to me, but I'd feel better if one of the GC experts reviewed this before it's merged.

CC@markshannon@pablogsal@nascheme@DinoV@nanjekyejoannah

colesbury reacted with thumbs up emoji

@nascheme
Copy link
Member

I've not looked at the code but the idea of the change sounds fine to me. I suspect there are some users who require that the GC threshold is precise, like thetest_sneaky_frame_object case. However, I don't think that's a reasonable thing and I think it's okay to break them. We are pretty likely to adjust how the thresholds work anyhow. Using atomic operations to count allocations/dellocations will be too expensive.

// We buffer the allocation count to avoid the overhead of atomic
// operations for every allocation.
gc->alloc_count++;
if (gc->alloc_count >=LOCAL_ALLOC_COUNT_THRESHOLD) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this could be tied to the configurable GC threshold and therefore the tests could continue to pass but maybe it doesn't matter enough and the extra read isn't worth it.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Yeah, I considered making it a configurable runtime threshold, but decided it wasn't worth it, at least for now.

I think there's a decent chance we change how we count allocations in the future. In thenogil forks, for example, I accounted for allocations inmi_page_to_full and_mi_page_unfull, which provides some natural batching and avoids the thread-local that's done in every allocation here, but wouldn't allow for a configurable threshold. I haven't attempted that yet because I'd like some performance measurements to justify it first.

Copy link
Contributor

@DinoVDinoV left a comment

Choose a reason for hiding this comment

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

LGTM!

@colesburycolesbury added the 🔨 test-with-buildbotsTest PR w/ buildbots; report in status section labelFeb 14, 2024
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by@colesbury for commitf99d14e 🤖

If you want to schedule another build, you need to add the🔨 test-with-buildbots label again.

@bedevere-botbedevere-bot removed the 🔨 test-with-buildbotsTest PR w/ buildbots; report in status section labelFeb 14, 2024
@colesburycolesbury merged commitb24c916 intopython:mainFeb 16, 2024
@colesburycolesbury deleted the gh-112529-gc-schedule branchFebruary 16, 2024 16:22
woodruffw pushed a commit to woodruffw-forks/cpython that referenced this pull requestMar 4, 2024
The GC keeps track of the number of allocations (less deallocations)since the last GC. This buffers the count in thread-local state and usesatomic operations to modify the per-interpreter count. The thread-localbuffering avoids contention on shared state.A consequence is that the GC scheduling is not as precise, so"test_sneaky_frame_object" is skipped because it requires that the GC berun exactly after allocating a frame object.
diegorusso pushed a commit to diegorusso/cpython that referenced this pull requestApr 17, 2024
The GC keeps track of the number of allocations (less deallocations)since the last GC. This buffers the count in thread-local state and usesatomic operations to modify the per-interpreter count. The thread-localbuffering avoids contention on shared state.A consequence is that the GC scheduling is not as precise, so"test_sneaky_frame_object" is skipped because it requires that the GC berun exactly after allocating a frame object.
LukasWoodtli pushed a commit to LukasWoodtli/cpython that referenced this pull requestJan 22, 2025
The GC keeps track of the number of allocations (less deallocations)since the last GC. This buffers the count in thread-local state and usesatomic operations to modify the per-interpreter count. The thread-localbuffering avoids contention on shared state.A consequence is that the GC scheduling is not as precise, so"test_sneaky_frame_object" is skipped because it requires that the GC berun exactly after allocating a frame object.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@ericsnowcurrentlyericsnowcurrentlyericsnowcurrently left review comments

@DinoVDinoVDinoV approved these changes

@naschemenaschemeAwaiting requested review from nascheme

@pablogsalpablogsalAwaiting requested review from pablogsalpablogsal is a code owner

@markshannonmarkshannonAwaiting requested review from markshannonmarkshannon is a code owner

Assignees

No one assigned

Labels

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

5 participants

@colesbury@ericsnowcurrently@nascheme@bedevere-bot@DinoV

[8]ページ先頭

©2009-2025 Movatter.jp