]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
Optimize small random numbers generation
authorAlexander Motin <mav@FreeBSD.org>
Tue, 22 Jun 2021 23:35:23 +0000 (19:35 -0400)
committerTony Hutter <hutter2@llnl.gov>
Tue, 14 Sep 2021 19:10:17 +0000 (12:10 -0700)
commitf3969ea78b5f54935474d49455cf9c4d6a1e107a
tree38dbfbee2cd0bbd24bbc642e2023d3f20bd82b6f
parent6fe6192796f6835163523db94130fb842022f6cf
Optimize small random numbers generation

In all places except two spa_get_random() is used for small values,
and the consumers do not require well seeded high quality values.
Switch those two exceptions directly to random_get_pseudo_bytes()
and optimize spa_get_random(), renaming it to random_in_range(),
since it is not related to SPA or ZFS in general.

On FreeBSD directly map random_in_range() to new prng32_bounded() KPI
added in FreeBSD 13.  On Linux and in user-space just reduce the type
used to uint32_t to avoid more expensive 64bit division.

Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Alexander Motin <mav@FreeBSD.org>
Sponsored-By: iXsystems, Inc.
Closes #12183
16 files changed:
include/os/freebsd/spl/sys/random.h
include/os/linux/spl/sys/random.h
include/sys/spa.h
include/sys/zfs_context.h
module/os/linux/zfs/arc_os.c
module/zfs/metaslab.c
module/zfs/mmp.c
module/zfs/multilist.c
module/zfs/spa.c
module/zfs/spa_misc.c
module/zfs/space_map.c
module/zfs/vdev_indirect.c
module/zfs/vdev_mirror.c
module/zfs/zil.c
module/zfs/zio_compress.c
module/zfs/zio_inject.c