* [f2fs-dev] [PATCH v3] f2fs: fix missing discard for active segments
@ 2025-03-17 10:16 ` Chunhai Guo
0 siblings, 0 replies; 6+ messages in thread
From: Chunhai Guo via Linux-f2fs-devel @ 2025-03-17 10:16 UTC (permalink / raw)
To: chao, jaegeuk; +Cc: Chunhai Guo, linux-kernel, linux-f2fs-devel
During a checkpoint, the current active segment X may not be handled
properly. This occurs when segment X has 0 valid blocks and a non-zero
number of discard blocks, for the following reasons:
locate_dirty_segment() does not mark any active segment as a prefree
segment. As a result, segment X is not included in dirty_segmap[PRE], and
f2fs_clear_prefree_segments() skips it when handling prefree segments.
add_discard_addrs() skips any segment with 0 valid blocks, so segment X is
also skipped.
Consequently, no `struct discard_cmd` is actually created for segment X.
However, the ckpt_valid_map and cur_valid_map of segment X are synced by
seg_info_to_raw_sit() during the current checkpoint process. As a result,
it cannot find the missing discard bits even in subsequent checkpoints.
Consequently, the value of sbi->discard_blks remains non-zero. Thus, when
f2fs is umounted, CP_TRIMMED_FLAG will not be set due to the non-zero
sbi->discard_blks.
Relevant code process:
f2fs_write_checkpoint()
f2fs_flush_sit_entries()
list_for_each_entry_safe(ses, tmp, head, set_list) {
for_each_set_bit_from(segno, bitmap, end) {
...
add_discard_addrs(sbi, cpc, false); // skip segment X due to its 0 valid blocks
...
seg_info_to_raw_sit(); // sync ckpt_valid_map with cur_valid_map for segment X
...
}
}
f2fs_clear_prefree_segments(); // segment X is not included in dirty_segmap[PRE] and is skipped
This issue is easy to reproduce with the following operations:
root # mkfs.f2fs -f /dev/f2fs_dev
root # mount -t f2fs /dev/f2fs_dev /mnt_point
root # dd if=/dev/blk_dev of=/mnt_point/1.bin bs=4k count=256
root # sync
root # rm /mnt_point/1.bin
root # umount /mnt_point
root # dump.f2fs /dev/f2fs_dev | grep "checkpoint state"
Info: checkpoint state = 45 : crc compacted_summary unmount ---- 'trimmed' flag is missing
Since add_discard_addrs() can handle active segments with non-zero valid
blocks, it is reasonable to fix this issue by allowing it to also handle
active segments with 0 valid blocks.
Fixes: b29555505d81 ("f2fs: add key functions for small discards")
Signed-off-by: Chunhai Guo <guochunhai@vivo.com>
---
v2->v3: Add the test case for this issue in the commit message.
v1->v2:
- Modify the commit message to make it easier to understand.
- Add fixes to the commit.
v1: https://lore.kernel.org/linux-f2fs-devel/20241203065108.2763436-1-guochunhai@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 50a346f7cb93..396ef71f41e3 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -2096,7 +2096,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
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH v3] f2fs: fix missing discard for active segments
@ 2025-03-17 10:16 ` Chunhai Guo
0 siblings, 0 replies; 6+ messages in thread
From: Chunhai Guo @ 2025-03-17 10:16 UTC (permalink / raw)
To: chao, jaegeuk; +Cc: linux-f2fs-devel, linux-kernel, Chunhai Guo
During a checkpoint, the current active segment X may not be handled
properly. This occurs when segment X has 0 valid blocks and a non-zero
number of discard blocks, for the following reasons:
locate_dirty_segment() does not mark any active segment as a prefree
segment. As a result, segment X is not included in dirty_segmap[PRE], and
f2fs_clear_prefree_segments() skips it when handling prefree segments.
add_discard_addrs() skips any segment with 0 valid blocks, so segment X is
also skipped.
Consequently, no `struct discard_cmd` is actually created for segment X.
However, the ckpt_valid_map and cur_valid_map of segment X are synced by
seg_info_to_raw_sit() during the current checkpoint process. As a result,
it cannot find the missing discard bits even in subsequent checkpoints.
Consequently, the value of sbi->discard_blks remains non-zero. Thus, when
f2fs is umounted, CP_TRIMMED_FLAG will not be set due to the non-zero
sbi->discard_blks.
Relevant code process:
f2fs_write_checkpoint()
f2fs_flush_sit_entries()
list_for_each_entry_safe(ses, tmp, head, set_list) {
for_each_set_bit_from(segno, bitmap, end) {
...
add_discard_addrs(sbi, cpc, false); // skip segment X due to its 0 valid blocks
...
seg_info_to_raw_sit(); // sync ckpt_valid_map with cur_valid_map for segment X
...
}
}
f2fs_clear_prefree_segments(); // segment X is not included in dirty_segmap[PRE] and is skipped
This issue is easy to reproduce with the following operations:
root # mkfs.f2fs -f /dev/f2fs_dev
root # mount -t f2fs /dev/f2fs_dev /mnt_point
root # dd if=/dev/blk_dev of=/mnt_point/1.bin bs=4k count=256
root # sync
root # rm /mnt_point/1.bin
root # umount /mnt_point
root # dump.f2fs /dev/f2fs_dev | grep "checkpoint state"
Info: checkpoint state = 45 : crc compacted_summary unmount ---- 'trimmed' flag is missing
Since add_discard_addrs() can handle active segments with non-zero valid
blocks, it is reasonable to fix this issue by allowing it to also handle
active segments with 0 valid blocks.
Fixes: b29555505d81 ("f2fs: add key functions for small discards")
Signed-off-by: Chunhai Guo <guochunhai@vivo.com>
---
v2->v3: Add the test case for this issue in the commit message.
v1->v2:
- Modify the commit message to make it easier to understand.
- Add fixes to the commit.
v1: https://lore.kernel.org/linux-f2fs-devel/20241203065108.2763436-1-guochunhai@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 50a346f7cb93..396ef71f41e3 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -2096,7 +2096,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
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [f2fs-dev] [PATCH v3] f2fs: fix missing discard for active segments
2025-03-17 10:16 ` Chunhai Guo
@ 2025-03-18 1:18 ` Chao Yu
-1 siblings, 0 replies; 6+ messages in thread
From: Chao Yu via Linux-f2fs-devel @ 2025-03-18 1:18 UTC (permalink / raw)
To: Chunhai Guo, jaegeuk; +Cc: linux-kernel, linux-f2fs-devel
On 3/17/25 18:16, Chunhai Guo wrote:
> During a checkpoint, the current active segment X may not be handled
> properly. This occurs when segment X has 0 valid blocks and a non-zero
> number of discard blocks, for the following reasons:
>
> locate_dirty_segment() does not mark any active segment as a prefree
> segment. As a result, segment X is not included in dirty_segmap[PRE], and
> f2fs_clear_prefree_segments() skips it when handling prefree segments.
>
> add_discard_addrs() skips any segment with 0 valid blocks, so segment X is
> also skipped.
>
> Consequently, no `struct discard_cmd` is actually created for segment X.
> However, the ckpt_valid_map and cur_valid_map of segment X are synced by
> seg_info_to_raw_sit() during the current checkpoint process. As a result,
> it cannot find the missing discard bits even in subsequent checkpoints.
> Consequently, the value of sbi->discard_blks remains non-zero. Thus, when
> f2fs is umounted, CP_TRIMMED_FLAG will not be set due to the non-zero
> sbi->discard_blks.
>
> Relevant code process:
>
> f2fs_write_checkpoint()
> f2fs_flush_sit_entries()
> list_for_each_entry_safe(ses, tmp, head, set_list) {
> for_each_set_bit_from(segno, bitmap, end) {
> ...
> add_discard_addrs(sbi, cpc, false); // skip segment X due to its 0 valid blocks
> ...
> seg_info_to_raw_sit(); // sync ckpt_valid_map with cur_valid_map for segment X
> ...
> }
> }
> f2fs_clear_prefree_segments(); // segment X is not included in dirty_segmap[PRE] and is skipped
>
> This issue is easy to reproduce with the following operations:
>
> root # mkfs.f2fs -f /dev/f2fs_dev
> root # mount -t f2fs /dev/f2fs_dev /mnt_point
> root # dd if=/dev/blk_dev of=/mnt_point/1.bin bs=4k count=256
> root # sync
> root # rm /mnt_point/1.bin
> root # umount /mnt_point
> root # dump.f2fs /dev/f2fs_dev | grep "checkpoint state"
> Info: checkpoint state = 45 : crc compacted_summary unmount ---- 'trimmed' flag is missing
>
> Since add_discard_addrs() can handle active segments with non-zero valid
> blocks, it is reasonable to fix this issue by allowing it to also handle
> active segments with 0 valid blocks.
>
> Fixes: b29555505d81 ("f2fs: add key functions for small discards")
> Signed-off-by: Chunhai Guo <guochunhai@vivo.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Thanks,
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH v3] f2fs: fix missing discard for active segments
@ 2025-03-18 1:18 ` Chao Yu
0 siblings, 0 replies; 6+ messages in thread
From: Chao Yu @ 2025-03-18 1:18 UTC (permalink / raw)
To: Chunhai Guo, jaegeuk; +Cc: chao, linux-f2fs-devel, linux-kernel
On 3/17/25 18:16, Chunhai Guo wrote:
> During a checkpoint, the current active segment X may not be handled
> properly. This occurs when segment X has 0 valid blocks and a non-zero
> number of discard blocks, for the following reasons:
>
> locate_dirty_segment() does not mark any active segment as a prefree
> segment. As a result, segment X is not included in dirty_segmap[PRE], and
> f2fs_clear_prefree_segments() skips it when handling prefree segments.
>
> add_discard_addrs() skips any segment with 0 valid blocks, so segment X is
> also skipped.
>
> Consequently, no `struct discard_cmd` is actually created for segment X.
> However, the ckpt_valid_map and cur_valid_map of segment X are synced by
> seg_info_to_raw_sit() during the current checkpoint process. As a result,
> it cannot find the missing discard bits even in subsequent checkpoints.
> Consequently, the value of sbi->discard_blks remains non-zero. Thus, when
> f2fs is umounted, CP_TRIMMED_FLAG will not be set due to the non-zero
> sbi->discard_blks.
>
> Relevant code process:
>
> f2fs_write_checkpoint()
> f2fs_flush_sit_entries()
> list_for_each_entry_safe(ses, tmp, head, set_list) {
> for_each_set_bit_from(segno, bitmap, end) {
> ...
> add_discard_addrs(sbi, cpc, false); // skip segment X due to its 0 valid blocks
> ...
> seg_info_to_raw_sit(); // sync ckpt_valid_map with cur_valid_map for segment X
> ...
> }
> }
> f2fs_clear_prefree_segments(); // segment X is not included in dirty_segmap[PRE] and is skipped
>
> This issue is easy to reproduce with the following operations:
>
> root # mkfs.f2fs -f /dev/f2fs_dev
> root # mount -t f2fs /dev/f2fs_dev /mnt_point
> root # dd if=/dev/blk_dev of=/mnt_point/1.bin bs=4k count=256
> root # sync
> root # rm /mnt_point/1.bin
> root # umount /mnt_point
> root # dump.f2fs /dev/f2fs_dev | grep "checkpoint state"
> Info: checkpoint state = 45 : crc compacted_summary unmount ---- 'trimmed' flag is missing
>
> Since add_discard_addrs() can handle active segments with non-zero valid
> blocks, it is reasonable to fix this issue by allowing it to also handle
> active segments with 0 valid blocks.
>
> Fixes: b29555505d81 ("f2fs: add key functions for small discards")
> Signed-off-by: Chunhai Guo <guochunhai@vivo.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Thanks,
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [f2fs-dev] [PATCH v3] f2fs: fix missing discard for active segments
2025-03-17 10:16 ` Chunhai Guo
@ 2025-03-18 1:30 ` patchwork-bot+f2fs
-1 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+f2fs--- via Linux-f2fs-devel @ 2025-03-18 1:30 UTC (permalink / raw)
To: Chunhai Guo; +Cc: jaegeuk, linux-kernel, linux-f2fs-devel
Hello:
This patch was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <jaegeuk@kernel.org>:
On Mon, 17 Mar 2025 04:16:24 -0600 you wrote:
> During a checkpoint, the current active segment X may not be handled
> properly. This occurs when segment X has 0 valid blocks and a non-zero
> number of discard blocks, for the following reasons:
>
> locate_dirty_segment() does not mark any active segment as a prefree
> segment. As a result, segment X is not included in dirty_segmap[PRE], and
> f2fs_clear_prefree_segments() skips it when handling prefree segments.
>
> [...]
Here is the summary with links:
- [f2fs-dev,v3] f2fs: fix missing discard for active segments
https://git.kernel.org/jaegeuk/f2fs/c/21263d035ff2
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [f2fs-dev] [PATCH v3] f2fs: fix missing discard for active segments
@ 2025-03-18 1:30 ` patchwork-bot+f2fs
0 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+f2fs @ 2025-03-18 1:30 UTC (permalink / raw)
To: Chunhai Guo; +Cc: chao, jaegeuk, linux-kernel, linux-f2fs-devel
Hello:
This patch was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <jaegeuk@kernel.org>:
On Mon, 17 Mar 2025 04:16:24 -0600 you wrote:
> During a checkpoint, the current active segment X may not be handled
> properly. This occurs when segment X has 0 valid blocks and a non-zero
> number of discard blocks, for the following reasons:
>
> locate_dirty_segment() does not mark any active segment as a prefree
> segment. As a result, segment X is not included in dirty_segmap[PRE], and
> f2fs_clear_prefree_segments() skips it when handling prefree segments.
>
> [...]
Here is the summary with links:
- [f2fs-dev,v3] f2fs: fix missing discard for active segments
https://git.kernel.org/jaegeuk/f2fs/c/21263d035ff2
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-03-18 1:30 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-17 10:16 [f2fs-dev] [PATCH v3] f2fs: fix missing discard for active segments Chunhai Guo via Linux-f2fs-devel
2025-03-17 10:16 ` Chunhai Guo
2025-03-18 1:18 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2025-03-18 1:18 ` Chao Yu
2025-03-18 1:30 ` [f2fs-dev] " patchwork-bot+f2fs--- via Linux-f2fs-devel
2025-03-18 1:30 ` patchwork-bot+f2fs
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.