Skip to content

Commit

Permalink
BatchIt random eviction
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nwf-msr authored and nwf committed Sep 22, 2024
1 parent c3c0c4f commit 7daf4b7
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/snmalloc/mem/remotecache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand All @@ -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;
}
}
Expand Down

0 comments on commit 7daf4b7

Please sign in to comment.