include/linux/bitmap.h: turn bitmap_set and bitmap_clear into memset when possible
authorMatthew Wilcox <[email protected]>
Mon, 10 Jul 2017 22:51:32 +0000 (15:51 -0700)
committerLinus Torvalds <[email protected]>
Mon, 10 Jul 2017 23:32:34 +0000 (16:32 -0700)
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/[email protected]
Signed-off-by: Matthew Wilcox <[email protected]>
Acked-by: Rasmus Villemoes <[email protected]>
Cc: Martin Schwidefsky <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
include/linux/bitmap.h

index 4e0f0c8167af753898b814249677b71c440eeb2e..c04c9d155e59c4df3a8ce40d9126744ff50fb403 100644 (file)
@@ -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((char *)map + start / 8, 0xff, nbits / 8);
        else
                __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((char *)map + start / 8, 0, nbits / 8);
        else
                __bitmap_clear(map, start, nbits);
 }