lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Wed, 22 Jun 2016 03:51:35 +0300
From:	Yury Norov <ynorov@...iumnetworks.com>
To:	Andrew Morton <akpm@...ux-foundation.org>
CC:	Yury Norov <yury.norov@...il.com>, <masmart@...dex.ru>,
	<linux-mm@...ck.org>, <linux-kernel@...r.kernel.org>,
	<cl@...ux.com>, <enberg@...nel.org>, <rientjes@...gle.com>,
	<iamjoonsoo.kim@....com>, <linux@...musvillemoes.dk>,
	Alexey Klimov <klimov.linux@...il.com>
Subject: Re: [PATCH] mm: slab.h: use ilog2() in kmalloc_index()

On Tue, Jun 21, 2016 at 02:52:37PM -0700, Andrew Morton wrote:
> On Tue, 21 Jun 2016 02:33:06 +0300 Yury Norov <yury.norov@...il.com> wrote:
> 
> > kmalloc_index() uses simple straightforward way to calculate
> > bit position of nearest or equal upper power of 2.
> > This effectively results in generation of 24 episodes of
> > compare-branch instructions in assembler.
> > 
> > There is shorter way to calculate this: fls(size - 1).
> > 
> > The patch removes hard-coded calculation of kmalloc slab and
> > uses ilog2() instead that works on top of fls(). ilog2 is used
> > with intention that compiler also might optimize constant case
> > during compile time if it detects that.
> > 
> > BUG() is moved to the beginning of function. We left it here to
> > provide identical behaviour to previous version. It may be removed
> > if there's no requirement in it anymore.
> > 
> > While we're at this, fix comment that describes return value.
> 
> kmalloc_index() is always called with a constant-valued `size' (see
> __builtin_constant_p() tests)

It might change one day. This function is public to any slab user.
If you really want to allow call kmalloc_index() for constants only,
you'd place __builtin_constant_p() tests inside kmalloc_index().

> so the compiler will evaluate the switch
> statement at compile-time.  This will be more efficient than calling
> fls() at runtime.

There will be no fls() for constant at runtime because ilog2() calculates 
constant values at compile-time as well. From this point of view,
this patch removes code duplication, as we already have compile-time
log() calculation in kernel, and should re-use it whenever possible.\

Yury.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