Skip to content

Commit 2a98dc0

Browse files
Matthew Wilcoxtorvalds
authored andcommitted
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/[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]>
1 parent e5af323 commit 2a98dc0

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

include/linux/bitmap.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,9 @@ static __always_inline void bitmap_set(unsigned long *map, unsigned int start,
319319
{
320320
if (__builtin_constant_p(nbits) && nbits == 1)
321321
__set_bit(start, map);
322+
else if (__builtin_constant_p(start & 7) && IS_ALIGNED(start, 8) &&
323+
__builtin_constant_p(nbits & 7) && IS_ALIGNED(nbits, 8))
324+
memset((char *)map + start / 8, 0xff, nbits / 8);
322325
else
323326
__bitmap_set(map, start, nbits);
324327
}
@@ -328,6 +331,9 @@ static __always_inline void bitmap_clear(unsigned long *map, unsigned int start,
328331
{
329332
if (__builtin_constant_p(nbits) && nbits == 1)
330333
__clear_bit(start, map);
334+
else if (__builtin_constant_p(start & 7) && IS_ALIGNED(start, 8) &&
335+
__builtin_constant_p(nbits & 7) && IS_ALIGNED(nbits, 8))
336+
memset((char *)map + start / 8, 0, nbits / 8);
331337
else
332338
__bitmap_clear(map, start, nbits);
333339
}

0 commit comments

Comments
 (0)