mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-05 10:31:46 +09:00
BACKPORT: FROMGIT: f2fs: fix to avoid running out of free segments
If checkpoint is disabled, GC can not reclaim any segments, we need
to detect such condition and bail out from fallocate() of a pinfile,
rather than letting allocator running out of free segment, which may
cause f2fs to be shutdown.
reproducer:
mkfs.f2fs -f /dev/vda 16777216
mount -o checkpoint=disable:10% /dev/vda /mnt/f2fs
for ((i=0;i<4096;i++)) do { dd if=/dev/zero of=/mnt/f2fs/$i bs=1M count=1; } done
sync
for ((i=0;i<4096;i+=2)) do { rm /mnt/f2fs/$i; } done
sync
touch /mnt/f2fs/pinfile
f2fs_io pinfile set /mnt/f2fs/pinfile
f2fs_io fallocate 0 0 4201644032 /mnt/f2fs/pinfile
cat /sys/kernel/debug/f2fs/status
output:
- Free: 0 (0)
Fixes: f5a53edcf0 ("f2fs: support aligned pinned file")
Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Bug: 399583169
(cherry picked from commit f7f8932ca6bb22494ef6db671633ad3b4d982271
https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs.git dev)
Link: https://lore.kernel.org/linux-f2fs-devel/20250312090125.4014447-1-chao@kernel.org/
[Jaegeuk Kim: replace f2fs_warn_ratelimited with f2fs_warn]
Change-Id: If19aa65412e6ed59f1c15a4a29e210679ec260a0
This commit is contained in:
@@ -1810,6 +1810,18 @@ static int f2fs_expand_inode_data(struct inode *inode, loff_t offset,
|
|||||||
next_alloc:
|
next_alloc:
|
||||||
f2fs_down_write(&sbi->pin_sem);
|
f2fs_down_write(&sbi->pin_sem);
|
||||||
|
|
||||||
|
if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) {
|
||||||
|
if (has_not_enough_free_secs(sbi, 0, 0)) {
|
||||||
|
f2fs_up_write(&sbi->pin_sem);
|
||||||
|
err = -ENOSPC;
|
||||||
|
f2fs_warn(sbi,
|
||||||
|
"ino:%lu, start:%lu, end:%lu, need to trigger GC to "
|
||||||
|
"reclaim enough free segment when checkpoint is enabled",
|
||||||
|
inode->i_ino, pg_start, pg_end);
|
||||||
|
goto out_err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (has_not_enough_free_secs(sbi, 0,
|
if (has_not_enough_free_secs(sbi, 0,
|
||||||
GET_SEC_FROM_SEG(sbi, overprovision_segments(sbi)))) {
|
GET_SEC_FROM_SEG(sbi, overprovision_segments(sbi)))) {
|
||||||
f2fs_down_write(&sbi->gc_lock);
|
f2fs_down_write(&sbi->gc_lock);
|
||||||
|
|||||||
Reference in New Issue
Block a user