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 — Use per-thread freelists in `--disable-gil` builds · Issue #111968 · python/cpython

Use per-thread freelists in --disable-gil builds #111968

New issue
Copy link
New issue
Copy link
Closed
Closed
Use per-thread freelists in --disable-gil builds#111968
Copy link
Assignees
corona10
Labels
3.13only security fixesonly security fixestopic-free-threadingtype-featureA feature request or enhancementA feature request or enhancement

Description

@colesbury
colesbury
opened on Nov 10, 2023
Issue body actions

Feature or enhancement

CPython uses freelists for frequently allocated Python objects, like dict, list, and slice. There freelists are generally stored in the per-interpreter state, which is not thread-safe without the GIL. In --disable-gil builds, the freelists should be stored in the per-thread state (i.e., PyThreadState). I think we probably want to keep the freelists in the interpreter state for the default build. This will probably require some refactoring.

Freelists:

  • float
  • slice (slice_cache)
  • tuple
  • list
  • dict (PyDictKeysObject and PyDictObject)
  • generator (value_freelist and asend_freelist)
  • PyContext

For context, here are similar changes in the nogil-3.12 fork, but I expect the changes in CPython 3.13 to be a bit different:

  • colesbury/nogil-3.12@07f5f8c318
  • colesbury/nogil-3.12@2a4c17e896

Linked PRs

  • gh-111968: Introduce _PyFreeListState and _PyFreeListState_GET API #113584
  • gh-111968: Use per-thread freelists for float in free-threading #113886
  • gh-111968: Unify naming scheme for freelist #113919
  • gh-111968: Use per-thread freelists for tuple in free-threading #113921
  • gh-111968: Explicit handling for finalized freelist #113929
  • gh-111968: Use per-thread slice_cache in free-threading #113972
  • gh-111968: Use per-thread freelists for PyContext in free-threading #114122
  • gh-111968: Use per-thread freelists for generator in free-threading #114189
  • gh-111968: Fix --without-freelists build #114270
  • gh-111968: Use per-thread freelists for dict in free-threading #114323
  • gh-111968: Unify freelist naming schema to Eric's suggestion #114581
  • gh-111968: Refactor _PyXXX_Fini to integrate with _PyObject_ClearFreeLists #114899
  • gh-111968: Rename freelist related struct names to Eric's suggestion #115329
  • gh-111968: Split _Py_dictkeys_freelist out of _Py_dict_freelist #115505
  • gh-111968: Split _Py_async_gen_asend_freelist out of _Py_async_gen_fr… #115546
  • gh-111968: remove redundant fetching of interpreter state in dict implementation  #136673

Activity

