Skip to content

Commit 68da4c4

Browse files
Ye Bintytso
authored andcommitted
ext4: fix inconsistent between segment fstrim and full fstrim
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 <[email protected]> Reviewed-by: Jan Kara <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 1f6bc02 commit 68da4c4

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

fs/ext4/mballoc.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6757,13 +6757,15 @@ static int ext4_try_to_trim_range(struct super_block *sb,
67576757
__acquires(ext4_group_lock_ptr(sb, e4b->bd_group))
67586758
__releases(ext4_group_lock_ptr(sb, e4b->bd_group))
67596759
{
6760-
ext4_grpblk_t next, count, free_count;
6760+
ext4_grpblk_t next, count, free_count, last, origin_start;
67616761
bool set_trimmed = false;
67626762
void *bitmap;
67636763

6764+
last = ext4_last_grp_cluster(sb, e4b->bd_group);
67646765
bitmap = e4b->bd_bitmap;
6765-
if (start == 0 && max >= ext4_last_grp_cluster(sb, e4b->bd_group))
6766+
if (start == 0 && max >= last)
67666767
set_trimmed = true;
6768+
origin_start = start;
67676769
start = max(e4b->bd_info->bb_first_free, start);
67686770
count = 0;
67696771
free_count = 0;
@@ -6772,7 +6774,10 @@ __releases(ext4_group_lock_ptr(sb, e4b->bd_group))
67726774
start = mb_find_next_zero_bit(bitmap, max + 1, start);
67736775
if (start > max)
67746776
break;
6775-
next = mb_find_next_bit(bitmap, max + 1, start);
6777+
6778+
next = mb_find_next_bit(bitmap, last + 1, start);
6779+
if (origin_start == 0 && next >= last)
6780+
set_trimmed = true;
67766781

67776782
if ((next - start) >= minblocks) {
67786783
int ret = ext4_trim_extent(sb, start, next - start, e4b);

0 commit comments

Comments
 (0)