* [f2fs-dev] [PATCH v2 0/3] f2fs-tools: cache free segments count to improve perfmance
@ 2023-09-28 9:20 Wu Bo via Linux-f2fs-devel
2023-09-28 9:20 ` [f2fs-dev] [PATCH v2 1/3] f2fs-tools: use 'IS_CUR_SEGNO()' to check if it is current segment Wu Bo via Linux-f2fs-devel
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Wu Bo via Linux-f2fs-devel @ 2023-09-28 9:20 UTC (permalink / raw)
To: Jaegeuk Kim, Chao Yu; +Cc: Wu Bo, Wu Bo, linux-f2fs-devel
The performance flame graph of resize shows that 'get_free_segments()' consum
most user space time:
https://linkthinking.cn/images/resize_flame.jpg
Every calling 'get_free_segments()', it will traverses all segments to calculate
the free segments count. And this path is called a lot in resize & sload &
defrag.
If the free segments count is cached, these tools performance will be
improved.
Changed in v2:
- Fixed some logic issues reviewed by Chao Yu
Wu Bo (3):
f2fs-tools: use 'IS_CUR_SEGNO()' to check if it is current segment
f2fs-tools: skip not matched segment when finding free block
f2fs-tools: cache free segments count to improve perfmance
fsck/f2fs.h | 1 +
fsck/mount.c | 25 ++++++++++++-------------
fsck/segment.c | 2 ++
3 files changed, 15 insertions(+), 13 deletions(-)
--
2.25.1
_______________________________________________
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] 5+ messages in thread* [f2fs-dev] [PATCH v2 1/3] f2fs-tools: use 'IS_CUR_SEGNO()' to check if it is current segment 2023-09-28 9:20 [f2fs-dev] [PATCH v2 0/3] f2fs-tools: cache free segments count to improve perfmance Wu Bo via Linux-f2fs-devel @ 2023-09-28 9:20 ` Wu Bo via Linux-f2fs-devel 2023-10-07 1:39 ` Chao Yu 2023-09-28 9:20 ` [f2fs-dev] [PATCH v2 2/3] f2fs-tools: skip not matched segment when finding free block Wu Bo via Linux-f2fs-devel 2023-09-28 9:20 ` [f2fs-dev] [PATCH v2 3/3] f2fs-tools: cache free segments count to improve perfmance Wu Bo via Linux-f2fs-devel 2 siblings, 1 reply; 5+ messages in thread From: Wu Bo via Linux-f2fs-devel @ 2023-09-28 9:20 UTC (permalink / raw) To: Jaegeuk Kim, Chao Yu; +Cc: Wu Bo, Wu Bo, linux-f2fs-devel Use IS_CUR_SEGNO() here can make code more concise and readable. --- fsck/mount.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/fsck/mount.c b/fsck/mount.c index df0314d..e4372cf 100644 --- a/fsck/mount.c +++ b/fsck/mount.c @@ -2532,16 +2532,8 @@ void build_sit_area_bitmap(struct f2fs_sb_info *sbi) ptr += SIT_VBLOCK_MAP_SIZE; if (se->valid_blocks == 0x0 && is_usable_seg(sbi, segno)) { - if (le32_to_cpu(sbi->ckpt->cur_node_segno[0]) == segno || - le32_to_cpu(sbi->ckpt->cur_data_segno[0]) == segno || - le32_to_cpu(sbi->ckpt->cur_node_segno[1]) == segno || - le32_to_cpu(sbi->ckpt->cur_data_segno[1]) == segno || - le32_to_cpu(sbi->ckpt->cur_node_segno[2]) == segno || - le32_to_cpu(sbi->ckpt->cur_data_segno[2]) == segno) { - continue; - } else { + if (!IS_CUR_SEGNO(sbi, segno)) free_segs++; - } } else { sum_vblocks += se->valid_blocks; } -- 2.25.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] 5+ messages in thread
* Re: [f2fs-dev] [PATCH v2 1/3] f2fs-tools: use 'IS_CUR_SEGNO()' to check if it is current segment 2023-09-28 9:20 ` [f2fs-dev] [PATCH v2 1/3] f2fs-tools: use 'IS_CUR_SEGNO()' to check if it is current segment Wu Bo via Linux-f2fs-devel @ 2023-10-07 1:39 ` Chao Yu 0 siblings, 0 replies; 5+ messages in thread From: Chao Yu @ 2023-10-07 1:39 UTC (permalink / raw) To: Wu Bo, Jaegeuk Kim; +Cc: Wu Bo, linux-f2fs-devel On 2023/9/28 17:20, Wu Bo wrote: > Use IS_CUR_SEGNO() here can make code more concise and readable. It missed to add your signed-off tag here, otherwise the patch looks good to me. Thanks, > --- > fsck/mount.c | 10 +--------- > 1 file changed, 1 insertion(+), 9 deletions(-) > > diff --git a/fsck/mount.c b/fsck/mount.c > index df0314d..e4372cf 100644 > --- a/fsck/mount.c > +++ b/fsck/mount.c > @@ -2532,16 +2532,8 @@ void build_sit_area_bitmap(struct f2fs_sb_info *sbi) > ptr += SIT_VBLOCK_MAP_SIZE; > > if (se->valid_blocks == 0x0 && is_usable_seg(sbi, segno)) { > - if (le32_to_cpu(sbi->ckpt->cur_node_segno[0]) == segno || > - le32_to_cpu(sbi->ckpt->cur_data_segno[0]) == segno || > - le32_to_cpu(sbi->ckpt->cur_node_segno[1]) == segno || > - le32_to_cpu(sbi->ckpt->cur_data_segno[1]) == segno || > - le32_to_cpu(sbi->ckpt->cur_node_segno[2]) == segno || > - le32_to_cpu(sbi->ckpt->cur_data_segno[2]) == segno) { > - continue; > - } else { > + if (!IS_CUR_SEGNO(sbi, segno)) > free_segs++; > - } > } else { > sum_vblocks += se->valid_blocks; > } _______________________________________________ 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] 5+ messages in thread
* [f2fs-dev] [PATCH v2 2/3] f2fs-tools: skip not matched segment when finding free block 2023-09-28 9:20 [f2fs-dev] [PATCH v2 0/3] f2fs-tools: cache free segments count to improve perfmance Wu Bo via Linux-f2fs-devel 2023-09-28 9:20 ` [f2fs-dev] [PATCH v2 1/3] f2fs-tools: use 'IS_CUR_SEGNO()' to check if it is current segment Wu Bo via Linux-f2fs-devel @ 2023-09-28 9:20 ` Wu Bo via Linux-f2fs-devel 2023-09-28 9:20 ` [f2fs-dev] [PATCH v2 3/3] f2fs-tools: cache free segments count to improve perfmance Wu Bo via Linux-f2fs-devel 2 siblings, 0 replies; 5+ messages in thread From: Wu Bo via Linux-f2fs-devel @ 2023-09-28 9:20 UTC (permalink / raw) To: Jaegeuk Kim, Chao Yu; +Cc: Wu Bo, Wu Bo, linux-f2fs-devel If the segment type is not matched, goto next segment to save time. --- fsck/mount.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fsck/mount.c b/fsck/mount.c index e4372cf..098e73d 100644 --- a/fsck/mount.c +++ b/fsck/mount.c @@ -2852,8 +2852,10 @@ next_segment: } } - if (type == want_type && !new_sec && - !f2fs_test_bit(offset, (const char *)bitmap)) + if (type != want_type) + goto next_segment; + else if (!new_sec && + !f2fs_test_bit(offset, (const char *)bitmap)) return 0; *to = left ? *to - 1: *to + 1; -- 2.25.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] 5+ messages in thread
* [f2fs-dev] [PATCH v2 3/3] f2fs-tools: cache free segments count to improve perfmance 2023-09-28 9:20 [f2fs-dev] [PATCH v2 0/3] f2fs-tools: cache free segments count to improve perfmance Wu Bo via Linux-f2fs-devel 2023-09-28 9:20 ` [f2fs-dev] [PATCH v2 1/3] f2fs-tools: use 'IS_CUR_SEGNO()' to check if it is current segment Wu Bo via Linux-f2fs-devel 2023-09-28 9:20 ` [f2fs-dev] [PATCH v2 2/3] f2fs-tools: skip not matched segment when finding free block Wu Bo via Linux-f2fs-devel @ 2023-09-28 9:20 ` Wu Bo via Linux-f2fs-devel 2 siblings, 0 replies; 5+ messages in thread From: Wu Bo via Linux-f2fs-devel @ 2023-09-28 9:20 UTC (permalink / raw) To: Jaegeuk Kim, Chao Yu; +Cc: Wu Bo, Wu Bo, linux-f2fs-devel 'get_free_segments()' is implemented by traversing all segments to calculate the total free segments. It cosume much time. Every time when call 'find_next_free_block()' this calculation will do it again. So if we cache the free segments count, it will greatly improve performance of dfrag & resize & sload. --- fsck/f2fs.h | 1 + fsck/mount.c | 9 +++++++-- fsck/segment.c | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/fsck/f2fs.h b/fsck/f2fs.h index e65644e..a7cdc4c 100644 --- a/fsck/f2fs.h +++ b/fsck/f2fs.h @@ -197,6 +197,7 @@ struct f2fs_sm_info { unsigned int main_segments; unsigned int reserved_segments; unsigned int ovp_segments; + unsigned int free_segments; }; struct f2fs_dentry_ptr { diff --git a/fsck/mount.c b/fsck/mount.c index 098e73d..0a37bc4 100644 --- a/fsck/mount.c +++ b/fsck/mount.c @@ -123,7 +123,7 @@ void update_free_segments(struct f2fs_sb_info *sbi) if (c.dbg_lv) return; - MSG(0, "\r [ %c ] Free segments: 0x%x", progress[i % 5], get_free_segments(sbi)); + MSG(0, "\r [ %c ] Free segments: 0x%x", progress[i % 5], SM_I(sbi)->free_segments); fflush(stdout); i++; } @@ -2430,6 +2430,10 @@ static int build_sit_entries(struct f2fs_sb_info *sbi) check_block_count(sbi, segno, &sit); seg_info_from_raw_sit(sbi, se, &sit); + if (se->valid_blocks == 0x0 && + is_usable_seg(sbi, segno) && + !IS_CUR_SEGNO(sbi, segno)) + SM_I(sbi)->free_segments++; } start_blk += readed; } while (start_blk < sit_blk_cnt); @@ -2485,6 +2489,7 @@ static int early_build_segment_manager(struct f2fs_sb_info *sbi) sm_info->ovp_segments = get_cp(overprov_segment_count); sm_info->main_segments = get_sb(segment_count_main); sm_info->ssa_blkaddr = get_sb(ssa_blkaddr); + sm_info->free_segments = 0; if (build_sit_info(sbi) || build_curseg(sbi)) { free(sm_info); @@ -2806,7 +2811,7 @@ int find_next_free_block(struct f2fs_sb_info *sbi, u64 *to, int left, if (*to > 0) *to -= left; - if (get_free_segments(sbi) <= SM_I(sbi)->reserved_segments + 1) + if (SM_I(sbi)->free_segments <= SM_I(sbi)->reserved_segments + 1) not_enough = 1; while (*to >= SM_I(sbi)->main_blkaddr && *to < end_blkaddr) { diff --git a/fsck/segment.c b/fsck/segment.c index 0307bdd..1cb7d02 100644 --- a/fsck/segment.c +++ b/fsck/segment.c @@ -77,6 +77,8 @@ int reserve_new_block(struct f2fs_sb_info *sbi, block_t *to, se = get_seg_entry(sbi, GET_SEGNO(sbi, blkaddr)); offset = OFFSET_IN_SEG(sbi, blkaddr); se->type = type; + if (se->valid_blocks == 0) + SM_I(sbi)->free_segments--; se->valid_blocks++; f2fs_set_bit(offset, (char *)se->cur_valid_map); if (need_fsync_data_record(sbi)) { -- 2.25.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] 5+ messages in thread
end of thread, other threads:[~2023-10-07 1:39 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-09-28 9:20 [f2fs-dev] [PATCH v2 0/3] f2fs-tools: cache free segments count to improve perfmance Wu Bo via Linux-f2fs-devel 2023-09-28 9:20 ` [f2fs-dev] [PATCH v2 1/3] f2fs-tools: use 'IS_CUR_SEGNO()' to check if it is current segment Wu Bo via Linux-f2fs-devel 2023-10-07 1:39 ` Chao Yu 2023-09-28 9:20 ` [f2fs-dev] [PATCH v2 2/3] f2fs-tools: skip not matched segment when finding free block Wu Bo via Linux-f2fs-devel 2023-09-28 9:20 ` [f2fs-dev] [PATCH v2 3/3] f2fs-tools: cache free segments count to improve perfmance Wu Bo via Linux-f2fs-devel
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).