Skip to content

Commit ecd0afa

Browse files
mitatorvalds
authored andcommitted
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>
1 parent a75613e commit ecd0afa

2 files changed

Lines changed: 3 additions & 12 deletions

File tree

fs/ext2/balloc.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,19 +1444,9 @@ ext2_fsblk_t ext2_new_block(struct inode *inode, unsigned long goal, int *errp)
14441444

14451445
#ifdef EXT2FS_DEBUG
14461446

1447-
static const int nibblemap[] = {4, 3, 3, 2, 3, 2, 2, 1, 3, 2, 2, 1, 2, 1, 1, 0};
1448-
1449-
unsigned long ext2_count_free (struct buffer_head * map, unsigned int numchars)
1447+
unsigned long ext2_count_free(struct buffer_head *map, unsigned int numchars)
14501448
{
1451-
unsigned int i;
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);
1449+
return numchars * BITS_PER_BYTE - memweight(map->b_data, numchars);
14601450
}
14611451

14621452
#endif /* EXT2FS_DEBUG */

fs/ext2/ialloc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ unsigned long ext2_count_free_inodes (struct super_block * sb)
644644
}
645645
brelse(bitmap_bh);
646646
printk("ext2_count_free_inodes: stored = %lu, computed = %lu, %lu\n",
647+
(unsigned long)
647648
percpu_counter_read(&EXT2_SB(sb)->s_freeinodes_counter),
648649
desc_count, bitmap_count);
649650
return desc_count;

0 commit comments

Comments
 (0)