From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751994AbdF1Pcs (ORCPT ); Wed, 28 Jun 2017 11:32:48 -0400 Received: from bombadil.infradead.org ([65.50.211.133]:45202 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751526AbdF1Pch (ORCPT ); Wed, 28 Jun 2017 11:32:37 -0400 From: Matthew Wilcox To: linux-kernel@vger.kernel.org Cc: Andrew Morton , Martin Schwidefsky , Rasmus Villemoes , Matthew Wilcox Subject: [PATCH v2 3/4] Turn bitmap_set and bitmap_clear into memset when possible Date: Wed, 28 Jun 2017 08:32:20 -0700 Message-Id: <20170628153221.11322-4-willy@infradead.org> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170628153221.11322-1-willy@infradead.org> References: <20170628153221.11322-1-willy@infradead.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Matthew Wilcox 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 Acked-by: Rasmus Villemoes --- include/linux/bitmap.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index 4e0f0c8167af..c04c9d155e59 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((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); } -- 2.11.0