From owner-freebsd-arch@FreeBSD.ORG Sun Jul 13 13:25:28 2014 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 54C93458; Sun, 13 Jul 2014 13:25:28 +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 EBF1E2688; Sun, 13 Jul 2014 13:25:27 +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 s6DDPLNw092428 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 13 Jul 2014 16:25:21 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.8.3 kib.kiev.ua s6DDPLNw092428 Received: (from kostik@localhost) by tom.home (8.14.9/8.14.9/Submit) id s6DDPLXo092426; Sun, 13 Jul 2014 16:25: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:25: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: <20140713132521.GY93733@kib.kiev.ua> References: <20140713035500.GC16884@dft-labs.eu> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="pDmaGFxwxkQ3NNKB" Content-Disposition: inline In-Reply-To: <20140713035500.GC16884@dft-labs.eu> 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:25:28 -0000 --pDmaGFxwxkQ3NNKB Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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 Stdd= ev > x 20 13133671 14900364 13893331 13827075 471500.= 82 > + 20 59479718 59527286 59496714 59499504 13752.9= 68 > 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.patch > 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? We use 4-space indent for the continuation lines. Look at the malloc(9) call in the patch 3. The filedescenttable is really long name. Could it be, for instance, fdescenttbl ? Other than that, I think that the patches 2 and 3 are fine. I did not looked at the patch 1. --pDmaGFxwxkQ3NNKB Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBAgAGBQJTwojAAAoJEJDCuSvBvK1BtIsP/3zuyAmdtT1PqaKnkriAsFQX ZAfDbBn61QpeaGLH2Diz4Cpa+Hq2W8BACL5RlWWbiYBgZhjMzSwv4tc/boORQQUn ObBbmNbCvjvUsxKgD3TfZR6XX0zuPiYnKZymhL3v/25ZyR9iTgWitGywQPVPOvgr G8NiONimPIQT8Mn70f57YwLFdnqThmuLFAXGfKOVH9+1dtBsIqEfQ8r8dasd6rDK iozaCjXDeAtpqNCDJ3xuA4ZxErZHptqaL9oz0kdOOXHLKm++WKvcaGJD8JPfHWHq 2BsQ8HKAxKeipxMT1lTR1fpq6Jabjawed6mSrhZmFBYn37FcXSu5IFN86MiyR3sy cXCysNoa9jLnzmQirvzgTYs0l1H28nIE8YCHAWdOtWsOkGWr/0LhFXXAkMagrhum tC/+8IUMiK8STTPVSD34ejuylP7KpLrCsTWMbjgqisRiHBC+F7Mcw3XvCuv7cd8k vjR0JQ2kOFe1vctHd2PmtKG3Pzc8egARmIAfRcHSIYoB3d4yVLldJ+9OqWjyTIJA GhKJ4LV1PLQz/uI7ZxVQ7UBOlVfQUn/qIidoJ7+2QULAsbRSUmucoDEvJT1CsqsN 6zItQLo87f4S5VjREbT/86euGaoiThwDbdaXeDLkoWKksVQiLud8qmHhJPg4tNZj rN23tB0N9qoHWLrSFwY4 =nHRc -----END PGP SIGNATURE----- --pDmaGFxwxkQ3NNKB--