Re: [PATCH 1/5] libext2fs: Move a modulo operation out of a hot loop.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From 8d712d4e49cdc8a0b82f27b5b62a7691fafcacbf Mon Sep 17 00:00:00 2001
From: Sami Liedes <sami.liedes@xxxxxx>
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@xxxxxx>

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))

Attachment: signature.asc
Description: Digital signature


[Index of Archives]     [Reiser Filesystem Development]     [Ceph FS]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite National Park]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]     [Linux Media]

  Powered by Linux