linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Yury Norov <yury.norov@gmail.com>
Cc: masmart@yandex.ru, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, cl@linux.com, enberg@kernel.org,
	rientjes@google.com, iamjoonsoo.kim@lge.com,
	linux@rasmusvillemoes.dk, Alexey Klimov <klimov.linux@gmail.com>
Subject: Re: [PATCH] mm: slab.h: use ilog2() in kmalloc_index()
Date: Tue, 21 Jun 2016 14:52:37 -0700	[thread overview]
Message-ID: <20160621145237.dae264ea5fe6b3b7f2d2d4e6@linux-foundation.org> (raw)
In-Reply-To: <1466465586-22096-1-git-send-email-yury.norov@gmail.com>

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.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2016-06-21 21:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-20 23:33 [PATCH] mm: slab.h: use ilog2() in kmalloc_index() Yury Norov
2016-06-21 21:52 ` Andrew Morton [this message]
2016-06-22  0:51   ` Yury Norov
2016-06-22 13:28     ` Christoph Lameter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160621145237.dae264ea5fe6b3b7f2d2d4e6@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=cl@linux.com \
    --cc=enberg@kernel.org \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=klimov.linux@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=masmart@yandex.ru \
    --cc=rientjes@google.com \
    --cc=yury.norov@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).