From 7daf4b7f0364b3c92c64329e3946aca0ef9645ab Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Wed, 4 Sep 2024 16:54:10 -0400 Subject: [PATCH] BatchIt random eviction In order not to thwart `mitigations(random_preserve)` too much, if it's on in combination with BatchIt, roll the dice every time we append to a batch to decide if we should stochastically evict this batch. By increasing the number of batches, we allow the recipient allocator increased opportunity to randomly stripe batches across the two `freelist::Builder` segments associated with each slab. --- src/snmalloc/mem/remotecache.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/snmalloc/mem/remotecache.h b/src/snmalloc/mem/remotecache.h index 0078e8384..585fb9146 100644 --- a/src/snmalloc/mem/remotecache.h +++ b/src/snmalloc/mem/remotecache.h @@ -77,8 +77,6 @@ namespace snmalloc LocalEntropy* entropy, Forward forward) { - UNUSED(entropy); - size_t ix_set = ring_set(meta); for (size_t ix_way = 0; ix_way < DEALLOC_BATCH_RING_ASSOC; ix_way++) @@ -88,6 +86,20 @@ namespace snmalloc { open_builder[ix].add( r, freelist::Object::key_root, meta->as_key_tweak()); + + if constexpr (mitigations(random_preserve)) + { + auto rand_limit = entropy->next_fresh_bits(MAX_CAPACITY_BITS); + if (open_builder[ix].extract_segment_length() >= rand_limit) + { + close_one_pending(forward, ix); + open_meta[ix] = 0; + } + } + else + { + UNUSED(entropy); + } return; } }