Skip to content

Commit 4a69aec

Browse files
Lukas Czernertytso
authored andcommitted
ext4: allow to change s_last_trim_minblks via sysfs
Ext4 has an optimization mechanism for batched disacrd (FITRIM) that should help speed up subsequent calls of FITRIM ioctl by skipping the groups that were previously trimmed. However because the FITRIM allows to set the minimum size of an extent to trim, ext4 stores the last minimum extent size and only avoids trimming the group if it was previously trimmed with minimum extent size equal to, or smaller than the current call. There is currently no way to bypass the optimization without umount/mount cycle. This becomes a problem when the file system is live migrated to a different storage, because the optimization will prevent possibly useful discard calls to the storage. Fix it by exporting the s_last_trim_minblks via sysfs interface which will allow us to set the minimum size to the number of blocks larger than subsequent FITRIM call, effectively bypassing the optimization. By setting the s_last_trim_minblks to ULONG_MAX the optimization will be effectively cleared regardless of the previous state, or file system configuration. For example: getconf ULONG_MAX > /sys/fs/ext4/dm-1/last_trim_minblks Signed-off-by: Lukas Czerner <[email protected]> Reported-by: Laurent GUERBY <[email protected]> Reviewed-by: Andreas Dilger <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 2327fb2 commit 4a69aec

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

fs/ext4/sysfs.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ EXT4_ATTR(last_error_time, 0444, last_error_time);
245245
EXT4_ATTR(journal_task, 0444, journal_task);
246246
EXT4_RW_ATTR_SBI_UI(mb_prefetch, s_mb_prefetch);
247247
EXT4_RW_ATTR_SBI_UI(mb_prefetch_limit, s_mb_prefetch_limit);
248+
EXT4_RW_ATTR_SBI_UL(last_trim_minblks, s_last_trim_minblks);
248249

249250
static unsigned int old_bump_val = 128;
250251
EXT4_ATTR_PTR(max_writeback_mb_bump, 0444, pointer_ui, &old_bump_val);
@@ -295,6 +296,7 @@ static struct attribute *ext4_attrs[] = {
295296
#endif
296297
ATTR_LIST(mb_prefetch),
297298
ATTR_LIST(mb_prefetch_limit),
299+
ATTR_LIST(last_trim_minblks),
298300
NULL,
299301
};
300302
ATTRIBUTE_GROUPS(ext4);

0 commit comments

Comments
 (0)