diff options
author | Theodore Ts'o <tytso@mit.edu> | 2013-06-06 11:40:37 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2013-06-06 11:40:37 -0400 |
commit | f4afb4f4e3e9af626ad695c87e4f9aaa780b29ec (patch) | |
tree | 4f675c6ecaa15df61e842e89dbcacd33d90974c2 | |
parent | 2f2e09eb15849562aede80ed007658e4504ded26 (diff) |
ext4: optimize test_root()
The test_root() function could potentially loop forever due to
overflow issues. So rewrite test_root() to avoid this issue; as a
bonus, it is 38% faster when benchmarked via a test loop:
int main(int argc, char **argv)
{
int i;
for (i = 0; i < 1 << 24; i++) {
if (test_root(i, 7))
printf("%d\n", i);
}
}
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
-rw-r--r-- | fs/ext4/balloc.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c index d0f13eada0ed..58339393fa6e 100644 --- a/fs/ext4/balloc.c +++ b/fs/ext4/balloc.c | |||
@@ -682,11 +682,15 @@ ext4_fsblk_t ext4_count_free_clusters(struct super_block *sb) | |||
682 | 682 | ||
683 | static inline int test_root(ext4_group_t a, int b) | 683 | static inline int test_root(ext4_group_t a, int b) |
684 | { | 684 | { |
685 | int num = b; | 685 | while (1) { |
686 | 686 | if (a < b) | |
687 | while (a > num) | 687 | return 0; |
688 | num *= b; | 688 | if (a == b) |
689 | return num == a; | 689 | return 1; |
690 | if ((a % b) != 0) | ||
691 | return 0; | ||
692 | a = a / b; | ||
693 | } | ||
690 | } | 694 | } |
691 | 695 | ||
692 | static int ext4_group_sparse(ext4_group_t group) | 696 | static int ext4_group_sparse(ext4_group_t group) |