mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
gh-112532: Isolate abandoned segments by interpreter (#113717)
* gh-112532: Isolate abandoned segments by interpreter Mimalloc segments are data structures that contain memory allocations along with metadata. Each segment is "owned" by a thread. When a thread exits, it abandons its segments to a global pool to be later reclaimed by other threads. This changes the pool to be per-interpreter instead of process-wide. This will be important for when we use mimalloc to find GC objects in the `--disable-gil` builds. We want heaps to only store Python objects from a single interpreter. Absent this change, the abandoning and reclaiming process could break this isolation. * Add missing '&_mi_abandoned_default' to 'tld_empty'
This commit is contained in:
parent
c2e8298eba
commit
fcb3c2a444
7 changed files with 102 additions and 76 deletions
|
@ -2533,6 +2533,11 @@ tstate_mimalloc_bind(PyThreadState *tstate)
|
|||
mi_tld_t *tld = &mts->tld;
|
||||
_mi_tld_init(tld, &mts->heaps[_Py_MIMALLOC_HEAP_MEM]);
|
||||
|
||||
// Exiting threads push any remaining in-use segments to the abandoned
|
||||
// pool to be re-claimed later by other threads. We use per-interpreter
|
||||
// pools to keep Python objects from different interpreters separate.
|
||||
tld->segments.abandoned = &tstate->interp->mimalloc.abandoned_pool;
|
||||
|
||||
// Initialize each heap
|
||||
for (Py_ssize_t i = 0; i < _Py_MIMALLOC_HEAP_COUNT; i++) {
|
||||
_mi_heap_init_ex(&mts->heaps[i], tld, _mi_arena_id_none());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue