[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20120310213456.GL6961@sli.dy.fi>
Date: Sat, 10 Mar 2012 23:34:56 +0200
From: Sami Liedes <sami.liedes@....fi>
To: linux-ext4@...r.kernel.org
Subject: Re: [PATCH 1/5] libext2fs: Move a modulo operation out of a hot loop.
From 8d712d4e49cdc8a0b82f27b5b62a7691fafcacbf Mon Sep 17 00:00:00 2001
From: Sami Liedes <sami.liedes@....fi>
Date: Sat, 10 Mar 2012 22:13:12 +0200
Subject: [PATCH] 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@....fi>
diff --git a/lib/ext2fs/alloc.c b/lib/ext2fs/alloc.c
index 948a0ec..eb4e0f5 100644
--- a/lib/ext2fs/alloc.c
+++ b/lib/ext2fs/alloc.c
@@ -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 modulo;
EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
@@ -126,17 +127,21 @@ 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;
+ modulo = (i - 1) % EXT2_INODES_PER_GROUP(fs->super);
do {
- if (((i - 1) % EXT2_INODES_PER_GROUP(fs->super)) == 0)
+ if (modulo == 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 (++modulo == EXT2_INODES_PER_GROUP(fs->super))
+ modulo = 0;
+ if (++i > fs->super->s_inodes_count) {
i = EXT2_FIRST_INODE(fs->super);
+ modulo = (i - 1) % EXT2_INODES_PER_GROUP(fs->super);
+ }
} while (i != start_inode);
if (ext2fs_test_inode_bitmap2(map, i))
Download attachment "signature.asc" of type "application/pgp-signature" (837 bytes)
Powered by blists - more mailing lists