Skip to content

Conversation

@kevmo314
Copy link
Contributor

@kevmo314 kevmo314 commented Dec 3, 2025

Fixes some lost allocation counts in the local allocation counters when threads are cleaned up.

// Flush the thread's local GC allocation count to the global count
// before the thread state is cleared, otherwise the count is lost.
_PyThreadStateImpl *tstate_impl = (_PyThreadStateImpl *)tstate;
_Py_atomic_add_int(&tstate->interp->gc.young.count,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since this is less common perhaps it's ok to allow the global GC count to go negative here? The compare-and-exchange loop is more accurate though, I can update to use that if preferred.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I think going negative here is fine

@colesbury colesbury self-requested a review December 4, 2025 21:54
@kumaraditya303 kumaraditya303 added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Dec 10, 2025
@kumaraditya303 kumaraditya303 enabled auto-merge (squash) December 10, 2025 07:04
@kumaraditya303 kumaraditya303 merged commit 49b1fb4 into python:main Dec 10, 2025
46 checks passed
@miss-islington-app
Copy link

Thanks @kevmo314 for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Dec 10, 2025
@miss-islington-app
Copy link

Sorry, @kevmo314 and @kumaraditya303, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 49b1fb43f65290dadeb83ed6f7c0c74995fda7a1 3.13

@bedevere-app
Copy link

bedevere-app bot commented Dec 10, 2025

GH-142504 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Dec 10, 2025
@bedevere-app
Copy link

bedevere-app bot commented Dec 10, 2025

GH-142506 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Dec 10, 2025
kumaraditya303 pushed a commit to kumaraditya303/cpython that referenced this pull request Dec 10, 2025
kumaraditya303 pushed a commit that referenced this pull request Dec 10, 2025
…-142233) (#142504)

gh-142048: Fix lost gc allocations count on thread cleanup (GH-142233)
(cherry picked from commit 49b1fb4)

Co-authored-by: Kevin Wang <[email protected]>
kumaraditya303 pushed a commit to kumaraditya303/cpython that referenced this pull request Dec 10, 2025
kumaraditya303 added a commit that referenced this pull request Dec 11, 2025
#142506)

[3.13] gh-142048: Fix lost gc allocations count on thread cleanup (GH-142233)
(cherry picked from commit 49b1fb4)

Co-authored-by: Kevin Wang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants