Repository navigation
Conversation
|
🤖 New build scheduled with the buildbot fleet by @corona10 for commit 2649e2b 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F159112%2Fmerge If you want to schedule another build, you need to add the 🔨 test-with-refleak-buildbots label again. |
Upgrade mimalloc from v2.1.2 to v2.5.2 as-is from upstream. v2.1.2: https://github.com/microsoft/mimalloc/releases/tag/v2.1.2 v2.5.2: https://github.com/microsoft/mimalloc/releases/tag/v2.5.2
|
🤖 New build scheduled with the buildbot fleet by @corona10 for commit f81e6c2 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F159112%2Fmerge If you want to schedule another build, you need to add the 🔨 test-with-refleak-buildbots label again. |
|
@mpage, could you trigger a free-threading benchmark for this change? :) |
Documentation build overview
16 files changed ·
|
|
🤖 New build scheduled with the buildbot fleet by @corona10 for commit 222601b 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F159112%2Fmerge If you want to schedule another build, you need to add the 🔨 test-with-refleak-buildbots label again. |
|
I will fix MSAN later: |
Most of the previous downstream changes were upstreamed in mimalloc v2.1.3 - v2.1.7 (heap tags, _mi_heap_init/_mi_tld_init, MI_PRIM_THREAD_ID, sub-processes, heap walk optimizations, platform fixes) and are dropped. Remaining CPython-specific changes, all marked with a "CPython" comment: - QSBR delayed page freeing for free-threaded builds (pythongh-115103, pythongh-145615): mi_page_t/mi_heap_t fields and _PyMem_mi_* hooks in page.c, heap.c and segment.c. - debug_offset: preserve the first bytes of a PyObject (ob_tid, refcount fields) when filling freed or uninitialized memory in debug builds (pythongh-115491). - Atomic mi_block_t.next loads/stores to avoid TSAN reports (pythongh-129748). - Relax the owning thread assertion in _mi_free_delayed_block for free-threaded builds, since the GC traverses heaps of other threads. - Call _mi_heap_delayed_free_partial() in mi_heap_visit_blocks() (pythongh-112532). - Only count reclaimed pages up to MI_MEDIUM_OBJ_SIZE_MAX as a "right page" in mi_segment_reclaim (pythongh-115103). - Rename the weak _ZSt15get_new_handlerv symbol and disable the mi_is_in_heap_region debug warning. - Zero-initialize _mi_page_empty instead of a positional initializer.
|
Here's the benchmarking run. Will report results when it completes. |
|
Hmm.. higher memory usage? |
|
Let me check where the memory pressure came from. |
|
Okay this is because, MIMALLOC_ALLOW_THP=1 become by default. |
|
@mpage Would you like to re-trigger the benchmark? The latest commit will resolve the higher memory usage issue. |
|
cc @daanx |
|
Based on Codex review, following compatibility fixes are still missing:
|
It's already happen in the current mimalloc, I think this could be of scope this PR. But let me check again. We may cover other stuff in separated PR if they are not the scope this PR too. |
| _Py_brc_init_state(interp); | ||
|
|
||
| interp->mimalloc.subproc = mi_subproc_new(); | ||
| if (interp->mimalloc.subproc == NULL) { |
There was a problem hiding this comment.
this part is introduced in this PR so free() part should be too.
There was a problem hiding this comment.
FYI, this leak already exists on main (free-threaded build).
import gc, resource, sys
from concurrent import interpreters
def rss_mib():
rss = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
return rss / (1024 * 1024) if sys.platform == "darwin" else rss / 1024
N = 100
interpreters.create().close() # warm up
gc.collect(); before = rss_mib()
for _ in range(N):
interp = interpreters.create()
interp.exec("x = [object() for _ in range(20000)]")
interp.close()
gc.collect(); after = rss_mib()
print(f"RSS {before:.1f} -> {after:.1f} MiB, {(after - before) / N * 1024:.0f} KiB per interpreter")On main (c6c0608):
RSS 22.9 -> 637.4 MiB, 6292 KiB per interpreter
When the last thread of an interpreter exits, its abandoned segments are never
reclaimed because no thread of that interpreter is left. So RSS keeps growing.
In this PR, the abandoned pool is replaced by interp->mimalloc.subproc, and the
situation is the same as before.
So I thought that it is okay to leave it as is.
But let me adding freeing logic at this change.
There was a problem hiding this comment.
FYI, abandoned_count == 0 never reach in my local experiment. So I think that it will not actually execute in practice.
@daanx |
|
I've addressed most of your suggestions except for Thank you for the suggestion. |
| mi_subproc_t *subproc = interp->mimalloc.subproc; | ||
| if (subproc != NULL) { | ||
| // Delete the sub-process only when no abandoned segment points to it. | ||
| if (mi_atomic_load_relaxed(&subproc->abandoned_count) == 0) { |
There was a problem hiding this comment.
FYI: #159112 (comment)
I'm still not sure it will execute in practice, but I think it would be fine since this issue has already happened in the main branch.
But having deletion logic as an option is good convention.
We can solve this issue in a separate PR.
|
🤖 New build scheduled with the buildbot fleet by @corona10 for commit 8b9cb49 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F159112%2Fmerge If you want to schedule another build, you need to add the 🔨 test-with-refleak-buildbots label again. |
|
@corona10 - Kicked off another run. Fingers crossed this one works. |
|
Okay benchmark result now looks good to me since there is no significant change Would you like to review this PR? |
Uh oh!
There was an error while loading. Please reload this page.