rand_harvestq high cpu usage when /dev/urandom is used

RW rwmaillists at googlemail.com
Wed Aug 22 00:19:07 UTC 2018


On Mon, 20 Aug 2018 18:43:37 +0100
RW wrote:

> On Mon, 20 Aug 2018 13:27:33 +0200
> Ali Abdallah wrote:
> 
> > Hello,
> > 
> > I was just sorting randomly some jpg image files using:
> > 
> > ls *.jpg  | sort -R --random-source=/dev/urandom  
> 
> urandom is a sim-link to random, so --random-source=/dev/urandom
> does nothing useful
> 
> > The above command never exited. Later I noticed that
> > one of my CPU is always running 100%. top -S reveals that it is
> > rand_harvestq kernel service.
> > 
> > Is this is a bug? This occurs on 12-ALPHA1 and 11.2  
> 
> It's a bit excessive


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.

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.




More information about the freebsd-hackers mailing list