From owner-freebsd-hackers@FreeBSD.ORG Thu Sep 20 09:03:15 2012 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4A2E0106566C for ; Thu, 20 Sep 2012 09:03:15 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id B43348FC1E for ; Thu, 20 Sep 2012 09:03:14 +0000 (UTC) Received: from skuns.kiev.zoral.com.ua (localhost [127.0.0.1]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id q8K93JJu041520; Thu, 20 Sep 2012 12:03:20 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5) with ESMTP id q8K9370S049969; Thu, 20 Sep 2012 12:03:07 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5/Submit) id q8K937tp049968; Thu, 20 Sep 2012 12:03:07 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Thu, 20 Sep 2012 12:03:07 +0300 From: Konstantin Belousov To: Dag-Erling Sm??rgrav Message-ID: <20120920090307.GY37286@deviant.kiev.zoral.com.ua> References: <86wqzr8hbk.fsf@ds4.des.no> <20120919061005.GR37286@deviant.kiev.zoral.com.ua> <86lig6map1.fsf@ds4.des.no> <20120919175354.GV37286@deviant.kiev.zoral.com.ua> <864nmtn8ap.fsf@ds4.des.no> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="36OpTq80o519DUb3" Content-Disposition: inline In-Reply-To: <864nmtn8ap.fsf@ds4.des.no> User-Agent: Mutt/1.5.21 (2010-09-15) X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-4.0 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: hackers@freebsd.org Subject: Re: fdgrowtable() cleanup X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Sep 2012 09:03:15 -0000 --36OpTq80o519DUb3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Sep 19, 2012 at 09:04:30PM +0200, Dag-Erling Sm??rgrav wrote: > Konstantin Belousov writes: > > "Dag-Erling Sm??rgrav" writes: > > > I assume you mean assignments, not calculations. I trust the compiler > > > to move them to where they are needed - a trivial optimization with S= SA. > > It is a dereference before the assignment, so I perceive it as the > > calculation. No, I do not think that compiler can move the dereference, > > because there are many sequential points between the calculation and > > use of the result. >=20 > Sequence points are a language feature and are only meaningful in the > translation phase. Once the code is in SSA form or some other > equivalent intermediate representation, the compiler can see that the > variables are only used in one specific case and move the assignments > inside that block. In fact, it will probably optimize them away, > because they are completely unnecessary - I added them solely for > readability after Niclas called my attention to the fact that it is > almost impossible to understand fdgrowtable() at a first reading. Compiler cannot change the semantic of the program regardless of the phase of compilation the change happens at. Compiler that would reorder reads from the global memory across sequential points seems to be not disallowed by c99, but it certainly contradicts to our semantic of the lock releases, which the compiler cannot infer from the non-inlined function calls. Malloc call is the sequential point and does have the release semantic FWIW. >=20 > > > Correct, thanks for pointing it out. The easiest solution is to place > > > the struct freetable between the file array and the flag array. > > As I know, for all ABIs FreeBSD run on, the structure alignment is the > > alignment of the most requiring member. You would introduce very tacit > > dependency between struct file and struct freetable. >=20 > The existing code *already* places the struct freetable immediately > after the struct file array. What I'm proposing now is to leave the > struct freetable where it was but move the fileflags array so they don't > overlap. The fileflags array is actually a char[] and has no alignment > requirement. Ok. >=20 > Memory usage will not increase, because the code already allocates > additional space for the struct freetable to make sure it will fit even > if onfiles < sizeof(struct freetable). >=20 > BTW, I just noticed that there is some dead code in fdgrowtable(): >=20 > nnfiles =3D NDSLOTS(nfd) * NDENTRIES; /* round up */ > if (nnfiles <=3D onfiles) > /* the table is already large enough */ > return; >=20 > /* ... */ >=20 > /* allocate new bitmaps if necessary */ > if (NDSLOTS(nnfiles) > NDSLOTS(onfiles)) > nmap =3D malloc(NDSLOTS(nnfiles) * NDSLOTSIZE, > M_FILEDESC, M_ZERO | M_WAITOK); > else > nmap =3D NULL; >=20 > Since neither nnflags nor onflags are modified between these two chunks > of code, the condition in the second if will always be true. You mean that new bitmap shall be always allocated, making the nmap =3D NULL assignment not needed ? I agree. It would also make the code in the last if () executed unconditionally. --36OpTq80o519DUb3 Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (FreeBSD) iEYEARECAAYFAlBa28sACgkQC3+MBN1Mb4iMvQCgs8ErLCd+u/rdXJlFY62KSEyL b/0AoOh4rMwY2hPpjBfHwu14/zyRA0Re =BFWO -----END PGP SIGNATURE----- --36OpTq80o519DUb3--