Lines Matching full:sbi
33 struct f2fs_sb_info *sbi = data; in gc_thread_func() local
34 struct f2fs_gc_kthread *gc_th = sbi->gc_thread; in gc_thread_func()
35 wait_queue_head_t *wq = &sbi->gc_thread->gc_wait_queue_head; in gc_thread_func()
36 wait_queue_head_t *fggc_wq = &sbi->gc_thread->fggc_wq; in gc_thread_func()
55 if (test_opt(sbi, GC_MERGE) && waitqueue_active(fggc_wq)) in gc_thread_func()
62 if (f2fs_readonly(sbi->sb)) { in gc_thread_func()
63 stat_other_skip_bggc_count(sbi); in gc_thread_func()
69 if (sbi->sb->s_writers.frozen >= SB_FREEZE_WRITE) { in gc_thread_func()
71 stat_other_skip_bggc_count(sbi); in gc_thread_func()
75 if (time_to_inject(sbi, FAULT_CHECKPOINT)) in gc_thread_func()
76 f2fs_stop_checkpoint(sbi, false, in gc_thread_func()
79 if (!sb_start_write_trylock(sbi->sb)) { in gc_thread_func()
80 stat_other_skip_bggc_count(sbi); in gc_thread_func()
99 if (sbi->gc_mode == GC_URGENT_HIGH || in gc_thread_func()
100 sbi->gc_mode == GC_URGENT_MID) { in gc_thread_func()
102 f2fs_down_write(&sbi->gc_lock); in gc_thread_func()
107 f2fs_down_write(&sbi->gc_lock); in gc_thread_func()
109 } else if (!f2fs_down_write_trylock(&sbi->gc_lock)) { in gc_thread_func()
110 stat_other_skip_bggc_count(sbi); in gc_thread_func()
114 if (!is_idle(sbi, GC_TIME)) { in gc_thread_func()
116 f2fs_up_write(&sbi->gc_lock); in gc_thread_func()
117 stat_io_skip_bggc_count(sbi); in gc_thread_func()
121 if (f2fs_sb_has_blkzoned(sbi)) { in gc_thread_func()
122 if (has_enough_free_blocks(sbi, in gc_thread_func()
125 f2fs_up_write(&sbi->gc_lock); in gc_thread_func()
132 if (need_to_boost_gc(sbi)) { in gc_thread_func()
134 if (f2fs_sb_has_blkzoned(sbi)) in gc_thread_func()
140 stat_inc_gc_call_count(sbi, foreground ? in gc_thread_func()
143 sync_mode = (F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_SYNC) || in gc_thread_func()
155 if (f2fs_gc(sbi, &gc_control)) { in gc_thread_func()
168 trace_f2fs_background_gc(sbi->sb, wait_ms, in gc_thread_func()
169 prefree_segments(sbi), free_segments(sbi)); in gc_thread_func()
172 f2fs_balance_fs_bg(sbi, true); in gc_thread_func()
174 if (sbi->gc_mode != GC_NORMAL) { in gc_thread_func()
175 spin_lock(&sbi->gc_remaining_trials_lock); in gc_thread_func()
176 if (sbi->gc_remaining_trials) { in gc_thread_func()
177 sbi->gc_remaining_trials--; in gc_thread_func()
178 if (!sbi->gc_remaining_trials) in gc_thread_func()
179 sbi->gc_mode = GC_NORMAL; in gc_thread_func()
181 spin_unlock(&sbi->gc_remaining_trials_lock); in gc_thread_func()
183 sb_end_write(sbi->sb); in gc_thread_func()
189 int f2fs_start_gc_thread(struct f2fs_sb_info *sbi) in f2fs_start_gc_thread() argument
192 dev_t dev = sbi->sb->s_bdev->bd_dev; in f2fs_start_gc_thread()
194 gc_th = f2fs_kmalloc(sbi, sizeof(struct f2fs_gc_kthread), GFP_KERNEL); in f2fs_start_gc_thread()
201 if (f2fs_sb_has_blkzoned(sbi)) { in f2fs_start_gc_thread()
217 sbi->gc_thread = gc_th; in f2fs_start_gc_thread()
218 init_waitqueue_head(&sbi->gc_thread->gc_wait_queue_head); in f2fs_start_gc_thread()
219 init_waitqueue_head(&sbi->gc_thread->fggc_wq); in f2fs_start_gc_thread()
220 sbi->gc_thread->f2fs_gc_task = kthread_run(gc_thread_func, sbi, in f2fs_start_gc_thread()
226 sbi->gc_thread = NULL; in f2fs_start_gc_thread()
233 void f2fs_stop_gc_thread(struct f2fs_sb_info *sbi) in f2fs_stop_gc_thread() argument
235 struct f2fs_gc_kthread *gc_th = sbi->gc_thread; in f2fs_stop_gc_thread()
242 sbi->gc_thread = NULL; in f2fs_stop_gc_thread()
245 static int select_gc_type(struct f2fs_sb_info *sbi, int gc_type) in select_gc_type() argument
250 if (sbi->am.atgc_enabled) in select_gc_type()
258 switch (sbi->gc_mode) { in select_gc_type()
274 static void select_policy(struct f2fs_sb_info *sbi, int gc_type, in select_policy() argument
277 struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); in select_policy()
290 p->gc_mode = select_gc_type(sbi, gc_type); in select_policy()
291 p->ofs_unit = SEGS_PER_SEC(sbi); in select_policy()
292 if (__is_large_section(sbi)) { in select_policy()
295 0, MAIN_SECS(sbi)); in select_policy()
307 (sbi->gc_mode != GC_URGENT_HIGH) && in select_policy()
309 p->max_search > sbi->max_victim_search) in select_policy()
310 p->max_search = sbi->max_victim_search; in select_policy()
313 if (f2fs_need_rand_seg(sbi)) in select_policy()
314 p->offset = get_random_u32_below(MAIN_SECS(sbi) * in select_policy()
315 SEGS_PER_SEC(sbi)); in select_policy()
319 p->offset = SIT_I(sbi)->last_victim[p->gc_mode]; in select_policy()
322 static unsigned int get_max_cost(struct f2fs_sb_info *sbi, in get_max_cost() argument
327 return BLKS_PER_SEG(sbi); in get_max_cost()
333 return SEGS_TO_BLKS(sbi, 2 * p->ofs_unit); in get_max_cost()
342 static unsigned int check_bg_victims(struct f2fs_sb_info *sbi) in check_bg_victims() argument
344 struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); in check_bg_victims()
352 for_each_set_bit(secno, dirty_i->victim_secmap, MAIN_SECS(sbi)) { in check_bg_victims()
353 if (sec_usage_check(sbi, secno)) in check_bg_victims()
356 return GET_SEG_FROM_SEC(sbi, secno); in check_bg_victims()
361 static unsigned int get_cb_cost(struct f2fs_sb_info *sbi, unsigned int segno) in get_cb_cost() argument
363 struct sit_info *sit_i = SIT_I(sbi); in get_cb_cost()
364 unsigned int secno = GET_SEC_FROM_SEG(sbi, segno); in get_cb_cost()
365 unsigned int start = GET_SEG_FROM_SEC(sbi, secno); in get_cb_cost()
371 unsigned int usable_segs_per_sec = f2fs_usable_segs_in_sec(sbi); in get_cb_cost()
374 mtime += get_seg_entry(sbi, start + i)->mtime; in get_cb_cost()
375 vblocks = get_valid_blocks(sbi, segno, true); in get_cb_cost()
380 u = BLKS_TO_SEGS(sbi, vblocks * 100); in get_cb_cost()
394 static inline unsigned int get_gc_cost(struct f2fs_sb_info *sbi, in get_gc_cost() argument
398 return get_seg_entry(sbi, segno)->ckpt_valid_blocks; in get_gc_cost()
400 if (p->one_time_gc && (get_valid_blocks(sbi, segno, true) >= in get_gc_cost()
401 CAP_BLKS_PER_SEC(sbi) * sbi->gc_thread->valid_thresh_ratio / in get_gc_cost()
407 return get_valid_blocks(sbi, segno, true); in get_gc_cost()
409 return get_cb_cost(sbi, segno); in get_gc_cost()
411 f2fs_bug_on(sbi, 1); in get_gc_cost()
427 static bool f2fs_check_victim_tree(struct f2fs_sb_info *sbi, in f2fs_check_victim_tree() argument
443 f2fs_info(sbi, "broken victim_rbtree, " in f2fs_check_victim_tree()
454 static struct victim_entry *__lookup_victim_entry(struct f2fs_sb_info *sbi, in __lookup_victim_entry() argument
457 struct atgc_management *am = &sbi->am; in __lookup_victim_entry()
472 static struct victim_entry *__create_victim_entry(struct f2fs_sb_info *sbi, in __create_victim_entry() argument
475 struct atgc_management *am = &sbi->am; in __create_victim_entry()
489 static void __insert_victim_entry(struct f2fs_sb_info *sbi, in __insert_victim_entry() argument
492 struct atgc_management *am = &sbi->am; in __insert_victim_entry()
512 ve = __create_victim_entry(sbi, mtime, segno); in __insert_victim_entry()
518 static void add_victim_entry(struct f2fs_sb_info *sbi, in add_victim_entry() argument
521 struct sit_info *sit_i = SIT_I(sbi); in add_victim_entry()
522 unsigned int secno = GET_SEC_FROM_SEG(sbi, segno); in add_victim_entry()
523 unsigned int start = GET_SEG_FROM_SEC(sbi, secno); in add_victim_entry()
527 if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) { in add_victim_entry()
529 get_valid_blocks(sbi, segno, true) == 0) in add_victim_entry()
533 for (i = 0; i < SEGS_PER_SEC(sbi); i++) in add_victim_entry()
534 mtime += get_seg_entry(sbi, start + i)->mtime; in add_victim_entry()
535 mtime = div_u64(mtime, SEGS_PER_SEC(sbi)); in add_victim_entry()
551 __insert_victim_entry(sbi, mtime, segno); in add_victim_entry()
554 static void atgc_lookup_victim(struct f2fs_sb_info *sbi, in atgc_lookup_victim() argument
557 struct sit_info *sit_i = SIT_I(sbi); in atgc_lookup_victim()
558 struct atgc_management *am = &sbi->am; in atgc_lookup_victim()
566 unsigned int sec_blocks = CAP_BLKS_PER_SEC(sbi); in atgc_lookup_victim()
598 vblocks = get_valid_blocks(sbi, ve->segno, true); in atgc_lookup_victim()
599 f2fs_bug_on(sbi, !vblocks || vblocks == sec_blocks); in atgc_lookup_victim()
605 f2fs_bug_on(sbi, age + u >= UINT_MAX); in atgc_lookup_victim()
627 static void atssr_lookup_victim(struct f2fs_sb_info *sbi, in atssr_lookup_victim() argument
630 struct sit_info *sit_i = SIT_I(sbi); in atssr_lookup_victim()
631 struct atgc_management *am = &sbi->am; in atssr_lookup_victim()
648 ve = __lookup_victim_entry(sbi, p->age); in atssr_lookup_victim()
661 vblocks = get_seg_entry(sbi, ve->segno)->ckpt_valid_blocks; in atssr_lookup_victim()
662 f2fs_bug_on(sbi, !vblocks); in atssr_lookup_victim()
665 if (vblocks == BLKS_PER_SEG(sbi)) in atssr_lookup_victim()
691 static void lookup_victim_by_age(struct f2fs_sb_info *sbi, in lookup_victim_by_age() argument
694 f2fs_bug_on(sbi, !f2fs_check_victim_tree(sbi, &sbi->am.root)); in lookup_victim_by_age()
697 atgc_lookup_victim(sbi, p); in lookup_victim_by_age()
699 atssr_lookup_victim(sbi, p); in lookup_victim_by_age()
701 f2fs_bug_on(sbi, 1); in lookup_victim_by_age()
704 static void release_victim_entry(struct f2fs_sb_info *sbi) in release_victim_entry() argument
706 struct atgc_management *am = &sbi->am; in release_victim_entry()
717 f2fs_bug_on(sbi, am->victim_count); in release_victim_entry()
718 f2fs_bug_on(sbi, !list_empty(&am->victim_list)); in release_victim_entry()
721 static bool f2fs_pin_section(struct f2fs_sb_info *sbi, unsigned int segno) in f2fs_pin_section() argument
723 struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); in f2fs_pin_section()
724 unsigned int secno = GET_SEC_FROM_SEG(sbi, segno); in f2fs_pin_section()
746 static void f2fs_unpin_all_sections(struct f2fs_sb_info *sbi, bool enable) in f2fs_unpin_all_sections() argument
748 unsigned int bitmap_size = f2fs_bitmap_size(MAIN_SECS(sbi)); in f2fs_unpin_all_sections()
750 if (f2fs_pinned_section_exists(DIRTY_I(sbi))) { in f2fs_unpin_all_sections()
751 memset(DIRTY_I(sbi)->pinned_secmap, 0, bitmap_size); in f2fs_unpin_all_sections()
752 DIRTY_I(sbi)->pinned_secmap_cnt = 0; in f2fs_unpin_all_sections()
754 DIRTY_I(sbi)->enable_pin_section = enable; in f2fs_unpin_all_sections()
777 int f2fs_get_victim(struct f2fs_sb_info *sbi, unsigned int *result, in f2fs_get_victim() argument
781 struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); in f2fs_get_victim()
782 struct sit_info *sm = SIT_I(sbi); in f2fs_get_victim()
791 last_segment = MAIN_SECS(sbi) * SEGS_PER_SEC(sbi); in f2fs_get_victim()
795 p.age_threshold = sbi->am.age_threshold; in f2fs_get_victim()
799 select_policy(sbi, gc_type, type, &p); in f2fs_get_victim()
802 p.min_cost = get_max_cost(sbi, &p); in f2fs_get_victim()
808 SIT_I(sbi)->dirty_min_mtime = ULLONG_MAX; in f2fs_get_victim()
811 if (!get_valid_blocks(sbi, *result, false)) { in f2fs_get_victim()
816 if (sec_usage_check(sbi, GET_SEC_FROM_SEG(sbi, *result))) in f2fs_get_victim()
827 if (__is_large_section(sbi) && p.alloc_mode == LFS) { in f2fs_get_victim()
828 if (sbi->next_victim_seg[BG_GC] != NULL_SEGNO) { in f2fs_get_victim()
829 p.min_segno = sbi->next_victim_seg[BG_GC]; in f2fs_get_victim()
831 sbi->next_victim_seg[BG_GC] = NULL_SEGNO; in f2fs_get_victim()
835 sbi->next_victim_seg[FG_GC] != NULL_SEGNO) { in f2fs_get_victim()
836 p.min_segno = sbi->next_victim_seg[FG_GC]; in f2fs_get_victim()
838 sbi->next_victim_seg[FG_GC] = NULL_SEGNO; in f2fs_get_victim()
845 p.min_segno = check_bg_victims(sbi); in f2fs_get_victim()
883 secno = GET_SEC_FROM_SEG(sbi, segno); in f2fs_get_victim()
885 if (sec_usage_check(sbi, secno)) in f2fs_get_victim()
889 if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) { in f2fs_get_victim()
895 if (get_ckpt_valid_blocks(sbi, segno, true)) in f2fs_get_victim()
903 if (!f2fs_segment_has_free_slot(sbi, segno)) in f2fs_get_victim()
915 add_victim_entry(sbi, &p, segno); in f2fs_get_victim()
919 cost = get_gc_cost(sbi, segno, &p); in f2fs_get_victim()
933 (MAIN_SECS(sbi) * SEGS_PER_SEC(sbi)); in f2fs_get_victim()
940 lookup_victim_by_age(sbi, &p); in f2fs_get_victim()
941 release_victim_entry(sbi); in f2fs_get_victim()
955 secno = GET_SEC_FROM_SEG(sbi, p.min_segno); in f2fs_get_victim()
957 sbi->cur_victim_sec = secno; in f2fs_get_victim()
966 trace_f2fs_get_victim(sbi->sb, type, gc_type, &p, in f2fs_get_victim()
967 sbi->cur_victim_sec, in f2fs_get_victim()
968 prefree_segments(sbi), free_segments(sbi)); in f2fs_get_victim()
1012 static int check_valid_map(struct f2fs_sb_info *sbi, in check_valid_map() argument
1015 struct sit_info *sit_i = SIT_I(sbi); in check_valid_map()
1020 sentry = get_seg_entry(sbi, segno); in check_valid_map()
1031 static int gc_node_segment(struct f2fs_sb_info *sbi, in gc_node_segment() argument
1040 unsigned int usable_blks_in_seg = f2fs_usable_blks_in_seg(sbi, segno); in gc_node_segment()
1042 start_addr = START_BLOCK(sbi, segno); in gc_node_segment()
1048 atomic_inc(&sbi->wb_sync_req[NODE]); in gc_node_segment()
1057 if (gc_type == BG_GC && has_not_enough_free_secs(sbi, 0, 0)) in gc_node_segment()
1060 if (check_valid_map(sbi, segno, off) == 0) in gc_node_segment()
1064 f2fs_ra_meta_pages(sbi, NAT_BLOCK_OFFSET(nid), 1, in gc_node_segment()
1070 f2fs_ra_node_page(sbi, nid); in gc_node_segment()
1075 node_page = f2fs_get_node_page(sbi, nid); in gc_node_segment()
1080 if (check_valid_map(sbi, segno, off) == 0) { in gc_node_segment()
1085 if (f2fs_get_node_info(sbi, nid, &ni, false)) { in gc_node_segment()
1098 stat_inc_node_blk_count(sbi, 1, gc_type); in gc_node_segment()
1105 atomic_dec(&sbi->wb_sync_req[NODE]); in gc_node_segment()
1138 static bool is_alive(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, in is_alive() argument
1149 node_page = f2fs_get_node_page(sbi, nid); in is_alive()
1153 if (f2fs_get_node_info(sbi, nid, dni, false)) { in is_alive()
1159 f2fs_warn(sbi, "%s: valid data with mismatched node version.", in is_alive()
1161 set_sbi_flag(sbi, SBI_NEED_FSCK); in is_alive()
1164 if (f2fs_check_nid_range(sbi, dni->ino)) { in is_alive()
1178 f2fs_err(sbi, "Inconsistent blkaddr offset: base:%u, ofs_in_node:%u, max:%u, ino:%u, nid:%u", in is_alive()
1190 unsigned int segno = GET_SEGNO(sbi, blkaddr); in is_alive()
1191 unsigned long offset = GET_BLKOFF_FROM_SEG0(sbi, blkaddr); in is_alive()
1193 if (unlikely(check_valid_map(sbi, segno, offset))) { in is_alive()
1194 if (!test_and_set_bit(segno, SIT_I(sbi)->invalid_segmap)) { in is_alive()
1195 f2fs_err(sbi, "mismatched blkaddr %u (source_blkaddr %u) in seg %u", in is_alive()
1197 set_sbi_flag(sbi, SBI_NEED_FSCK); in is_alive()
1208 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); in ra_data_block() local
1214 .sbi = sbi, in ra_data_block()
1231 if (unlikely(!f2fs_is_valid_blkaddr(sbi, dn.data_blkaddr, in ra_data_block()
1249 if (unlikely(!f2fs_is_valid_blkaddr(sbi, dn.data_blkaddr, in ra_data_block()
1267 fio.encrypted_page = f2fs_pagecache_get_page(META_MAPPING(sbi), in ra_data_block()
1281 f2fs_update_iostat(sbi, inode, FS_DATA_READ_IO, F2FS_BLKSIZE); in ra_data_block()
1282 f2fs_update_iostat(sbi, NULL, FS_GDATA_READ_IO, F2FS_BLKSIZE); in ra_data_block()
1302 .sbi = F2FS_I_SB(inode), in move_data_block()
1317 bool lfs_mode = f2fs_lfs_mode(fio.sbi); in move_data_block()
1318 int type = fio.sbi->am.atgc_enabled && (gc_type == BG_GC) && in move_data_block()
1319 (fio.sbi->gc_mode != GC_URGENT_HIGH) ? in move_data_block()
1355 err = f2fs_get_node_info(fio.sbi, dn.nid, &ni, false); in move_data_block()
1364 f2fs_down_write(&fio.sbi->io_order_lock); in move_data_block()
1366 mpage = f2fs_grab_cache_page(META_MAPPING(fio.sbi), in move_data_block()
1383 f2fs_update_iostat(fio.sbi, inode, FS_DATA_READ_IO, in move_data_block()
1385 f2fs_update_iostat(fio.sbi, NULL, FS_GDATA_READ_IO, in move_data_block()
1389 if (unlikely(mpage->mapping != META_MAPPING(fio.sbi) || in move_data_block()
1400 err = f2fs_allocate_data_block(fio.sbi, NULL, fio.old_blkaddr, &newaddr, in move_data_block()
1408 fio.encrypted_page = f2fs_pagecache_get_page(META_MAPPING(fio.sbi), in move_data_block()
1422 f2fs_invalidate_internal_cache(fio.sbi, fio.old_blkaddr); in move_data_block()
1426 dec_page_count(fio.sbi, F2FS_DIRTY_META); in move_data_block()
1435 f2fs_update_iostat(fio.sbi, NULL, FS_GC_DATA_IO, F2FS_BLKSIZE); in move_data_block()
1443 f2fs_do_replace_block(fio.sbi, &sum, newaddr, fio.old_blkaddr, in move_data_block()
1447 f2fs_up_write(&fio.sbi->io_order_lock); in move_data_block()
1483 .sbi = F2FS_I_SB(inode), in move_data_page()
1531 static int gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, in gc_data_segment() argument
1535 struct super_block *sb = sbi->sb; in gc_data_segment()
1541 unsigned int usable_blks_in_seg = f2fs_usable_blks_in_seg(sbi, segno); in gc_data_segment()
1543 start_addr = START_BLOCK(sbi, segno); in gc_data_segment()
1561 if ((gc_type == BG_GC && has_not_enough_free_secs(sbi, 0, 0)) || in gc_data_segment()
1562 (!force_migrate && get_valid_blocks(sbi, segno, true) == in gc_data_segment()
1563 CAP_BLKS_PER_SEC(sbi))) in gc_data_segment()
1566 if (check_valid_map(sbi, segno, off) == 0) in gc_data_segment()
1570 f2fs_ra_meta_pages(sbi, NAT_BLOCK_OFFSET(nid), 1, in gc_data_segment()
1576 f2fs_ra_node_page(sbi, nid); in gc_data_segment()
1581 if (!is_alive(sbi, entry, &dni, start_addr + off, &nofs)) in gc_data_segment()
1585 f2fs_ra_node_page(sbi, dni.ino); in gc_data_segment()
1606 set_sbi_flag(sbi, SBI_NEED_FSCK); in gc_data_segment()
1607 f2fs_err_ratelimited(sbi, in gc_data_segment()
1623 sbi->skipped_gc_rwsem++; in gc_data_segment()
1664 sbi->skipped_gc_rwsem++; in gc_data_segment()
1669 sbi->skipped_gc_rwsem++; in gc_data_segment()
1697 stat_inc_data_blk_count(sbi, 1, gc_type); in gc_data_segment()
1707 static int __get_victim(struct f2fs_sb_info *sbi, unsigned int *victim, in __get_victim() argument
1710 struct sit_info *sit_i = SIT_I(sbi); in __get_victim()
1714 ret = f2fs_get_victim(sbi, victim, gc_type, NO_CHECK_TYPE, in __get_victim()
1720 static int do_garbage_collect(struct f2fs_sb_info *sbi, in do_garbage_collect() argument
1729 unsigned int end_segno = start_segno + SEGS_PER_SEC(sbi); in do_garbage_collect()
1732 unsigned char type = IS_DATASEG(get_seg_entry(sbi, segno)->type) ? in do_garbage_collect()
1737 if (__is_large_section(sbi)) { in do_garbage_collect()
1738 sec_end_segno = rounddown(end_segno, SEGS_PER_SEC(sbi)); in do_garbage_collect()
1746 if (f2fs_sb_has_blkzoned(sbi)) in do_garbage_collect()
1747 sec_end_segno -= SEGS_PER_SEC(sbi) - in do_garbage_collect()
1748 f2fs_usable_segs_in_sec(sbi); in do_garbage_collect()
1752 sbi->migration_window_granularity; in do_garbage_collect()
1754 if (f2fs_sb_has_blkzoned(sbi) && in do_garbage_collect()
1755 !has_enough_free_blocks(sbi, in do_garbage_collect()
1756 sbi->gc_thread->boost_zoned_gc_percent)) in do_garbage_collect()
1767 sanity_check_seg_type(sbi, get_seg_entry(sbi, segno)->type); in do_garbage_collect()
1770 if (__is_large_section(sbi)) in do_garbage_collect()
1771 f2fs_ra_meta_pages(sbi, GET_SUM_BLOCK(sbi, segno), in do_garbage_collect()
1776 sum_page = f2fs_get_sum_page(sbi, segno++); in do_garbage_collect()
1782 sum_page = find_get_page(META_MAPPING(sbi), in do_garbage_collect()
1783 GET_SUM_BLOCK(sbi, segno)); in do_garbage_collect()
1797 sum_page = find_get_page(META_MAPPING(sbi), in do_garbage_collect()
1798 GET_SUM_BLOCK(sbi, segno)); in do_garbage_collect()
1801 if (get_valid_blocks(sbi, segno, false) == 0) in do_garbage_collect()
1803 if (gc_type == BG_GC && __is_large_section(sbi) && in do_garbage_collect()
1804 migrated >= sbi->migration_granularity) in do_garbage_collect()
1806 if (!PageUptodate(sum_page) || unlikely(f2fs_cp_error(sbi))) in do_garbage_collect()
1811 f2fs_err(sbi, "Inconsistent segment (%u) type [%d, %d] in SSA and SIT", in do_garbage_collect()
1813 f2fs_stop_checkpoint(sbi, false, in do_garbage_collect()
1826 submitted += gc_node_segment(sbi, sum->entries, segno, in do_garbage_collect()
1829 submitted += gc_data_segment(sbi, sum->entries, gc_list, in do_garbage_collect()
1833 stat_inc_gc_seg_count(sbi, data_type, gc_type); in do_garbage_collect()
1834 sbi->gc_reclaimed_segs[sbi->gc_mode]++; in do_garbage_collect()
1839 get_valid_blocks(sbi, segno, false) == 0) in do_garbage_collect()
1842 if (__is_large_section(sbi)) in do_garbage_collect()
1843 sbi->next_victim_seg[gc_type] = in do_garbage_collect()
1851 f2fs_submit_merged_write(sbi, data_type); in do_garbage_collect()
1856 stat_inc_gc_sec_count(sbi, data_type, gc_type); in do_garbage_collect()
1861 int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control) in f2fs_gc() argument
1875 trace_f2fs_gc_begin(sbi->sb, gc_type, gc_control->no_bg_gc, in f2fs_gc()
1877 get_pages(sbi, F2FS_DIRTY_NODES), in f2fs_gc()
1878 get_pages(sbi, F2FS_DIRTY_DENTS), in f2fs_gc()
1879 get_pages(sbi, F2FS_DIRTY_IMETA), in f2fs_gc()
1880 free_sections(sbi), in f2fs_gc()
1881 free_segments(sbi), in f2fs_gc()
1882 reserved_segments(sbi), in f2fs_gc()
1883 prefree_segments(sbi)); in f2fs_gc()
1885 cpc.reason = __get_cp_reason(sbi); in f2fs_gc()
1887 sbi->skipped_gc_rwsem = 0; in f2fs_gc()
1888 if (unlikely(!(sbi->sb->s_flags & SB_ACTIVE))) { in f2fs_gc()
1892 if (unlikely(f2fs_cp_error(sbi))) { in f2fs_gc()
1898 if (has_not_enough_free_secs(sbi, 0, 0)) { in f2fs_gc()
1906 if (prefree_segments(sbi)) { in f2fs_gc()
1907 stat_inc_cp_call_count(sbi, TOTAL_CALL); in f2fs_gc()
1908 ret = f2fs_write_checkpoint(sbi, &cpc); in f2fs_gc()
1922 ret = __get_victim(sbi, &segno, gc_type, gc_control->one_time); in f2fs_gc()
1926 f2fs_pinned_section_exists(DIRTY_I(sbi))) { in f2fs_gc()
1927 f2fs_unpin_all_sections(sbi, false); in f2fs_gc()
1933 seg_freed = do_garbage_collect(sbi, segno, &gc_list, gc_type, in f2fs_gc()
1941 if (seg_freed == f2fs_usable_segs_in_sec(sbi)) { in f2fs_gc()
1950 sbi->cur_victim_sec = NULL_SEGNO; in f2fs_gc()
1952 if (has_enough_free_secs(sbi, sec_freed, 0)) { in f2fs_gc()
1958 if (sbi->skipped_gc_rwsem) in f2fs_gc()
1963 stat_inc_cp_call_count(sbi, TOTAL_CALL); in f2fs_gc()
1964 ret = f2fs_write_checkpoint(sbi, &cpc); in f2fs_gc()
1967 } else if (has_enough_free_secs(sbi, 0, 0)) { in f2fs_gc()
1971 __get_secs_required(sbi, NULL, &upper_secs, NULL); in f2fs_gc()
1977 if (free_sections(sbi) <= upper_secs + NR_GC_CHECKPOINT_SECS && in f2fs_gc()
1978 prefree_segments(sbi)) { in f2fs_gc()
1979 stat_inc_cp_call_count(sbi, TOTAL_CALL); in f2fs_gc()
1980 ret = f2fs_write_checkpoint(sbi, &cpc); in f2fs_gc()
1991 SIT_I(sbi)->last_victim[ALLOC_NEXT] = 0; in f2fs_gc()
1992 SIT_I(sbi)->last_victim[FLUSH_DEVICE] = gc_control->victim_segno; in f2fs_gc()
1995 f2fs_unpin_all_sections(sbi, true); in f2fs_gc()
1997 trace_f2fs_gc_end(sbi->sb, ret, total_freed, total_sec_freed, in f2fs_gc()
1998 get_pages(sbi, F2FS_DIRTY_NODES), in f2fs_gc()
1999 get_pages(sbi, F2FS_DIRTY_DENTS), in f2fs_gc()
2000 get_pages(sbi, F2FS_DIRTY_IMETA), in f2fs_gc()
2001 free_sections(sbi), in f2fs_gc()
2002 free_segments(sbi), in f2fs_gc()
2003 reserved_segments(sbi), in f2fs_gc()
2004 prefree_segments(sbi)); in f2fs_gc()
2006 f2fs_up_write(&sbi->gc_lock); in f2fs_gc()
2027 static void init_atgc_management(struct f2fs_sb_info *sbi) in init_atgc_management() argument
2029 struct atgc_management *am = &sbi->am; in init_atgc_management()
2031 if (test_opt(sbi, ATGC) && in init_atgc_management()
2032 SIT_I(sbi)->elapsed_time >= DEF_GC_THREAD_AGE_THRESHOLD) in init_atgc_management()
2045 void f2fs_build_gc_manager(struct f2fs_sb_info *sbi) in f2fs_build_gc_manager() argument
2047 sbi->gc_pin_file_threshold = DEF_GC_FAILED_PINNED_FILES; in f2fs_build_gc_manager()
2050 if (f2fs_is_multi_device(sbi) && !__is_large_section(sbi)) in f2fs_build_gc_manager()
2051 SIT_I(sbi)->last_victim[ALLOC_NEXT] = in f2fs_build_gc_manager()
2052 GET_SEGNO(sbi, FDEV(0).end_blk) + 1; in f2fs_build_gc_manager()
2054 init_atgc_management(sbi); in f2fs_build_gc_manager()
2057 int f2fs_gc_range(struct f2fs_sb_info *sbi, in f2fs_gc_range() argument
2064 if (unlikely(f2fs_cp_error(sbi))) in f2fs_gc_range()
2067 for (segno = start_seg; segno <= end_seg; segno += SEGS_PER_SEC(sbi)) { in f2fs_gc_range()
2073 do_garbage_collect(sbi, segno, &gc_list, FG_GC, true, false); in f2fs_gc_range()
2076 if (!dry_run && get_valid_blocks(sbi, segno, true)) in f2fs_gc_range()
2079 !get_valid_blocks(sbi, segno, true) && --gc_secs == 0) in f2fs_gc_range()
2089 static int free_segment_range(struct f2fs_sb_info *sbi, in free_segment_range() argument
2099 MAIN_SECS(sbi) -= secs; in free_segment_range()
2100 start = MAIN_SECS(sbi) * SEGS_PER_SEC(sbi); in free_segment_range()
2101 end = MAIN_SEGS(sbi) - 1; in free_segment_range()
2103 mutex_lock(&DIRTY_I(sbi)->seglist_lock); in free_segment_range()
2105 if (SIT_I(sbi)->last_victim[gc_mode] >= start) in free_segment_range()
2106 SIT_I(sbi)->last_victim[gc_mode] = 0; in free_segment_range()
2109 if (sbi->next_victim_seg[gc_type] >= start) in free_segment_range()
2110 sbi->next_victim_seg[gc_type] = NULL_SEGNO; in free_segment_range()
2111 mutex_unlock(&DIRTY_I(sbi)->seglist_lock); in free_segment_range()
2115 err = f2fs_allocate_segment_for_resize(sbi, type, start, end); in free_segment_range()
2121 err = f2fs_gc_range(sbi, start, end, dry_run, 0); in free_segment_range()
2125 stat_inc_cp_call_count(sbi, TOTAL_CALL); in free_segment_range()
2126 err = f2fs_write_checkpoint(sbi, &cpc); in free_segment_range()
2130 next_inuse = find_next_inuse(FREE_I(sbi), end + 1, start); in free_segment_range()
2132 f2fs_err(sbi, "segno %u should be free but still inuse!", in free_segment_range()
2134 f2fs_bug_on(sbi, 1); in free_segment_range()
2137 MAIN_SECS(sbi) += secs; in free_segment_range()
2141 static void update_sb_metadata(struct f2fs_sb_info *sbi, int secs) in update_sb_metadata() argument
2143 struct f2fs_super_block *raw_sb = F2FS_RAW_SUPER(sbi); in update_sb_metadata()
2148 int segs = secs * SEGS_PER_SEC(sbi); in update_sb_metadata()
2150 f2fs_down_write(&sbi->sb_lock); in update_sb_metadata()
2161 (long long)SEGS_TO_BLKS(sbi, segs)); in update_sb_metadata()
2162 if (f2fs_is_multi_device(sbi)) { in update_sb_metadata()
2163 int last_dev = sbi->s_ndevs - 1; in update_sb_metadata()
2171 f2fs_up_write(&sbi->sb_lock); in update_sb_metadata()
2174 static void update_fs_metadata(struct f2fs_sb_info *sbi, int secs) in update_fs_metadata() argument
2176 int segs = secs * SEGS_PER_SEC(sbi); in update_fs_metadata()
2177 long long blks = SEGS_TO_BLKS(sbi, segs); in update_fs_metadata()
2179 le64_to_cpu(F2FS_CKPT(sbi)->user_block_count); in update_fs_metadata()
2181 SM_I(sbi)->segment_count = (int)SM_I(sbi)->segment_count + segs; in update_fs_metadata()
2182 MAIN_SEGS(sbi) = (int)MAIN_SEGS(sbi) + segs; in update_fs_metadata()
2183 MAIN_SECS(sbi) += secs; in update_fs_metadata()
2184 FREE_I(sbi)->free_sections = (int)FREE_I(sbi)->free_sections + secs; in update_fs_metadata()
2185 FREE_I(sbi)->free_segments = (int)FREE_I(sbi)->free_segments + segs; in update_fs_metadata()
2186 F2FS_CKPT(sbi)->user_block_count = cpu_to_le64(user_block_count + blks); in update_fs_metadata()
2188 if (f2fs_is_multi_device(sbi)) { in update_fs_metadata()
2189 int last_dev = sbi->s_ndevs - 1; in update_fs_metadata()
2197 div_u64(blks, sbi->blocks_per_blkz); in update_fs_metadata()
2204 struct f2fs_sb_info *sbi = F2FS_I_SB(file_inode(filp)); in f2fs_resize_fs() local
2211 old_block_count = le64_to_cpu(F2FS_RAW_SUPER(sbi)->block_count); in f2fs_resize_fs()
2215 if (f2fs_is_multi_device(sbi)) { in f2fs_resize_fs()
2216 int last_dev = sbi->s_ndevs - 1; in f2fs_resize_fs()
2219 if (block_count + SEGS_TO_BLKS(sbi, last_segs) <= in f2fs_resize_fs()
2225 div_u64_rem(block_count, BLKS_PER_SEC(sbi), &rem); in f2fs_resize_fs()
2232 if (is_sbi_flag_set(sbi, SBI_NEED_FSCK)) { in f2fs_resize_fs()
2233 f2fs_err(sbi, "Should run fsck to repair first."); in f2fs_resize_fs()
2237 if (test_opt(sbi, DISABLE_CHECKPOINT)) { in f2fs_resize_fs()
2238 f2fs_err(sbi, "Checkpoint should be enabled."); in f2fs_resize_fs()
2247 secs = div_u64(shrunk_blocks, BLKS_PER_SEC(sbi)); in f2fs_resize_fs()
2250 if (!f2fs_down_write_trylock(&sbi->gc_lock)) { in f2fs_resize_fs()
2256 f2fs_lock_op(sbi); in f2fs_resize_fs()
2258 spin_lock(&sbi->stat_lock); in f2fs_resize_fs()
2259 if (shrunk_blocks + valid_user_blocks(sbi) + in f2fs_resize_fs()
2260 sbi->current_reserved_blocks + sbi->unusable_block_count + in f2fs_resize_fs()
2261 F2FS_OPTION(sbi).root_reserved_blocks > sbi->user_block_count) in f2fs_resize_fs()
2263 spin_unlock(&sbi->stat_lock); in f2fs_resize_fs()
2268 err = free_segment_range(sbi, secs, true); in f2fs_resize_fs()
2271 f2fs_unlock_op(sbi); in f2fs_resize_fs()
2272 f2fs_up_write(&sbi->gc_lock); in f2fs_resize_fs()
2278 err = freeze_super(sbi->sb, FREEZE_HOLDER_USERSPACE); in f2fs_resize_fs()
2282 if (f2fs_readonly(sbi->sb)) { in f2fs_resize_fs()
2283 err = thaw_super(sbi->sb, FREEZE_HOLDER_USERSPACE); in f2fs_resize_fs()
2289 f2fs_down_write(&sbi->gc_lock); in f2fs_resize_fs()
2290 f2fs_down_write(&sbi->cp_global_sem); in f2fs_resize_fs()
2292 spin_lock(&sbi->stat_lock); in f2fs_resize_fs()
2293 if (shrunk_blocks + valid_user_blocks(sbi) + in f2fs_resize_fs()
2294 sbi->current_reserved_blocks + sbi->unusable_block_count + in f2fs_resize_fs()
2295 F2FS_OPTION(sbi).root_reserved_blocks > sbi->user_block_count) in f2fs_resize_fs()
2298 sbi->user_block_count -= shrunk_blocks; in f2fs_resize_fs()
2299 spin_unlock(&sbi->stat_lock); in f2fs_resize_fs()
2303 set_sbi_flag(sbi, SBI_IS_RESIZEFS); in f2fs_resize_fs()
2304 err = free_segment_range(sbi, secs, false); in f2fs_resize_fs()
2308 update_sb_metadata(sbi, -secs); in f2fs_resize_fs()
2310 err = f2fs_commit_super(sbi, false); in f2fs_resize_fs()
2312 update_sb_metadata(sbi, secs); in f2fs_resize_fs()
2316 update_fs_metadata(sbi, -secs); in f2fs_resize_fs()
2317 clear_sbi_flag(sbi, SBI_IS_RESIZEFS); in f2fs_resize_fs()
2318 set_sbi_flag(sbi, SBI_IS_DIRTY); in f2fs_resize_fs()
2320 stat_inc_cp_call_count(sbi, TOTAL_CALL); in f2fs_resize_fs()
2321 err = f2fs_write_checkpoint(sbi, &cpc); in f2fs_resize_fs()
2323 update_fs_metadata(sbi, secs); in f2fs_resize_fs()
2324 update_sb_metadata(sbi, secs); in f2fs_resize_fs()
2325 f2fs_commit_super(sbi, false); in f2fs_resize_fs()
2328 clear_sbi_flag(sbi, SBI_IS_RESIZEFS); in f2fs_resize_fs()
2330 set_sbi_flag(sbi, SBI_NEED_FSCK); in f2fs_resize_fs()
2331 f2fs_err(sbi, "resize_fs failed, should run fsck to repair!"); in f2fs_resize_fs()
2333 spin_lock(&sbi->stat_lock); in f2fs_resize_fs()
2334 sbi->user_block_count += shrunk_blocks; in f2fs_resize_fs()
2335 spin_unlock(&sbi->stat_lock); in f2fs_resize_fs()
2338 f2fs_up_write(&sbi->cp_global_sem); in f2fs_resize_fs()
2339 f2fs_up_write(&sbi->gc_lock); in f2fs_resize_fs()
2340 thaw_super(sbi->sb, FREEZE_HOLDER_USERSPACE); in f2fs_resize_fs()