diff options
author | Sam Gross <colesbury@gmail.com> | 2024-02-16 16:22:27 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-16 16:22:27 (GMT) |
commit | b24c9161a651f549ed48f4b4dba8996fe9cc4e09 (patch) | |
tree | 549acacced5ca0b1923e0df94b40ef633c6cdf8f /Include | |
parent | f92857a93016aa26ba93959d2bdb690ef52e7f07 (diff) | |
download | cpython-b24c9161a651f549ed48f4b4dba8996fe9cc4e09.zip cpython-b24c9161a651f549ed48f4b4dba8996fe9cc4e09.tar.gz cpython-b24c9161a651f549ed48f4b4dba8996fe9cc4e09.tar.bz2 |
gh-112529: Make the GC scheduling thread-safe (#114880)
The GC keeps track of the number of allocations (less deallocations)
since the last GC. This buffers the count in thread-local state and uses
atomic operations to modify the per-interpreter count. The thread-local
buffering avoids contention on shared state.
A consequence is that the GC scheduling is not as precise, so
"test_sneaky_frame_object" is skipped because it requires that the GC be
run exactly after allocating a frame object.
Diffstat (limited to 'Include')
-rw-r--r-- | Include/internal/pycore_gc.h | 7 | ||||
-rw-r--r-- | Include/internal/pycore_tstate.h | 1 |
2 files changed, 8 insertions, 0 deletions
diff --git a/Include/internal/pycore_gc.h b/Include/internal/pycore_gc.h index 582a16b..a98864f 100644 --- a/Include/internal/pycore_gc.h +++ b/Include/internal/pycore_gc.h @@ -260,6 +260,13 @@ struct _gc_runtime_state { Py_ssize_t long_lived_pending; }; +#ifdef Py_GIL_DISABLED +struct _gc_thread_state { + /* Thread-local allocation count. */ + Py_ssize_t alloc_count; +}; +#endif + extern void _PyGC_InitState(struct _gc_runtime_state *); diff --git a/Include/internal/pycore_tstate.h b/Include/internal/pycore_tstate.h index 97aa85a..7fb9ab2 100644 --- a/Include/internal/pycore_tstate.h +++ b/Include/internal/pycore_tstate.h @@ -28,6 +28,7 @@ typedef struct _PyThreadStateImpl { PyThreadState base; #ifdef Py_GIL_DISABLED + struct _gc_thread_state gc; struct _mimalloc_thread_state mimalloc; struct _Py_object_freelists freelists; struct _brc_thread_state brc; |