Next
  1. colesbury
    added
    type-featureA feature request or enhancementA feature request or enhancement
    3.13only security fixesonly security fixes
    topic-free-threading
    on Nov 10, 2023
  2. Yaro1 commented on Dec 10, 2023

    @Yaro1
    Yaro1
    on Dec 10, 2023
    More actions

    Hi!
    I'm new here, but if you don't mind I would like to take that issue

  3. colesbury commented on Dec 10, 2023

    @colesbury
    colesbury
    on Dec 10, 2023
    ContributorAuthor
    More actions

    Hi @Yaro1, thanks for volunteering. You are welcome to take this on, but I don't think it's a great first issue. There are some subtleties and it also depends on #112776.

  4. Yaro1 commented on Dec 10, 2023

    @Yaro1
    Yaro1
    on Dec 10, 2023
    More actions

    Got it, thanks.
    Can I take please in that case some of the issues from #108219 ?

  5. colesbury commented on Dec 10, 2023

    @colesbury
    colesbury
    on Dec 10, 2023
    ContributorAuthor
    More actions

    I don't think there are any good issues right now that are scoped out and not blocked on other work.

  6. Yaro1 commented on Dec 10, 2023

    @Yaro1
    Yaro1
    on Dec 10, 2023
    More actions

    Okay, got it. Thank you

  7. corona10 commented on Dec 27, 2023

    @corona10
    corona10
    on Dec 27, 2023
    Member
    More actions

    @colesbury I would like to take a look at this issue, Is there any pending issues that are related to this issue?

  8. colesbury commented on Dec 27, 2023

    @colesbury
    colesbury
    on Dec 27, 2023
    ContributorAuthor
    More actions

    @corona10, thanks! I think the issues were fixed (problems with PyThreadState_Clear() being called by the wrong interpreter)

    Reacted by Donghee Na
  9. corona10
    self-assigned this
    on Dec 27, 2023
  10. corona10
    added 2 commits that reference this issue on Dec 30, 2023

    pythongh-111968: Introduce _Py_freelist_state and _PyFreeListState_GE…

    6acf43d

    pythongh-111968: Introduce _Py_freelist_state and _PyFreeListState_GE…

    cd4863c
  11. corona10 commented on Jan 2, 2024

    @corona10
    corona10
    on Jan 2, 2024
    Member
    More actions

    #113584 will introduce seamless management of freelists that runtimes do not need to care about the implementation detail :)

    graph TD;
        PerThread --> FreeList;
        PerInterpreter --> FreeList;
        GC -- if free-threaded --> gc_freethreading;
        GC -- if default build --> gc_gil;
        gc_freethreading --> PerThread;
        gc_gil --> PerInterpreter;
        _PyFreeListState -- if free-threaded --> PerThread;
        _PyFreeListState -- if default build --> PerInterpreter;
        Runtime -- _PyFreeListState_GET --> _PyFreeListState;
        list --> Runtime;
        tuple --> Runtime;
        slice --> Runtime;
        float --> Runtime;
        dict --> Runtime;
        generator --> Runtime;
        PyContext --> Runtime;
    
    Loading
    Reacted by Erlend E. Aasland
    Reacted by Erlend E. Aasland and Łukasz Langa
  12. corona10
    added a commit that references this issue on Jan 5, 2024

    Merge remote-tracking branch 'upstream/main' into pythongh-111968

    4e84130
  13. 73 remaining items

  14. Glyphack
    added 10 commits that reference this issue on Sep 2, 2024

    pythongh-111968: Introduce _PyFreeListState and _PyFreeListState_GET …

    2cdb9b2

    pythongh-111968: Use per-thread freelists for float in free-threading (…

    7706be8

    pythongh-111968: Unify naming scheme for freelist (pythongh-113919)

    6852eb9

    pythongh-111968: Use per-thread freelists for tuple in free-threading (…

    6f94e65

    pythongh-111968: Explicit handling for finalized freelist (pythongh-1…

    698dab6

    pythongh-111968: Use per-thread slice_cache in free-threading (python…

    de68319

    pythongh-111968: Use per-thread freelists for PyContext in free-threa…

    6da2d24

    pythongh-111968: Use per-thread freelists for generator in free-threa…

    891e195

    pythongh-111968: Fix --without-freelists build (pythongh-114270)

    beb44b3

    pythongh-111968: Unify freelist naming schema to Eric's suggestion (p…

    f617cad
  15. LukasWoodtli
    added 2 commits that reference this issue on Jan 22, 2025

    pythongh-111968: Split _Py_dictkeys_freelist out of _Py_dict_freelist (…

    6c72605

    pythongh-111968: Split _Py_async_gen_asend_freelist out of _Py_async_…

    a207147
  16. kumaraditya303
    added a commit that references this issue on Jul 15, 2025

    gh-111968: remove redundant fetching of interpreter state in `dict` i…

    a8f42e6
  17. taegyunkim
    added a commit that references this issue on Aug 4, 2025

    pythongh-111968: remove redundant fetching of interpreter state in `d…

    0dcd696
  18. Agent-Hellboy
    added a commit that references this issue on Aug 19, 2025

    pythongh-111968: remove redundant fetching of interpreter state in `d…

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

Metadata

Metadata

Assignees

  • @corona10
    corona10

Labels

3.13only security fixesonly security fixestopic-free-threadingtype-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.