F2FS roll-forward recovery
F2FS roll-forward recovery is the mount-time pass that reapplies data blocks and direct node blocks written by fsync after the last stable checkpoint.
Instead of forcing a checkpoint, fsync on F2FS can write only the file's data blocks and direct node blocks, leaving a special flag in those node blocks. At mount, after choosing the newest valid checkpoint pack and freeing orphan inodes, recovery collects the marked direct node blocks written after the checkpoint, loads the matching node blocks from the checkpointed state, replaces data indices that differ, marks those nodes dirty and finally writes a new checkpoint. [1]
In Linux v6.16 a node block counts as recoverable only when its stored checkpoint version matches the current checkpoint, and when the checkpoint carries the CRC recovery flag its upper 32 bits must also equal the checkpoint CRC. The walk follows each node's next-block address and uses Floyd's cycle detection, so a looped chain ends recovery with EINVAL and a request to run fsck. [5] [4]
Orphan-inode recovery runs before this step, and a checkpoint marked as disabled skips roll-forward entirely. The disable_roll_forward and norecovery mount options also skip it, and norecovery is accepted only for a read-only mount. With roll-forward skipped on a read-write mount, the presence of recoverable data makes the mount fail with EINVAL. [2]
Relations
- related
- F2FS, F2FS checkpoint, fsync, Btrfs tree log, Max filesystem
Advantages
- A small fsync writes only the affected data and direct node blocks rather than all node and dentry blocks a checkpoint would write, which the design paper gives as the reason for its lower fsync latency. [1]
Limitations
- Updates that were neither checkpointed nor written by fsync are not reconstructed, since recovery only collects marked direct node blocks. [1]
- On a read-only device after an unclean shutdown, mounting fails with EROFS while recoverable data exists, unless one of the two skip options is used, which leaves those updates out of the mounted view. [2]
Citations
- Lee, Sim, Hwang and Cho (2015). F2FS: A New File System for Flash Storage. FAST 15, pp. 273-286, section 2.7.
- Linux v6.16 fs/f2fs/super.c: mount-time recovery and disabled-checkpoint state.
- Linux v6.16 fs/f2fs/recovery.c: fsync node chain walk and loop detection
- Linux v6.16 fs/f2fs/node.h: is_recoverable_dnode checkpoint version check
Further reading
Sources & caveats
- lee is the FAST 15 design paper, read in sections 2.7.1 and 2.7.2.
- mount616 is Linux v6.16 fs/f2fs/super.c, read in option parsing and the recovery part of f2fs_fill_super.
- recovery616 is Linux v6.16 fs/f2fs/recovery.c, read in sanity_check_node_chain.
- node616 is Linux v6.16 fs/f2fs/node.h, read in is_recoverable_dnode.
- The source audit is not a runtime crash test.