public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jan Blunck <jblunck@suse.de>
To: linux-kernel@vger.kernel.org
Cc: dm-devel@redhat.com
Subject: Re: [patch 01/11] dm-snap: Replace special round_down()
Date: Sun, 12 Aug 2007 17:20:01 +0000 (UTC)	[thread overview]
Message-ID: <f9nfg1$bnd$1@sea.gmane.org> (raw)
In-Reply-To: 25205.2138712772$1186776751@news.gmane.org

On Fri, 10 Aug 2007 22:02:05 +0200, Jan Blunck wrote:

> This patch removes the special round_down() to next power of 2 implementation
> used only at one place in the snapshot target. It is replaced by an equivalent
> 1 << fls() which might use an architecture specific implementation.
> 
> Signed-off-by: Jan Blunck <jblunck@suse.de>
> ---
>  drivers/md/dm-snap.c |   12 +-----------
>  1 file changed, 1 insertion(+), 11 deletions(-)
> 
> --- a/drivers/md/dm-snap.c
> +++ b/drivers/md/dm-snap.c
> @@ -333,16 +333,6 @@ static int calc_max_buckets(void)
>  }
>  
>  /*
> - * Rounds a number down to a power of 2.
> - */
> -static uint32_t round_down(uint32_t n)
> -{
> -	while (n & (n - 1))
> -		n &= (n - 1);
> -	return n;
> -}
> -
> -/*
>   * Allocate room for a suitable hash table.
>   */
>  static int init_hash_tables(struct dm_snapshot *s)
> @@ -361,7 +351,7 @@ static int init_hash_tables(struct dm_sn
>  	hash_size = min(hash_size, max_buckets);
>  
>  	/* Round it down to a power of 2 */
> -	hash_size = round_down(hash_size);
> +	hash_size = 1 << fls(hash_size);
>  	if (init_exception_table(&s->complete, hash_size))
>  		return -ENOMEM;
>  
>

Err, this is sooo stupid. First, 1 << fls(n) isn't round down but
roundup_pow_of_2(). Second, hash_size is of type sector_t which could be
u64 with CONFIG_LBD.

-- 
Subject: dm-snap: Replace special round_down()

This patch removes the special round_down() to next power of 2 implementation
used only at one place in the snapshot target. It is replaced by an equivalent
1 << fls() which might use an architecture specific implementation.

Signed-off-by: Jan Blunck <jblunck@suse.de>
---
 drivers/md/dm-snap.c |   12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)

--- a/drivers/md/dm-snap.c
+++ b/drivers/md/dm-snap.c
@@ -333,16 +333,6 @@ static int calc_max_buckets(void)
 }
 
 /*
- * Rounds a number down to a power of 2.
- */
-static uint32_t round_down(uint32_t n)
-{
-	while (n & (n - 1))
-		n &= (n - 1);
-	return n;
-}
-
-/*
  * Allocate room for a suitable hash table.
  */
 static int init_hash_tables(struct dm_snapshot *s)
@@ -361,7 +351,7 @@ static int init_hash_tables(struct dm_sn
 	hash_size = min(hash_size, max_buckets);
 
 	/* Round it down to a power of 2 */
-	hash_size = round_down(hash_size);
+	hash_size = 1 << (fls_long(hash_size) - 1);
 	if (init_exception_table(&s->complete, hash_size))
 		return -ENOMEM;


  parent reply	other threads:[~2007-08-12 17:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20070810200204.455820246@suse.de>
     [not found] ` <20070810200205.703776854@suse.de>
2007-08-10 20:38   ` [patch 05/11] dm-snap: remove SECTOR_SHIFT define Alasdair G Kergon
2007-08-13  9:20     ` Jan Blunck
     [not found] ` <20070810200205.299669010@suse.de>
2007-08-10 20:43   ` [patch 03/11] dm-snap: Remove dead queued_bios code Alasdair G Kergon
2007-08-13  9:29     ` Jan Blunck
     [not found] ` <25205.2138712772$1186776751@news.gmane.org>
2007-08-12 17:20   ` Jan Blunck [this message]
     [not found] ` <20070810200204.896267894@suse.de>
2007-08-13  9:35   ` [dm-devel] [patch 01/11] dm-snap: Replace special round_down() Jan Blunck

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='f9nfg1$bnd$1@sea.gmane.org' \
    --to=jblunck@suse.de \
    --cc=dm-devel@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    /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