gh-117783: Immortalize objects that use deferred reference counting (#118112)

Deferred reference counting is not fully implemented yet. As a temporary
measure, we immortalize objects that would use deferred reference
counting to avoid multi-threaded scaling bottlenecks.

This is only performed in the free-threaded build once the first
non-main thread is started. Additionally, some tests, including refleak
tests, suppress this behavior.
This commit is contained in:
Sam Gross 2024-04-29 14:36:02 -04:00 committed by GitHub
parent 8d4b756fd3
commit 7ccacb220d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 134 additions and 8 deletions

View file

@ -312,6 +312,18 @@ struct _gc_runtime_state {
collections, and are awaiting to undergo a full collection for
the first time. */
Py_ssize_t long_lived_pending;
/* gh-117783: Deferred reference counting is not fully implemented yet, so
as a temporary measure we treat objects using deferred referenence
counting as immortal. */
struct {
/* Immortalize objects instead of marking them as using deferred
reference counting. */
int enabled;
/* Set enabled=1 when the first background thread is created. */
int enable_on_thread_created;
} immortalize;
#endif
};
@ -343,6 +355,11 @@ extern void _PyGC_ClearAllFreeLists(PyInterpreterState *interp);
extern void _Py_ScheduleGC(PyThreadState *tstate);
extern void _Py_RunGC(PyThreadState *tstate);
#ifdef Py_GIL_DISABLED
// gh-117783: Immortalize objects that use deferred reference counting
extern void _PyGC_ImmortalizeDeferredObjects(PyInterpreterState *interp);
#endif
#ifdef __cplusplus
}
#endif