GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-137110: Untrack immortal objects from expand_region_transitivity_reachable by sergey-miryanov · Pull Request #137111 · python/cpython Conversation
|
| if (_Py_IsImmortal(op)) { | |
| assert(!_Py_IsStaticImmortal(op)); | |
| _PyObject_GC_UNTRACK(op); | |
| gc = next; | |
| continue; | |
| } |
update_refs called for all collections (young, increment and full). But for incremental collection if increment_size < gcstate->work_to_do we steal some objects from neighbor gen and call expand_region_transitively_reachable where immortal objects moved to permanent generation:
Lines 1397 to 1402 in 1e69cd1
| if (_Py_IsImmortal(op)) { | |
| PyGC_Head *next = GC_NEXT(gc); | |
| gc_list_move(gc, &gcstate->permanent_generation.head); | |
| gc = next; | |
| continue; | |
| } |
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 main branch
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I'm not sure, but this probably should skip news. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
AFAIU moving immortal objects to the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@nascheme Could you please take a look? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I can (although not just now). Probably @markshannon would be the most useful reviewer since he's most familiar with that code. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@markshannon Could you please take a look? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This PR is stale because it has been open for 30 days with no activity. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Now that the generational GC has landed, I'll close this as obsolete. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.