gh-115103: Implement delayed memory reclamation (QSBR) (#115180)

This adds a safe memory reclamation scheme based on FreeBSD's "GUS" and
quiescent state based reclamation (QSBR). The API provides a mechanism
for callers to detect when it is safe to free memory that may be
concurrently accessed by readers.
This commit is contained in:
Sam Gross 2024-02-16 15:25:19 -05:00 committed by GitHub
parent 711f42de2e
commit 5903190727
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 577 additions and 2 deletions

View file

@ -86,6 +86,12 @@
#define PRE_DISPATCH_GOTO() ((void)0)
#endif
#ifdef Py_GIL_DISABLED
#define QSBR_QUIESCENT_STATE(tstate) _Py_qsbr_quiescent_state(((_PyThreadStateImpl *)tstate)->qsbr)
#else
#define QSBR_QUIESCENT_STATE(tstate)
#endif
/* Do interpreter dispatch accounting for tracing and instrumentation */
#define DISPATCH() \
@ -117,6 +123,7 @@
#define CHECK_EVAL_BREAKER() \
_Py_CHECK_EMSCRIPTEN_SIGNALS_PERIODICALLY(); \
QSBR_QUIESCENT_STATE(tstate); \
if (_Py_atomic_load_uintptr_relaxed(&tstate->interp->ceval.eval_breaker) & _PY_EVAL_EVENTS_MASK) { \
if (_Py_HandlePending(tstate) != 0) { \
GOTO_ERROR(error); \