Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 13 Jul 2014 16:34:21 +0300
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        Mateusz Guzik <mjguzik@gmail.com>
Cc:        freebsd-arch@freebsd.org
Subject:   Re: Getting rid of atomic_load_acq_int(&fdp->fd_nfiles)) from fget_unlocked
Message-ID:  <20140713133421.GA93733@kib.kiev.ua>
In-Reply-To: <20140713132521.GY93733@kib.kiev.ua>
References:  <20140713035500.GC16884@dft-labs.eu> <20140713132521.GY93733@kib.kiev.ua>

next in thread | previous in thread | raw e-mail | index | archive | help

--zE+0D7H8clM/QbKf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sun, Jul 13, 2014 at 04:25:21PM +0300, Konstantin Belousov wrote:
> On Sun, Jul 13, 2014 at 05:55:00AM +0200, Mateusz Guzik wrote:
> > Currently:
> >         /*
> >          * Avoid reads reordering and then a first access to the
> >          * fdp->fd_ofiles table which could result in OOB operation.
> >          */
> >         if (fd < 0 || fd >=3D atomic_load_acq_int(&fdp->fd_nfiles))
> >                 return (EBADF);
> >=20
> > However, if we put fd_nfiles and fd_otable into one atomically replaced
> > structure the only need to:
> > 1. make sure the pointer is read once
> > 2. issue a data dependency barrier - this is a noop on all supported
> > architectures and we don't even have approprate macro, so doing nothing
> > seems fine
> >=20
> > The motivation is to boost performance to amortize for seqlock cost, in
> > case it hits the tree.
> >=20
> > This has no impact on races with capability lookup.
> >=20
> > In a microbenchmark of 16 threads reading from the same pipe fd
> > immediately returning EAGAIN the numbers are:
> > x vanilla-readpipe-run-sum            =20
> > + noacq-readpipe-run-sum
> > [..]
> >     N           Min           Max        Median           Avg        St=
ddev
> > x  20      13133671      14900364      13893331      13827075     47150=
0.82
> > +  20      59479718      59527286      59496714      59499504     13752=
=2E968
> > Difference at 95.0% confidence
> > 	4.56724e+07 +/- 213483
> > 	330.312% +/- 1.54395%
> >=20
> > There are 3 steps:
> > 1. tidy up capsicum to accept fde:
> > http://people.freebsd.org/~mjg/patches/single-fdtable-read-capsicum.pat=
ch
> > 2. add __READ_ONCE:
> > http://people.freebsd.org/~mjg/patches/read-once.patch
> > 3. put stuff into one structure:
> > http://people.freebsd.org/~mjg/patches/filedescenttable.patch
> >=20
> > Comments?
>=20
> We use 4-space indent for the continuation lines.  Look at the malloc(9)
> call in the patch 3.
>=20
> The filedescenttable is really long name.  Could it be, for instance,
> fdescenttbl ?
>=20
> Other than that, I think that the patches 2 and 3 are fine.  I did not
> looked at the patch 1.


As an afterthought, you do not need __READ_ONCE(), the __DEVOLATILE() alone
would do what you need as well.

--zE+0D7H8clM/QbKf
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQIcBAEBAgAGBQJTwordAAoJEJDCuSvBvK1Bw4oP/3O1Zv2SYSRXPUfr666VceRr
p6Xi7ljuuBizsWAhr0IOK6dL10cyTt+uxyEhUfJhPG3awUXwLV1iw2x42ACRKq1m
vSqDFbTSzVf3Uj3zhQQ5CpHeKR7OdNhjCTu2KK0JL9gEOH46ZlNpPRQhrkhXhhmi
xru8fBguBxcw7OGrMmPd9I5lHpqgzD6zX/xiob7w0DhGRRkd39eTpcuY37QHs3Ti
Hhgb+hOfliTjvlPthixv4c9AUn00imQwYaudfLhBMCywBNzuxNgcUegRTaMM+lpI
QlRhBZczyVnCiomK5POgRb0cOUKrWBKSPfSuU4YPzHIG84LnRpThDEHNTq6JKSDa
b2LWGLHRFqhMTYlS8t1ecYP05mZl2edooQ1wSXqPujK/3vgNfH1nFs1C1eLcjpvL
hlbtohRYuXox6Oj07LWTmgYcggP01wwPhxPzw/UiG/Y3IHGgx9TQC3RirEtXOWhL
+p/i/QT1XyTQwR7XxLhPIp5SUd32zBgryAgwTL/lsyp/gnNJ6030T9EAkUNaoIEX
LhxWn59jYYc9IV70jwI4Gw85yyBOviSjUmGfgm6bdNEGytvirTx+zhQCfIJ5yWey
jc8LS6+1JDix+3AMFFpFqUdNqzvdsSKmChoNpdWoMmqH0HXw5qytN+BQUnG1vjAZ
U1/qYhqgyS55biK0r5yC
=M+4j
-----END PGP SIGNATURE-----

--zE+0D7H8clM/QbKf--



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