Initial implementation of choosing a random free slot within a slab efficiently: github.com/AndroidHardeni.
It would be possible to do it in an unbiased way for x86 on Haswell and later using popcount and then PDEP for finding the nth unset bit quickly: en.wikipedia.org/wiki/Bit_Manip.
Conversation
Replying to
It's a low value security feature and can't be adding more than a few extra cycles to a performance critical code path. PDEP works but would require having specialized builds for modern CPU revisions and there's no equivalent on arm64 which is far more important for this project.
