Skip to content

Commit e3a1997

Browse files
Sheng YongJaegeuk Kim
authored andcommitted
f2fs: only fragment segment in the same section
When new_curseg() is allocating a new segment, if mode=fragment:xxx is switched on in large section scenario, __get_next_segno() will select the next segno randomly in the range of [0, maxsegno] in order to fragment segments. If the candidate segno is free, get_new_segment() will use it directly as the new segment. However, if the section of the candidate is not empty, and some other segments have already been used, and have a different type (e.g NODE) with the candidate (e.g DATA), GC will complain inconsistent segment type later. This could be reproduced by the following steps: dd if=/dev/zero of=test.img bs=1M count=10240 mkfs.f2fs -s 128 test.img mount -t f2fs test.img /mnt -o mode=fragment:block echo 1 > /sys/fs/f2fs/loop0/max_fragment_chunk echo 512 > /sys/fs/f2fs/loop0/max_fragment_hole dd if=/dev/zero of=/mnt/testfile bs=4K count=100 umount /mnt F2FS-fs (loop0): Inconsistent segment (4377) type [0, 1] in SSA and SIT In order to allow simulating segment fragmentation in large section scenario, this patch reduces the candidate range: * if curseg is the last segment in the section, return curseg->segno to make get_new_segment() itself find the next free segment. * if curseg is in the middle of the section, select candicate randomly in the range of [curseg + 1, last_seg_in_the_same_section] to keep type consistent. Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Sheng Yong <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent f06c0f8 commit e3a1997

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

fs/f2fs/segment.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2784,11 +2784,19 @@ static unsigned int __get_next_segno(struct f2fs_sb_info *sbi, int type)
27842784
unsigned short seg_type = curseg->seg_type;
27852785

27862786
sanity_check_seg_type(sbi, seg_type);
2787-
if (f2fs_need_rand_seg(sbi))
2788-
return get_random_u32_below(MAIN_SECS(sbi) * SEGS_PER_SEC(sbi));
2787+
if (__is_large_section(sbi)) {
2788+
if (f2fs_need_rand_seg(sbi)) {
2789+
unsigned int hint = GET_SEC_FROM_SEG(sbi, curseg->segno);
27892790

2790-
if (__is_large_section(sbi))
2791+
if (GET_SEC_FROM_SEG(sbi, curseg->segno + 1) != hint)
2792+
return curseg->segno;
2793+
return get_random_u32_inclusive(curseg->segno + 1,
2794+
GET_SEG_FROM_SEC(sbi, hint + 1) - 1);
2795+
}
27912796
return curseg->segno;
2797+
} else if (f2fs_need_rand_seg(sbi)) {
2798+
return get_random_u32_below(MAIN_SECS(sbi) * SEGS_PER_SEC(sbi));
2799+
}
27922800

27932801
/* inmem log may not locate on any segment after mount */
27942802
if (!curseg->inited)

0 commit comments

Comments
 (0)