diff options
author | Matthew Wilcox <mawilcox@microsoft.com> | 2017-07-10 18:51:29 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-07-10 19:32:34 -0400 |
commit | e5af323c9badd5dc09af7ccf9d45616ebffc623c (patch) | |
tree | da5f5087eb7c2eb2c5953bd34e5facc714de9d67 /include/linux/bitmap.h | |
parent | 3cc78125a081bb79eb38f3e9a585e5a81bb81cb1 (diff) |
bitmap: optimise bitmap_set and bitmap_clear of a single bit
We have eight users calling bitmap_clear for a single bit and seventeen
calling bitmap_set for a single bit. Rather than fix all of them to
call __clear_bit or __set_bit, turn bitmap_clear and bitmap_set into
inline functions and make this special case efficient.
Link: http://lkml.kernel.org/r/20170628153221.11322-3-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>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/bitmap.h')
-rw-r--r-- | include/linux/bitmap.h | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index 3b77588a9360..4e0f0c8167af 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h | |||
@@ -112,9 +112,8 @@ extern int __bitmap_intersects(const unsigned long *bitmap1, | |||
112 | extern int __bitmap_subset(const unsigned long *bitmap1, | 112 | extern int __bitmap_subset(const unsigned long *bitmap1, |
113 | const unsigned long *bitmap2, unsigned int nbits); | 113 | const unsigned long *bitmap2, unsigned int nbits); |
114 | extern int __bitmap_weight(const unsigned long *bitmap, unsigned int nbits); | 114 | extern int __bitmap_weight(const unsigned long *bitmap, unsigned int nbits); |
115 | 115 | extern void __bitmap_set(unsigned long *map, unsigned int start, int len); | |
116 | extern void bitmap_set(unsigned long *map, unsigned int start, int len); | 116 | extern void __bitmap_clear(unsigned long *map, unsigned int start, int len); |
117 | extern void bitmap_clear(unsigned long *map, unsigned int start, int len); | ||
118 | 117 | ||
119 | extern unsigned long bitmap_find_next_zero_area_off(unsigned long *map, | 118 | extern unsigned long bitmap_find_next_zero_area_off(unsigned long *map, |
120 | unsigned long size, | 119 | unsigned long size, |
@@ -315,6 +314,24 @@ static __always_inline int bitmap_weight(const unsigned long *src, unsigned int | |||
315 | return __bitmap_weight(src, nbits); | 314 | return __bitmap_weight(src, nbits); |
316 | } | 315 | } |
317 | 316 | ||
317 | static __always_inline void bitmap_set(unsigned long *map, unsigned int start, | ||
318 | unsigned int nbits) | ||
319 | { | ||
320 | if (__builtin_constant_p(nbits) && nbits == 1) | ||
321 | __set_bit(start, map); | ||
322 | else | ||
323 | __bitmap_set(map, start, nbits); | ||
324 | } | ||
325 | |||
326 | static __always_inline void bitmap_clear(unsigned long *map, unsigned int start, | ||
327 | unsigned int nbits) | ||
328 | { | ||
329 | if (__builtin_constant_p(nbits) && nbits == 1) | ||
330 | __clear_bit(start, map); | ||
331 | else | ||
332 | __bitmap_clear(map, start, nbits); | ||
333 | } | ||
334 | |||
318 | static inline void bitmap_shift_right(unsigned long *dst, const unsigned long *src, | 335 | static inline void bitmap_shift_right(unsigned long *dst, const unsigned long *src, |
319 | unsigned int shift, int nbits) | 336 | unsigned int shift, int nbits) |
320 | { | 337 | { |