f2fs: introduce is_cur{seg,sec}()
Chao Yu
maintainerPATCH 1/1 f2fs: introduce is_cur{seg,sec}()
There are redundant codes in IS_CUR{SEG,SEC}() macros, let's introduce inline is_cur{seg,sec}() functions, and use a loop in it for cleanup.
Meanwhile, it enhances expansibility, as it doesn't need to change is_cur{seg,sec}() when we add a new log header.
--- fs/f2fs/debug.c | 4 ++-- fs/f2fs/gc.c | 2 +- fs/f2fs/segment.c | 22 +++++++++---------- fs/f2fs/segment.h | 54 +++++++++++++++++++++-------------------------- 4 files changed, 38 insertions(+), 44 deletions(-)
fs/f2fs/debug.c +2 -2
@@ -91,7 +91,7 @@ static void update_multidevice_stats(struct f2fs_sb_info *sbi) seg_blks =get_seg_entry (sbi, j)->valid_blocks;/* update segment stats */ -if (IS_CURSEG (sbi, j)) +if (is_curseg (sbi, j)) dev_stats[i].devstats[0 ][DEVSTAT_INUSE ]++;else if (seg_blks ==BLKS_PER_SEG (sbi)) dev_stats[i].devstats[0 ][DEVSTAT_FULL ]++;
@@ -109,7 +109,7 @@ static void update_multidevice_stats(struct f2fs_sb_info *sbi) sec_blks =get_sec_entry (sbi, j)->valid_blocks;/* update section stats */ -if (IS_CURSEC (sbi,GET_SEC_FROM_SEG (sbi, j))) +if (is_cursec (sbi,GET_SEC_FROM_SEG (sbi, j))) dev_stats[i].devstats[1 ][DEVSTAT_INUSE ]++;else if (sec_blks ==BLKS_PER_SEC (sbi)) dev_stats[i].devstats[1 ][DEVSTAT_FULL ]++;
fs/f2fs/gc.c +1 -1
@@ -2065,7 +2065,7 @@ int f2fs_gc_range(struct f2fs_sb_info *sbi, .iroot = RADIX_TREE_INIT(gc_list.iroot, GFP_NOFS), }; -if (IS_CURSEC (sbi,GET_SEC_FROM_SEG (sbi, segno))) +if (is_cursec (sbi,GET_SEC_FROM_SEG (sbi, segno)))continue ;do_garbage_collect (sbi, segno, &gc_list,FG_GC , true, false);
fs/f2fs/segment.c +11 -11
@@ -773,7 +773,7 @@ static void __locate_dirty_segment(struct f2fs_sb_info *sbi, unsigned int segno,struct dirty_seglist_info *dirty_i =DIRTY_I (sbi);/* need not be added */ -if (IS_CURSEG (sbi, segno)) +if (is_curseg (sbi, segno))return ;if (!test_and_set_bit (segno, dirty_i->dirty_segmap[dirty_type]))
@@ -800,7 +800,7 @@ static void __locate_dirty_segment(struct f2fs_sb_info *sbi, unsigned int segno, !valid_blocks) || valid_blocks == CAP_BLKS_PER_SEC(sbi)); -if (!IS_CURSEC (sbi, secno)) +if (!is_cursec (sbi, secno))set_bit (secno, dirty_i->dirty_secmap); } }
@@ -839,7 +839,7 @@ static void __remove_dirty_segment(struct f2fs_sb_info *sbi, unsigned int segno,return ; } -if (!IS_CURSEC (sbi, secno)) +if (!is_cursec (sbi, secno))set_bit (secno, dirty_i->dirty_secmap); } }
@@ -856,7 +856,7 @@ static void locate_dirty_segment(struct f2fs_sb_info *sbi, unsigned int segno)unsigned short valid_blocks, ckpt_valid_blocks;unsigned int usable_blocks; -if (segno ==NULL_SEGNO ||IS_CURSEG (sbi, segno)) +if (segno ==NULL_SEGNO ||is_curseg (sbi, segno))return ; usable_blocks =f2fs_usable_blks_in_seg (sbi, segno);
@@ -889,7 +889,7 @@ void f2fs_dirty_to_prefree(struct f2fs_sb_info *sbi)for_each_set_bit (segno, dirty_i->dirty_segmap[DIRTY ],MAIN_SEGS (sbi)) {if (get_valid_blocks (sbi, segno, false))continue ; -if (IS_CURSEG (sbi, segno)) +if (is_curseg (sbi, segno))continue ;__locate_dirty_segment (sbi, segno,PRE );__remove_dirty_segment (sbi, segno,DIRTY );
@@ -2108,7 +2108,7 @@ static bool add_discard_addrs(struct f2fs_sb_info *sbi, struct cp_control *cpc,if (!force) {if (!f2fs_realtime_discard_enable (sbi) || (!se->valid_blocks && - !IS_CURSEG (sbi, cpc->trim_start)) || + !is_curseg (sbi, cpc->trim_start)) ||SM_I (sbi)->dcc_info->nr_discards >=SM_I (sbi)->dcc_info->max_discards)return false;
@@ -2236,7 +2236,7 @@ void f2fs_clear_prefree_segments(struct f2fs_sb_info *sbi, next: secno =GET_SEC_FROM_SEG (sbi, start); start_segno =GET_SEG_FROM_SEC (sbi, secno); -if (!IS_CURSEC (sbi, secno) && +if (!is_cursec (sbi, secno) && !get_valid_blocks (sbi, start, true))f2fs_issue_discard (sbi,START_BLOCK (sbi, start_segno),BLKS_PER_SEC (sbi));
@@ -4107,14 +4107,14 @@ void f2fs_do_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,if (!recover_curseg) {/* for recovery flow */ -if (se->valid_blocks ==0 && !IS_CURSEG (sbi, segno)) { +if (se->valid_blocks ==0 && !is_curseg (sbi, segno)) {if (old_blkaddr ==NULL_ADDR ) type =CURSEG_COLD_DATA ;else type =CURSEG_WARM_DATA ; } }else { -if (IS_CURSEG (sbi, segno)) { +if (is_curseg (sbi, segno)) {/* se->type is volatile as SSR allocation */ type =__f2fs_get_curseg (sbi, segno);f2fs_bug_on (sbi, type ==NO_CHECK_TYPE );
@@ -5150,7 +5150,7 @@ static void init_dirty_segmap(struct f2fs_sb_info *sbi)if (!valid_blocks || valid_blocks ==CAP_BLKS_PER_SEC (sbi))continue ; -if (IS_CURSEC (sbi, secno)) +if (is_cursec (sbi, secno))continue ;set_bit (secno, dirty_i->dirty_secmap); }
@@ -5286,7 +5286,7 @@ static int check_zone_write_pointer(struct f2fs_sb_info *sbi,* Get # of valid block of the zone. */ valid_block_cnt =get_valid_blocks (sbi, zone_segno, true); -if (IS_CURSEC (sbi,GET_SEC_FROM_SEG (sbi, zone_segno))) { +if (is_cursec (sbi,GET_SEC_FROM_SEG (sbi, zone_segno))) {f2fs_notice (sbi,"Open zones: valid block[0x%x,0x%x] cond[%s]" , zone_segno, valid_block_cnt,blk_zone_cond_str (zone->cond));
fs/f2fs/segment.h +24 -30
78 lines not on this page · raw message
Signature · 1 line
2.49.0
This patch was applied to jaegeuk/f2fs.git (dev) by Jaegeuk Kim <[email protected]>:
Hello:
This patch was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <[email protected]>:
Quoted 9 lines · On Mon, 7 Jul 2025 19:46:14 +0800 you wrote:
There are redundant codes in IS_CUR{SEG,SEC}() macros, let's introduce inline is_cur{seg,sec}() functions, and use a loop in it for cleanup.
Meanwhile, it enhances expansibility, as it doesn't need to change is_cur{seg,sec}() when we add a new log header.
Signed-off-by Chao Yu <[email protected]>[...]
Here is the summary with links:
- [f2fs-dev] f2fs: introduce is_cur{seg,sec}()
https://git.kernel.org/jaegeuk/f2fs/c/c1cfc87e4952
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html