linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Weiner <hannes@cmpxchg.org>
To: "Robert P. J. Day" <rpjday@crashcourse.ca>
Cc: linux-mm@kvack.org, Andrew Morton <akpm@osdl.org>
Subject: Re: [PATCH] MM: Rewrite some tests with is_power_of_2() for clarity.
Date: Mon, 27 Apr 2009 19:04:28 +0200	[thread overview]
Message-ID: <20090427170428.GA1890@cmpxchg.org> (raw)
In-Reply-To: <alpine.LFD.2.00.0904240834270.22152@localhost.localdomain>

On Fri, Apr 24, 2009 at 08:46:15AM -0400, Robert P. J. Day wrote:
> 
> Replace some conditional tests with the semantically clearer call to
> is_power_of_2().
> 
> Signed-off-by: Robert P. J. Day <rpjday@crashcourse.ca>
>
> ---
> 
>   there are other tests of the form "n & (n - 1)" in mm/, but they are
> testing for single bitness so they should be left alone.
> 
>   compile-tested on x86_64 with "make defconfig".
> 
> 
> diff --git a/mm/bootmem.c b/mm/bootmem.c
> index daf9271..5b379c2 100644
> --- a/mm/bootmem.c
> +++ b/mm/bootmem.c
> @@ -12,6 +12,7 @@
>  #include <linux/pfn.h>
>  #include <linux/bootmem.h>
>  #include <linux/module.h>
> +#include <linux/log2.h>
> 
>  #include <asm/bug.h>
>  #include <asm/io.h>
> @@ -438,7 +439,7 @@ static void * __init alloc_bootmem_core(struct bootmem_data *bdata,
>  		align, goal, limit);
> 
>  	BUG_ON(!size);
> -	BUG_ON(align & (align - 1));
> +	BUG_ON(!is_power_of_2(align));

Note that this is no 1:1 translation.  align could be zero before but
not anymore.  Have you checked whether all callsites are ready for
this?  The common bootmem macros use alignment to cacheline or page
boundary.  I haven't checked all callsites that might use __api,
though.

OTOH, it's doubtful that 'no alignment' should be expressed as 0
instead of 1.

Still, it probably makes sense to express this change in semantics in
the changelog.

> diff --git a/mm/slub.c b/mm/slub.c
> index 7ab54ec..640831a 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -26,6 +26,7 @@
>  #include <linux/memory.h>
>  #include <linux/math64.h>
>  #include <linux/fault-inject.h>
> +#include <linux/log2.h>
> 
>  /*
>   * Lock order:
> @@ -3056,7 +3057,7 @@ void __init kmem_cache_init(void)
>  	 * around with ARCH_KMALLOC_MINALIGN
>  	 */
>  	BUILD_BUG_ON(KMALLOC_MIN_SIZE > 256 ||
> -		(KMALLOC_MIN_SIZE & (KMALLOC_MIN_SIZE - 1)));
> +		(!is_power_of_2(KMALLOC_MIN_SIZE)));

Maybe you can remove the parens here.  But that's probably optional.

	Hannes

--
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>

  parent reply	other threads:[~2009-04-27 17:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-24 12:46 [PATCH] MM: Rewrite some tests with is_power_of_2() for clarity Robert P. J. Day
2009-04-27 15:59 ` Christoph Lameter
2009-04-27 17:04 ` Johannes Weiner [this message]
2009-04-27 19:58   ` Andrew Morton

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=20090427170428.GA1890@cmpxchg.org \
    --to=hannes@cmpxchg.org \
    --cc=akpm@osdl.org \
    --cc=linux-mm@kvack.org \
    --cc=rpjday@crashcourse.ca \
    /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).