Skip to content

Commit f7f8932

Browse files
chaseyuJaegeuk Kim
authored andcommitted
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: f5a53ed ("f2fs: support aligned pinned file") Signed-off-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent 7ff0104 commit f7f8932

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

fs/f2fs/file.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,6 +1838,18 @@ static int f2fs_expand_inode_data(struct inode *inode, loff_t offset,
18381838
next_alloc:
18391839
f2fs_down_write(&sbi->pin_sem);
18401840

1841+
if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) {
1842+
if (has_not_enough_free_secs(sbi, 0, 0)) {
1843+
f2fs_up_write(&sbi->pin_sem);
1844+
err = -ENOSPC;
1845+
f2fs_warn_ratelimited(sbi,
1846+
"ino:%lu, start:%lu, end:%lu, need to trigger GC to "
1847+
"reclaim enough free segment when checkpoint is enabled",
1848+
inode->i_ino, pg_start, pg_end);
1849+
goto out_err;
1850+
}
1851+
}
1852+
18411853
if (has_not_enough_free_secs(sbi, 0, f2fs_sb_has_blkzoned(sbi) ?
18421854
ZONED_PIN_SEC_REQUIRED_COUNT :
18431855
GET_SEC_FROM_SEG(sbi, overprovision_segments(sbi)))) {

0 commit comments

Comments
 (0)