aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext2/balloc.c
diff options
context:
space:
mode:
authorAkinobu Mita <akinobu.mita@gmail.com>2012-07-30 17:41:05 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-07-30 20:25:16 -0400
commitecd0afa3ced0ebf36901b53fd9ee431f8a34a161 (patch)
treef78190903beee21c2c2d872ed9645cbcb316796d /fs/ext2/balloc.c
parenta75613ec73ec87726a81fe421385a13c25fdcfc4 (diff)
ext2: use memweight()
Convert ext2_count_free() to use memweight() instead of table lookup based counting clear bits implementation. This change only affects the code segments enabled by EXT2FS_DEBUG. Note that this memweight() call can't be replaced with a single bitmap_weight() call, although the pointer to the memory area is aligned to long-word boundary. Because the size of the memory area may not be a multiple of BITS_PER_LONG, then it returns wrong value on big-endian architecture. This also includes the following changes. - Remove unnecessary map == NULL check in ext2_count_free() which always takes non-null pointer as the memory area. - Fix printk format warning that only reveals with EXT2FS_DEBUG. Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> Acked-by: Jan Kara <jack@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/ext2/balloc.c')
-rw-r--r--fs/ext2/balloc.c14
1 files changed, 2 insertions, 12 deletions
diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
index 1c3613998862..376aa77f3ca7 100644
--- a/fs/ext2/balloc.c
+++ b/fs/ext2/balloc.c
@@ -1444,19 +1444,9 @@ ext2_fsblk_t ext2_new_block(struct inode *inode, unsigned long goal, int *errp)
1444 1444
1445#ifdef EXT2FS_DEBUG 1445#ifdef EXT2FS_DEBUG
1446 1446
1447static const int nibblemap[] = {4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0}; 1447unsigned long ext2_count_free(struct buffer_head *map, unsigned int numchars)
1448
1449unsigned long ext2_count_free (struct buffer_head * map, unsigned int numchars)
1450{ 1448{
1451 unsigned int i; 1449 return numchars * BITS_PER_BYTE - memweight(map->b_data, numchars);
1452 unsigned long sum = 0;
1453
1454 if (!map)
1455 return (0);
1456 for (i = 0; i < numchars; i++)
1457 sum += nibblemap[map->b_data[i] & 0xf] +
1458 nibblemap[(map->b_data[i] >> 4) & 0xf];
1459 return (sum);
1460} 1450}
1461 1451
1462#endif /* EXT2FS_DEBUG */ 1452#endif /* EXT2FS_DEBUG */