Modify heuristic for adding new slabs. (#429)
If there is only one slab remaining, then we probabalisticly allocator a new one. If a slab is barely in use, then this could cause us to effectively double the number of slabs in use. This commit checks if the remaining slab has enough remaining elements to provide randomisation.
This commit is contained in:
committed by
GitHub
parent
c299826f58
commit
5fd3288997
@@ -689,11 +689,16 @@ namespace snmalloc
|
||||
{
|
||||
#ifdef SNMALLOC_CHECK_CLIENT
|
||||
// Occassionally don't use the last list.
|
||||
if (
|
||||
SNMALLOC_UNLIKELY(alloc_classes[sizeclass].length == 1) &&
|
||||
(entropy.next_bit() == 0))
|
||||
if (SNMALLOC_UNLIKELY(alloc_classes[sizeclass].length == 1))
|
||||
{
|
||||
return small_alloc_slow<zero_mem>(sizeclass, fast_free_list);
|
||||
// If the slab has a lot of free space, then we shouldn't allocate a
|
||||
// new slab.
|
||||
auto min = alloc_classes[sizeclass]
|
||||
.available.peek()
|
||||
->free_queue.min_list_length();
|
||||
if ((min * 2) < threshold_for_waking_slab(sizeclass))
|
||||
if (entropy.next_bit() == 0)
|
||||
return small_alloc_slow<zero_mem>(sizeclass, fast_free_list);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user