|
17 | 17 |
|
18 | 18 | #include "pydtrace.h" |
19 | 19 |
|
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 | | - |
24 | 20 | // Minimum growth in mimalloc heap bytes (estimated from full pages) since the |
25 | 21 | // last GC. |
26 | 22 | #define GC_HEAP_BYTES_MIN_DELTA (512 * 1024) |
@@ -2006,32 +2002,27 @@ cleanup_worklist(struct worklist *worklist) |
2006 | 2002 | } |
2007 | 2003 |
|
2008 | 2004 | // 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. |
2022 | 2005 | Py_ssize_t |
2023 | 2006 | _PyGC_GetHeapBytes(PyInterpreterState *interp) |
2024 | 2007 | { |
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. |
2029 | 2020 | intptr_t total = _Py_atomic_load_intptr_relaxed( |
2030 | 2021 | (intptr_t *)&interp->mimalloc.abandoned_pool.full_page_bytes); |
2031 | 2022 | total += _Py_atomic_load_intptr_relaxed( |
2032 | 2023 | (intptr_t *)&_mi_abandoned_default.full_page_bytes); |
2033 | 2024 | 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); |
2035 | 2026 | HEAD_LOCK(&_PyRuntime); |
2036 | 2027 | _Py_FOR_EACH_TSTATE_UNLOCKED(interp, p) { |
2037 | 2028 | _PyThreadStateImpl *t = (_PyThreadStateImpl *)p; |
|
0 commit comments