Skip to content

Commit 057f862

Browse files
committed
Use _mi_heap_main_get().
1 parent 801737f commit 057f862

1 file changed

Lines changed: 13 additions & 22 deletions

File tree

Python/gc_free_threading.c

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717

1818
#include "pydtrace.h"
1919

20-
// Declared in mimalloc/internal.h only at function scope; we read its
21-
// full_page_bytes counter from _PyGC_GetHeapBytes().
22-
extern mi_heap_t _mi_heap_main;
23-
2420
// Minimum growth in mimalloc heap bytes (estimated from full pages) since the
2521
// last GC.
2622
#define GC_HEAP_BYTES_MIN_DELTA (512 * 1024)
@@ -2006,32 +2002,27 @@ cleanup_worklist(struct worklist *worklist)
20062002
}
20072003

20082004
// Return an estimate, in bytes, of how much memory is being used.
2009-
//
2010-
// Computed from mimalloc full-page byte counters: each mi_heap_t and
2011-
// mi_abandoned_pool_t carries a `full_page_bytes` field maintained by the
2012-
// page-state helpers in Objects/mimalloc/page.c. We sum:
2013-
// - per-tstate heaps for this interpreter (live full pages)
2014-
// - the interpreter's abandoned pool (full pages between abandon and reclaim)
2015-
// - _mi_heap_main (default heap on the main thread, used pre-tstate and
2016-
// for non-Python threads)
2017-
// - _mi_abandoned_default (full pages abandoned from default heaps)
2018-
// Per-thread auto-default heaps used by non-Python threads are not
2019-
// enumerated; their bytes show up in _mi_abandoned_default once the OS
2020-
// thread exits. This is acceptable because almost all FT-Python allocation
2021-
// routes through tstate-bound heaps.
20222005
Py_ssize_t
20232006
_PyGC_GetHeapBytes(PyInterpreterState *interp)
20242007
{
2025-
// `full_page_bytes` is `_Atomic(intptr_t)`; cast to `intptr_t *` to
2026-
// strip the qualifier for the CPython atomic helpers. The mimalloc-side
2027-
// writes use `mi_atomic_addi` directly on the `_Atomic(intptr_t)` field;
2028-
// the cast is only needed for the read side.
2008+
// Computed from mimalloc full-page byte counters: each mi_heap_t and
2009+
// mi_abandoned_pool_t carries a `full_page_bytes` field.
2010+
// Sum:
2011+
// - per-tstate heaps for this interpreter (live full pages)
2012+
// - the interpreter's abandoned pool (full pages between abandon and reclaim)
2013+
// - _mi_heap_main (default heap on the main thread, used pre-tstate and
2014+
// for non-Python threads)
2015+
// - _mi_abandoned_default (full pages abandoned from default heaps)
2016+
// Per-thread auto-default heaps used by non-Python threads are not
2017+
// enumerated; their bytes show up in _mi_abandoned_default once the OS
2018+
// thread exits. This should be acceptable because almost all Python
2019+
// allocation is done by tstate-bound heaps.
20292020
intptr_t total = _Py_atomic_load_intptr_relaxed(
20302021
(intptr_t *)&interp->mimalloc.abandoned_pool.full_page_bytes);
20312022
total += _Py_atomic_load_intptr_relaxed(
20322023
(intptr_t *)&_mi_abandoned_default.full_page_bytes);
20332024
total += _Py_atomic_load_intptr_relaxed(
2034-
(intptr_t *)&_mi_heap_main.full_page_bytes);
2025+
(intptr_t *)&_mi_heap_main_get()->full_page_bytes);
20352026
HEAD_LOCK(&_PyRuntime);
20362027
_Py_FOR_EACH_TSTATE_UNLOCKED(interp, p) {
20372028
_PyThreadStateImpl *t = (_PyThreadStateImpl *)p;

0 commit comments

Comments
 (0)