All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch 086/115] include/linux/bitmap.h: turn bitmap_set and bitmap_clear into memset when possible
@ 2017-07-10 22:51 akpm
  0 siblings, 0 replies; only message in thread
From: akpm @ 2017-07-10 22:51 UTC (permalink / raw)
  To: akpm, linux, mawilcox, mm-commits, schwidefsky, torvalds, willy

From: Matthew Wilcox <mawilcox@microsoft.com>
Subject: include/linux/bitmap.h: turn bitmap_set and bitmap_clear into memset when possible

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.

Link: http://lkml.kernel.org/r/20170628153221.11322-4-willy@infradead.org
Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
Acked-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Matthew Wilcox <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 include/linux/bitmap.h |    6 ++++++
 1 file changed, 6 insertions(+)

diff -puN include/linux/bitmap.h~turn-bitmap_set-and-bitmap_clear-into-memset-when-possible include/linux/bitmap.h
--- a/include/linux/bitmap.h~turn-bitmap_set-and-bitmap_clear-into-memset-when-possible
+++ a/include/linux/bitmap.h
@@ -319,6 +319,9 @@ static __always_inline void bitmap_set(u
 {
 	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((char *)map + start / 8, 0xff, nbits / 8);
 	else
 		__bitmap_set(map, start, nbits);
 }
@@ -328,6 +331,9 @@ static __always_inline void bitmap_clear
 {
 	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((char *)map + start / 8, 0, nbits / 8);
 	else
 		__bitmap_clear(map, start, nbits);
 }
_

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-07-10 22:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-10 22:51 [patch 086/115] include/linux/bitmap.h: turn bitmap_set and bitmap_clear into memset when possible akpm

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.