add slot randomization to configuration header

pull/50/head
Daniel Micay 2018-09-07 00:25:02 -04:00
parent bed303a76f
commit ba3a8b0058
2 changed files with 9 additions and 5 deletions

View File

@ -3,5 +3,6 @@
#define GUARD_SLABS true #define GUARD_SLABS true
#define WRITE_AFTER_FREE_CHECK true #define WRITE_AFTER_FREE_CHECK true
#define SLOT_RANDOMIZE true
#endif #endif

View File

@ -204,6 +204,7 @@ static size_t get_free_slot(struct random_state *rng, size_t slots, struct slab_
fatal_error("no zero bits"); fatal_error("no zero bits");
} }
if (SLOT_RANDOMIZE) {
// randomize start location for linear search (uniform random choice is too slow) // randomize start location for linear search (uniform random choice is too slow)
uint64_t random_split = ~(~0UL << get_random_u16_uniform(rng, slots)); uint64_t random_split = ~(~0UL << get_random_u16_uniform(rng, slots));
@ -211,6 +212,8 @@ static size_t get_free_slot(struct random_state *rng, size_t slots, struct slab_
if (slot) { if (slot) {
return slot - 1; return slot - 1;
} }
}
return ffzl(masked) - 1; return ffzl(masked) - 1;
} }