Patch "ext4: fix inconsistent between segment fstrim and full fstrim" has been added to the 5.15-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    ext4: fix inconsistent between segment fstrim and full fstrim

to the 5.15-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     ext4-fix-inconsistent-between-segment-fstrim-and-ful.patch
and it can be found in the queue-5.15 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 743b337ca7ba0833d15fe93c646ff8989e75c650
Author: Ye Bin <yebin10@xxxxxxxxxx>
Date:   Sat Dec 16 09:09:19 2023 +0800

    ext4: fix inconsistent between segment fstrim and full fstrim
    
    [ Upstream commit 68da4c44b994aea797eb9821acb3a4a36015293e ]
    
    Suppose we issue two FITRIM ioctls for ranges [0,15] and [16,31] with
    mininum length of trimmed range set to 8 blocks. If we have say a range of
    blocks 10-22 free, this range will not be trimmed because it straddles the
    boundary of the two FITRIM ranges and neither part is big enough. This is a
    bit surprising to some users that call FITRIM on smaller ranges of blocks
    to limit impact on the system. Also XFS trims all free space extents that
    overlap with the specified range so we are inconsistent among filesystems.
    Let's change ext4_try_to_trim_range() to consider for trimming the whole
    free space extent that straddles the end of specified range, not just the
    part of it within the range.
    
    Signed-off-by: Ye Bin <yebin10@xxxxxxxxxx>
    Reviewed-by: Jan Kara <jack@xxxxxxx>
    Link: https://lore.kernel.org/r/20231216010919.1995851-1-yebin10@xxxxxxxxxx
    Signed-off-by: Theodore Ts'o <tytso@xxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index a82ebc746cc4..762c2f8b5b2a 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -6457,13 +6457,15 @@ static int ext4_try_to_trim_range(struct super_block *sb,
 __acquires(ext4_group_lock_ptr(sb, e4b->bd_group))
 __releases(ext4_group_lock_ptr(sb, e4b->bd_group))
 {
-	ext4_grpblk_t next, count, free_count;
+	ext4_grpblk_t next, count, free_count, last, origin_start;
 	bool set_trimmed = false;
 	void *bitmap;
 
+	last = ext4_last_grp_cluster(sb, e4b->bd_group);
 	bitmap = e4b->bd_bitmap;
-	if (start == 0 && max >= ext4_last_grp_cluster(sb, e4b->bd_group))
+	if (start == 0 && max >= last)
 		set_trimmed = true;
+	origin_start = start;
 	start = max(e4b->bd_info->bb_first_free, start);
 	count = 0;
 	free_count = 0;
@@ -6472,7 +6474,10 @@ __releases(ext4_group_lock_ptr(sb, e4b->bd_group))
 		start = mb_find_next_zero_bit(bitmap, max + 1, start);
 		if (start > max)
 			break;
-		next = mb_find_next_bit(bitmap, max + 1, start);
+
+		next = mb_find_next_bit(bitmap, last + 1, start);
+		if (origin_start == 0 && next >= last)
+			set_trimmed = true;
 
 		if ((next - start) >= minblocks) {
 			int ret = ext4_trim_extent(sb, start, next - start, e4b);




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux