From owner-svn-src-all@freebsd.org Wed Jun 6 11:35:18 2018 Return-Path: Delivered-To: svn-src-all@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 3A34DFF20B2; Wed, 6 Jun 2018 11:35:18 +0000 (UTC) (envelope-from rpokala@freebsd.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "smtp.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id DEE9470153; Wed, 6 Jun 2018 11:35:17 +0000 (UTC) (envelope-from rpokala@freebsd.org) Received: from [172.20.12.186] (unknown [38.64.177.126]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) (Authenticated sender: rpokala) by smtp.freebsd.org (Postfix) with ESMTPSA id 8552F256B3; Wed, 6 Jun 2018 11:35:17 +0000 (UTC) (envelope-from rpokala@freebsd.org) User-Agent: Microsoft-MacOutlook/10.d.1.180523 Date: Wed, 06 Jun 2018 07:35:12 -0400 Subject: Re: svn commit: r334702 - head/sys/sys From: Ravi Pokala To: Mateusz Guzik , , , Message-ID: <6E6E92B2-7536-4281-8EAF-72823E84902E@panasas.com> Thread-Topic: svn commit: r334702 - head/sys/sys References: <201806060508.w56586c9053686@repo.freebsd.org> In-Reply-To: <201806060508.w56586c9053686@repo.freebsd.org> Mime-version: 1.0 Content-type: text/plain; charset="UTF-8" Content-transfer-encoding: quoted-printable X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Jun 2018 11:35:18 -0000 Hi Mateusz, =EF=BB=BF-----Original Message----- From: on behalf of Mateusz Guzik Date: 2018-06-06, Wednesday at 01:08 To: , , Subject: svn commit: r334702 - head/sys/sys > Author: mjg > Date: Wed Jun 6 05:08:05 2018 > New Revision: 334702 > URL: https://svnweb.freebsd.org/changeset/base/334702 >=20 > Log: > malloc: elaborate on r334545 due to frequent questions I was one of the questioners. :-) Thank you for explaining the conditional = logic. > ... > + * Passing the flag down requires malloc to blindly zero the entire obje= ct. > + * In practice a lot of the zeroing can be avoided if most of the object > + * gets explicitly initialized after the allocation. Letting the compile= r > + * zero in place gives it the opportunity to take advantage of this stat= e. This part, I still don't understand. :-( The call to bzero() is still for the full length passed in, so how does thi= s help? > ... > + * _malloc_item =3D malloc(_size, type, (flags) &~ M_ZERO); > + * if (((flags) & M_WAITOK) !=3D 0 || _malloc_item !=3D NULL) > + * bzero(_malloc_item, _size); > + * > + * If the flag is set, the compiler knows the left side is always true, > + * therefore the entire statement is true and the callsite is: I think you mean "... the *right* side is always true ...", since the left = side is the check for the flag being set. "If the flag is set, compiler know= s (the check for the flag being set) is always true" is tautological. > ... > + * If the flag is not set, the compiler knows the left size is always fa= lse > + * and the NULL check is needed, therefore the callsite is: Same issue here. > ... > #ifdef _KERNEL > #define malloc(size, type, flags) ({ \ Now that I'm taking another look at this, I'm confused as to why the entire= macro expansion is inside parentheses? (The braces make sense, since this i= s a block with local variables which need to be contained.) > void *_malloc_item; \ > @@ -193,7 +228,8 @@ void *malloc(size_t size, struct malloc_type *type, i= n > if (__builtin_constant_p(size) && __builtin_constant_p(flags) &&\ > ((flags) & M_ZERO) !=3D 0) { \ > _malloc_item =3D malloc(_size, type, (flags) &~ M_ZERO); \ > - if (((flags) & M_WAITOK) !=3D 0 || _malloc_item !=3D NULL) \ > + if (((flags) & M_WAITOK) !=3D 0 || \ > + __predict_true(_malloc_item !=3D NULL)) \ > bzero(_malloc_item, _size); \ > } else { \ > _malloc_item =3D malloc(_size, type, flags); \ This confuses me too. If the constant-size/constant-flags/M_ZERO-is-set tes= t fails, then it falls down to calling malloc(). Which we are in the middle = of defining. So what does that expand to? Thanks, Ravi (rpokala@)