diff options
author | Alexander Motin <[email protected]> | 2021-06-22 19:35:23 -0400 |
---|---|---|
committer | GitHub <[email protected]> | 2021-06-22 17:35:23 -0600 |
commit | 29274c9f6d7caa864d2c95cb797ca3cf32b4ef66 (patch) | |
tree | bfbbeb3232ea78004c7da180789a6c1a6e328ab0 /module/zfs/zil.c | |
parent | ba91311561834774bc8fedfafb19ca1012c9dadd (diff) |
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 <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Alexander Motin <[email protected]>
Sponsored-By: iXsystems, Inc.
Closes #12183
Diffstat (limited to 'module/zfs/zil.c')
-rw-r--r-- | module/zfs/zil.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/module/zfs/zil.c b/module/zfs/zil.c index d9c304208..5443c2a1f 100644 --- a/module/zfs/zil.c +++ b/module/zfs/zil.c @@ -205,8 +205,10 @@ zil_init_log_chain(zilog_t *zilog, blkptr_t *bp) { zio_cksum_t *zc = &bp->blk_cksum; - zc->zc_word[ZIL_ZC_GUID_0] = spa_get_random(-1ULL); - zc->zc_word[ZIL_ZC_GUID_1] = spa_get_random(-1ULL); + (void) random_get_pseudo_bytes((void *)&zc->zc_word[ZIL_ZC_GUID_0], + sizeof (zc->zc_word[ZIL_ZC_GUID_0])); + (void) random_get_pseudo_bytes((void *)&zc->zc_word[ZIL_ZC_GUID_1], + sizeof (zc->zc_word[ZIL_ZC_GUID_1])); zc->zc_word[ZIL_ZC_OBJSET] = dmu_objset_id(zilog->zl_os); zc->zc_word[ZIL_ZC_SEQ] = 1ULL; } |