Lines Matching full:sbi

29 static inline void sanity_check_seg_type(struct f2fs_sb_info *sbi,  in sanity_check_seg_type()  argument
32 f2fs_bug_on(sbi, seg_type >= NR_PERSISTENT_LOG); in sanity_check_seg_type()
39 #define IS_CURSEG(sbi, seg) \ argument
40 (((seg) == CURSEG_I(sbi, CURSEG_HOT_DATA)->segno) || \
41 ((seg) == CURSEG_I(sbi, CURSEG_WARM_DATA)->segno) || \
42 ((seg) == CURSEG_I(sbi, CURSEG_COLD_DATA)->segno) || \
43 ((seg) == CURSEG_I(sbi, CURSEG_HOT_NODE)->segno) || \
44 ((seg) == CURSEG_I(sbi, CURSEG_WARM_NODE)->segno) || \
45 ((seg) == CURSEG_I(sbi, CURSEG_COLD_NODE)->segno) || \
46 ((seg) == CURSEG_I(sbi, CURSEG_COLD_DATA_PINNED)->segno) || \
47 ((seg) == CURSEG_I(sbi, CURSEG_ALL_DATA_ATGC)->segno))
49 #define IS_CURSEC(sbi, secno) \ argument
50 (((secno) == CURSEG_I(sbi, CURSEG_HOT_DATA)->segno / \
51 SEGS_PER_SEC(sbi)) || \
52 ((secno) == CURSEG_I(sbi, CURSEG_WARM_DATA)->segno / \
53 SEGS_PER_SEC(sbi)) || \
54 ((secno) == CURSEG_I(sbi, CURSEG_COLD_DATA)->segno / \
55 SEGS_PER_SEC(sbi)) || \
56 ((secno) == CURSEG_I(sbi, CURSEG_HOT_NODE)->segno / \
57 SEGS_PER_SEC(sbi)) || \
58 ((secno) == CURSEG_I(sbi, CURSEG_WARM_NODE)->segno / \
59 SEGS_PER_SEC(sbi)) || \
60 ((secno) == CURSEG_I(sbi, CURSEG_COLD_NODE)->segno / \
61 SEGS_PER_SEC(sbi)) || \
62 ((secno) == CURSEG_I(sbi, CURSEG_COLD_DATA_PINNED)->segno / \
63 SEGS_PER_SEC(sbi)) || \
64 ((secno) == CURSEG_I(sbi, CURSEG_ALL_DATA_ATGC)->segno / \
65 SEGS_PER_SEC(sbi)))
67 #define MAIN_BLKADDR(sbi) \ argument
68 (SM_I(sbi) ? SM_I(sbi)->main_blkaddr : \
69 le32_to_cpu(F2FS_RAW_SUPER(sbi)->main_blkaddr))
70 #define SEG0_BLKADDR(sbi) \ argument
71 (SM_I(sbi) ? SM_I(sbi)->seg0_blkaddr : \
72 le32_to_cpu(F2FS_RAW_SUPER(sbi)->segment0_blkaddr))
74 #define MAIN_SEGS(sbi) (SM_I(sbi)->main_segments) argument
75 #define MAIN_SECS(sbi) ((sbi)->total_sections) argument
77 #define TOTAL_SEGS(sbi) \ argument
78 (SM_I(sbi) ? SM_I(sbi)->segment_count : \
79 le32_to_cpu(F2FS_RAW_SUPER(sbi)->segment_count))
80 #define TOTAL_BLKS(sbi) (SEGS_TO_BLKS(sbi, TOTAL_SEGS(sbi))) argument
82 #define MAX_BLKADDR(sbi) (SEG0_BLKADDR(sbi) + TOTAL_BLKS(sbi)) argument
83 #define SEGMENT_SIZE(sbi) (1ULL << ((sbi)->log_blocksize + \ argument
84 (sbi)->log_blocks_per_seg))
86 #define START_BLOCK(sbi, segno) (SEG0_BLKADDR(sbi) + \ argument
87 (SEGS_TO_BLKS(sbi, GET_R2L_SEGNO(FREE_I(sbi), segno))))
89 #define NEXT_FREE_BLKADDR(sbi, curseg) \ argument
90 (START_BLOCK(sbi, (curseg)->segno) + (curseg)->next_blkoff)
92 #define GET_SEGOFF_FROM_SEG0(sbi, blk_addr) ((blk_addr) - SEG0_BLKADDR(sbi)) argument
93 #define GET_SEGNO_FROM_SEG0(sbi, blk_addr) \ argument
94 (BLKS_TO_SEGS(sbi, GET_SEGOFF_FROM_SEG0(sbi, blk_addr)))
95 #define GET_BLKOFF_FROM_SEG0(sbi, blk_addr) \ argument
96 (GET_SEGOFF_FROM_SEG0(sbi, blk_addr) & (BLKS_PER_SEG(sbi) - 1))
98 #define GET_SEGNO(sbi, blk_addr) \ argument
100 NULL_SEGNO : GET_L2R_SEGNO(FREE_I(sbi), \
101 GET_SEGNO_FROM_SEG0(sbi, blk_addr)))
102 #define CAP_BLKS_PER_SEC(sbi) \ argument
103 (BLKS_PER_SEC(sbi) - (sbi)->unusable_blocks_per_sec)
104 #define CAP_SEGS_PER_SEC(sbi) \ argument
105 (SEGS_PER_SEC(sbi) - \
106 BLKS_TO_SEGS(sbi, (sbi)->unusable_blocks_per_sec))
107 #define GET_SEC_FROM_SEG(sbi, segno) \ argument
108 (((segno) == -1) ? -1 : (segno) / SEGS_PER_SEC(sbi))
109 #define GET_SEG_FROM_SEC(sbi, secno) \ argument
110 ((secno) * SEGS_PER_SEC(sbi))
111 #define GET_ZONE_FROM_SEC(sbi, secno) \ argument
112 (((secno) == -1) ? -1 : (secno) / (sbi)->secs_per_zone)
113 #define GET_ZONE_FROM_SEG(sbi, segno) \ argument
114 GET_ZONE_FROM_SEC(sbi, GET_SEC_FROM_SEG(sbi, segno))
116 #define GET_SUM_BLOCK(sbi, segno) \ argument
117 ((sbi)->sm_info->ssa_blkaddr + (segno))
128 #define SIT_BLK_CNT(sbi) \ argument
129 DIV_ROUND_UP(MAIN_SEGS(sbi), SIT_ENTRY_PER_BLOCK)
315 static inline struct curseg_info *CURSEG_I(struct f2fs_sb_info *sbi, int type) in CURSEG_I() argument
317 return (struct curseg_info *)(SM_I(sbi)->curseg_array + type); in CURSEG_I()
320 static inline struct seg_entry *get_seg_entry(struct f2fs_sb_info *sbi, in get_seg_entry() argument
323 struct sit_info *sit_i = SIT_I(sbi); in get_seg_entry()
327 static inline struct sec_entry *get_sec_entry(struct f2fs_sb_info *sbi, in get_sec_entry() argument
330 struct sit_info *sit_i = SIT_I(sbi); in get_sec_entry()
331 return &sit_i->sec_entries[GET_SEC_FROM_SEG(sbi, segno)]; in get_sec_entry()
334 static inline unsigned int get_valid_blocks(struct f2fs_sb_info *sbi, in get_valid_blocks() argument
341 if (use_section && __is_large_section(sbi)) in get_valid_blocks()
342 return get_sec_entry(sbi, segno)->valid_blocks; in get_valid_blocks()
344 return get_seg_entry(sbi, segno)->valid_blocks; in get_valid_blocks()
347 static inline unsigned int get_ckpt_valid_blocks(struct f2fs_sb_info *sbi, in get_ckpt_valid_blocks() argument
350 if (use_section && __is_large_section(sbi)) { in get_ckpt_valid_blocks()
351 unsigned int secno = GET_SEC_FROM_SEG(sbi, segno); in get_ckpt_valid_blocks()
352 unsigned int start_segno = GET_SEG_FROM_SEC(sbi, secno); in get_ckpt_valid_blocks()
356 for (i = 0; i < SEGS_PER_SEC(sbi); i++, start_segno++) { in get_ckpt_valid_blocks()
357 struct seg_entry *se = get_seg_entry(sbi, start_segno); in get_ckpt_valid_blocks()
363 return get_seg_entry(sbi, segno)->ckpt_valid_blocks; in get_ckpt_valid_blocks()
390 static inline void seg_info_to_sit_page(struct f2fs_sb_info *sbi, in seg_info_to_sit_page() argument
397 (unsigned long)MAIN_SEGS(sbi)); in seg_info_to_sit_page()
404 se = get_seg_entry(sbi, start + i); in seg_info_to_sit_page()
428 static inline void __set_free(struct f2fs_sb_info *sbi, unsigned int segno) in __set_free() argument
430 struct free_segmap_info *free_i = FREE_I(sbi); in __set_free()
431 unsigned int secno = GET_SEC_FROM_SEG(sbi, segno); in __set_free()
432 unsigned int start_segno = GET_SEG_FROM_SEC(sbi, secno); in __set_free()
434 unsigned int usable_segs = f2fs_usable_segs_in_sec(sbi); in __set_free()
441 start_segno + SEGS_PER_SEC(sbi), start_segno); in __set_free()
449 static inline void __set_inuse(struct f2fs_sb_info *sbi, in __set_inuse() argument
452 struct free_segmap_info *free_i = FREE_I(sbi); in __set_inuse()
453 unsigned int secno = GET_SEC_FROM_SEG(sbi, segno); in __set_inuse()
461 static inline void __set_test_and_free(struct f2fs_sb_info *sbi, in __set_test_and_free() argument
464 struct free_segmap_info *free_i = FREE_I(sbi); in __set_test_and_free()
465 unsigned int secno = GET_SEC_FROM_SEG(sbi, segno); in __set_test_and_free()
466 unsigned int start_segno = GET_SEG_FROM_SEC(sbi, secno); in __set_test_and_free()
468 unsigned int usable_segs = f2fs_usable_segs_in_sec(sbi); in __set_test_and_free()
474 if (!inmem && IS_CURSEC(sbi, secno)) in __set_test_and_free()
477 start_segno + SEGS_PER_SEC(sbi), start_segno); in __set_test_and_free()
487 static inline void __set_test_and_inuse(struct f2fs_sb_info *sbi, in __set_test_and_inuse() argument
490 struct free_segmap_info *free_i = FREE_I(sbi); in __set_test_and_inuse()
491 unsigned int secno = GET_SEC_FROM_SEG(sbi, segno); in __set_test_and_inuse()
502 static inline void get_sit_bitmap(struct f2fs_sb_info *sbi, in get_sit_bitmap() argument
505 struct sit_info *sit_i = SIT_I(sbi); in get_sit_bitmap()
510 f2fs_bug_on(sbi, 1); in get_sit_bitmap()
515 static inline block_t written_block_count(struct f2fs_sb_info *sbi) in written_block_count() argument
517 return SIT_I(sbi)->written_valid_blocks; in written_block_count()
520 static inline unsigned int free_segments(struct f2fs_sb_info *sbi) in free_segments() argument
522 return FREE_I(sbi)->free_segments; in free_segments()
525 static inline unsigned int reserved_segments(struct f2fs_sb_info *sbi) in reserved_segments() argument
527 return SM_I(sbi)->reserved_segments + in reserved_segments()
528 SM_I(sbi)->additional_reserved_segments; in reserved_segments()
531 static inline unsigned int free_sections(struct f2fs_sb_info *sbi) in free_sections() argument
533 return FREE_I(sbi)->free_sections; in free_sections()
536 static inline unsigned int prefree_segments(struct f2fs_sb_info *sbi) in prefree_segments() argument
538 return DIRTY_I(sbi)->nr_dirty[PRE]; in prefree_segments()
541 static inline unsigned int dirty_segments(struct f2fs_sb_info *sbi) in dirty_segments() argument
543 return DIRTY_I(sbi)->nr_dirty[DIRTY_HOT_DATA] + in dirty_segments()
544 DIRTY_I(sbi)->nr_dirty[DIRTY_WARM_DATA] + in dirty_segments()
545 DIRTY_I(sbi)->nr_dirty[DIRTY_COLD_DATA] + in dirty_segments()
546 DIRTY_I(sbi)->nr_dirty[DIRTY_HOT_NODE] + in dirty_segments()
547 DIRTY_I(sbi)->nr_dirty[DIRTY_WARM_NODE] + in dirty_segments()
548 DIRTY_I(sbi)->nr_dirty[DIRTY_COLD_NODE]; in dirty_segments()
551 static inline int overprovision_segments(struct f2fs_sb_info *sbi) in overprovision_segments() argument
553 return SM_I(sbi)->ovp_segments; in overprovision_segments()
556 static inline int reserved_sections(struct f2fs_sb_info *sbi) in reserved_sections() argument
558 return GET_SEC_FROM_SEG(sbi, reserved_segments(sbi)); in reserved_sections()
561 static inline bool has_curseg_enough_space(struct f2fs_sb_info *sbi, in has_curseg_enough_space() argument
570 segno = CURSEG_I(sbi, i)->segno; in has_curseg_enough_space()
571 left_blocks = CAP_BLKS_PER_SEC(sbi) - in has_curseg_enough_space()
572 get_ckpt_valid_blocks(sbi, segno, true); in has_curseg_enough_space()
578 segno = CURSEG_I(sbi, CURSEG_HOT_DATA)->segno; in has_curseg_enough_space()
579 left_blocks = CAP_BLKS_PER_SEC(sbi) - in has_curseg_enough_space()
580 get_ckpt_valid_blocks(sbi, segno, true); in has_curseg_enough_space()
590 static inline void __get_secs_required(struct f2fs_sb_info *sbi, in __get_secs_required() argument
593 unsigned int total_node_blocks = get_pages(sbi, F2FS_DIRTY_NODES) + in __get_secs_required()
594 get_pages(sbi, F2FS_DIRTY_DENTS) + in __get_secs_required()
595 get_pages(sbi, F2FS_DIRTY_IMETA); in __get_secs_required()
596 unsigned int total_dent_blocks = get_pages(sbi, F2FS_DIRTY_DENTS); in __get_secs_required()
597 unsigned int node_secs = total_node_blocks / CAP_BLKS_PER_SEC(sbi); in __get_secs_required()
598 unsigned int dent_secs = total_dent_blocks / CAP_BLKS_PER_SEC(sbi); in __get_secs_required()
599 unsigned int node_blocks = total_node_blocks % CAP_BLKS_PER_SEC(sbi); in __get_secs_required()
600 unsigned int dent_blocks = total_dent_blocks % CAP_BLKS_PER_SEC(sbi); in __get_secs_required()
608 *curseg_p = has_curseg_enough_space(sbi, in __get_secs_required()
612 static inline bool has_not_enough_free_secs(struct f2fs_sb_info *sbi, in has_not_enough_free_secs() argument
618 if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) in has_not_enough_free_secs()
621 __get_secs_required(sbi, &lower_secs, &upper_secs, &curseg_space); in has_not_enough_free_secs()
623 free_secs = free_sections(sbi) + freed; in has_not_enough_free_secs()
624 lower_secs += needed + reserved_sections(sbi); in has_not_enough_free_secs()
625 upper_secs += needed + reserved_sections(sbi); in has_not_enough_free_secs()
634 static inline bool has_enough_free_secs(struct f2fs_sb_info *sbi, in has_enough_free_secs() argument
637 return !has_not_enough_free_secs(sbi, freed, needed); in has_enough_free_secs()
640 static inline bool f2fs_is_checkpoint_ready(struct f2fs_sb_info *sbi) in f2fs_is_checkpoint_ready() argument
642 if (likely(!is_sbi_flag_set(sbi, SBI_CP_DISABLED))) in f2fs_is_checkpoint_ready()
644 if (likely(has_enough_free_secs(sbi, 0, 0))) in f2fs_is_checkpoint_ready()
649 static inline bool excess_prefree_segs(struct f2fs_sb_info *sbi) in excess_prefree_segs() argument
651 return prefree_segments(sbi) > SM_I(sbi)->rec_prefree_segments; in excess_prefree_segs()
654 static inline int utilization(struct f2fs_sb_info *sbi) in utilization() argument
656 return div_u64((u64)valid_user_blocks(sbi) * 100, in utilization()
657 sbi->user_block_count); in utilization()
699 static inline bool IS_F2FS_IPU_DISABLE(struct f2fs_sb_info *sbi) in IS_F2FS_IPU_DISABLE() argument
701 return SM_I(sbi)->ipu_policy == F2FS_IPU_DISABLE; in IS_F2FS_IPU_DISABLE()
705 static inline bool IS_##name(struct f2fs_sb_info *sbi) \
707 return SM_I(sbi)->ipu_policy & BIT(name); \
719 static inline unsigned int curseg_segno(struct f2fs_sb_info *sbi, in curseg_segno() argument
722 struct curseg_info *curseg = CURSEG_I(sbi, type); in curseg_segno()
726 static inline unsigned char curseg_alloc_type(struct f2fs_sb_info *sbi, in curseg_alloc_type() argument
729 struct curseg_info *curseg = CURSEG_I(sbi, type); in curseg_alloc_type()
733 static inline bool valid_main_segno(struct f2fs_sb_info *sbi, in valid_main_segno() argument
736 return segno <= (MAIN_SEGS(sbi) - 1); in valid_main_segno()
741 struct f2fs_sb_info *sbi = fio->sbi; in verify_fio_blkaddr() local
744 verify_blkaddr(sbi, fio->old_blkaddr, __is_meta_io(fio) ? in verify_fio_blkaddr()
746 verify_blkaddr(sbi, fio->new_blkaddr, __is_meta_io(fio) ? in verify_fio_blkaddr()
753 static inline int check_block_count(struct f2fs_sb_info *sbi, in check_block_count() argument
759 unsigned int usable_blks_per_seg = f2fs_usable_blks_in_seg(sbi, segno); in check_block_count()
777 f2fs_err(sbi, "Mismatch valid blocks %d vs. %d", in check_block_count()
779 set_sbi_flag(sbi, SBI_NEED_FSCK); in check_block_count()
780 f2fs_handle_error(sbi, ERROR_INCONSISTENT_SIT); in check_block_count()
784 if (usable_blks_per_seg < BLKS_PER_SEG(sbi)) in check_block_count()
785 f2fs_bug_on(sbi, find_next_bit_le(&raw_sit->valid_map, in check_block_count()
786 BLKS_PER_SEG(sbi), in check_block_count()
787 usable_blks_per_seg) != BLKS_PER_SEG(sbi)); in check_block_count()
791 || !valid_main_segno(sbi, segno))) { in check_block_count()
792 f2fs_err(sbi, "Wrong valid blocks %d or segno %u", in check_block_count()
794 set_sbi_flag(sbi, SBI_NEED_FSCK); in check_block_count()
795 f2fs_handle_error(sbi, ERROR_INCONSISTENT_SIT); in check_block_count()
801 static inline pgoff_t current_sit_addr(struct f2fs_sb_info *sbi, in current_sit_addr() argument
804 struct sit_info *sit_i = SIT_I(sbi); in current_sit_addr()
808 f2fs_bug_on(sbi, !valid_main_segno(sbi, start)); in current_sit_addr()
813 f2fs_bug_on(sbi, 1); in current_sit_addr()
823 static inline pgoff_t next_sit_addr(struct f2fs_sb_info *sbi, in next_sit_addr() argument
826 struct sit_info *sit_i = SIT_I(sbi); in next_sit_addr()
846 static inline unsigned long long get_mtime(struct f2fs_sb_info *sbi, in get_mtime() argument
849 struct sit_info *sit_i = SIT_I(sbi); in get_mtime()
873 static inline block_t start_sum_block(struct f2fs_sb_info *sbi) in start_sum_block() argument
875 return __start_cp_addr(sbi) + in start_sum_block()
876 le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); in start_sum_block()
879 static inline block_t sum_blk_addr(struct f2fs_sb_info *sbi, int base, int type) in sum_blk_addr() argument
881 return __start_cp_addr(sbi) + in sum_blk_addr()
882 le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_total_block_count) in sum_blk_addr()
886 static inline bool sec_usage_check(struct f2fs_sb_info *sbi, unsigned int secno) in sec_usage_check() argument
888 if (IS_CURSEC(sbi, secno) || (sbi->cur_victim_sec == secno)) in sec_usage_check()
900 static inline int nr_pages_to_skip(struct f2fs_sb_info *sbi, int type) in nr_pages_to_skip() argument
902 if (sbi->sb->s_bdi->wb.dirty_exceeded) in nr_pages_to_skip()
906 return BLKS_PER_SEG(sbi); in nr_pages_to_skip()
908 return SEGS_TO_BLKS(sbi, 8); in nr_pages_to_skip()
918 static inline long nr_pages_to_write(struct f2fs_sb_info *sbi, int type, in nr_pages_to_write() argument
935 static inline void wake_up_discard_thread(struct f2fs_sb_info *sbi, bool force) in wake_up_discard_thread() argument
937 struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info; in wake_up_discard_thread()
954 if (!wakeup || !is_idle(sbi, DISCARD_TIME)) in wake_up_discard_thread()
961 static inline unsigned int first_zoned_segno(struct f2fs_sb_info *sbi) in first_zoned_segno() argument
965 for (devi = 0; devi < sbi->s_ndevs; devi++) in first_zoned_segno()
967 return GET_SEGNO(sbi, FDEV(devi).start_blk); in first_zoned_segno()