Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 22 Aug 2018 01:19:01 +0100
From:      RW <rwmaillists@googlemail.com>
To:        freebsd-hackers@freebsd.org
Subject:   Re: rand_harvestq high cpu usage when /dev/urandom is used
Message-ID:  <20180822011901.6eb678cb@gumby.homeunix.com>
In-Reply-To: <20180820184337.6e07e951@gumby.homeunix.com>
References:  <CAO3OKx_3nKDEKP_eii0QoC7DG57Y_KLrHxwJrV7r7UMRL%2BX5_A@mail.gmail.com> <20180820184337.6e07e951@gumby.homeunix.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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.





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20180822011901.6eb678cb>