linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Minor ext3 speedup
@ 2005-01-13 12:15 Jan Kara
  2005-01-15 17:04 ` Matthew Wilcox
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Kara @ 2005-01-13 12:15 UTC (permalink / raw)
  To: akpm; +Cc: Andreas Dilger, linux-fsdevel

[-- Attachment #1: Type: text/plain, Size: 281 bytes --]

  Hello Andrew!

  Attached patch removes unnecessary division and modulo from ext3 code
paths. It reduces (according to oprofile) the CPU usage measurably under
a dbench load (see description of the patch for the numbers).

								Honza

-- 
Jan Kara <jack@suse.cz>
SuSE CR Labs

[-- Attachment #2: ext3-speedup-2.6.10-linus.diff --]
[-- Type: text/plain, Size: 1275 bytes --]

Remove unnecessary division and modulo from ext3 code in often used paths.
Without the patch an oprofile of dbench load shows ext3_get_group_desc()
uses 0.84% and ext3_group_sparse() 1.51%, with the patch the numbers are
0.33% and 0.27% respectively.

Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Andreas Dilger <adilger@clusterfs.com>

--- linux/fs/ext3/balloc.c	2005-01-13 13:31:42.000000000 +0100
+++ linux/fs/ext3/balloc.c	2005-01-13 14:59:13.069702736 +0100
@@ -56,8 +56,8 @@
 	}
 	smp_rmb();
 
-	group_desc = block_group / EXT3_DESC_PER_BLOCK(sb);
-	desc = block_group % EXT3_DESC_PER_BLOCK(sb);
+	group_desc = block_group >> EXT3_DESC_PER_BLOCK_BITS(sb);
+	desc = block_group & (EXT3_DESC_PER_BLOCK(sb) - 1);
 	if (!EXT3_SB(sb)->s_group_desc[group_desc]) {
 		ext3_error (sb, "ext3_get_group_desc",
 			    "Group descriptor not loaded - "
@@ -1440,19 +1440,17 @@
 
 static inline int test_root(int a, int b)
 {
-	if (a == 0)
-		return 1;
-	while (1) {
-		if (a == 1)
-			return 1;
-		if (a % b)
-			return 0;
-		a = a / b;
-	}
+	int num = b;
+
+	while (a > num)
+		num *= b;
+	return num == a;
 }
 
 static int ext3_group_sparse(int group)
 {
+	if (group <= 1)
+		return 1;
 	return (test_root(group, 3) || test_root(group, 5) ||
 		test_root(group, 7));
 }

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-01-16  9:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-01-13 12:15 [PATCH] Minor ext3 speedup Jan Kara
2005-01-15 17:04 ` Matthew Wilcox
2005-01-16  9:03   ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).