Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1428223

Re: [PATCH] mm: slab.h: use ilog2() in kmalloc_index()

From Andrew Morton <akpm@linux-foundation.org>
Newsgroups linux.kernel
Subject Re: [PATCH] mm: slab.h: use ilog2() in kmalloc_index()
Date 2016-06-22 00:10 +0200
Message-ID <rMC1Q-3dH-13@gated-at.bofh.it> (permalink)
References <rMh74-6ol-41@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Tue, 21 Jun 2016 02:33:06 +0300 Yury Norov <yury.norov@gmail.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) so the compiler will evaluate the switch
statement at compile-time.  This will be more efficient than calling
fls() at runtime.

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] mm: slab.h: use ilog2() in kmalloc_index() Yury Norov <yury.norov@gmail.com> - 2016-06-21 01:50 +0200
  Re: [PATCH] mm: slab.h: use ilog2() in kmalloc_index() Andrew Morton <akpm@linux-foundation.org> - 2016-06-22 00:10 +0200
    Re: [PATCH] mm: slab.h: use ilog2() in kmalloc_index() Christoph Lameter <cl@linux.com> - 2016-06-22 15:30 +0200

csiph-web