You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Large RSS increase when memory is allocated by multiple threads and freed by an uninitialized thread #1364
I see a large memory-footprint regression starting between mimalloc 3.1.6 and 3.2.6 when objects are allocated by multiple threads but freed by a dedicated thread which has never allocated memory or called mi_thread_init().
The attached mimalloc_uninitialized_remote_free_repro.c, written for me by ChatGPT, reproduces this. It creates 16 producer threads, each maintaining a fixed live set of 592-byte allocations. Replaced objects are passed through bounded queues to one reclaimer thread which only calls free(). Thus the logical outstanding allocation size is strictly bounded at about 370 MiB.
Results on my system (x86-64 Linux, Ubuntu 26.04):
steady RSS
3.1.6, reclaimer not initialized ~437 MiB
3.2.6, reclaimer not initialized ~1.80 GiB
3.4.5, reclaimer not initialized ~1.77 GiB
3.4.5, reclaimer initialized ~441 MiB
In all cases the application allocation/free counts remain bounded and end with exactly zero outstanding allocations.
With 3.4.5, initializing only the reclaimer also changes the allocator statistics dramatically:
without mi_thread_init: reclaima=0, reabandon=0
with mi_thread_init: reclaima=62.0M, reabandon=62.0M
My reading of the v3 code is that remote frees of partially-used abandoned pages cannot successfully reclaim/reabandon the page when _mi_page_associated_theap_peek() finds no theap for the freeing thread. The page therefore cannot be efficiently reused until its remaining allocations have all been freed.
Since free() is expected to work from a thread which has never allocated, requiring an explicit mi_thread_init() on such a thread is unfortunate. Is this intended, or should the remote-free path handle this case without application intervention?
Thanks for the report -- this is indeed a bug but not so much that the thread needs to be initialized (since reclaimnig pages in a pure free-ing thread does not help), but the "reabandon" was also not working; this is now fixed in the latest dev3. Can you try if it works for you?
Thanks Daan. I can confirm that it fixes the testcase for me. I'm now trying the actual program which was seeing huge memory growth compared to 3.1.6, but it make take a few days to be sure that it too is fixed.
My issue is fixed: I ran a version using dev3 in parallel with a second instance using v3.1.5, and not only did it work fine (no crashes or other funny business), but also memory usage stabilized at essentially the same value for both: 6.9G vs 6.8G.
Activity
perf(memory): bound the frame pool by bytes and stop paying for idle …
all free to reabandon pages even if the thread is uninitialized, issue …
daanx commentedon Aug 18, 2026
Thanks for the report -- this is indeed a bug but not so much that the thread needs to be initialized (since reclaimnig pages in a pure free-ing thread does not help), but the "reabandon" was also not working; this is now fixed in the latest
dev3. Can you try if it works for you?CunningBaldrick commentedon Aug 19, 2026
Thanks Daan. I can confirm that it fixes the testcase for me. I'm now trying the actual program which was seeing huge memory growth compared to 3.1.6, but it make take a few days to be sure that it too is fixed.
CunningBaldrick commentedon Aug 24, 2026
My issue is fixed: I ran a version using dev3 in parallel with a second instance using v3.1.5, and not only did it work fine (no crashes or other funny business), but also memory usage stabilized at essentially the same value for both: 6.9G vs 6.8G.