From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Kara Subject: [PATCH] Minor ext3 speedup Date: Thu, 13 Jan 2005 13:15:06 +0100 Message-ID: <20050113121505.GA10014@atrey.karlin.mff.cuni.cz> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="wRRV7LY7NUeQGEoC" Cc: Andreas Dilger , linux-fsdevel@vger.kernel.org Return-path: Received: from atrey.karlin.mff.cuni.cz ([195.113.31.123]:57784 "EHLO atrey.karlin.mff.cuni.cz") by vger.kernel.org with ESMTP id S261603AbVAMMPH (ORCPT ); Thu, 13 Jan 2005 07:15:07 -0500 To: akpm@osdl.org Content-Disposition: inline Sender: linux-fsdevel-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org --wRRV7LY7NUeQGEoC Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 SuSE CR Labs --wRRV7LY7NUeQGEoC Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="ext3-speedup-2.6.10-linus.diff" 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 Signed-off-by: Andreas Dilger --- 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)); } --wRRV7LY7NUeQGEoC--