Repository navigation
Implement biased reference counting in --disable-gil builds #110481
Copy link
Copy link
Closed
Labels
3.13only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement
Description
Activity
- addedtype-featureA feature request or enhancementA feature request or enhancementinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)3.13only security fixesonly security fixes
on Oct 6, 2023 - added 4 commits that reference this issue
on Oct 30, 2023 - added a commit that references this issue
on Nov 10, 2023 29 remaining items
Since #117271 was merged,
test_multiprocessingtests are consistently failing on noGIL Refleaks buildbots. For example: https://buildbot.python.org/all/#/builders/1368/builds/606I put up #117370, which fixes the refleaks.
- added 2 commits that reference this issue
on Apr 2, 2024 - added 6 commits that reference this issue
on Sep 2, 2024
Metadata
Metadata
Assignees
Labels
3.13only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement
Feature or enhancement
CPython's current reference counting implementation would not be thread-safe without the GIL. In
--disable-gilbuilds, we should implement biased reference counting, which is thread-safe and has lower execution overhead compared to plain atomic reference counting. The design is described in the "Biased Reference Counting" section of PEP 703.This will require changing the
PyObjectstruct in--disable-gilbuilds. I expect the--disable-gilstruct to look like:Not all the fields will be used immediately, but it will be easier to include them as part of implementing this change.
I intend to split the implementation across (at least) two PRs to make it easier to review.
PyObjectfields and implement the core biased reference counting operations, but not the inter-thread queue to reduce the initial complexity. (done)The inter-thread queue is needed eventually (before actually disabling the GIL), but since the
--disable-gilbuilds still currently require the GIL, it doesn't have to be in the initial PR.Linked PRs
is_shared_refcnt_dead. #111974