summaryrefslogtreecommitdiff
path: root/fs/ext4/mballoc.c
diff options
context:
space:
mode:
authorWang Jianchao <wangjianchao@kuaishou.com>2021-08-30 10:52:46 +0300
committerTheodore Ts'o <tytso@mit.edu>2021-08-31 06:35:53 +0300
commit5036ab8df278f9879d8958679bd043e32515a3e4 (patch)
tree6faf71ad1579daab0cfca48cdac8b85388b88158 /fs/ext4/mballoc.c
parent55cdd0af2bc5ffc92a2deb745627755aecd5db33 (diff)
downloadlinux-5036ab8df278f9879d8958679bd043e32515a3e4.tar.xz
ext4: flush background discard kwork when retry allocation
The background discard kwork tries to mark blocks used and issue discard. This can make filesystem suffer from NOSPC error, xfstest generic/371 can fail due to it. Fix it by flushing discard kwork in ext4_should_retry_alloc. At the same time, give up discard at the moment. Signed-off-by: Wang Jianchao <wangjianchao@kuaishou.com> Link: https://lore.kernel.org/r/20210830075246.12516-6-jianchao.wan9@gmail.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'fs/ext4/mballoc.c')
-rw-r--r--fs/ext4/mballoc.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 907b3577988c..34670cb63588 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -3331,9 +3331,11 @@ static void ext4_discard_work(struct work_struct *work)
load_grp = UINT_MAX;
list_for_each_entry_safe(fd, nfd, &discard_list, efd_list) {
/*
- * If filesystem is umounting or no memory, give up the discard
+ * If filesystem is umounting or no memory or suffering
+ * from no space, give up the discard
*/
- if ((sb->s_flags & SB_ACTIVE) && !err) {
+ if ((sb->s_flags & SB_ACTIVE) && !err &&
+ !atomic_read(&sbi->s_retry_alloc_pending)) {
grp = fd->efd_group;
if (grp != load_grp) {
if (load_grp != UINT_MAX)
@@ -3431,6 +3433,7 @@ int ext4_mb_init(struct super_block *sb)
INIT_LIST_HEAD(&sbi->s_freed_data_list);
INIT_LIST_HEAD(&sbi->s_discard_list);
INIT_WORK(&sbi->s_discard_work, ext4_discard_work);
+ atomic_set(&sbi->s_retry_alloc_pending, 0);
sbi->s_mb_max_to_scan = MB_DEFAULT_MAX_TO_SCAN;
sbi->s_mb_min_to_scan = MB_DEFAULT_MIN_TO_SCAN;