From owner-freebsd-arch@FreeBSD.ORG Sun Jul 13 13:34:26 2014 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id D7ED9910; Sun, 13 Jul 2014 13:34:26 +0000 (UTC) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 613A02746; Sun, 13 Jul 2014 13:34:26 +0000 (UTC) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.14.9/8.14.9) with ESMTP id s6DDYLhA094582 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 13 Jul 2014 16:34:21 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.8.3 kib.kiev.ua s6DDYLhA094582 Received: (from kostik@localhost) by tom.home (8.14.9/8.14.9/Submit) id s6DDYLpN094581; Sun, 13 Jul 2014 16:34:21 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Sun, 13 Jul 2014 16:34:21 +0300 From: Konstantin Belousov To: Mateusz Guzik Subject: Re: Getting rid of atomic_load_acq_int(&fdp->fd_nfiles)) from fget_unlocked Message-ID: <20140713133421.GA93733@kib.kiev.ua> References: <20140713035500.GC16884@dft-labs.eu> <20140713132521.GY93733@kib.kiev.ua> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="zE+0D7H8clM/QbKf" Content-Disposition: inline In-Reply-To: <20140713132521.GY93733@kib.kiev.ua> User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on tom.home Cc: freebsd-arch@freebsd.org X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 13 Jul 2014 13:34:27 -0000 --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--