segment allocation cleanups
Hi Jaegeuk and Chao,
this series cleans up the segment allocation code a bit.
Diffstat
segment.c | 71 ++++++++++++++++++++++++++------------------------------------ segment.h | 6 ----- 2 files changed, 30 insertions(+), 47 deletions(-)
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
PATCH 1/3 f2fs: remove struct segment_allocation default_salloc_ops
There is only single instance of these ops, so remove the indirection and call allocate_segment_by_default directly.
--- fs/f2fs/segment.c | 11 ++--------- fs/f2fs/segment.h | 6 ------ 2 files changed, 2 insertions(+), 15 deletions(-)
fs/f2fs/segment.c +2 -9
@@ -2913,7 +2913,7 @@ static void __allocate_new_segment(struct f2fs_sb_info *sbi, int type,return ; alloc: old_segno = curseg->segno; -SIT_I (sbi)->s_ops->allocate_segment (sbi, type, true); +allocate_segment_by_default (sbi, type, true);locate_dirty_segment (sbi, old_segno); }
@@ -2944,10 +2944,6 @@ void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi)f2fs_up_read (&SM_I (sbi)->curseg_lock); } -static const struct segment_allocation default_salloc_ops = { - .allocate_segment = allocate_segment_by_default, -}; -bool f2fs_exist_trim_candidates (struct f2fs_sb_info *sbi,struct cp_control *cpc) {
@@ -3272,7 +3268,7 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,get_atssr_segment (sbi, type, se->type,AT_SSR , se->mtime); else - sit_i->s_ops->allocate_segment(sbi, type, false); +allocate_segment_by_default (sbi ,type ,false ); }/* * segment dirty status should be updated after segment allocation,
@@ -4258,9 +4254,6 @@ static int build_sit_info(struct f2fs_sb_info *sbi)return -ENOMEM ;#endif -/* init SIT information */ - sit_i->s_ops = &default_salloc_ops; - sit_i->sit_base_addr =le32_to_cpu (raw_super->sit_blkaddr); sit_i->sit_blocks = sit_segs << sbi->log_blocks_per_seg; sit_i->written_valid_blocks =0 ;
fs/f2fs/segment.h +0 -6
@@ -222,10 +222,6 @@ struct sec_entry {unsigned int valid_blocks;/* # of valid blocks in a section */ }; -struct segment_allocation { -void (*allocate_segment)(struct f2fs_sb_info *,int ,bool ); -}; -#define MAX_SKIP_GC_COUNT 16struct revoke_entry {
@@ -235,8 +231,6 @@ struct revoke_entry { };struct sit_info { -const struct segment_allocation *s_ops; -block_t sit_base_addr;/* start block address of SIT area */ block_t sit_blocks;/* # of blocks used by SIT area */ block_t written_valid_blocks;/* # of valid blocks in main area */
Signature · 8 lines
2.30.2 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Re: [f2fs-dev] [PATCH 1/3] f2fs: remove struct segment_allocation default_salloc_ops
Quoted 4 lines · Christoph Hellwig
There is only single instance of these ops, so remove the indirection and call
allocate_segment_by_defaultdirectly.Signed-off-by Christoph Hellwig <[email protected]>
Thanks,
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
PATCH 2/3 f2fs: open code allocate_segment_by_default
In reply to Christoph Hellwigallocate_segment_by_default has just two callers, which use very different code pathes inside it based on the force paramter. Just open code the logic in the two callers using a new helper to decided if a new segment should be allocated.
--- fs/f2fs/segment.c | 50 +++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 26 deletions(-)
fs/f2fs/segment.c +24 -26
@@ -2836,31 +2836,20 @@ static int get_ssr_segment(struct f2fs_sb_info *sbi, int type,return 0 ; } -/* -* flush out current segment and replace it with new segment -* This function should be returned with success, otherwise BUG -*/ -static void allocate_segment_by_default (struct f2fs_sb_info *sbi, -int type,bool force) +static bool need_new_seg (struct f2fs_sb_info *sbi,int type) {struct curseg_info *curseg =CURSEG_I (sbi, type); -if (force) -new_curseg (sbi, type, true); -else if (!is_set_ckpt_flags (sbi,CP_CRC_RECOVERY_FLAG ) && - curseg->seg_type ==CURSEG_WARM_NODE ) -new_curseg (sbi, type, false); -else if (curseg->alloc_type ==LFS && -is_next_segment_free (sbi, curseg, type) && -likely (!is_sbi_flag_set (sbi,SBI_CP_DISABLED ))) -new_curseg (sbi, type, false); -else if (f2fs_need_SSR (sbi) && -get_ssr_segment (sbi, type,SSR ,0 )) -change_curseg (sbi, type, true); -else -new_curseg (sbi, type, false); - -stat_inc_seg_type (sbi, curseg); +if (!is_set_ckpt_flags (sbi,CP_CRC_RECOVERY_FLAG ) && + curseg->seg_type ==CURSEG_WARM_NODE ) +return true; +if (curseg->alloc_type ==LFS && +is_next_segment_free (sbi, curseg, type) && +likely (!is_sbi_flag_set (sbi,SBI_CP_DISABLED ))) +return true; +if (!f2fs_need_SSR (sbi) || !get_ssr_segment (sbi, type,SSR ,0 )) +return true; +return false; } void f2fs_allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type,
@@ -2913,7 +2902,8 @@ static void __allocate_new_segment(struct f2fs_sb_info *sbi, int type,return ; alloc: old_segno = curseg->segno; -allocate_segment_by_default (sbi, type, true); +new_curseg (sbi, type, true); +stat_inc_seg_type (sbi, curseg);locate_dirty_segment (sbi, old_segno); }
@@ -3264,11 +3254,19 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,update_sit_entry (sbi, old_blkaddr,-1 );if (!__has_curseg_space (sbi, curseg)) { -if (from_gc) +/* +* Flush out current segment and replace it with new segment. +*/ +if (from_gc) {get_atssr_segment (sbi, type, se->type,AT_SSR , se->mtime); -else -allocate_segment_by_default (sbi, type, false); + }else { +if (need_new_seg (sbi, type)) +new_curseg (sbi, type, false); +else +change_curseg (sbi, type, true); +stat_inc_seg_type (sbi, curseg); + } }/* * segment dirty status should be updated after segment allocation,
Signature · 8 lines
2.30.2 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Re: [f2fs-dev] [PATCH 2/3] f2fs: open code allocate_segment_by_default
Quoted 6 lines · Christoph Hellwig
allocate_segment_by_defaulthas just two callers, which use very different code pathes inside it based on the force paramter. Just open code the logic in the two callers using a new helper to decided if a new segment should be allocated.Signed-off-by Christoph Hellwig <[email protected]>
Thanks,
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
PATCH 3/3 f2fs: remove the unused flush argument to change_curseg
In reply to Christoph Hellwig--- fs/f2fs/segment.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
fs/f2fs/segment.c +7 -9
@@ -2643,7 +2643,7 @@ bool f2fs_segment_has_free_slot(struct f2fs_sb_info *sbi, int segno)* This function always allocates a used segment(from dirty seglist) by SSR * manner, so it should recover the existing segment information of valid blocks */ -static void change_curseg (struct f2fs_sb_info *sbi,int type,bool flush) +static void change_curseg (struct f2fs_sb_info *sbi,int type) {struct dirty_seglist_info *dirty_i =DIRTY_I (sbi);struct curseg_info *curseg =CURSEG_I (sbi, type);
@@ -2651,9 +2651,7 @@ static void change_curseg(struct f2fs_sb_info *sbi, int type, bool flush)struct f2fs_summary_block *sum_node;struct page *sum_page; -if (flush) -write_sum_page (sbi, curseg->sum_blk, -GET_SUM_BLOCK (sbi, curseg->segno)); +write_sum_page (sbi, curseg->sum_blk,GET_SUM_BLOCK (sbi, curseg->segno));__set_test_and_inuse (sbi, new_segno);
@@ -2692,7 +2690,7 @@ static void get_atssr_segment(struct f2fs_sb_info *sbi, int type,struct seg_entry *se =get_seg_entry (sbi, curseg->next_segno); curseg->seg_type = se->type; -change_curseg (sbi, type, true); +change_curseg (sbi, type); }else {/* allocate cold segment by default */ curseg->seg_type =CURSEG_COLD_DATA ;
@@ -2867,7 +2865,7 @@ void f2fs_allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type, goto unlock;if (f2fs_need_SSR (sbi) &&get_ssr_segment (sbi, type,SSR ,0 )) -change_curseg (sbi, type, true); +change_curseg (sbi, type);else new_curseg (sbi, type, true);
@@ -3264,7 +3262,7 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,if (need_new_seg (sbi, type))new_curseg (sbi, type, false);else -change_curseg (sbi, type, true); +change_curseg (sbi, type);stat_inc_seg_type (sbi, curseg); } }
@@ -3527,7 +3525,7 @@ void f2fs_do_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,/* change the current segment */ if (segno != curseg->segno) { curseg->next_segno = segno; -change_curseg (sbi, type, true); +change_curseg (sbi, type); } curseg->next_blkoff =GET_BLKOFF_FROM_SEG0 (sbi, new_blkaddr);
@@ -3555,7 +3553,7 @@ void f2fs_do_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,if (recover_curseg) {if (old_cursegno != curseg->segno) { curseg->next_segno = old_cursegno; -change_curseg (sbi, type, true); +change_curseg (sbi, type); } curseg->next_blkoff = old_blkoff; curseg->alloc_type = old_alloc_type;
Signature · 8 lines
2.30.2 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Re: [f2fs-dev] [PATCH 3/3] f2fs: remove the unused flush argument to change_curseg
Quoted 1 line · Christoph Hellwig
Signed-off-by Christoph Hellwig <[email protected]>
Thanks,
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Jaegeuk Kim
maintainerQuoted 3 lines · Christoph Hellwig
Hi Jaegeuk and Chao,
this series cleans up the segment allocation code a bit.
Thanks, applied for test.
Quoted 5 lines
Diffstat
segment.c | 71 ++++++++++++++++++++++++++------------------------------------ segment.h | 6 ----- 2 files changed, 30 insertions(+), 47 deletions(-)
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel