mirror of https://github.com/vitalif/e2fsprogs
libext2fs: move a modulo operation out of a hot loop.
Filesystem shrinking in particular is a heavy user of this loop in ext2fs_new_inode(). This change makes resize2fs use 24% less CPU time for shrinking a 100G filesystem. Signed-off-by: Sami Liedes <sami.liedes@iki.fi> Signed-off-by: Theodore Ts'o <tytso@mit.edu>bitmap-optimize
parent
010dc7b90d
commit
75556776d3
|
@ -109,6 +109,7 @@ errcode_t ext2fs_new_inode(ext2_filsys fs, ext2_ino_t dir,
|
|||
ext2_ino_t dir_group = 0;
|
||||
ext2_ino_t i;
|
||||
ext2_ino_t start_inode;
|
||||
ext2_ino_t ino_in_group;
|
||||
|
||||
EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
|
||||
|
||||
|
@ -126,17 +127,22 @@ errcode_t ext2fs_new_inode(ext2_filsys fs, ext2_ino_t dir,
|
|||
if (start_inode > fs->super->s_inodes_count)
|
||||
return EXT2_ET_INODE_ALLOC_FAIL;
|
||||
i = start_inode;
|
||||
ino_in_group = (i - 1) % EXT2_INODES_PER_GROUP(fs->super);
|
||||
|
||||
do {
|
||||
if (((i - 1) % EXT2_INODES_PER_GROUP(fs->super)) == 0)
|
||||
if (ino_in_group == 0)
|
||||
check_inode_uninit(fs, map, (i - 1) /
|
||||
EXT2_INODES_PER_GROUP(fs->super));
|
||||
|
||||
if (!ext2fs_fast_test_inode_bitmap2(map, i))
|
||||
break;
|
||||
i++;
|
||||
if (i > fs->super->s_inodes_count)
|
||||
if (++ino_in_group == EXT2_INODES_PER_GROUP(fs->super))
|
||||
ino_in_group = 0;
|
||||
if (++i > fs->super->s_inodes_count) {
|
||||
i = EXT2_FIRST_INODE(fs->super);
|
||||
ino_in_group = ((i - 1) %
|
||||
EXT2_INODES_PER_GROUP(fs->super));
|
||||
}
|
||||
} while (i != start_inode);
|
||||
|
||||
if (ext2fs_test_inode_bitmap2(map, i))
|
||||
|
|
Loading…
Reference in New Issue