locate_dirty_segment() does not set any current active segment as a prefree segment. Thus, the issue described below may occur:
Step 1: During a checkpoint, add_discard_addrs() does not handle the current active 'segment X' with 0 valid blocks (and non-zero discard blocks). As a result, no struct discard_cmd is created for 'segment X' and the value of sbi->discard_blks cannot be reduced to 0 after the checkpoint. Step 2: f2fs is umounted without setting CP_TRIMMED_FLAG, as sbi->discard_blks is non-zero. Since add_discard_addrs() can handle active segments with non-zero valid blocks, it is reasonable to fix this issue by also handling active segments with 0 valid blocks in add_discard_addrs(). Signed-off-by: Chunhai Guo <guochun...@vivo.com> --- fs/f2fs/segment.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index eade36c5ef13..4fb1dc4aab97 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -2090,7 +2090,9 @@ static bool add_discard_addrs(struct f2fs_sb_info *sbi, struct cp_control *cpc, return false; if (!force) { - if (!f2fs_realtime_discard_enable(sbi) || !se->valid_blocks || + if (!f2fs_realtime_discard_enable(sbi) || + (!se->valid_blocks && + !IS_CURSEG(sbi, cpc->trim_start)) || SM_I(sbi)->dcc_info->nr_discards >= SM_I(sbi)->dcc_info->max_discards) return false; -- 2.34.1 _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel