@@ -1080,23 +1080,11 @@ static inline int should_optimize_scan(struct ext4_allocation_context *ac)
1080
1080
}
1081
1081
1082
1082
/*
1083
- * Return next linear group for allocation. If linear traversal should not be
1084
- * performed, this function just returns the same group
1083
+ * Return next linear group for allocation.
1085
1084
*/
1086
1085
static ext4_group_t
1087
- next_linear_group (struct ext4_allocation_context * ac , ext4_group_t group ,
1088
- ext4_group_t ngroups )
1086
+ next_linear_group (ext4_group_t group , ext4_group_t ngroups )
1089
1087
{
1090
- if (!should_optimize_scan (ac ))
1091
- goto inc_and_return ;
1092
-
1093
- if (ac -> ac_groups_linear_remaining ) {
1094
- ac -> ac_groups_linear_remaining -- ;
1095
- goto inc_and_return ;
1096
- }
1097
-
1098
- return group ;
1099
- inc_and_return :
1100
1088
/*
1101
1089
* Artificially restricted ngroups for non-extent
1102
1090
* files makes group > ngroups possible on first loop.
@@ -1122,8 +1110,19 @@ static void ext4_mb_choose_next_group(struct ext4_allocation_context *ac,
1122
1110
{
1123
1111
* new_cr = ac -> ac_criteria ;
1124
1112
1125
- if (!should_optimize_scan (ac ) || ac -> ac_groups_linear_remaining ) {
1126
- * group = next_linear_group (ac , * group , ngroups );
1113
+ if (!should_optimize_scan (ac )) {
1114
+ * group = next_linear_group (* group , ngroups );
1115
+ return ;
1116
+ }
1117
+
1118
+ /*
1119
+ * Optimized scanning can return non adjacent groups which can cause
1120
+ * seek overhead for rotational disks. So try few linear groups before
1121
+ * trying optimized scan.
1122
+ */
1123
+ if (ac -> ac_groups_linear_remaining ) {
1124
+ * group = next_linear_group (* group , ngroups );
1125
+ ac -> ac_groups_linear_remaining -- ;
1127
1126
return ;
1128
1127
}
1129
1128
0 commit comments