summaryrefslogtreecommitdiff
path: root/Include/cpython
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2023-04-24 17:23:57 -0600
committerGitHub <noreply@github.com>2023-04-24 17:23:57 -0600
commitdf3173d28ef25a0f97d2cca8cf4e64e062a08d06 (patch)
treef2b6f378f81ceee48a9e710154b9d6c4b0f959a2 /Include/cpython
parent01be52e42eac468b6511b56ee60cd1b99baf3848 (diff)
downloadcpython-git-df3173d28ef25a0f97d2cca8cf4e64e062a08d06.tar.gz
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.
Diffstat (limited to 'Include/cpython')
-rw-r--r--Include/cpython/initconfig.h4
-rw-r--r--Include/cpython/pystate.h4
2 files changed, 8 insertions, 0 deletions
diff --git a/Include/cpython/initconfig.h b/Include/cpython/initconfig.h
index 8bc681b1a9..79c1023baa 100644
--- a/Include/cpython/initconfig.h
+++ b/Include/cpython/initconfig.h
@@ -245,6 +245,8 @@ PyAPI_FUNC(PyStatus) PyConfig_SetWideStringList(PyConfig *config,
/* --- PyInterpreterConfig ------------------------------------ */
typedef struct {
+ // XXX "allow_object_sharing"? "own_objects"?
+ int use_main_obmalloc;
int allow_fork;
int allow_exec;
int allow_threads;
@@ -254,6 +256,7 @@ typedef struct {
#define _PyInterpreterConfig_INIT \
{ \
+ .use_main_obmalloc = 0, \
.allow_fork = 0, \
.allow_exec = 0, \
.allow_threads = 1, \
@@ -263,6 +266,7 @@ typedef struct {
#define _PyInterpreterConfig_LEGACY_INIT \
{ \
+ .use_main_obmalloc = 1, \
.allow_fork = 1, \
.allow_exec = 1, \
.allow_threads = 1, \
diff --git a/Include/cpython/pystate.h b/Include/cpython/pystate.h
index ea6ed8d2bc..f33c72d4cf 100644
--- a/Include/cpython/pystate.h
+++ b/Include/cpython/pystate.h
@@ -11,6 +11,10 @@ is available in a given context. For example, forking the process
might not be allowed in the current interpreter (i.e. os.fork() would fail).
*/
+/* Set if the interpreter share obmalloc runtime state
+ with the main interpreter. */
+#define Py_RTFLAGS_USE_MAIN_OBMALLOC (1UL << 5)
+
/* Set if import should check a module for subinterpreter support. */
#define Py_RTFLAGS_MULTI_INTERP_EXTENSIONS (1UL << 8)