linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: Matthew Wilcox <willy@infradead.org>
Cc: linux-kernel@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Martin Schwidefsky <schwidefsky@de.ibm.com>,
	Matthew Wilcox <mawilcox@microsoft.com>
Subject: Re: [PATCH 2/3] Turn bitmap_set and bitmap_clear into memset when possible
Date: Wed, 07 Jun 2017 23:16:37 +0200	[thread overview]
Message-ID: <87bmpzbiru.fsf@rasmusvillemoes.dk> (raw)
In-Reply-To: <20170607142924.28552-3-willy@infradead.org> (Matthew Wilcox's message of "Wed, 7 Jun 2017 07:29:23 -0700")

On Wed, Jun 07 2017, Matthew Wilcox <willy@infradead.org> wrote:

> From: Matthew Wilcox <mawilcox@microsoft.com>
>
> Several callers have constant 'start' and an 'nbits' that is a multiple of
> 8, so we can turn them into calls to memset.  We don't need the entirety
> of 'start' and 'nbits' to  be constant, we just need to know whether
> they're divisible by 8.
>
> Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
> ---
>  include/linux/bitmap.h | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
> index 4e0f0c8167af..0b3e4452b054 100644
> --- a/include/linux/bitmap.h
> +++ b/include/linux/bitmap.h
> @@ -319,6 +319,9 @@ static __always_inline void bitmap_set(unsigned long *map, unsigned int start,
>  {
>  	if (__builtin_constant_p(nbits) && nbits == 1)
>  		__set_bit(start, map);
> +	else if (__builtin_constant_p(start & 7) && IS_ALIGNED(start, 8) &&
> +		 __builtin_constant_p(nbits & 7) && IS_ALIGNED(nbits, 8))
> +		memset(map + start / 8, 0xff, nbits / 8);
>  	else

Isn't the pointer arithmetic wrong here? I think you need to cast map to
(char*).

> 
>  		__bitmap_set(map, start, nbits);
>  }
> @@ -328,6 +331,9 @@ static __always_inline void bitmap_clear(unsigned long *map, unsigned int start,
>  {
>  	if (__builtin_constant_p(nbits) && nbits == 1)
>  		__clear_bit(start, map);
> +	else if (__builtin_constant_p(start & 7) && IS_ALIGNED(start, 8) &&
> +		 __builtin_constant_p(nbits & 7) && IS_ALIGNED(nbits, 8))
> +		memset(map + start / 8, 0, nbits / 8);
>  	else

Ditto.

Do you have an example of how the generated code changes, both in the
case of actual constants and a case where gcc can see that start and
nbits are byte-aligned without knowing their actual values?

  reply	other threads:[~2017-06-07 21:16 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-07 14:29 [PATCH 0/3] Bitmap optimisations Matthew Wilcox
2017-06-07 14:29 ` [PATCH 1/3] bitmap: Optimise bitmap_set and bitmap_clear of a single bit Matthew Wilcox
2017-06-07 14:29 ` [PATCH 2/3] Turn bitmap_set and bitmap_clear into memset when possible Matthew Wilcox
2017-06-07 21:16   ` Rasmus Villemoes [this message]
2017-06-27  7:02     ` Matthew Wilcox
2017-06-27  7:58       ` Rasmus Villemoes
2017-06-07 14:29 ` [PATCH 3/3] bitmap: Use memcmp optimisation in more situations Matthew Wilcox
2017-06-08  1:48   ` Andy Shevchenko
2017-06-08  2:55     ` Matthew Wilcox
2017-06-08 12:31       ` Andy Shevchenko
2017-06-08 13:43         ` Rasmus Villemoes
2017-06-08 14:47           ` Andy Shevchenko
2017-06-07 21:37 ` [PATCH 0/3] Bitmap optimisations Rasmus Villemoes

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=87bmpzbiru.fsf@rasmusvillemoes.dk \
    --to=linux@rasmusvillemoes.dk \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mawilcox@microsoft.com \
    --cc=schwidefsky@de.ibm.com \
    --cc=willy@infradead.org \
    /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).