Skip to content

Commit 8442d94

Browse files
Christoph HellwigJaegeuk Kim
authored andcommitted
f2fs: open code allocate_segment_by_default
allocate_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. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent 1c8a8ec commit 8442d94

File tree

1 file changed

+24
-26
lines changed

1 file changed

+24
-26
lines changed

fs/f2fs/segment.c

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2849,31 +2849,20 @@ static int get_ssr_segment(struct f2fs_sb_info *sbi, int type,
28492849
return 0;
28502850
}
28512851

2852-
/*
2853-
* flush out current segment and replace it with new segment
2854-
* This function should be returned with success, otherwise BUG
2855-
*/
2856-
static void allocate_segment_by_default(struct f2fs_sb_info *sbi,
2857-
int type, bool force)
2852+
static bool need_new_seg(struct f2fs_sb_info *sbi, int type)
28582853
{
28592854
struct curseg_info *curseg = CURSEG_I(sbi, type);
28602855

2861-
if (force)
2862-
new_curseg(sbi, type, true);
2863-
else if (!is_set_ckpt_flags(sbi, CP_CRC_RECOVERY_FLAG) &&
2864-
curseg->seg_type == CURSEG_WARM_NODE)
2865-
new_curseg(sbi, type, false);
2866-
else if (curseg->alloc_type == LFS &&
2867-
is_next_segment_free(sbi, curseg, type) &&
2868-
likely(!is_sbi_flag_set(sbi, SBI_CP_DISABLED)))
2869-
new_curseg(sbi, type, false);
2870-
else if (f2fs_need_SSR(sbi) &&
2871-
get_ssr_segment(sbi, type, SSR, 0))
2872-
change_curseg(sbi, type, true);
2873-
else
2874-
new_curseg(sbi, type, false);
2875-
2876-
stat_inc_seg_type(sbi, curseg);
2856+
if (!is_set_ckpt_flags(sbi, CP_CRC_RECOVERY_FLAG) &&
2857+
curseg->seg_type == CURSEG_WARM_NODE)
2858+
return true;
2859+
if (curseg->alloc_type == LFS &&
2860+
is_next_segment_free(sbi, curseg, type) &&
2861+
likely(!is_sbi_flag_set(sbi, SBI_CP_DISABLED)))
2862+
return true;
2863+
if (!f2fs_need_SSR(sbi) || !get_ssr_segment(sbi, type, SSR, 0))
2864+
return true;
2865+
return false;
28772866
}
28782867

28792868
void f2fs_allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type,
@@ -2926,7 +2915,8 @@ static void __allocate_new_segment(struct f2fs_sb_info *sbi, int type,
29262915
return;
29272916
alloc:
29282917
old_segno = curseg->segno;
2929-
allocate_segment_by_default(sbi, type, true);
2918+
new_curseg(sbi, type, true);
2919+
stat_inc_seg_type(sbi, curseg);
29302920
locate_dirty_segment(sbi, old_segno);
29312921
}
29322922

@@ -3276,11 +3266,19 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
32763266
update_sit_entry(sbi, old_blkaddr, -1);
32773267

32783268
if (!__has_curseg_space(sbi, curseg)) {
3279-
if (from_gc)
3269+
/*
3270+
* Flush out current segment and replace it with new segment.
3271+
*/
3272+
if (from_gc) {
32803273
get_atssr_segment(sbi, type, se->type,
32813274
AT_SSR, se->mtime);
3282-
else
3283-
allocate_segment_by_default(sbi, type, false);
3275+
} else {
3276+
if (need_new_seg(sbi, type))
3277+
new_curseg(sbi, type, false);
3278+
else
3279+
change_curseg(sbi, type, true);
3280+
stat_inc_seg_type(sbi, curseg);
3281+
}
32843282
}
32853283
/*
32863284
* segment dirty status should be updated after segment allocation,

0 commit comments

Comments
 (0)