linux/fs/f2fs
Chao Yu c737047f46 f2fs: fix to trigger foreground gc during f2fs_map_blocks() in lfs mode
[ Upstream commit 1005a3ca28 ]

w/ "mode=lfs" mount option, generic/299 will cause system panic as below:

------------[ cut here ]------------
kernel BUG at fs/f2fs/segment.c:2835!
Call Trace:
 <TASK>
 f2fs_allocate_data_block+0x6f4/0xc50
 f2fs_map_blocks+0x970/0x1550
 f2fs_iomap_begin+0xb2/0x1e0
 iomap_iter+0x1d6/0x430
 __iomap_dio_rw+0x208/0x9a0
 f2fs_file_write_iter+0x6b3/0xfa0
 aio_write+0x15d/0x2e0
 io_submit_one+0x55e/0xab0
 __x64_sys_io_submit+0xa5/0x230
 do_syscall_64+0x84/0x2f0
 entry_SYSCALL_64_after_hwframe+0x76/0x7e
RIP: 0010:new_curseg+0x70f/0x720

The root cause of we run out-of-space is: in f2fs_map_blocks(), f2fs may
trigger foreground gc only if it allocates any physical block, it will be
a little bit later when there is multiple threads writing data w/
aio/dio/bufio method in parallel, since we always use OPU in lfs mode, so
f2fs_map_blocks() does block allocations aggressively.

In order to fix this issue, let's give a chance to trigger foreground
gc in prior to block allocation in f2fs_map_blocks().

Fixes: 36abef4e79 ("f2fs: introduce mode=lfs mount option")
Cc: Daeho Jeong <daehojeong@google.com>
Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
[ The context change is due to the commit 2f51ade952
("f2fs: f2fs_do_map_lock") in v6.3 which is irrelevant to
the logic of this patch. ]
Signed-off-by: Rahul Sharma <black.hawk@163.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
History 2026-06-01 17:35:11 +02:00
..
acl.c vfs: add rcu argument to ->get_acl() callback 2021-08-18 22:08:24 +02:00
acl.h vfs: add rcu argument to ->get_acl() callback 2021-08-18 22:08:24 +02:00
checkpoint.c f2fs: fix typos in comments 2024-06-16 13:39:36 +02:00
compress.c f2fs: fix typos in comments 2024-06-16 13:39:36 +02:00
data.c f2fs: fix to trigger foreground gc during f2fs_map_blocks() in lfs mode 2026-06-01 17:35:11 +02:00
debug.c f2fs: use spin_lock to avoid hang 2022-04-08 14:23:58 +02:00
dir.c f2fs: Introduce linear search for dentries 2025-03-13 12:50:14 +01:00
extent_cache.c f2fs: fix KMSAN uninit-value in extent_info usage 2025-08-28 16:24:12 +02:00
f2fs.h f2fs: use global inline_xattr_slab instead of per-sb slab cache 2026-01-19 13:10:07 +01:00
file.c f2fs: fix to avoid updating zero-sized extent in extent cache 2026-01-19 13:10:07 +01:00
gc.c f2fs: reduce stack memory cost by using bitfield in struct f2fs_io_info 2024-03-26 18:21:32 -04:00
gc.h f2fs: introduce gc_merge mount option 2021-03-30 18:48:56 -07:00
hash.c f2fs: don't use casefolded comparison for "." and ".." 2022-06-09 10:23:17 +02:00
inline.c f2fs: Introduce linear search for dentries 2025-03-13 12:50:14 +01:00
inode.c f2fs: fix to do sanity check on ino and xnid 2025-08-28 16:24:31 +02:00
iostat.c f2fs: fix to avoid potential memory corruption in __update_iostat_latency() 2023-03-11 13:57:26 +01:00
iostat.h f2fs: introduce periodic iostat io latency traces 2021-08-23 10:25:51 -07:00
Kconfig f2fs: separate out iostat feature 2021-08-23 10:25:51 -07:00
Makefile f2fs: separate out iostat feature 2021-08-23 10:25:51 -07:00
namei.c f2fs: invalidate dentry cache on failed whiteout creation 2026-01-19 13:09:51 +01:00
node.c f2fs: fix to avoid out-of-boundary access in dnode page 2025-08-28 16:24:36 +02:00
node.h f2fs: swap: support migrating swapfile in aligned write mode 2021-06-23 01:09:35 -07:00
recovery.c f2fs: fix to detect recoverable inode during dryrun of find_fsync_dnodes() 2026-01-19 13:10:07 +01:00
segment.c f2fs: check curseg->inited before write_sum_page in change_curseg 2024-12-14 19:51:05 +01:00
segment.h f2fs: remove struct segment_allocation default_salloc_ops 2024-12-14 19:51:05 +01:00
shrinker.c f2fs: avoid race condition for shrinker count 2020-12-03 00:59:26 -08:00
super.c f2fs: fix null-ptr-deref in f2fs_submit_page_bio() 2026-06-01 17:35:09 +02:00
sysfs.c f2fs: fix out-of-bounds access in sysfs attribute read/write 2026-02-19 16:21:47 +01:00
verity.c fs: f2fs: initialize fsdata in pagecache_write() 2023-03-11 13:57:23 +01:00
xattr.c f2fs: use global inline_xattr_slab instead of per-sb slab cache 2026-01-19 13:10:07 +01:00
xattr.h f2fs: use global inline_xattr_slab instead of per-sb slab cache 2026-01-19 13:10:07 +01:00