From df3173d28ef25a0f97d2cca8cf4e64e062a08d06 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Mon, 24 Apr 2023 17:23:57 -0600 Subject: gh-101659: Isolate "obmalloc" State to Each Interpreter (gh-101660) This is strictly about moving the "obmalloc" runtime state from `_PyRuntimeState` to `PyInterpreterState`. Doing so improves isolation between interpreters, specifically most of the memory (incl. objects) allocated for each interpreter's use. This is important for a per-interpreter GIL, but such isolation is valuable even without it. FWIW, a per-interpreter obmalloc is the proverbial canary-in-the-coalmine when it comes to the isolation of objects between interpreters. Any object that leaks (unintentionally) to another interpreter is highly likely to cause a crash (on debug builds at least). That's a useful thing to know, relative to interpreter isolation. --- Include/internal/pycore_obmalloc_init.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'Include/internal/pycore_obmalloc_init.h') diff --git a/Include/internal/pycore_obmalloc_init.h b/Include/internal/pycore_obmalloc_init.h index c9f197e72d..8ee72ff2d4 100644 --- a/Include/internal/pycore_obmalloc_init.h +++ b/Include/internal/pycore_obmalloc_init.h @@ -54,9 +54,13 @@ extern "C" { # error "NB_SMALL_SIZE_CLASSES should be less than 64" #endif -#define _obmalloc_state_INIT(obmalloc) \ +#define _obmalloc_global_state_INIT \ { \ .dump_debug_stats = -1, \ + } + +#define _obmalloc_state_INIT(obmalloc) \ + { \ .pools = { \ .used = _obmalloc_pools_INIT(obmalloc.pools), \ }, \ -- cgit v1.2.1