Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 7 Dec 2016 11:41:21 -0800
From:      Gleb Smirnoff <glebius@FreeBSD.org>
To:        Mateusz Guzik <mjguzik@gmail.com>
Cc:        Fabien Thomas <fabient@FreeBSD.org>, svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org
Subject:   Re: svn commit: r309143 - head/sys/libkern
Message-ID:  <20161207194121.GM27748@FreeBSD.org>
In-Reply-To: <20161125160010.GA3307@dft-labs.eu>
References:  <201611251349.uAPDnX09042110@repo.freebsd.org> <20161125160010.GA3307@dft-labs.eu>

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



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