Re: [PATCH v2 08/10] ext2: use memweight()

From: Jan Kara
Date: Mon Jun 04 2012 - 06:10:16 EST


On Sat 02-06-12 22:40:14, Akinobu Mita wrote:
> Use memweight() to count the total number of bits clear in memory area.
> This change only affects the code segments enabled by EXT2FS_DEBUG.
>
> This also fixes printk format warning that only reveals with EXT2FS_DEBUG.
>
> Signed-off-by: Akinobu Mita <akinobu.mita@xxxxxxxxx>
> Cc: Jan Kara <jack@xxxxxxx>
> Cc: linux-ext4@xxxxxxxxxxxxxxx
> ---
>
> No changes from v1
>
> fs/ext2/balloc.c | 22 ++--------------------
> fs/ext2/ext2.h | 1 -
> fs/ext2/ialloc.c | 5 ++++-
> 3 files changed, 6 insertions(+), 22 deletions(-)
>
> diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
> index 1c36139..9095500 100644
> --- a/fs/ext2/balloc.c
> +++ b/fs/ext2/balloc.c
> @@ -1442,25 +1442,6 @@ ext2_fsblk_t ext2_new_block(struct inode *inode, unsigned long goal, int *errp)
> return ext2_new_blocks(inode, goal, &count, errp);
> }
>
> -#ifdef EXT2FS_DEBUG
> -
> -static const int nibblemap[] = {4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0};
> -
> -unsigned long ext2_count_free (struct buffer_head * map, unsigned int numchars)
> -{
> - unsigned int i;
> - unsigned long sum = 0;
> -
> - if (!map)
> - return (0);
> - for (i = 0; i < numchars; i++)
> - sum += nibblemap[map->b_data[i] & 0xf] +
> - nibblemap[(map->b_data[i] >> 4) & 0xf];
> - return (sum);
> -}
> -
> -#endif /* EXT2FS_DEBUG */
> -
So actually if you look at this function, you see that it counts bits in
map->b_data. That is guaranteed to be long aligned pointer so there's no
need for your memweight(). bitmap_weight() would be enough, especially
given that it can handle number of bits which is not a multiple of
BITS_PER_LONG.

For ext3 it's the same BTW.

Honza
--
Jan Kara <jack@xxxxxxx>
SUSE Labs, CR
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/