[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20170607142924.28552-3-willy@infradead.org>
Date: Wed, 7 Jun 2017 07:29:23 -0700
From: Matthew Wilcox <willy@...radead.org>
To: linux-kernel@...r.kernel.org
Cc: Andrew Morton <akpm@...ux-foundation.org>,
Martin Schwidefsky <schwidefsky@...ibm.com>,
Rasmus Villemoes <linux@...musvillemoes.dk>,
Matthew Wilcox <mawilcox@...rosoft.com>
Subject: [PATCH 2/3] Turn bitmap_set and bitmap_clear into memset when possible
From: Matthew Wilcox <mawilcox@...rosoft.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@...rosoft.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
__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
__bitmap_clear(map, start, nbits);
}
--
2.11.0
Powered by blists - more mailing lists