Commit 2c70c5e3 authored by Chao Yu's avatar Chao Yu Committed by Jaegeuk Kim

f2fs: introduce __is_large_section() for cleanup

Introduce a wrapper __is_large_section() to clean up codes.
Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent 7beb01f7
...@@ -197,7 +197,7 @@ static void update_mem_info(struct f2fs_sb_info *sbi) ...@@ -197,7 +197,7 @@ static void update_mem_info(struct f2fs_sb_info *sbi)
si->base_mem += 2 * SIT_VBLOCK_MAP_SIZE * MAIN_SEGS(sbi); si->base_mem += 2 * SIT_VBLOCK_MAP_SIZE * MAIN_SEGS(sbi);
si->base_mem += SIT_VBLOCK_MAP_SIZE * MAIN_SEGS(sbi); si->base_mem += SIT_VBLOCK_MAP_SIZE * MAIN_SEGS(sbi);
si->base_mem += SIT_VBLOCK_MAP_SIZE; si->base_mem += SIT_VBLOCK_MAP_SIZE;
if (sbi->segs_per_sec > 1) if (__is_large_section(sbi))
si->base_mem += MAIN_SECS(sbi) * sizeof(struct sec_entry); si->base_mem += MAIN_SECS(sbi) * sizeof(struct sec_entry);
si->base_mem += __bitmap_size(sbi, SIT_BITMAP); si->base_mem += __bitmap_size(sbi, SIT_BITMAP);
......
...@@ -2762,6 +2762,8 @@ static inline void f2fs_update_iostat(struct f2fs_sb_info *sbi, ...@@ -2762,6 +2762,8 @@ static inline void f2fs_update_iostat(struct f2fs_sb_info *sbi,
spin_unlock(&sbi->iostat_lock); spin_unlock(&sbi->iostat_lock);
} }
#define __is_large_section(sbi) ((sbi)->segs_per_sec > 1)
#define __is_meta_io(fio) (PAGE_TYPE_OF_BIO(fio->type) == META && \ #define __is_meta_io(fio) (PAGE_TYPE_OF_BIO(fio->type) == META && \
(!is_read_io(fio->op) || fio->is_meta)) (!is_read_io(fio->op) || fio->is_meta))
......
...@@ -2560,7 +2560,7 @@ static int f2fs_ioc_flush_device(struct file *filp, unsigned long arg) ...@@ -2560,7 +2560,7 @@ static int f2fs_ioc_flush_device(struct file *filp, unsigned long arg)
return -EFAULT; return -EFAULT;
if (sbi->s_ndevs <= 1 || sbi->s_ndevs - 1 <= range.dev_num || if (sbi->s_ndevs <= 1 || sbi->s_ndevs - 1 <= range.dev_num ||
sbi->segs_per_sec != 1) { __is_large_section(sbi)) {
f2fs_msg(sbi->sb, KERN_WARNING, f2fs_msg(sbi->sb, KERN_WARNING,
"Can't flush %u in %d for segs_per_sec %u != 1\n", "Can't flush %u in %d for segs_per_sec %u != 1\n",
range.dev_num, sbi->s_ndevs, range.dev_num, sbi->s_ndevs,
......
...@@ -1109,7 +1109,7 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi, ...@@ -1109,7 +1109,7 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
int submitted = 0; int submitted = 0;
/* readahead multi ssa blocks those have contiguous address */ /* readahead multi ssa blocks those have contiguous address */
if (sbi->segs_per_sec > 1) if (__is_large_section(sbi))
f2fs_ra_meta_pages(sbi, GET_SUM_BLOCK(sbi, segno), f2fs_ra_meta_pages(sbi, GET_SUM_BLOCK(sbi, segno),
sbi->segs_per_sec, META_SSA, true); sbi->segs_per_sec, META_SSA, true);
...@@ -1318,7 +1318,7 @@ void f2fs_build_gc_manager(struct f2fs_sb_info *sbi) ...@@ -1318,7 +1318,7 @@ void f2fs_build_gc_manager(struct f2fs_sb_info *sbi)
sbi->gc_pin_file_threshold = DEF_GC_FAILED_PINNED_FILES; sbi->gc_pin_file_threshold = DEF_GC_FAILED_PINNED_FILES;
/* give warm/cold data area from slower device */ /* give warm/cold data area from slower device */
if (sbi->s_ndevs && sbi->segs_per_sec == 1) if (sbi->s_ndevs && !__is_large_section(sbi))
SIT_I(sbi)->last_victim[ALLOC_NEXT] = SIT_I(sbi)->last_victim[ALLOC_NEXT] =
GET_SEGNO(sbi, FDEV(0).end_blk) + 1; GET_SEGNO(sbi, FDEV(0).end_blk) + 1;
} }
...@@ -1884,7 +1884,7 @@ void f2fs_clear_prefree_segments(struct f2fs_sb_info *sbi, ...@@ -1884,7 +1884,7 @@ void f2fs_clear_prefree_segments(struct f2fs_sb_info *sbi,
unsigned int start = 0, end = -1; unsigned int start = 0, end = -1;
unsigned int secno, start_segno; unsigned int secno, start_segno;
bool force = (cpc->reason & CP_DISCARD); bool force = (cpc->reason & CP_DISCARD);
bool need_align = test_opt(sbi, LFS) && sbi->segs_per_sec > 1; bool need_align = test_opt(sbi, LFS) && __is_large_section(sbi);
mutex_lock(&dirty_i->seglist_lock); mutex_lock(&dirty_i->seglist_lock);
...@@ -1916,7 +1916,7 @@ void f2fs_clear_prefree_segments(struct f2fs_sb_info *sbi, ...@@ -1916,7 +1916,7 @@ void f2fs_clear_prefree_segments(struct f2fs_sb_info *sbi,
(end - 1) <= cpc->trim_end) (end - 1) <= cpc->trim_end)
continue; continue;
if (!test_opt(sbi, LFS) || sbi->segs_per_sec == 1) { if (!test_opt(sbi, LFS) || !__is_large_section(sbi)) {
f2fs_issue_discard(sbi, START_BLOCK(sbi, start), f2fs_issue_discard(sbi, START_BLOCK(sbi, start),
(end - start) << sbi->log_blocks_per_seg); (end - start) << sbi->log_blocks_per_seg);
continue; continue;
...@@ -2148,7 +2148,7 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del) ...@@ -2148,7 +2148,7 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del)
/* update total number of valid blocks to be written in ckpt area */ /* update total number of valid blocks to be written in ckpt area */
SIT_I(sbi)->written_valid_blocks += del; SIT_I(sbi)->written_valid_blocks += del;
if (sbi->segs_per_sec > 1) if (__is_large_section(sbi))
get_sec_entry(sbi, segno)->valid_blocks += del; get_sec_entry(sbi, segno)->valid_blocks += del;
} }
...@@ -2414,7 +2414,7 @@ static void reset_curseg(struct f2fs_sb_info *sbi, int type, int modified) ...@@ -2414,7 +2414,7 @@ static void reset_curseg(struct f2fs_sb_info *sbi, int type, int modified)
static unsigned int __get_next_segno(struct f2fs_sb_info *sbi, int type) static unsigned int __get_next_segno(struct f2fs_sb_info *sbi, int type)
{ {
/* if segs_per_sec is large than 1, we need to keep original policy. */ /* if segs_per_sec is large than 1, we need to keep original policy. */
if (sbi->segs_per_sec != 1) if (__is_large_section(sbi))
return CURSEG_I(sbi, type)->segno; return CURSEG_I(sbi, type)->segno;
if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED)))
...@@ -2724,7 +2724,7 @@ int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range) ...@@ -2724,7 +2724,7 @@ int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range)
struct discard_policy dpolicy; struct discard_policy dpolicy;
unsigned long long trimmed = 0; unsigned long long trimmed = 0;
int err = 0; int err = 0;
bool need_align = test_opt(sbi, LFS) && sbi->segs_per_sec > 1; bool need_align = test_opt(sbi, LFS) && __is_large_section(sbi);
if (start >= MAX_BLKADDR(sbi) || range->len < sbi->blocksize) if (start >= MAX_BLKADDR(sbi) || range->len < sbi->blocksize)
return -EINVAL; return -EINVAL;
...@@ -3882,7 +3882,7 @@ static int build_sit_info(struct f2fs_sb_info *sbi) ...@@ -3882,7 +3882,7 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
if (!sit_i->tmp_map) if (!sit_i->tmp_map)
return -ENOMEM; return -ENOMEM;
if (sbi->segs_per_sec > 1) { if (__is_large_section(sbi)) {
sit_i->sec_entries = sit_i->sec_entries =
f2fs_kvzalloc(sbi, array_size(sizeof(struct sec_entry), f2fs_kvzalloc(sbi, array_size(sizeof(struct sec_entry),
MAIN_SECS(sbi)), MAIN_SECS(sbi)),
...@@ -4037,7 +4037,7 @@ static int build_sit_entries(struct f2fs_sb_info *sbi) ...@@ -4037,7 +4037,7 @@ static int build_sit_entries(struct f2fs_sb_info *sbi)
se->valid_blocks; se->valid_blocks;
} }
if (sbi->segs_per_sec > 1) if (__is_large_section(sbi))
get_sec_entry(sbi, start)->valid_blocks += get_sec_entry(sbi, start)->valid_blocks +=
se->valid_blocks; se->valid_blocks;
} }
...@@ -4081,7 +4081,7 @@ static int build_sit_entries(struct f2fs_sb_info *sbi) ...@@ -4081,7 +4081,7 @@ static int build_sit_entries(struct f2fs_sb_info *sbi)
sbi->discard_blks -= se->valid_blocks; sbi->discard_blks -= se->valid_blocks;
} }
if (sbi->segs_per_sec > 1) { if (__is_large_section(sbi)) {
get_sec_entry(sbi, start)->valid_blocks += get_sec_entry(sbi, start)->valid_blocks +=
se->valid_blocks; se->valid_blocks;
get_sec_entry(sbi, start)->valid_blocks -= get_sec_entry(sbi, start)->valid_blocks -=
......
...@@ -333,7 +333,7 @@ static inline unsigned int get_valid_blocks(struct f2fs_sb_info *sbi, ...@@ -333,7 +333,7 @@ static inline unsigned int get_valid_blocks(struct f2fs_sb_info *sbi,
* In order to get # of valid blocks in a section instantly from many * In order to get # of valid blocks in a section instantly from many
* segments, f2fs manages two counting structures separately. * segments, f2fs manages two counting structures separately.
*/ */
if (use_section && sbi->segs_per_sec > 1) if (use_section && __is_large_section(sbi))
return get_sec_entry(sbi, segno)->valid_blocks; return get_sec_entry(sbi, segno)->valid_blocks;
else else
return get_seg_entry(sbi, segno)->valid_blocks; return get_seg_entry(sbi, segno)->valid_blocks;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment