Thread (15 messages) 15 messages, 3 authors, 2023-03-01

Re: [PATCH v4 6/9] ext4: Fix best extent lstart adjustment logic in ext4_mb_new_inode_pa()

flat view

From: Jan Kara <jack@suse.cz>
Date: 2023-02-27 12:01:34
Also in: linux-fsdevel, lkml

On Fri 17-02-23 17:44:15, Ojaswin Mujoo wrote:
When the length of best extent found is less than the length of goal extent
we need to make sure that the best extent atleast covers the start of the
original request. This is done by adjusting the ac_b_ex.fe_logical (logical
start) of the extent.

While doing so, the current logic sometimes results in the best extent's logical
range overflowing the goal extent. Since this best extent is later added to the
inode preallocation list, we have a possibility of introducing overlapping
preallocations. This is discussed in detail here [1].

To fix this, replace the existing logic with the below logic for adjusting best
extent as it keeps fragmentation in check while ensuring logical range of best
extent doesn't overflow out of goal extent:

1. Check if best extent can be kept at end of goal range and still cover
   original start.
2. Else, check if best extent can be kept at start of goal range and still cover
   original start.
3. Else, keep the best extent at start of original request.

Also, add a few extra BUG_ONs that might help catch errors faster.

[1] https://lore.kernel.org/r/Y+OGkVvzPN0RMv0O@li-bb2b2a4c-3307-11b2-a85c-8fa5c3a69313.ibm.com (local)

Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
Looks good to me. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

Just one style nit below.
quoted hunk ↗ jump to hunk
+		/*
+		 * Use the below logic for adjusting best extent as it keeps
+		 * fragmentation in check while ensuring logical range of best
+		 * extent doesn't overflow out of goal extent:
+		 *
+		 * 1. Check if best ex can be kept at end of goal and still
+		 *    cover original start
+		 * 2. Else, check if best ex can be kept at start of goal and
+		 *    still cover original start
+		 * 3. Else, keep the best ex at start of original request.
+		 */
+		new_bex_end = ac->ac_g_ex.fe_logical +
+			EXT4_C2B(sbi, ac->ac_g_ex.fe_len);
+		new_bex_start = new_bex_end - EXT4_C2B(sbi, ac->ac_b_ex.fe_len);
+		if (ac->ac_o_ex.fe_logical >= new_bex_start)
+				goto adjust_bex;
		^^^ The indentation looks too big here

-- 
Jan Kara [off-list ref]
SUSE Labs, CR
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help