f2fs: cleanup w/ f2fs_need_rand_{blk,seg,seg_blk}
Chao Yu
maintainerPATCH 1/2 f2fs: cleanup w/ f2fs_need_rand_{blk,seg,seg_blk}
No logic changes.
--- fs/f2fs/f2fs.h | 13 +++++++++++-- fs/f2fs/gc.c | 2 +- fs/f2fs/segment.c | 8 ++++---- fs/f2fs/super.c | 4 ++-- 4 files changed, 18 insertions(+), 9 deletions(-)
fs/f2fs/f2fs.h +11 -2
@@ -4146,10 +4146,19 @@ static inline struct inode *fio_inode(struct f2fs_io_info *fio)#define MIN_FRAGMENT_SIZE 1#define MAX_FRAGMENT_SIZE 512 +static inline bool f2fs_need_rand_blk (struct f2fs_sb_info *sbi) +{ +return F2FS_OPTION (sbi).fs_mode ==FS_MODE_FRAGMENT_BLK ; +} +static inline bool f2fs_need_rand_seg (struct f2fs_sb_info *sbi) { -return F2FS_OPTION (sbi).fs_mode ==FS_MODE_FRAGMENT_SEG || -F2FS_OPTION (sbi).fs_mode ==FS_MODE_FRAGMENT_BLK ; +return F2FS_OPTION (sbi).fs_mode ==FS_MODE_FRAGMENT_SEG ; +} + +static inline bool f2fs_need_rand_seg_blk (struct f2fs_sb_info *sbi) +{ +return f2fs_need_rand_blk (sbi) ||f2fs_need_rand_seg (sbi); }/*
fs/f2fs/gc.c +1 -1
@@ -310,7 +310,7 @@ static void select_policy(struct f2fs_sb_info *sbi, int gc_type, p->max_search = sbi->max_victim_search;/* let's select beginning hot/small space first. */ -if (f2fs_need_rand_seg (sbi)) { +if (f2fs_need_rand_seg_blk (sbi)) { p->offset =get_random_u32_below (MAIN_SECS (sbi) *SEGS_PER_SEC (sbi));SIT_I (sbi)->last_victim[p->gc_mode] = p->offset;
fs/f2fs/segment.c +4 -4
@@ -3055,7 +3055,7 @@ static unsigned int __get_next_segno(struct f2fs_sb_info *sbi, int type)sanity_check_seg_type (sbi, seg_type);if (__is_large_section (sbi)) { -if (f2fs_need_rand_seg (sbi)) { +if (f2fs_need_rand_seg_blk (sbi)) {unsigned int hint =GET_SEC_FROM_SEG (sbi, curseg->segno);if (GET_SEC_FROM_SEG (sbi, curseg->segno +1 ) != hint)
@@ -3064,7 +3064,7 @@ static unsigned int __get_next_segno(struct f2fs_sb_info *sbi, int type) GET_SEG_FROM_SEC(sbi, hint + 1) - 1); }return curseg->segno; - }else if (f2fs_need_rand_seg (sbi)) { + }else if (f2fs_need_rand_seg_blk (sbi)) {return get_random_u32_below (MAIN_SECS (sbi) *SEGS_PER_SEC (sbi)); }
@@ -3120,7 +3120,7 @@ static int new_curseg(struct f2fs_sb_info *sbi, int type, bool new_sec) curseg->next_segno = segno;reset_curseg (sbi, type,1 ); curseg->alloc_type =LFS ; -if (F2FS_OPTION (sbi).fs_mode ==FS_MODE_FRAGMENT_BLK ) +if (f2fs_need_rand_blk (sbi)) curseg->fragment_remained_chunk =get_random_u32_inclusive (1 , sbi->max_fragment_chunk);return 0 ;
@@ -3939,7 +3939,7 @@ int f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct folio *folio, curseg->next_blkoff =f2fs_find_next_ssr_block (sbi, curseg); }else { curseg->next_blkoff++; -if (F2FS_OPTION (sbi).fs_mode ==FS_MODE_FRAGMENT_BLK ) +if (f2fs_need_rand_blk (sbi))f2fs_randomize_chunk (sbi, curseg); }if (curseg->next_blkoff >=f2fs_usable_blks_in_seg (sbi, curseg->segno))
fs/f2fs/super.c +2 -2
@@ -2457,9 +2457,9 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)seq_puts (seq,"adaptive" ); else if (F2FS_OPTION(sbi).fs_mode == FS_MODE_LFS) seq_puts(seq, "lfs"); - else if (F2FS_OPTION(sbi).fs_mode == FS_MODE_FRAGMENT_SEG) + else if (f2fs_need_rand_seg(sbi)) seq_puts(seq, "fragment:segment"); - else if (F2FS_OPTION(sbi).fs_mode == FS_MODE_FRAGMENT_BLK) + else if (f2fs_need_rand_blk(sbi)) seq_puts(seq, "fragment:block"); seq_printf(seq, ",active_logs=%u", F2FS_OPTION(sbi).active_logs); if (test_opt(sbi, RESERVE_ROOT) || test_opt(sbi, RESERVE_NODE))
Signature · 1 line
2.49.0
Chao Yu
maintainerPATCH 2/2 f2fs: fix to avoid pinfile fragment on fragment:{block,segment} mode
pinfile fallocate() conflicts w/ mode=fragment:{block,segment} mount option, result in fragment blocks in pinfile, it violate semantics of pinfile introduced in commit f5a53edcf01e ("f2fs: support aligned pinned file").
mkfs.f2fs -f /dev/vdb
mount -t f2fs -o mode=fragment:block /dev/vdb /mnt/f2fs/ dd if=/dev/zero of=/mnt/f2fs/file bs=1M count=3900 sync
touch /mnt/f2fs/pinfilef2fs_io pinfile set /mnt/f2fs/pinfilef2fs_io fallocate 0 0 $((1024*1024*16)) /mnt/f2fs/pinfile syncf2fs_io fiemap 0 $((1024*1024*16)) /mnt/f2fs/pinfile
[Before]
fallocate failed: No space left on device
Fiemap: offset = 0 len = 16777216
logical addr. physical addr. length flags
0 0000000000000000 00000000d7200000 0000000000004000 00001000 1 0000000000004000 00000000d7207000 0000000000001000 00001000 2 0000000000005000 00000000d720c000 0000000000002000 00001000 3 0000000000007000 00000000d7211000 0000000000001000 00001000 4 0000000000008000 00000000d7214000 0000000000001000 00001000 5 0000000000009000 00000000d7218000 0000000000001000 00001000 6 000000000000a000 00000000d721d000 0000000000001000 00001000 7 000000000000b000 00000000d721f000 0000000000004000 00001000 ... 96 00000000000f1000 00000000d73e9000 0000000000004000 00001000 97 00000000000f5000 00000000d73f1000 0000000000003000 00001000 98 00000000000f8000 00000000d73f5000 0000000000004000 00001000 99 00000000000fc000 00000000d73fa000 0000000000001000 00001000 100 00000000000fd000 00000000d73ff000 0000000000001000 00001001
[After]
fallocated a file: i_size=16777216, i_blocks=32808
Fiemap: offset = 0 len = 16777216
logical addr. physical addr. length flags
0 0000000000000000 0000000018a00000 0000000000400000 00001000 1 0000000000400000 0000000019000000 0000000000400000 00001000 2 0000000000800000 0000000032400000 0000000000200000 00001000 3 0000000000a00000 0000000038000000 0000000000200000 00001000 4 0000000000c00000 0000000039c00000 0000000000200000 00001000 5 0000000000e00000 0000000044c00000 0000000000200000 00001001
Let's ignore mode=fragment:{block,segment} mount option while fallocate() on pinfile.
--- fs/f2fs/f2fs.h | 15 +++++++++++---- fs/f2fs/gc.c | 2 +- fs/f2fs/segment.c | 8 ++++---- fs/f2fs/super.c | 4 ++-- 4 files changed, 18 insertions(+), 11 deletions(-)
fs/f2fs/f2fs.h +11 -4
@@ -4146,19 +4146,26 @@ static inline struct inode *fio_inode(struct f2fs_io_info *fio)#define MIN_FRAGMENT_SIZE 1#define MAX_FRAGMENT_SIZE 512 -static inline bool f2fs_need_rand_blk (struct f2fs_sb_info *sbi) +static inline bool f2fs_need_rand_blk (struct f2fs_sb_info *sbi, +enum log_type type) { +if (type ==CURSEG_COLD_DATA_PINNED ) +return false;return F2FS_OPTION (sbi).fs_mode ==FS_MODE_FRAGMENT_BLK ; } -static inline bool f2fs_need_rand_seg (struct f2fs_sb_info *sbi) +static inline bool f2fs_need_rand_seg (struct f2fs_sb_info *sbi, +enum log_type type) { +if (type ==CURSEG_COLD_DATA_PINNED ) +return false;return F2FS_OPTION (sbi).fs_mode ==FS_MODE_FRAGMENT_SEG ; } -static inline bool f2fs_need_rand_seg_blk (struct f2fs_sb_info *sbi) +static inline bool f2fs_need_rand_seg_blk (struct f2fs_sb_info *sbi, +enum log_type type) { -return f2fs_need_rand_blk (sbi) ||f2fs_need_rand_seg (sbi); +return f2fs_need_rand_blk (sbi, type) ||f2fs_need_rand_seg (sbi, type); }/*
fs/f2fs/gc.c +1 -1
@@ -310,7 +310,7 @@ static void select_policy(struct f2fs_sb_info *sbi, int gc_type, p->max_search = sbi->max_victim_search;/* let's select beginning hot/small space first. */ -if (f2fs_need_rand_seg_blk (sbi)) { +if (f2fs_need_rand_seg_blk (sbi, type)) { p->offset =get_random_u32_below (MAIN_SECS (sbi) *SEGS_PER_SEC (sbi));SIT_I (sbi)->last_victim[p->gc_mode] = p->offset;
fs/f2fs/segment.c +4 -4
@@ -3055,7 +3055,7 @@ static unsigned int __get_next_segno(struct f2fs_sb_info *sbi, int type)sanity_check_seg_type (sbi, seg_type);if (__is_large_section (sbi)) { -if (f2fs_need_rand_seg_blk (sbi)) { +if (f2fs_need_rand_seg_blk (sbi, type)) {unsigned int hint =GET_SEC_FROM_SEG (sbi, curseg->segno);if (GET_SEC_FROM_SEG (sbi, curseg->segno +1 ) != hint)
@@ -3064,7 +3064,7 @@ static unsigned int __get_next_segno(struct f2fs_sb_info *sbi, int type) GET_SEG_FROM_SEC(sbi, hint + 1) - 1); }return curseg->segno; - }else if (f2fs_need_rand_seg_blk (sbi)) { + }else if (f2fs_need_rand_seg_blk (sbi, type)) {return get_random_u32_below (MAIN_SECS (sbi) *SEGS_PER_SEC (sbi)); }
@@ -3120,7 +3120,7 @@ static int new_curseg(struct f2fs_sb_info *sbi, int type, bool new_sec) curseg->next_segno = segno;reset_curseg (sbi, type,1 ); curseg->alloc_type =LFS ; -if (f2fs_need_rand_blk (sbi)) +if (f2fs_need_rand_blk (sbi, type)) curseg->fragment_remained_chunk =get_random_u32_inclusive (1 , sbi->max_fragment_chunk);return 0 ;
@@ -3939,7 +3939,7 @@ int f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct folio *folio, curseg->next_blkoff =f2fs_find_next_ssr_block (sbi, curseg); }else { curseg->next_blkoff++; -if (f2fs_need_rand_blk (sbi)) +if (f2fs_need_rand_blk (sbi, type))f2fs_randomize_chunk (sbi, curseg); }if (curseg->next_blkoff >=f2fs_usable_blks_in_seg (sbi, curseg->segno))
fs/f2fs/super.c +2 -2
@@ -2457,9 +2457,9 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)seq_puts (seq,"adaptive" ); else if (F2FS_OPTION(sbi).fs_mode == FS_MODE_LFS) seq_puts(seq, "lfs"); - else if (f2fs_need_rand_seg(sbi)) + else if (f2fs_need_rand_seg(sbi, NO_CHECK_TYPE)) seq_puts(seq, "fragment:segment"); - else if (f2fs_need_rand_blk(sbi)) + else if (f2fs_need_rand_blk(sbi, NO_CHECK_TYPE)) seq_puts(seq, "fragment:block"); seq_printf(seq, ",active_logs=%u", F2FS_OPTION(sbi).active_logs); if (test_opt(sbi, RESERVE_ROOT) || test_opt(sbi, RESERVE_NODE))
Signature · 1 line
2.49.0
Re: [f2fs-dev] [PATCH 1/2] f2fs: cleanup w/ f2fs_need_rand_{blk, seg, seg_blk}
In reply to Chao YuThis series was applied to jaegeuk/f2fs.git (dev) by Jaegeuk Kim <[email protected]>:
Hello:
This series was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <[email protected]>:
Quoted 9 lines · On Wed, 12 Aug 2026 12:20:07 +0000 you wrote:
No logic changes.
Signed-off-by Chao Yu <[email protected]>--- fs/f2fs/f2fs.h | 13 +++++++++++-- fs/f2fs/gc.c | 2 +- fs/f2fs/segment.c | 8 ++++---- fs/f2fs/super.c | 4 ++-- 4 files changed, 18 insertions(+), 9 deletions(-)
Here is the summary with links:
- [f2fs-dev,1/2] f2fs: cleanup w/ f2fs_need_rand_{blk, seg, seg_blk}
https://git.kernel.org/jaegeuk/f2fs/c/d2e65712dd31 - [f2fs-dev,2/2] f2fs: fix to avoid pinfile fragment on fragment:{block, segment} mode https://git.kernel.org/jaegeuk/f2fs/c/b4539b948270
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html