add patch factor-out-loop-for-freeing-inode-xattr-space
[ext4-patch-queue.git] / optimize-group-search-for-inode-allocation
blob944b85974ddebeb0a2cde2fb2de9c8e14e3f0f74
1 ext4: optimize group search for inode allocation
3 From: Lokesh Jaliminche <lokesh.jaliminche@gmail.com>
5 Added a check at the start of group search loop to
6 avoid looping unecessarily in case of empty group.
7 This also allow group search to jump directly to
8 "found_flex_bg" with "stats" and "group" already set,
9 so there is no need to go through the extra steps of
10 setting "best_desc" , "best_group" and then break
11 out of the loop just to set "stats" and "group" again.
13 Reviewed-by: Andreas Dilger <adilger@dilger.ca>
14 Signed-off-by: Lokesh Nagappa Jaliminche <lokesh.jaliminche@gmail.com>
15 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
16 ---
17  fs/ext4/ialloc.c |   10 ++++++++++
18  1 files changed, 10 insertions(+), 0 deletions(-)
20 diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
21 index 1b8024d..3463d30 100644
22 --- a/fs/ext4/ialloc.c
23 +++ b/fs/ext4/ialloc.c
24 @@ -477,6 +477,12 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent,
25              (ext4_test_inode_flag(parent, EXT4_INODE_TOPDIR)))) {
26                 int best_ndir = inodes_per_group;
27                 int ret = -1;
28 +               /* Maximum usable blocks per group as some blocks are used
29 +                * for inode tables and allocation bitmaps */
30 +               unsigned long long  max_blocks_per_flex =
31 +                       ((sbi->s_blocks_per_group -
32 +                         (sbi->s_itb_per_group +  2)) *
33 +                        flex_size) >>  sbi->s_cluster_bits;
35                 if (qstr) {
36                         hinfo.hash_version = DX_HASH_HALF_MD4;
37 @@ -489,6 +495,10 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent,
38                 for (i = 0; i < ngroups; i++) {
39                         g = (parent_group + i) % ngroups;
40                         get_orlov_stats(sb, g, flex_size, &stats);
41 +                       /* can't get better group than empty group */
42 +                       if (max_blocks_per_flex == stats.free_clusters &&
43 +                           (inodes_per_group * flex_size) == stats.free_inodes)
44 +                               goto found_flex_bg;
45                         if (!stats.free_inodes)
46                                 continue;
47                         if (stats.used_dirs >= best_ndir)
48 -- 
49 1.7.1