]> git.itanic.dy.fi Git - linux-stable/blobdiff - fs/ext4/mballoc.c
ext4: make mballoc try target group first even with mb_optimize_scan
[linux-stable] / fs / ext4 / mballoc.c
index 697af6603652426b6115a6505b9863c09c900d2f..7d5e66fded0e55d9531026b4746a4765a3fe5c2a 100644 (file)
@@ -1049,8 +1049,10 @@ static void ext4_mb_choose_next_group(struct ext4_allocation_context *ac,
 {
        *new_cr = ac->ac_criteria;
 
-       if (!should_optimize_scan(ac) || ac->ac_groups_linear_remaining)
+       if (!should_optimize_scan(ac) || ac->ac_groups_linear_remaining) {
+               *group = next_linear_group(ac, *group, ngroups);
                return;
+       }
 
        if (*new_cr == 0) {
                ext4_mb_choose_next_group_cr0(ac, new_cr, group, ngroups);
@@ -2630,7 +2632,7 @@ static noinline_for_stack int
 ext4_mb_regular_allocator(struct ext4_allocation_context *ac)
 {
        ext4_group_t prefetch_grp = 0, ngroups, group, i;
-       int cr = -1;
+       int cr = -1, new_cr;
        int err = 0, first_err = 0;
        unsigned int nr = 0, prefetch_ios = 0;
        struct ext4_sb_info *sbi;
@@ -2705,13 +2707,11 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac)
                ac->ac_groups_linear_remaining = sbi->s_mb_max_linear_groups;
                prefetch_grp = group;
 
-               for (i = 0; i < ngroups; group = next_linear_group(ac, group, ngroups),
-                            i++) {
-                       int ret = 0, new_cr;
+               for (i = 0, new_cr = cr; i < ngroups; i++,
+                    ext4_mb_choose_next_group(ac, &new_cr, &group, ngroups)) {
+                       int ret = 0;
 
                        cond_resched();
-
-                       ext4_mb_choose_next_group(ac, &new_cr, &group, ngroups);
                        if (new_cr != cr) {
                                cr = new_cr;
                                goto repeat;