mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Chanho Min <chanho.min@lge.com>
Cc: Nadia Yvette Chambers <nyc@holomorphy.com>,
	Jiri Kosina <jkosina@suse.cz>, Joe Perches <joe@perches.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH RESEND v3] bitmap: speed up bitmap_find_free_region
Date: Wed, 8 May 2013 13:24:54 -0700	[thread overview]
Message-ID: <20130508132454.5dc3770be27f6312701129a2@linux-foundation.org> (raw)
In-Reply-To: <1367914553-1999-1-git-send-email-chanho.min@lge.com>

On Tue,  7 May 2013 17:15:53 +0900 Chanho Min <chanho.min@lge.com> wrote:

> In bitmap_find_free_region, If we skip the all-ones words and find bits
> in a not-all-ones word, we can improve performance of it.
> 
> For example, If bitmap_find_free_region() is called with order=0, First,
> It scans bitmap array by the increment of long type, then find 1 free bit
> within 1 long type value. In 32 bits system and 1024 bits size, in the worst
> case, We need 1024 for-loops to find 1 free bit. But, If this is applied,
> it takes 64 for-loops. Instead, It will be needed additional if-comparison
> of every word and It can take time slightly as 'Test case 3'. But, In many
> cases, It will speed up significantly.
> 
> ...
>
> --- a/lib/bitmap.c
> +++ b/lib/bitmap.c
> @@ -1114,14 +1114,21 @@ done:
>   */
>  int bitmap_find_free_region(unsigned long *bitmap, int bits, int order)
>  {
> -	int pos, end;		/* scans bitmap by regions of size order */
> -
> -	for (pos = 0 ; (end = pos + (1 << order)) <= bits; pos = end) {
> -		if (!__reg_op(bitmap, pos, order, REG_OP_ISFREE))
> -			continue;
> -		__reg_op(bitmap, pos, order, REG_OP_ALLOC);
> -		return pos;
> -	}
> +	int pos, end, nbit, i;	/* scans bitmap by regions of size order */
> +	int nlongs = BITS_TO_LONGS(bits);
> +
> +	for (i = 0; i < nlongs; i++)
> +		if (bitmap[i] != ~0UL) {
> +			pos = i * BITS_PER_LONG;
> +			nbit = min(bits, pos + BITS_PER_LONG);
> +			for (; (end = pos + (1 << order)) <= nbit; pos = end) {
> +				if (!__reg_op(bitmap, pos, order,
> +					REG_OP_ISFREE))
> +					continue;
> +				__reg_op(bitmap, pos, order, REG_OP_ALLOC);
> +				return pos;
> +			}
> +		}
>  	return -ENOMEM;

It could be improved further by returning to the long-at-a-time search
if we failed to find a suffificiently large free region at `i'.  Oh
well, I guess we can do that later if someone cares enough.

We now have a definition of four(!) locals on a single line followed by
a head-scratching comment which doesn't really pertain to any of those
locals anyway.  Let's do this:

From: Andrew Morton <akpm@linux-foundation.org>
Subject: lib-bitmapc-speed-up-bitmap_find_free_region-fix

reduce scope of locals, remove barely comprehensible comment

Cc: Chanho Min <chanho.min@lge.com>
Cc: Jiri Kosina <jkosina@suse.cz>
Cc: Joe Perches <joe@perches.com>
Cc: Nadia Yvette Chambers <nyc@holomorphy.com>
Cc: anish singh <anish198519851985@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 lib/bitmap.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff -puN lib/bitmap.c~lib-bitmapc-speed-up-bitmap_find_free_region-fix lib/bitmap.c
--- a/lib/bitmap.c~lib-bitmapc-speed-up-bitmap_find_free_region-fix
+++ a/lib/bitmap.c
@@ -1114,13 +1114,15 @@ done:
  */
 int bitmap_find_free_region(unsigned long *bitmap, int bits, int order)
 {
-	int pos, end, nbit, i;	/* scans bitmap by regions of size order */
 	int nlongs = BITS_TO_LONGS(bits);
+	int i;
 
 	for (i = 0; i < nlongs; i++)
 		if (bitmap[i] != ~0UL) {
-			pos = i * BITS_PER_LONG;
-			nbit = min(bits, pos + BITS_PER_LONG);
+			int pos = i * BITS_PER_LONG;
+			int nbit = min(bits, pos + BITS_PER_LONG);
+			int end;
+
 			for (; (end = pos + (1 << order)) <= nbit; pos = end) {
 				if (!__reg_op(bitmap, pos, order,
 					REG_OP_ISFREE))
_


      parent reply	other threads:[~2013-05-08 20:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-07  8:15 Chanho Min
2013-05-07 11:42 ` anish singh
2013-05-08  0:59 ` Re : " Chanho Min
2013-05-08 20:24 ` Andrew Morton [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130508132454.5dc3770be27f6312701129a2@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=chanho.min@lge.com \
    --cc=jkosina@suse.cz \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nyc@holomorphy.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®