mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
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.
This commit is contained in:
parent
f92857a930
commit
b24c9161a6
7 changed files with 71 additions and 16 deletions
|
|
@ -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 *);
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue