Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752567AbbKLAns (ORCPT ); Wed, 11 Nov 2015 19:43:48 -0500 Received: from mailout2.samsung.com ([203.254.224.25]:59563 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752403AbbKLAnr (ORCPT ); Wed, 11 Nov 2015 19:43:47 -0500 X-AuditID: cbfee61b-f79d56d0000048c5-36-5643e0c193cf From: Fan Li To: "'Jaegeuk Kim'" Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Subject: [f2fs-dev] [PATCH] f2fs: optimize __find_rev_next_bit Date: Thu, 12 Nov 2015 08:43:04 +0800 Message-id: <000001d11ce3$2f947f30$8ebd7d90$@samsung.com> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-index: AdEc4wd9supp6CFzRj62bTxxJJkvqQ== Content-language: en-us X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrNLMWRmVeSWpSXmKPExsVy+t9jQd2DD5zDDPa8kbJ4sn4Ws8WlRe4W l3fNYXNg9ti0qpPNY/eCz0wenzfJBTBHcdmkpOZklqUW6dslcGWc7r3MWHBVuGJTcydLA+MM /i5GTg4JAROJV0vfsUHYYhIX7q0Hsrk4hARmMUocW3qTCcJ5xSix5dwPdpAqNgF1iS0zu5lA bBEBNYnefVOAbA4OZgEPiV3HSkHCwgJ2Ek+XLQMrZxFQlXi99RPYAl4BS4lXU96yQtiCEj8m 32MBsZkFtCTW7zzOBGHLS2xe85YZ4iAFiR1nXzNCrNKTmPH/FFS9uMSkBw/ZJzACXYkwahaS UbOQjJqFpGUBI8sqRonUguSC4qT0XKO81HK94sTc4tK8dL3k/NxNjOAgfia9g/HwLvdDjAIc jEo8vBNmOocJsSaWFVfmHmKU4GBWEuENmAcU4k1JrKxKLcqPLyrNSS0+xCjNwaIkzqvvaRQm JJCeWJKanZpakFoEk2Xi4JRqYLSvYn/TeDZ8Y6f37BsCr1+IZh3s2PyS8eGRe2+CO/P7JBXy bvm7aG+LYXT6OjOSqW/WQh1NcV+Xp4fKjRVZX6YHvoj04bjDyd/wY77qhr8e0bp7vcrUJiSd TvAr/f6jektVWHfI3/ZVVX4v5j1cZZN42TXiUGLV4/mln3O+povcvBt7i7uoW4mlOCPRUIu5 qDgRAET3B6ZeAgAA Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2672 Lines: 95 1. Skip __reverse_ulong if the bitmap is empty. 2. Reduce branches and codes. According to my test, the performance of this new version is 5% higher on an empty bitmap of 64bytes, and remains about the same in the worst scenario. Signed-off-by: Fan li --- fs/f2fs/segment.c | 46 ++++++++++++++++++---------------------------- 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index f77b325..efbf6b5 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -86,6 +86,7 @@ static inline unsigned long __reverse_ffs(unsigned long word) /* * __find_rev_next(_zero)_bit is copied from lib/find_next_bit.c because * f2fs_set_bit makes MSB and LSB reversed in a byte. + * @size must be integral times of unsigned long. * Example: * MSB <--> LSB * f2fs_set_bit(0, bitmap) => 1000 0000 @@ -95,47 +96,36 @@ static unsigned long __find_rev_next_bit(const unsigned long *addr, unsigned long size, unsigned long offset) { const unsigned long *p = addr + BIT_WORD(offset); - unsigned long result = offset & ~(BITS_PER_LONG - 1); + unsigned long result = size; unsigned long tmp; if (offset >= size) return size; - size -= result; + size -= (offset & ~(BITS_PER_LONG - 1)); offset %= BITS_PER_LONG; - if (!offset) - goto aligned; - tmp = __reverse_ulong((unsigned char *)p); - tmp &= ~0UL >> offset; - - if (size < BITS_PER_LONG) - goto found_first; - if (tmp) - goto found_middle; + while (1) { + if (*p == 0) + goto pass; - size -= BITS_PER_LONG; - result += BITS_PER_LONG; - p++; -aligned: - while (size & ~(BITS_PER_LONG-1)) { tmp = __reverse_ulong((unsigned char *)p); + + tmp &= ~0UL >> offset; + if (size < BITS_PER_LONG) + tmp &= (~0UL << (BITS_PER_LONG - size)); if (tmp) - goto found_middle; - result += BITS_PER_LONG; + goto found; +pass: + if (size <= BITS_PER_LONG) + break; size -= BITS_PER_LONG; + offset = 0; p++; } - if (!size) - return result; - - tmp = __reverse_ulong((unsigned char *)p); -found_first: - tmp &= (~0UL << (BITS_PER_LONG - size)); - if (!tmp) /* Are any bits set? */ - return result + size; /* Nope. */ -found_middle: - return result + __reverse_ffs(tmp); + return result; +found: + return result - size + __reverse_ffs(tmp); } static unsigned long __find_rev_next_zero_bit(const unsigned long *addr, -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/