From 81da26d7d30c87bc0f094c91fbbae39513d2d35a Mon Sep 17 00:00:00 2001 From: Daan Date: Fri, 11 Oct 2024 10:52:35 -0700 Subject: [PATCH] make target test for stealing one less since we are about to reclaim_or_alloc a fresh segment --- src/segment.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/segment.c b/src/segment.c index bb7483f1..3d411f9c 100644 --- a/src/segment.c +++ b/src/segment.c @@ -1424,9 +1424,10 @@ static void mi_segment_force_abandon(mi_segment_t* segment, mi_segments_tld_t* t // this should be called from `reclaim_or_alloc` so we know all segments are (about) fully in use. static void mi_segments_try_abandon(mi_heap_t* heap, mi_segments_tld_t* tld) { const size_t target = (size_t)mi_option_get_clamp(mi_option_target_segments_per_thread,0,1024); - if (target == 0 || tld->count <= target) return; + // we call this when we are about to add a fresh segment so we should be under our target segment count. + if (target == 0 || tld->count < target) return; - const size_t min_target = (target > 4 ? (target*3)/4 : target); // 75% + const size_t min_target = (target > 4 ? (target*3)/4 : target); // 75% // todo: we should maintain a list of segments per thread; for now, only consider segments from the heap full pages for (int i = 0; i < 16 && tld->count >= min_target; i++) {