From 0bc51664d8954f911a4f7a5adcb6c1d676026b93 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 3ce99b419..6f187052c 100644 --- a/src/snmalloc/mem/remotecache.h +++ b/src/snmalloc/mem/remotecache.h @@ -64,8 +64,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++) @@ -75,6 +73,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; } }