[f2fs-dev] [PATCH] f2fs: continue to allocate pinned section when gc happens EAGAIN

From: wangzijie
Date: Wed Jun 11 2025 - 23:28:01 EST


Wu Bo once mentioned a fallocate fail scenario in this link[1].
After commit 3fdd89b452c2("f2fs: prevent writing without fallocate()
for pinned files"), we cannot directly generate 4K size file and
pin it, but we can still generate non-segment aligned pinned file:

touch test_file
./f2fs_io pinfile set test_file
./f2fs_io fallocate 0 0 8192 test_file
truncate -s 4096 test_file

By doing this, pin+fallocate failure(gc happens EAGAIN but f2fs shows
enough spare space) may occurs.

>From message in commit 2e42b7f817ac("f2fs: stop allocating pinned sections
if EAGAIN happens"), gc EAGAIN doesn't guarantee a free section, so we stop
allocating. But after commit 48ea8b200414 ("f2fs: fix to avoid panic once
fallocation fails for pinfile"), we have a way to avoid panic caused by
concurrent pinfile allocation run out of free section, so I think that we
can continue to allocate pinned section when gc happens EAGAIN. Even if we
don't have free section, f2fs_allocate_pinning_section() can fail with ENOSPC.

[1] https://lore.kernel.org/linux-f2fs-devel/20231030094024.263707-1-bo.wu@xxxxxxxx/t/#u

Signed-off-by: wangzijie <wangzijie1@xxxxxxxxx>
---
fs/f2fs/file.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 6bd3de64f..05c80d2b5 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -1859,7 +1859,7 @@ static int f2fs_expand_inode_data(struct inode *inode, loff_t offset,
f2fs_down_write(&sbi->gc_lock);
stat_inc_gc_call_count(sbi, FOREGROUND);
err = f2fs_gc(sbi, &gc_control);
- if (err && err != -ENODATA) {
+ if (err && err != -ENODATA && err != -EAGAIN) {
f2fs_up_write(&sbi->pin_sem);
goto out_err;
}
--
2.25.1