rand_harvestq high cpu usage when /dev/urandom is used

Conrad Meyer cem at freebsd.org
Wed Aug 22 00:56:48 UTC 2018


On Tue, Aug 21, 2018 at 5:19 PM, RW via freebsd-hackers
<freebsd-hackers at freebsd.org> wrote:
>
> I think I see what is going on. If you have a hardware entropy source
> then when you read N bytes out of /dev/random, random_sources_feed()
> tries to put at least that amount into each of the entropy pools (32
> for fortuna). So if you are reading at 100MB/s, you are trying to feed
> 3.2GB/s into the pools. Overwriting a slow drive from /dev/random seems
> to be enough to waste a CPU core my PC.

Yep, I came to a similar conclusion[1].  I think you're off by a
factor of two, though — it's even worse than that!  It tries to reseed
64x as many bytes from the configured random sources as data read out
of the random device.

> Fortuna is only allowed to resend after 100ms, and anything more than
> 1kB/reseed (pools*keysize) is a waste of CPU cycles. IMO
> random_sources_feed() should limit itself to RANDOM_KEYSIZE bytes per
> call for each pool/source combination - even that's overkill.

I am less familiar on what Fortuna permits, but yeah, clearly what we
have now is excessive.

Best,
Conrad

[1]: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=230808#c1


More information about the freebsd-hackers mailing list