Skip to content

Commit cf4ff93

Browse files
LiBaokun96tytso
authored andcommitted
ext4: correct the judgment of BUG in ext4_mb_normalize_request
ext4_mb_normalize_request() can move logical start of allocated blocks to reduce fragmentation and better utilize preallocation. However logical block requested as a start of allocation (ac->ac_o_ex.fe_logical) should always be covered by allocated blocks so we should check that by modifying and to or in the assertion. Signed-off-by: Baokun Li <libaokun1@huawei.com> Reviewed-by: Ritesh Harjani <ritesh.list@gmail.com> Link: https://lore.kernel.org/r/20220528110017.354175-3-libaokun1@huawei.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent a08f789 commit cf4ff93

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

fs/ext4/mballoc.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4185,7 +4185,22 @@ ext4_mb_normalize_request(struct ext4_allocation_context *ac,
41854185
}
41864186
rcu_read_unlock();
41874187

4188-
if (start + size <= ac->ac_o_ex.fe_logical &&
4188+
/*
4189+
* In this function "start" and "size" are normalized for better
4190+
* alignment and length such that we could preallocate more blocks.
4191+
* This normalization is done such that original request of
4192+
* ac->ac_o_ex.fe_logical & fe_len should always lie within "start" and
4193+
* "size" boundaries.
4194+
* (Note fe_len can be relaxed since FS block allocation API does not
4195+
* provide gurantee on number of contiguous blocks allocation since that
4196+
* depends upon free space left, etc).
4197+
* In case of inode pa, later we use the allocated blocks
4198+
* [pa_start + fe_logical - pa_lstart, fe_len/size] from the preallocated
4199+
* range of goal/best blocks [start, size] to put it at the
4200+
* ac_o_ex.fe_logical extent of this inode.
4201+
* (See ext4_mb_use_inode_pa() for more details)
4202+
*/
4203+
if (start + size <= ac->ac_o_ex.fe_logical ||
41894204
start > ac->ac_o_ex.fe_logical) {
41904205
ext4_msg(ac->ac_sb, KERN_ERR,
41914206
"start %lu, size %lu, fe_logical %lu",

0 commit comments

Comments
 (0)