Skip to content

Commit 4c0cfeb

Browse files
committed
ext4: clean up mballoc criteria comments
Line wrap and slightly clarify the comments describing mballoc's cirtiera. Define EXT4_MB_NUM_CRS as part of the enum, so that it will automatically get updated when criteria is added or removed. Also fix a potential unitialized use of 'cr' variable if CONFIG_EXT4_DEBUG is enabled. Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent ab8627e commit 4c0cfeb

2 files changed

Lines changed: 34 additions & 30 deletions

File tree

fs/ext4/ext4.h

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -128,47 +128,52 @@ enum SHIFT_DIRECTION {
128128
};
129129

130130
/*
131-
* Number of criterias defined. For each criteria, mballoc has slightly
132-
* different way of finding the required blocks nad usually, higher the
133-
* criteria the slower the allocation. We start at lower criterias and keep
134-
* falling back to higher ones if we are not able to find any blocks.
135-
*/
136-
#define EXT4_MB_NUM_CRS 5
137-
/*
138-
* All possible allocation criterias for mballoc. Lower are faster.
131+
* For each criteria, mballoc has slightly different way of finding
132+
* the required blocks nad usually, higher the criteria the slower the
133+
* allocation. We start at lower criterias and keep falling back to
134+
* higher ones if we are not able to find any blocks. Lower (earlier)
135+
* criteria are faster.
139136
*/
140137
enum criteria {
141138
/*
142-
* Used when number of blocks needed is a power of 2. This doesn't
143-
* trigger any disk IO except prefetch and is the fastest criteria.
139+
* Used when number of blocks needed is a power of 2. This
140+
* doesn't trigger any disk IO except prefetch and is the
141+
* fastest criteria.
144142
*/
145143
CR_POWER2_ALIGNED,
146144

147145
/*
148-
* Tries to lookup in-memory data structures to find the most suitable
149-
* group that satisfies goal request. No disk IO except block prefetch.
146+
* Tries to lookup in-memory data structures to find the most
147+
* suitable group that satisfies goal request. No disk IO
148+
* except block prefetch.
150149
*/
151150
CR_GOAL_LEN_FAST,
152151

153152
/*
154-
* Same as CR_GOAL_LEN_FAST but is allowed to reduce the goal length to
155-
* the best available length for faster allocation.
153+
* Same as CR_GOAL_LEN_FAST but is allowed to reduce the goal
154+
* length to the best available length for faster allocation.
156155
*/
157156
CR_BEST_AVAIL_LEN,
158157

159158
/*
160-
* Reads each block group sequentially, performing disk IO if necessary, to
161-
* find find_suitable block group. Tries to allocate goal length but might trim
162-
* the request if nothing is found after enough tries.
159+
* Reads each block group sequentially, performing disk IO if
160+
* necessary, to find find_suitable block group. Tries to
161+
* allocate goal length but might trim the request if nothing
162+
* is found after enough tries.
163163
*/
164164
CR_GOAL_LEN_SLOW,
165165

166166
/*
167-
* Finds the first free set of blocks and allocates those. This is only
168-
* used in rare cases when CR_GOAL_LEN_SLOW also fails to allocate
169-
* anything.
167+
* Finds the first free set of blocks and allocates
168+
* those. This is only used in rare cases when
169+
* CR_GOAL_LEN_SLOW also fails to allocate anything.
170170
*/
171171
CR_ANY_FREE,
172+
173+
/*
174+
* Number of criterias defined.
175+
*/
176+
EXT4_MB_NUM_CRS
172177
};
173178

174179
/* criteria below which we use fast block scanning and avoid unnecessary IO */

fs/ext4/mballoc.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,11 +1035,9 @@ static void ext4_mb_choose_next_group_best_avail(struct ext4_allocation_context
10351035

10361036
if (num_stripe_clusters > 0) {
10371037
/*
1038-
* Try to round up the adjusted goal to stripe size
1039-
* (in cluster units) multiple for efficiency.
1040-
*
1041-
* XXX: Is s->stripe always a power of 2? In that case
1042-
* we can use the faster round_up() variant.
1038+
* Try to round up the adjusted goal length to
1039+
* stripe size (in cluster units) multiple for
1040+
* efficiency.
10431041
*/
10441042
ac->ac_g_ex.fe_len = roundup(ac->ac_g_ex.fe_len,
10451043
num_stripe_clusters);
@@ -2758,7 +2756,7 @@ static noinline_for_stack int
27582756
ext4_mb_regular_allocator(struct ext4_allocation_context *ac)
27592757
{
27602758
ext4_group_t prefetch_grp = 0, ngroups, group, i;
2761-
enum criteria cr, new_cr;
2759+
enum criteria new_cr, cr = CR_GOAL_LEN_FAST;
27622760
int err = 0, first_err = 0;
27632761
unsigned int nr = 0, prefetch_ios = 0;
27642762
struct ext4_sb_info *sbi;
@@ -2815,12 +2813,13 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac)
28152813
spin_unlock(&sbi->s_md_lock);
28162814
}
28172815

2818-
/* Let's just scan groups to find more-less suitable blocks */
2819-
cr = ac->ac_2order ? CR_POWER2_ALIGNED : CR_GOAL_LEN_FAST;
28202816
/*
2821-
* cr == CR_POWER2_ALIGNED try to get exact allocation,
2822-
* cr == CR_ANY_FREE try to get anything
2817+
* Let's just scan groups to find more-less suitable blocks We
2818+
* start with CR_GOAL_LEN_FAST, unless it is power of 2
2819+
* aligned, in which case let's do that faster approach first.
28232820
*/
2821+
if (ac->ac_2order)
2822+
cr = CR_POWER2_ALIGNED;
28242823
repeat:
28252824
for (; cr < EXT4_MB_NUM_CRS && ac->ac_status == AC_STATUS_CONTINUE; cr++) {
28262825
ac->ac_criteria = cr;

0 commit comments

Comments
 (0)