From b0c8d86c41066832d35db85952d65f483b1fecf6 Mon Sep 17 00:00:00 2001 From: Daan Leijen Date: Tue, 4 Feb 2025 15:03:27 -0800 Subject: [PATCH] refactor mi_free_try_collect_mt --- src/free.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/free.c b/src/free.c index ebcf08ab..5e83ad95 100644 --- a/src/free.c +++ b/src/free.c @@ -217,12 +217,13 @@ static void mi_decl_noinline mi_free_try_collect_mt(mi_page_t* page, mi_block_t* return; } + const bool too_full = mi_page_is_used_at_frac(page, 8); // more than 7/8th of the page is in use? + // 2. if the page is not too full, we can try to reclaim it for ourselves // note: this seems a bad idea but it speeds up some benchmarks (like `larson`) quite a bit. - if (_mi_option_get_fast(mi_option_page_reclaim_on_free) != 0 && - page->block_size <= MI_SMALL_MAX_OBJ_SIZE && // only for small sized blocks - !mi_page_is_used_at_frac(page,8) // and not too full - // && !mi_page_is_abandoned_mapped(page) + if (!too_full && + _mi_option_get_fast(mi_option_page_reclaim_on_free) != 0 && + page->block_size <= MI_SMALL_MAX_OBJ_SIZE // only for small sized blocks ) { // the page has still some blocks in use (but not too many) @@ -252,7 +253,7 @@ static void mi_decl_noinline mi_free_try_collect_mt(mi_page_t* page, mi_block_t* } // 3. if the page is unmapped, try to reabandon so it can possibly be mapped and found for allocations - if (!mi_page_is_used_at_frac(page,8) && // only reabandon if a full page starts to have enough blocks available to prevent immediate re-abandon of a full page + if (!too_full && // only reabandon if a full page starts to have enough blocks available to prevent immediate re-abandon of a full page !mi_page_is_abandoned_mapped(page) && page->memid.memkind == MI_MEM_ARENA && _mi_arenas_page_try_reabandon_to_mapped(page)) {