aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext2
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
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')
-rw-r--r--fs/ext2/balloc.c14
-rw-r--r--fs/ext2/ialloc.c1
2 files changed, 3 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 */
diff --git a/fs/ext2/ialloc.c b/fs/ext2/ialloc.c
index c13eb7b91a11..8f370e012e61 100644
--- a/fs/ext2/ialloc.c
+++ b/fs/ext2/ialloc.c
@@ -644,6 +644,7 @@ unsigned long ext2_count_free_inodes (struct super_block * sb)
644 } 644 }
645 brelse(bitmap_bh); 645 brelse(bitmap_bh);
646 printk("ext2_count_free_inodes: stored = %lu, computed = %lu, %lu\n", 646 printk("ext2_count_free_inodes: stored = %lu, computed = %lu, %lu\n",
647 (unsigned long)
647 percpu_counter_read(&EXT2_SB(sb)->s_freeinodes_counter), 648 percpu_counter_read(&EXT2_SB(sb)->s_freeinodes_counter),
648 desc_count, bitmap_count); 649 desc_count, bitmap_count);
649 return desc_count; 650 return desc_count;