-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
gh-137110: Untrack immortal objects from expand_region_transitivity_reachable #137111
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
base: main
Are you sure you want to change the base?
gh-137110: Untrack immortal objects from expand_region_transitivity_reachable #137111
Conversation
|
I'm not sure, but this probably should skip news. |
|
AFAIU moving immortal objects to the |
|
@nascheme Could you please take a look? |
efimov-mikhail
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I can (although not just now). Probably @markshannon would be the most useful reviewer since he's most familiar with that code. |
I'd need to study the GC code more to familiarize myself with how this works. However, would it be possible to change the other case and always move immortal objects to the permanent generation, rather than untracking? I think it's safer to do that, for a couple of reasons. First, the 3.13 GC did not untrack, only move. Second, if an object's dealloc assumes that it is tracked, untracking it could cause a crash (if I would guess that immortal container objects (tracked by the GC) are quite rare. So the performance benefit from untracking should be tiny. |
|
Thanks! We always untrack newly created immortal objects. In the PR that I linked (which unfortunately was reverted), immortal objects were untracked in an analogous function - https://github.com/python/cpython/pull/127519/files#diff-a848a0ef178aa113a092e72403da0e344f37bd141bb90a7aa65015c77bfe7385R1451. Also, IIUC, moving immortal objects to the permanent generation would prevent us from flipping visited and pending spaces unless we remove those objects from the permanent generation. OTOH, the case that handled by this condition is very rare - it is for accidentally immortalized objects. |
The free-threading gc untracks any immortal objects encountered during gc so I think it makes sense to do the same for normal builds as well. |
|
@markshannon Could you please take a look? |
There is some inconsistency in handling of immortal objects in default-build's GC.
In
update_refsimmortal objects just untracked (all immortal objects that we face in GC is an accidentally immortalized).cpython/Python/gc.c
Lines 495 to 500 in 1e69cd1
update_refscalled for all collections (young, increment and full). But for incremental collection ifincrement_size < gcstate->work_to_dowe steal some objects from neighbor gen and callexpand_region_transitively_reachablewhere immortal objects moved to permanent generation:cpython/Python/gc.c
Lines 1397 to 1402 in 1e69cd1
So, one part of immortal objects can be untracked, and other part can be moved to perm gen.
As I understand from #127519 it is preferring to untrack immortal objects in all cases.
CPython versions tested on:
CPython main branch