Date: Wed, 6 Jun 2018 00:56:47 +0200 From: Mateusz Guzik <mjguzik@gmail.com> To: Gleb Smirnoff <glebius@freebsd.org> Cc: Eric van Gyzen <eric@vangyzen.net>, Mateusz Guzik <mjg@freebsd.org>, src-committers <src-committers@freebsd.org>, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r334545 - in head/sys: contrib/zstd/lib/freebsd kern netinet/libalias sys Message-ID: <CAGudoHGeEYZV2Cnxh8AYoReWpJRD0VRkaNTAMd=B_3%2Bz7E2UOA@mail.gmail.com> In-Reply-To: <20180605225215.GC1005@FreeBSD.org> References: <201806022220.w52MK9TT026244@repo.freebsd.org> <1b77e282-e24b-d14c-9811-4cf214d58280@vangyzen.net> <CAGudoHGcZ9b8fvQVx-%2Bxqsr47GzrTZR6%2Bh2C_EqTp3rSjGvATw@mail.gmail.com> <20180605225215.GC1005@FreeBSD.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Jun 6, 2018 at 12:52 AM, Gleb Smirnoff <glebius@freebsd.org> wrote: > On Tue, Jun 05, 2018 at 06:35:37PM +0200, Mateusz Guzik wrote: > M> > On 06/02/2018 17:20, Mateusz Guzik wrote: > M> > > +#ifdef _KERNEL > M> > > +#define malloc(size, type, flags) ({ > \ > M> > > + void *_malloc_item; > \ > M> > > + size_t _size = (size); > \ > M> > > + if (__builtin_constant_p(size) && __builtin_constant_p(flags) > &&\ > M> > > + ((flags) & M_ZERO)) { > \ > M> > > + _malloc_item = malloc(_size, type, (flags) &~ > M_ZERO); \ > M> > > + if (((flags) & M_WAITOK) || _malloc_item != NULL) > \ > M> > > + bzero(_malloc_item, _size); > \ > M> > > + } else { > \ > M> > > + _malloc_item = malloc(_size, type, flags); > \ > M> > > + } > \ > M> > > + _malloc_item; > \ > M> > > +}) > M> > > +#endif > M> > > M> > Mateusz, > M> > > M> > Thank you for this and for all of your performance work. It is all > very > M> > interesting stuff. > M> > > M> > > M> Thank you for the kind words. It is positive feedback like this which > M> keeps me going! > > Btw, what was the point of checking flags || result? Most places in kernel > ignore flags and just test result regerdless of M_WAITOK/M_NOWAIT. > > The result is already in a register, why do you think checking for absense > of M_WAITOK is faster that checking for !NULL _malloc_item? > This part is only reachable if flags are known at compilation time. If they contain M_WAITOK, the flag check will get elided along (we know for a fact it passes) and subsequently the NULL check will be short circuited, iow for known M_WAITOK|M_ZERO flags this is: _malloc_item = malloc(_size, type, flags & ~ M_ZERO); bzero(_malloc_item, _size); -- Mateusz Guzik <mjguzik gmail.com>
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAGudoHGeEYZV2Cnxh8AYoReWpJRD0VRkaNTAMd=B_3%2Bz7E2UOA>