From 5ce1a9bfef782d3df453d8125b71b05499081950 Mon Sep 17 00:00:00 2001 From: daanx Date: Fri, 1 Mar 2024 18:58:11 -0800 Subject: [PATCH 1/2] fix cas call --- src/arena.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/arena.c b/src/arena.c index 0875e49e..00132bf8 100644 --- a/src/arena.c +++ b/src/arena.c @@ -751,7 +751,8 @@ bool _mi_arena_segment_clear_abandoned(mi_segment_t* segment ) if (segment->memid.memkind != MI_MEM_ARENA) { // not in an arena, consider it un-abandoned now. // but we need to still claim it atomically -- we use the thread_id for that. - if (mi_atomic_cas_strong_acq_rel(&segment->thread_id, 0, _mi_thread_id())) { + size_t expected = 0; + if (mi_atomic_cas_strong_acq_rel(&segment->thread_id, &expected, _mi_thread_id())) { mi_atomic_decrement_relaxed(&abandoned_count); return true; } From 3090f23c258a80daa92c5c98d2efff4dd95f9c52 Mon Sep 17 00:00:00 2001 From: daanx Date: Fri, 1 Mar 2024 18:59:13 -0800 Subject: [PATCH 2/2] fix return value of get_reclaim_tries --- src/segment.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/segment.c b/src/segment.c index 87cbfbb5..3db4e813 100644 --- a/src/segment.c +++ b/src/segment.c @@ -921,7 +921,7 @@ void _mi_abandoned_reclaim_all(mi_heap_t* heap, mi_segments_tld_t* tld) { static long mi_segment_get_reclaim_tries(void) { // limit the tries to 10% (default) of the abandoned segments with at least 8 tries, and at most 1024. const size_t perc = (size_t)mi_option_get_clamp(mi_option_max_segment_reclaim, 0, 100); - if (perc <= 0) return NULL; + if (perc <= 0) return 0; const size_t abandoned_count = _mi_arena_segment_abandoned_count(); const size_t relative_count = (abandoned_count > 10000 ? (abandoned_count / 100) * perc : (abandoned_count * perc) / 100); // avoid overflow long max_tries = (long)(relative_count < 8 ? 8 : (relative_count > 1024 ? 1024 : relative_count));