Skip to content

Commit 4fbf8bc

Browse files
LiBaokun96tytso
authored andcommitted
ext4: correct best extent lstart adjustment logic
When yangerkun review commit 93cdf49 ("ext4: Fix best extent lstart adjustment logic in ext4_mb_new_inode_pa()"), it was found that the best extent did not completely cover the original request after adjusting the best extent lstart in ext4_mb_new_inode_pa() as follows: original request: 2/10(8) normalized request: 0/64(64) best extent: 0/9(9) When we check if best ex can be kept at start of goal, ac_o_ex.fe_logical is 2 less than the adjusted best extent logical end 9, so we think the adjustment is done. But obviously 0/9(9) doesn't cover 2/10(8), so we should determine here if the original request logical end is less than or equal to the adjusted best extent logical end. In addition, add a comment stating when adjusted best_ex will not cover the original request, and remove the duplicate assertion because adjusting lstart makes no change to b_ex.fe_len. Link: https://lore.kernel.org/r/3630fa7f-b432-7afd-5f79-781bc3b2c5ea@huawei.com Fixes: 93cdf49 ("ext4: Fix best extent lstart adjustment logic in ext4_mb_new_inode_pa()") Cc: <stable@kernel.org> Signed-off-by: yangerkun <yangerkun@huawei.com> Signed-off-by: Baokun Li <libaokun1@huawei.com> Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com> Link: https://lore.kernel.org/r/20240201141845.1879253-1-libaokun1@huawei.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent d8b945f commit 4fbf8bc

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

fs/ext4/mballoc.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5172,10 +5172,16 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
51725172
.fe_len = ac->ac_orig_goal_len,
51735173
};
51745174
loff_t orig_goal_end = extent_logical_end(sbi, &ex);
5175+
loff_t o_ex_end = extent_logical_end(sbi, &ac->ac_o_ex);
51755176

5176-
/* we can't allocate as much as normalizer wants.
5177-
* so, found space must get proper lstart
5178-
* to cover original request */
5177+
/*
5178+
* We can't allocate as much as normalizer wants, so we try
5179+
* to get proper lstart to cover the original request, except
5180+
* when the goal doesn't cover the original request as below:
5181+
*
5182+
* orig_ex:2045/2055(10), isize:8417280 -> normalized:0/2048
5183+
* best_ex:0/200(200) -> adjusted: 1848/2048(200)
5184+
*/
51795185
BUG_ON(ac->ac_g_ex.fe_logical > ac->ac_o_ex.fe_logical);
51805186
BUG_ON(ac->ac_g_ex.fe_len < ac->ac_o_ex.fe_len);
51815187

@@ -5187,7 +5193,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
51875193
* 1. Check if best ex can be kept at end of goal (before
51885194
* cr_best_avail trimmed it) and still cover original start
51895195
* 2. Else, check if best ex can be kept at start of goal and
5190-
* still cover original start
5196+
* still cover original end
51915197
* 3. Else, keep the best ex at start of original request.
51925198
*/
51935199
ex.fe_len = ac->ac_b_ex.fe_len;
@@ -5197,15 +5203,14 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
51975203
goto adjust_bex;
51985204

51995205
ex.fe_logical = ac->ac_g_ex.fe_logical;
5200-
if (ac->ac_o_ex.fe_logical < extent_logical_end(sbi, &ex))
5206+
if (o_ex_end <= extent_logical_end(sbi, &ex))
52015207
goto adjust_bex;
52025208

52035209
ex.fe_logical = ac->ac_o_ex.fe_logical;
52045210
adjust_bex:
52055211
ac->ac_b_ex.fe_logical = ex.fe_logical;
52065212

52075213
BUG_ON(ac->ac_o_ex.fe_logical < ac->ac_b_ex.fe_logical);
5208-
BUG_ON(ac->ac_o_ex.fe_len > ac->ac_b_ex.fe_len);
52095214
BUG_ON(extent_logical_end(sbi, &ex) > orig_goal_end);
52105215
}
52115216

0 commit comments

Comments
 (0)