mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-03 22:19:32 +03:00
ensure we dont reclaim a segment on a free if that would go above the target segment count
This commit is contained in:
parent
3f3aee918a
commit
4f46cf7d5a
1 changed files with 2 additions and 0 deletions
|
@ -1261,6 +1261,8 @@ bool _mi_segment_attempt_reclaim(mi_heap_t* heap, mi_segment_t* segment) {
|
||||||
if (mi_atomic_load_relaxed(&segment->thread_id) != 0) return false; // it is not abandoned
|
if (mi_atomic_load_relaxed(&segment->thread_id) != 0) return false; // it is not abandoned
|
||||||
if (segment->subproc != heap->tld->segments.subproc) return false; // only reclaim within the same subprocess
|
if (segment->subproc != heap->tld->segments.subproc) return false; // only reclaim within the same subprocess
|
||||||
if (!_mi_heap_memid_is_suitable(heap,segment->memid)) return false; // don't reclaim between exclusive and non-exclusive arena's
|
if (!_mi_heap_memid_is_suitable(heap,segment->memid)) return false; // don't reclaim between exclusive and non-exclusive arena's
|
||||||
|
const long target = _mi_option_get_fast(mi_option_target_segments_per_thread);
|
||||||
|
if (target > 0 && (size_t)target <= heap->tld->segments.count) return false; // don't reclaim if going above the target count
|
||||||
// don't reclaim more from a `free` call than half the current segments
|
// don't reclaim more from a `free` call than half the current segments
|
||||||
// this is to prevent a pure free-ing thread to start owning too many segments
|
// this is to prevent a pure free-ing thread to start owning too many segments
|
||||||
// (but not for out-of-arena segments as that is the main way to be reclaimed for those)
|
// (but not for out-of-arena segments as that is the main way to be reclaimed for those)
|
||||||
|
|
Loading…
Add table
Reference in a new issue