From owner-svn-src-head@freebsd.org Thu Jun 7 19:38:33 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 286EAFE96BD for ; Thu, 7 Jun 2018 19:38:33 +0000 (UTC) (envelope-from marklmi26-fbsd@yahoo.com) Received: from sonic304-22.consmr.mail.ne1.yahoo.com (sonic304-22.consmr.mail.ne1.yahoo.com [66.163.191.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B99497B460 for ; Thu, 7 Jun 2018 19:38:32 +0000 (UTC) (envelope-from marklmi26-fbsd@yahoo.com) X-YMail-OSG: n4sz2LQVM1nSWG5KeRDsSuk_IW0z_dd0AU7Yp3j4u0SKqQjz2HTzdRbGfL3LWTd hvdAWeX7XknVUGTJX3it4crUJw36fGqC2AtvhcNDnao7kDza.NpMH7fZIIjjVMT0N0l9GG1rvTls y4tilL_7weSvhegsPaYGunv1v_cELIrLlC.yW4hrH586S6OC25wdkwLIosJqrOixhJYhmYJba_Lk gUHxJV6xcAzEj1kSzQwfljV3hEl0H9_EZvI2QSg5uihp9mk2oZDVWG5Uz7p0EeADU8FFOxWYXdyU g59cbxBtGhV1PUNl_NnM71hg6_aVrwy2WQGW3HdscGH2UBGeLlrXFck4wMPpdE4BzzZs7HwSo1zD 2m5_X3AIS28g2pxnE5EtTEcB1SyCH0YSrwiupIsCElJUu7E65HJEyU3Ry6_II2Dxv50VibhowuQy ZyfXFo5D9c0BZeIQq4TEPrJvZWqOfcnYp1fPx5MWTuRvAe3K0JDD2rZUnejKk.PhdGmVBrStub4w p1asiATGTyMQK_VFq6qL0xvT2niyBl3MgEG.W7SeOjMfrujtYBGeXLydpssQYak54aLMqcAgN.Gm HrqwItN0gVxgak_erCYL1qq9POTLk8d91S_OFl4vgzSHs2D3U3Hwym9jR2SPR8842VdIWk81NGkS fds1rjThwywEamtUGxxILTD9WyJINaxNfLTU4GArlEgwaB4Xa3k8SUVeZl8Wvd6mnMMvi.DCqalI pkoDdToDEctH6_FD9aFb.P776tX91vnoJv_HZMrHhqtvRsWpdj8Sq3Wt9mR4fUbCNSnhdFUwCvfv hTLsdaklgtcIE48oWVQmyh0MO6VEBTeTJ4gj7yMfHvPb6TSVZa40rVVFDqt2YkTyRZpwmYaGqMQk gE6yDdNZTWZ2GxCWNWUmgSi1HrgVOd6c3irGYcKVcbrnEbljFcFvqOK6En86mcmnkl6DVb.wXaAD wbGCVvKMO Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.ne1.yahoo.com with HTTP; Thu, 7 Jun 2018 19:38:26 +0000 Received: from ip70-189-131-151.lv.lv.cox.net (EHLO [192.168.0.109]) ([70.189.131.151]) by smtp411.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 7bcc51cd6159f764eae5b7d4a75be276; Thu, 07 Jun 2018 19:38:21 +0000 (UTC) From: Mark Millard Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Mac OS X Mail 11.4 \(3445.8.2\)) Subject: Re: svn commit: r334702 - head/sys/sys Message-Id: Date: Thu, 7 Jun 2018 12:38:19 -0700 To: jtl@freebsd.org, svn-src-head@freebsd.org X-Mailer: Apple Mail (2.3445.8.2) X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Jun 2018 19:38:33 -0000 Jonathan T. Looney jtl at freebsd.org wrote on Thu Jun 7 03:00:00 UTC 2018 : > I believe the theory is that the compiler (remember, this is > __builtin_memset) can optimize away portions of the zeroing, or can > optimize zeroing for small sizes. > > For example, imagine you do this: > > struct foo { > uint32_t a; > uint32_t b; > }; > > struct foo * > alloc_foo(void) > { > struct foo *rv; > > rv = malloc(sizeof(*rv), M_TMP, M_WAITOK|M_ZERO); > rv->a = 1; > rv->b = 2; > return (rv); > } > > In theory, the compiler can be smart enough to know that the entire > structure is initialized, so it is not necessary to zero it. > > (I personally have not tested how well this works in practice. However, > this change theoretically lets the compiler be smarter and optimize away > unneeded work.) > > At minimum, it should let the compiler replace calls to memset() (and the > loops there) with optimal instructions to zero the exact amount of memory > that needs to be initialized. (Again, I haven't personally tested how smart > the compilers we use are about producing optimal code in this situation.) Change struct foo to something like (just a specific illustration of a more general type of context): struct foo { uint16_t a; // assume padding in the struct uint32_t b; }; Are the compilers well behaved about always initializing the padding (if any) to zero when the __builtin_memset is used to implement M_ZERO but the compiler is optimizing what is actually zeroed based on what was initialized explicitly? === Mark Millard marklmi at yahoo.com ( dsl-only.net went away in early 2018-Mar)