mirror of
https://github.com/python/cpython.git
synced 2025-12-15 21:44:50 +00:00
gh-115184: Fix refleak tracking issues in free-threaded build (#115188)
Fixes a few issues related to refleak tracking in the free-threaded build: - Count blocks in abandoned segments - Call `_mi_page_free_collect` earlier during heap traversal in order to get an accurate count of blocks in use. - Add missing refcount tracking in `_Py_DecRefSharedDebug` and `_Py_ExplicitMergeRefcount`. - Pause threads in `get_num_global_allocated_blocks` to ensure that traversing the mimalloc heaps is safe.
This commit is contained in:
parent
769d444826
commit
31633f4473
3 changed files with 16 additions and 6 deletions
|
|
@ -1073,7 +1073,12 @@ get_mimalloc_allocated_blocks(PyInterpreterState *interp)
|
|||
mi_heap_visit_blocks(heap, false, &count_blocks, &allocated_blocks);
|
||||
}
|
||||
}
|
||||
// TODO(sgross): count blocks in abandoned segments.
|
||||
|
||||
mi_abandoned_pool_t *pool = &interp->mimalloc.abandoned_pool;
|
||||
for (uint8_t tag = 0; tag < _Py_MIMALLOC_HEAP_COUNT; tag++) {
|
||||
_mi_abandoned_pool_visit_blocks(pool, tag, false, &count_blocks,
|
||||
&allocated_blocks);
|
||||
}
|
||||
#else
|
||||
// TODO(sgross): this only counts the current thread's blocks.
|
||||
mi_heap_t *heap = mi_heap_get_default();
|
||||
|
|
@ -1189,6 +1194,7 @@ get_num_global_allocated_blocks(_PyRuntimeState *runtime)
|
|||
}
|
||||
}
|
||||
else {
|
||||
_PyEval_StopTheWorldAll(&_PyRuntime);
|
||||
HEAD_LOCK(runtime);
|
||||
PyInterpreterState *interp = PyInterpreterState_Head();
|
||||
assert(interp != NULL);
|
||||
|
|
@ -1208,6 +1214,7 @@ get_num_global_allocated_blocks(_PyRuntimeState *runtime)
|
|||
}
|
||||
}
|
||||
HEAD_UNLOCK(runtime);
|
||||
_PyEval_StartTheWorldAll(&_PyRuntime);
|
||||
#ifdef Py_DEBUG
|
||||
assert(got_main);
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue