Skip to content

Commit 5229a65

Browse files
jankaratytso
authored andcommitted
ext4: do not let fstrim block system suspend
Len Brown has reported that system suspend sometimes fail due to inability to freeze a task working in ext4_trim_fs() for one minute. Trimming a large filesystem on a disk that slowly processes discard requests can indeed take a long time. Since discard is just an advisory call, it is perfectly fine to interrupt it at any time and the return number of discarded blocks until that moment. Do that when we detect the task is being frozen. Cc: stable@kernel.org Reported-by: Len Brown <lenb@kernel.org> Suggested-by: Dave Chinner <david@fromorbit.com> References: https://bugzilla.kernel.org/show_bug.cgi?id=216322 Signed-off-by: Jan Kara <jack@suse.cz> Link: https://lore.kernel.org/r/20230913150504.9054-2-jack@suse.cz Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent 45e4ab3 commit 5229a65

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

fs/ext4/mballoc.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/slab.h>
1717
#include <linux/nospec.h>
1818
#include <linux/backing-dev.h>
19+
#include <linux/freezer.h>
1920
#include <trace/events/ext4.h>
2021

2122
/*
@@ -6916,6 +6917,11 @@ static ext4_grpblk_t ext4_last_grp_cluster(struct super_block *sb,
69166917
EXT4_CLUSTER_BITS(sb);
69176918
}
69186919

6920+
static bool ext4_trim_interrupted(void)
6921+
{
6922+
return fatal_signal_pending(current) || freezing(current);
6923+
}
6924+
69196925
static int ext4_try_to_trim_range(struct super_block *sb,
69206926
struct ext4_buddy *e4b, ext4_grpblk_t start,
69216927
ext4_grpblk_t max, ext4_grpblk_t minblocks)
@@ -6949,8 +6955,8 @@ __releases(ext4_group_lock_ptr(sb, e4b->bd_group))
69496955
free_count += next - start;
69506956
start = next + 1;
69516957

6952-
if (fatal_signal_pending(current))
6953-
return -ERESTARTSYS;
6958+
if (ext4_trim_interrupted())
6959+
return count;
69546960

69556961
if (need_resched()) {
69566962
ext4_unlock_group(sb, e4b->bd_group);
@@ -7072,6 +7078,8 @@ int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range)
70727078
end = EXT4_CLUSTERS_PER_GROUP(sb) - 1;
70737079

70747080
for (group = first_group; group <= last_group; group++) {
7081+
if (ext4_trim_interrupted())
7082+
break;
70757083
grp = ext4_get_group_info(sb, group);
70767084
if (!grp)
70777085
continue;

0 commit comments

Comments
 (0)