[PATCH v2 1/2] f2fs: fix to avoid pinfile fragment on checkpoint=disable mode

From: Hungyu Lin

Date: Fri Dec 04 2026 - 21:21:34 EST


fallocate() on pinfile allocates a whole section at a time, so on a
large section device the pinned log moves to the next segment in the
middle of the allocation. If checkpoint is disabled, need_new_seg()
picks an SSR segment at that point instead of the next segment of the
section, so that the rest of the blocks come from dirty segments. It
results in fragment blocks in pinfile, which violates the semantics of
pinfile introduced in commit f5a53edcf01e ("f2fs: support aligned
pinned file"), and fallocate() may also fail with -ENOSPC, as the pinned
log is closed once an SSR segment at the end of a section is used up.

mkfs.f2fs -f -s 4 /dev/vda
mount /dev/vda /mnt/f2fs
for ((i=0;i<32;i++)) do
dd if=/dev/zero of=/mnt/f2fs/$i bs=1M count=1
done
sync
for ((i=0;i<32;i+=2)) do { rm /mnt/f2fs/$i; } done
sync
mount -o remount,checkpoint=disable:10% /mnt/f2fs
touch /mnt/f2fs/pinfile
f2fs_io pinfile set /mnt/f2fs/pinfile
f2fs_io fallocate 0 0 $((1024*1024*16)) /mnt/f2fs/pinfile
filefrag -v /mnt/f2fs/pinfile

Before, fallocate() fails with -ENOSPC after 2816 blocks and filefrag
shows 9 extents: the first segment of each new section and 256-block
pieces of dirty segments. After, it succeeds and the file is one extent
of 4096 blocks.

Let's always allocate a new segment in LFS manner for pinfile.

Fixes: e1175f022911 ("f2fs: fix to align to section for fallocate() on pinned file")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Hungyu Lin <dennylin0707@xxxxxxxxx>
---
fs/f2fs/segment.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 84fa9b95de82..61be4dbf76db 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -3445,6 +3445,8 @@ static bool need_new_seg(struct f2fs_sb_info *sbi, int type)
{
struct curseg_info *curseg = CURSEG_I(sbi, type);

+ if (type == CURSEG_COLD_DATA_PINNED)
+ return true;
if (!is_set_ckpt_flags(sbi, CP_CRC_RECOVERY_FLAG) &&
curseg->seg_type == CURSEG_WARM_NODE)
return true;
--
2.43.0