do not reclaim segments on collect

This commit is contained in:
daan 2020-01-23 15:48:51 -08:00
parent 76e727f7d1
commit 12701b1aac

View file

@ -114,25 +114,20 @@ static void mi_heap_collect_ex(mi_heap_t* heap, mi_collect_t collect)
if (!mi_heap_is_initialized(heap)) return; if (!mi_heap_is_initialized(heap)) return;
_mi_deferred_free(heap, collect >= MI_FORCE); _mi_deferred_free(heap, collect >= MI_FORCE);
// collect (some) abandoned pages // note: never reclaim on collect but leave it to threads that need storage to reclaim
if (collect >= MI_NORMAL && !heap->no_reclaim) { if (
if (collect == MI_NORMAL) {
// this may free some segments (but also take ownership of abandoned pages)
_mi_segment_try_reclaim_abandoned(heap, false, &heap->tld->segments);
}
else if (
#ifdef NDEBUG #ifdef NDEBUG
collect == MI_FORCE collect == MI_FORCE
#else #else
collect >= MI_FORCE collect >= MI_FORCE
#endif #endif
&& _mi_is_main_thread() && mi_heap_is_backing(heap)) && _mi_is_main_thread() && mi_heap_is_backing(heap) && !heap->no_reclaim)
{ {
// the main thread is abandoned (end-of-program), try to reclaim all abandoned segments. // the main thread is abandoned (end-of-program), try to reclaim all abandoned segments.
// if all memory is freed by now, all segments should be freed. // if all memory is freed by now, all segments should be freed.
_mi_segment_try_reclaim_abandoned(heap, true, &heap->tld->segments); _mi_segment_try_reclaim_abandoned(heap, true, &heap->tld->segments);
} }
}
// if abandoning, mark all pages to no longer add to delayed_free // if abandoning, mark all pages to no longer add to delayed_free
if (collect == MI_ABANDON) { if (collect == MI_ABANDON) {