Re: [f2fs-dev] [PATCH] f2fs: write a checkpoint in fsync after the warm node log is moved

From: Chao Yu

Date: Tue Dec 01 2026 - 02:58:44 EST


On 11/16/26 05:35, Daeho Jeong wrote:
> From: Daeho Jeong <daehojeong@xxxxxxxxxx>
>
> Roll-forward recovery finds fsynced node blocks by following the chain in
> the warm node log. It starts from the next free block of the log recorded
> in the last checkpoint, and each node block has the address of the next
> one in its footer. f2fs_allocate_data_block() fills the footer after it
> moves the log to a new segment, so the chain is kept when a segment is
> full.
>
> f2fs_allocate_segment_for_resize() moves the log out of the range to be
> removed in the middle of a segment. No node block is allocated there, so
> the last node block in the old segment still points to the next block of
> the old segment, and nothing points to the new one. The node blocks
> written after that cannot be found by recovery until the next checkpoint.
>
> For example, with F2FS_IOC_RESIZE_FS:
>
> - fsync(A) writes a node block to segment X, which is in the range.
> - resize moves the warm node log from segment X to segment Y.
> - fsync(B) writes a node block to segment Y and returns 0.
> - after a sudden power-off, recovery follows the chain in segment X,
> recovers A and stops there. B is lost.
>
> Checkpoint is blocked during the first GC pass of resize, so this lasts
> until the pass is done. f2fs_ioc_reserve_dev_alias() moves the logs in
> the same way.
>
> Set SBI_NEED_CP when the warm node log is moved, so that fsync writes a
> checkpoint instead of relying on the chain. The next checkpoint clears
> the flag and starts a new chain from the new segment. Such an fsync waits
> for the first GC pass of resize, since checkpoint is blocked until then.
>
> An fsync which has already passed need_do_checkpoint() can still write
> its node blocks after the log is moved. So check the flag again after
> the node blocks are written, and write a checkpoint in that case, too.
>
> Test: four tasks create and fsync files while F2FS_IOC_RESIZE_FS shrinks
> the filesystem, and the machine is rebooted by sysrq-b 1.5 seconds after
> the log is moved. Without this patch, all the files whose fsync returned
> after the move were lost (454 and 437 files in two runs). With this
> patch, no fsync returned in that window and no file with a returned
> fsync was lost. The second check was tested with a debug patch which
> delays an fsync between need_do_checkpoint() and its node writes.
>
> Fixes: b4b10061ef98 ("f2fs: refactor resize_fs to avoid meta updates in progress")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Daeho Jeong <daehojeong@xxxxxxxxxx>
Reviewed-by: Chao Yu <chao@xxxxxxxxxx>

Thanks,