GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Implement biased reference counting in `--disable-gil` builds · Issue #110481 · python/cpython

Implement biased reference counting in --disable-gil builds #110481

New issue
Copy link
New issue
Copy link
Closed
Closed
Implement biased reference counting in --disable-gil builds#110481
Copy link
Assignees
colesbury
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

@colesbury
colesbury
opened on Oct 6, 2023
Issue body actions

Feature or enhancement

CPython's current reference counting implementation would not be thread-safe without the GIL. In --disable-gil builds, 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 PyObject struct in --disable-gil builds. I expect the --disable-gil struct to look like:

struct _object {
  uintptr_t ob_tid;
  uint16_t _padding;
  uint8_t ob_mutex;
  uint8_t ob_gc_bits;
  uint32_t ob_ref_local;
  Py_ssize_t ob_ref_shared;
  PyTypeObject *ob_type;
};

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.

  1. The first PR will add the new PyObject fields and implement the core biased reference counting operations, but not the inter-thread queue to reduce the initial complexity. (done)
  2. A later PR will implement the inter-thread queue. (not yet implemented)

The inter-thread queue is needed eventually (before actually disabling the GIL), but since the --disable-gil builds still currently require the GIL, it doesn't have to be in the initial PR.

Linked PRs

  • gh-110481: Implement biased reference counting #110764
  • gh-110481: Fix _Py_ThreadId for non-free-threaded mode #111503
  • gh-110481: Non-limited Py_INCREF/DECREF() in cpython/object.h #111505
  • gh-110481: Implement _Py_DECREF_NO_DEALLOC for free-threaded build #111560
  • gh-110481: fix 'unused function' warning for is_shared_refcnt_dead. #111974
  • gh-110481: Fix Py_SET_REFCNT() integer overflow #112174
  • gh-110481, doc: Add "immortal" term to the glossary #112180
  • gh-110481: Fix typo in Py_SET_REFCNT() #112595
  • gh-110481: Implement inter-thread queue for biased reference counting #114824
  • gh-110481: Fix biased reference counting queue initialization. #117271
Reacted by Donghee Na, An Long, Michael Droettboom and Gregory P. Smith
Reacted by stonebig, jon-chuang, Vladimir and Amuthan Mannar
Reacted by Dima Tisnek

Activity

Next
  1. colesbury
    added
    type-featureA feature request or enhancementA feature request or enhancement
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    3.13only security fixesonly security fixes
    on Oct 6, 2023
  2. colesbury
    self-assigned this
    on Oct 12, 2023
  3. corona10
    added 2 commits that reference this issue on Oct 30, 2023

    gh-110481: Implement biased reference counting (gh-110764)

    6dfb8fe

    pythongh-110481: Fix build bot for free-threaded mode

    8ef44ef
  4. vstinner
    added 4 commits that reference this issue on Oct 30, 2023

    pythongh-110481: Non-limited Py_INCREF/DECREF() in cpython/object.h

    3088de3

    pythongh-110481: Non-limited Py_INCREF/DECREF() in cpython/object.h

    0e9c6c2

    pythongh-110481: Move non-limited Py_INCREF() to cpython/object.h

    5b93bdd

    pythongh-110481: Move non-limited Py_INCREF() to cpython/object.h

    2d3a76e
  5. corona10
    added 2 commits that reference this issue on Oct 30, 2023

    gh-110481: Fix _Py_ThreadId for non-free-threaded mode (gh-111503)

    55df2de

    pythongh-110481: Implement _Py_DECREF_NO_DEALLOC for free-threaded build

    6c2ffb8
  6. FullteaR
    added 2 commits that reference this issue on Nov 3, 2023

    pythongh-110481: Implement biased reference counting (pythongh-110764)

    6a480d8

    pythongh-110481: Fix _Py_ThreadId for non-free-threaded mode (pythong…

    2efd0c7
  7. corona10
    added a commit that references this issue on Nov 10, 2023

    gh-110481: fix 'unused function' warning for `is_shared_refcnt_dead`. (…

    fa84e5f
  8. 29 remaining items

  9. colesbury
    added 2 commits that reference this issue on Mar 27, 2024

    Merge branch 'pythongh-110481-brc-bind' into nogil-integration

    11897fc

    gh-110481: Fix biased reference counting queue initialization. (#117271)

    8dbfdb2
  10. encukou commented on Mar 29, 2024

    @encukou
    encukou
    on Mar 29, 2024
    Member
    More actions

    Since #117271 was merged, test_multiprocessing tests are consistently failing on noGIL Refleaks buildbots. For example: https://buildbot.python.org/all/#/builders/1368/builds/606

  11. encukou
    reopened this on Mar 29, 2024
  12. colesbury commented on Mar 29, 2024

    @colesbury
    colesbury
    on Mar 29, 2024
    ContributorAuthor
    More actions

    I put up #117370, which fixes the refleaks.

  13. NGRsoftlab
    added 2 commits that reference this issue on Apr 2, 2024

    Squashed commit of the following:

    1b5fe4c

    Squashed commit of the following:

    a016a54
  14. colesbury
    closed this as completedon Apr 10, 2024
  15. diegorusso
    added a commit that references this issue on Apr 17, 2024

    pythongh-110481: Fix biased reference counting queue initialization. (p…

    dc8140b
  16. Glyphack
    added 6 commits that reference this issue on Sep 2, 2024

    pythongh-110481: Implement biased reference counting (pythongh-110764)

    2295beb

    pythongh-110481: Fix _Py_ThreadId for non-free-threaded mode (pythong…

    8a0a8b8

    pythongh-110481: fix 'unused function' warning for `is_shared_refcnt_…

    29f912a

    pythongh-110481, doc: Add "immortal" term to the glossary (python#112180

    06048e1

    pythongh-110481: Fix Py_SET_REFCNT() integer overflow (python#112174)

    ac8e22b

    pythongh-110481: Fix typo in Py_SET_REFCNT() (python#112595)

    33fba34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @colesbury
    colesbury

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

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.