svn commit: r309143 - head/sys/libkern

Gleb Smirnoff glebius at FreeBSD.org
Wed Dec 7 19:41:29 UTC 2016


On Fri, Nov 25, 2016 at 05:00:10PM +0100, Mateusz Guzik wrote:
M> On Fri, Nov 25, 2016 at 01:49:33PM +0000, Fabien Thomas wrote:
M> > Author: fabient
M> > Date: Fri Nov 25 13:49:33 2016
M> > New Revision: 309143
M> > URL: https://svnweb.freebsd.org/changeset/base/309143
M> > 
M> > Log:
M> >   In a dual processor system (2*6 cores) during IPSec throughput tests,
M> >   we see a lot of contention on the arc4 lock, used to generate the IV
M> >   of the ESP output packets.
M> >   
M> >   The idea of this patch is to split this mutex in order to reduce the
M> >   contention on this lock.
M> >   
M> > +MALLOC_DEFINE(M_ARC4RANDOM, "arc4random", "arc4random structures");
M> >  
M> > -static u_int8_t arc4_randbyte(void);
M> > +struct arc4_s {
M> > +	u_int8_t i, j;
M> > +	int numruns;
M> > +	u_int8_t sbox[256];
M> > +	time_t t_reseed;
M> > +
M> > +	struct mtx mtx;
M> > +};
M> > +
M> 
M> Why is the lock at the end? Right now you got false sharing with the
M> next entry.
M> 
M> That said, I suggest:
M> 1. moving thelock to the beginning
M> 2. annotating the struct with __aligned(CACHE_LINE_SIZE)

It could be even better not to allocate them with regular malloc at all,
but to put them into the per cpu areas. I haven't tried, but looks like
the DPCPU mechanism defined in sys/pcpu.h would fit that well.

-- 
Totus tuus, Glebius.


More information about the svn-src-all mailing list