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 (try_to_freeze() || 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()
97 if (sbi->gc_mode == GC_URGENT_HIGH || in gc_thread_func()
98 sbi->gc_mode == GC_URGENT_MID) { in gc_thread_func()
100 f2fs_down_write(&sbi->gc_lock); in gc_thread_func()
105 f2fs_down_write(&sbi->gc_lock); in gc_thread_func()
107 } else if (!f2fs_down_write_trylock(&sbi->gc_lock)) { in gc_thread_func()
108 stat_other_skip_bggc_count(sbi); in gc_thread_func()
112 if (!is_idle(sbi, GC_TIME)) { in gc_thread_func()
114 f2fs_up_write(&sbi->gc_lock); in gc_thread_func()
115 stat_io_skip_bggc_count(sbi); in gc_thread_func()
119 if (has_enough_invalid_blocks(sbi)) in gc_thread_func()
124 stat_inc_gc_call_count(sbi, foreground ? in gc_thread_func()
127 sync_mode = F2FS_OPTION(sbi).bggc_mode == BGGC_MODE_SYNC; in gc_thread_func()
138 if (f2fs_gc(sbi, &gc_control)) { in gc_thread_func()
151 trace_f2fs_background_gc(sbi->sb, wait_ms, in gc_thread_func()
152 prefree_segments(sbi), free_segments(sbi)); in gc_thread_func()
155 f2fs_balance_fs_bg(sbi, true); in gc_thread_func()
157 if (sbi->gc_mode != GC_NORMAL) { in gc_thread_func()
158 spin_lock(&sbi->gc_remaining_trials_lock); in gc_thread_func()
159 if (sbi->gc_remaining_trials) { in gc_thread_func()
160 sbi->gc_remaining_trials--; in gc_thread_func()
161 if (!sbi->gc_remaining_trials) in gc_thread_func()
162 sbi->gc_mode = GC_NORMAL; in gc_thread_func()
164 spin_unlock(&sbi->gc_remaining_trials_lock); in gc_thread_func()
166 sb_end_write(sbi->sb); in gc_thread_func()
172 int f2fs_start_gc_thread(struct f2fs_sb_info *sbi) in f2fs_start_gc_thread() argument
175 dev_t dev = sbi->sb->s_bdev->bd_dev; in f2fs_start_gc_thread()
177 gc_th = f2fs_kmalloc(sbi, sizeof(struct f2fs_gc_kthread), GFP_KERNEL); in f2fs_start_gc_thread()
188 sbi->gc_thread = gc_th; in f2fs_start_gc_thread()
189 init_waitqueue_head(&sbi->gc_thread->gc_wait_queue_head); in f2fs_start_gc_thread()
190 init_waitqueue_head(&sbi->gc_thread->fggc_wq); in f2fs_start_gc_thread()
191 sbi->gc_thread->f2fs_gc_task = kthread_run(gc_thread_func, sbi, in f2fs_start_gc_thread()
197 sbi->gc_thread = NULL; in f2fs_start_gc_thread()
204 void f2fs_stop_gc_thread(struct f2fs_sb_info *sbi) in f2fs_stop_gc_thread() argument
206 struct f2fs_gc_kthread *gc_th = sbi->gc_thread; in f2fs_stop_gc_thread()
213 sbi->gc_thread = NULL; in f2fs_stop_gc_thread()
216 static int select_gc_type(struct f2fs_sb_info *sbi, int gc_type) in select_gc_type() argument
221 if (sbi->am.atgc_enabled) in select_gc_type()
229 switch (sbi->gc_mode) { in select_gc_type()
247 static void select_policy(struct f2fs_sb_info *sbi, int gc_type, in select_policy() argument
250 struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); in select_policy()
263 p->gc_mode = select_gc_type(sbi, gc_type); in select_policy()
264 p->ofs_unit = SEGS_PER_SEC(sbi); in select_policy()
265 if (__is_large_section(sbi)) { in select_policy()
268 0, MAIN_SECS(sbi)); in select_policy()
280 (sbi->gc_mode != GC_URGENT_HIGH) && in select_policy()
282 p->max_search > sbi->max_victim_search) in select_policy()
283 p->max_search = sbi->max_victim_search; in select_policy()
286 if (f2fs_need_rand_seg(sbi)) in select_policy()
287 p->offset = get_random_u32_below(MAIN_SECS(sbi) * in select_policy()
288 SEGS_PER_SEC(sbi)); in select_policy()
292 p->offset = SIT_I(sbi)->last_victim[p->gc_mode]; in select_policy()
295 static unsigned int get_max_cost(struct f2fs_sb_info *sbi, in get_max_cost() argument
300 return BLKS_PER_SEG(sbi); in get_max_cost()
306 return 2 * BLKS_PER_SEG(sbi) * p->ofs_unit; in get_max_cost()
315 static unsigned int check_bg_victims(struct f2fs_sb_info *sbi) in check_bg_victims() argument
317 struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); in check_bg_victims()
325 for_each_set_bit(secno, dirty_i->victim_secmap, MAIN_SECS(sbi)) { in check_bg_victims()
326 if (sec_usage_check(sbi, secno)) in check_bg_victims()
329 return GET_SEG_FROM_SEC(sbi, secno); in check_bg_victims()
334 static unsigned int get_cb_cost(struct f2fs_sb_info *sbi, unsigned int segno) in get_cb_cost() argument
336 struct sit_info *sit_i = SIT_I(sbi); in get_cb_cost()
337 unsigned int secno = GET_SEC_FROM_SEG(sbi, segno); in get_cb_cost()
338 unsigned int start = GET_SEG_FROM_SEC(sbi, secno); in get_cb_cost()
344 unsigned int usable_segs_per_sec = f2fs_usable_segs_in_sec(sbi, segno); in get_cb_cost()
347 mtime += get_seg_entry(sbi, start + i)->mtime; in get_cb_cost()
348 vblocks = get_valid_blocks(sbi, segno, true); in get_cb_cost()
353 u = (vblocks * 100) >> sbi->log_blocks_per_seg; in get_cb_cost()
367 static inline unsigned int get_gc_cost(struct f2fs_sb_info *sbi, in get_gc_cost() argument
371 return get_seg_entry(sbi, segno)->ckpt_valid_blocks; in get_gc_cost()
375 return get_valid_blocks(sbi, segno, true); in get_gc_cost()
377 return get_cb_cost(sbi, segno); in get_gc_cost()
379 f2fs_bug_on(sbi, 1); in get_gc_cost()
395 static bool f2fs_check_victim_tree(struct f2fs_sb_info *sbi, in f2fs_check_victim_tree() argument
411 f2fs_info(sbi, "broken victim_rbtree, " in f2fs_check_victim_tree()
422 static struct victim_entry *__lookup_victim_entry(struct f2fs_sb_info *sbi, in __lookup_victim_entry() argument
425 struct atgc_management *am = &sbi->am; in __lookup_victim_entry()
440 static struct victim_entry *__create_victim_entry(struct f2fs_sb_info *sbi, in __create_victim_entry() argument
443 struct atgc_management *am = &sbi->am; in __create_victim_entry()
457 static void __insert_victim_entry(struct f2fs_sb_info *sbi, in __insert_victim_entry() argument
460 struct atgc_management *am = &sbi->am; in __insert_victim_entry()
480 ve = __create_victim_entry(sbi, mtime, segno); in __insert_victim_entry()
486 static void add_victim_entry(struct f2fs_sb_info *sbi, in add_victim_entry() argument
489 struct sit_info *sit_i = SIT_I(sbi); in add_victim_entry()
490 unsigned int secno = GET_SEC_FROM_SEG(sbi, segno); in add_victim_entry()
491 unsigned int start = GET_SEG_FROM_SEC(sbi, secno); in add_victim_entry()
495 if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) { in add_victim_entry()
497 get_valid_blocks(sbi, segno, true) == 0) in add_victim_entry()
501 for (i = 0; i < SEGS_PER_SEC(sbi); i++) in add_victim_entry()
502 mtime += get_seg_entry(sbi, start + i)->mtime; in add_victim_entry()
503 mtime = div_u64(mtime, SEGS_PER_SEC(sbi)); in add_victim_entry()
519 __insert_victim_entry(sbi, mtime, segno); in add_victim_entry()
522 static void atgc_lookup_victim(struct f2fs_sb_info *sbi, in atgc_lookup_victim() argument
525 struct sit_info *sit_i = SIT_I(sbi); in atgc_lookup_victim()
526 struct atgc_management *am = &sbi->am; in atgc_lookup_victim()
534 unsigned int sec_blocks = CAP_BLKS_PER_SEC(sbi); in atgc_lookup_victim()
566 vblocks = get_valid_blocks(sbi, ve->segno, true); in atgc_lookup_victim()
567 f2fs_bug_on(sbi, !vblocks || vblocks == sec_blocks); in atgc_lookup_victim()
573 f2fs_bug_on(sbi, age + u >= UINT_MAX); in atgc_lookup_victim()
595 static void atssr_lookup_victim(struct f2fs_sb_info *sbi, in atssr_lookup_victim() argument
598 struct sit_info *sit_i = SIT_I(sbi); in atssr_lookup_victim()
599 struct atgc_management *am = &sbi->am; in atssr_lookup_victim()
616 ve = __lookup_victim_entry(sbi, p->age); in atssr_lookup_victim()
629 vblocks = get_seg_entry(sbi, ve->segno)->ckpt_valid_blocks; in atssr_lookup_victim()
630 f2fs_bug_on(sbi, !vblocks); in atssr_lookup_victim()
633 if (vblocks == BLKS_PER_SEG(sbi)) in atssr_lookup_victim()
659 static void lookup_victim_by_age(struct f2fs_sb_info *sbi, in lookup_victim_by_age() argument
662 f2fs_bug_on(sbi, !f2fs_check_victim_tree(sbi, &sbi->am.root)); in lookup_victim_by_age()
665 atgc_lookup_victim(sbi, p); in lookup_victim_by_age()
667 atssr_lookup_victim(sbi, p); in lookup_victim_by_age()
669 f2fs_bug_on(sbi, 1); in lookup_victim_by_age()
672 static void release_victim_entry(struct f2fs_sb_info *sbi) in release_victim_entry() argument
674 struct atgc_management *am = &sbi->am; in release_victim_entry()
685 f2fs_bug_on(sbi, am->victim_count); in release_victim_entry()
686 f2fs_bug_on(sbi, !list_empty(&am->victim_list)); in release_victim_entry()
689 static bool f2fs_pin_section(struct f2fs_sb_info *sbi, unsigned int segno) in f2fs_pin_section() argument
691 struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); in f2fs_pin_section()
692 unsigned int secno = GET_SEC_FROM_SEG(sbi, segno); in f2fs_pin_section()
714 static void f2fs_unpin_all_sections(struct f2fs_sb_info *sbi, bool enable) in f2fs_unpin_all_sections() argument
716 unsigned int bitmap_size = f2fs_bitmap_size(MAIN_SECS(sbi)); in f2fs_unpin_all_sections()
718 if (f2fs_pinned_section_exists(DIRTY_I(sbi))) { in f2fs_unpin_all_sections()
719 memset(DIRTY_I(sbi)->pinned_secmap, 0, bitmap_size); in f2fs_unpin_all_sections()
720 DIRTY_I(sbi)->pinned_secmap_cnt = 0; in f2fs_unpin_all_sections()
722 DIRTY_I(sbi)->enable_pin_section = enable; in f2fs_unpin_all_sections()
745 int f2fs_get_victim(struct f2fs_sb_info *sbi, unsigned int *result, in f2fs_get_victim() argument
749 struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); in f2fs_get_victim()
750 struct sit_info *sm = SIT_I(sbi); in f2fs_get_victim()
759 last_segment = MAIN_SECS(sbi) * SEGS_PER_SEC(sbi); in f2fs_get_victim()
763 p.age_threshold = sbi->am.age_threshold; in f2fs_get_victim()
766 select_policy(sbi, gc_type, type, &p); in f2fs_get_victim()
769 p.min_cost = get_max_cost(sbi, &p); in f2fs_get_victim()
775 SIT_I(sbi)->dirty_min_mtime = ULLONG_MAX; in f2fs_get_victim()
778 if (!get_valid_blocks(sbi, *result, false)) { in f2fs_get_victim()
783 if (sec_usage_check(sbi, GET_SEC_FROM_SEG(sbi, *result))) in f2fs_get_victim()
794 if (__is_large_section(sbi) && p.alloc_mode == LFS) { in f2fs_get_victim()
795 if (sbi->next_victim_seg[BG_GC] != NULL_SEGNO) { in f2fs_get_victim()
796 p.min_segno = sbi->next_victim_seg[BG_GC]; in f2fs_get_victim()
798 sbi->next_victim_seg[BG_GC] = NULL_SEGNO; in f2fs_get_victim()
802 sbi->next_victim_seg[FG_GC] != NULL_SEGNO) { in f2fs_get_victim()
803 p.min_segno = sbi->next_victim_seg[FG_GC]; in f2fs_get_victim()
805 sbi->next_victim_seg[FG_GC] = NULL_SEGNO; in f2fs_get_victim()
812 p.min_segno = check_bg_victims(sbi); in f2fs_get_victim()
850 secno = GET_SEC_FROM_SEG(sbi, segno); in f2fs_get_victim()
852 if (sec_usage_check(sbi, secno)) in f2fs_get_victim()
856 if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) { in f2fs_get_victim()
862 if (get_ckpt_valid_blocks(sbi, segno, true)) in f2fs_get_victim()
870 if (!f2fs_segment_has_free_slot(sbi, segno)) in f2fs_get_victim()
882 add_victim_entry(sbi, &p, segno); in f2fs_get_victim()
886 cost = get_gc_cost(sbi, segno, &p); in f2fs_get_victim()
900 (MAIN_SECS(sbi) * SEGS_PER_SEC(sbi)); in f2fs_get_victim()
907 lookup_victim_by_age(sbi, &p); in f2fs_get_victim()
908 release_victim_entry(sbi); in f2fs_get_victim()
922 secno = GET_SEC_FROM_SEG(sbi, p.min_segno); in f2fs_get_victim()
924 sbi->cur_victim_sec = secno; in f2fs_get_victim()
933 trace_f2fs_get_victim(sbi->sb, type, gc_type, &p, in f2fs_get_victim()
934 sbi->cur_victim_sec, in f2fs_get_victim()
935 prefree_segments(sbi), free_segments(sbi)); in f2fs_get_victim()
979 static int check_valid_map(struct f2fs_sb_info *sbi, in check_valid_map() argument
982 struct sit_info *sit_i = SIT_I(sbi); in check_valid_map()
987 sentry = get_seg_entry(sbi, segno); in check_valid_map()
998 static int gc_node_segment(struct f2fs_sb_info *sbi, in gc_node_segment() argument
1007 unsigned int usable_blks_in_seg = f2fs_usable_blks_in_seg(sbi, segno); in gc_node_segment()
1009 start_addr = START_BLOCK(sbi, segno); in gc_node_segment()
1015 atomic_inc(&sbi->wb_sync_req[NODE]); in gc_node_segment()
1024 if (gc_type == BG_GC && has_not_enough_free_secs(sbi, 0, 0)) in gc_node_segment()
1027 if (check_valid_map(sbi, segno, off) == 0) in gc_node_segment()
1031 f2fs_ra_meta_pages(sbi, NAT_BLOCK_OFFSET(nid), 1, in gc_node_segment()
1037 f2fs_ra_node_page(sbi, nid); in gc_node_segment()
1042 node_page = f2fs_get_node_page(sbi, nid); in gc_node_segment()
1047 if (check_valid_map(sbi, segno, off) == 0) { in gc_node_segment()
1052 if (f2fs_get_node_info(sbi, nid, &ni, false)) { in gc_node_segment()
1065 stat_inc_node_blk_count(sbi, 1, gc_type); in gc_node_segment()
1072 atomic_dec(&sbi->wb_sync_req[NODE]); in gc_node_segment()
1105 static bool is_alive(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, in is_alive() argument
1116 node_page = f2fs_get_node_page(sbi, nid); in is_alive()
1120 if (f2fs_get_node_info(sbi, nid, dni, false)) { in is_alive()
1126 f2fs_warn(sbi, "%s: valid data with mismatched node version.", in is_alive()
1128 set_sbi_flag(sbi, SBI_NEED_FSCK); in is_alive()
1131 if (f2fs_check_nid_range(sbi, dni->ino)) { in is_alive()
1145 f2fs_err(sbi, "Inconsistent blkaddr offset: base:%u, ofs_in_node:%u, max:%u, ino:%u, nid:%u", in is_alive()
1157 unsigned int segno = GET_SEGNO(sbi, blkaddr); in is_alive()
1158 unsigned long offset = GET_BLKOFF_FROM_SEG0(sbi, blkaddr); in is_alive()
1160 if (unlikely(check_valid_map(sbi, segno, offset))) { in is_alive()
1161 if (!test_and_set_bit(segno, SIT_I(sbi)->invalid_segmap)) { in is_alive()
1162 f2fs_err(sbi, "mismatched blkaddr %u (source_blkaddr %u) in seg %u", in is_alive()
1164 set_sbi_flag(sbi, SBI_NEED_FSCK); in is_alive()
1175 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); in ra_data_block() local
1181 .sbi = sbi, in ra_data_block()
1198 if (unlikely(!f2fs_is_valid_blkaddr(sbi, dn.data_blkaddr, in ra_data_block()
1201 f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR); in ra_data_block()
1217 if (unlikely(!f2fs_is_valid_blkaddr(sbi, dn.data_blkaddr, in ra_data_block()
1220 f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR); in ra_data_block()
1236 fio.encrypted_page = f2fs_pagecache_get_page(META_MAPPING(sbi), in ra_data_block()
1250 f2fs_update_iostat(sbi, inode, FS_DATA_READ_IO, F2FS_BLKSIZE); in ra_data_block()
1251 f2fs_update_iostat(sbi, NULL, FS_GDATA_READ_IO, F2FS_BLKSIZE); in ra_data_block()
1271 .sbi = F2FS_I_SB(inode), in move_data_block()
1286 bool lfs_mode = f2fs_lfs_mode(fio.sbi); in move_data_block()
1287 int type = fio.sbi->am.atgc_enabled && (gc_type == BG_GC) && in move_data_block()
1288 (fio.sbi->gc_mode != GC_URGENT_HIGH) ? in move_data_block()
1324 err = f2fs_get_node_info(fio.sbi, dn.nid, &ni, false); in move_data_block()
1333 f2fs_down_write(&fio.sbi->io_order_lock); in move_data_block()
1335 mpage = f2fs_grab_cache_page(META_MAPPING(fio.sbi), in move_data_block()
1352 f2fs_update_iostat(fio.sbi, inode, FS_DATA_READ_IO, in move_data_block()
1354 f2fs_update_iostat(fio.sbi, NULL, FS_GDATA_READ_IO, in move_data_block()
1358 if (unlikely(mpage->mapping != META_MAPPING(fio.sbi) || in move_data_block()
1369 f2fs_allocate_data_block(fio.sbi, NULL, fio.old_blkaddr, &newaddr, in move_data_block()
1372 fio.encrypted_page = f2fs_pagecache_get_page(META_MAPPING(fio.sbi), in move_data_block()
1386 f2fs_invalidate_internal_cache(fio.sbi, fio.old_blkaddr); in move_data_block()
1390 dec_page_count(fio.sbi, F2FS_DIRTY_META); in move_data_block()
1399 f2fs_update_iostat(fio.sbi, NULL, FS_GC_DATA_IO, F2FS_BLKSIZE); in move_data_block()
1407 f2fs_do_replace_block(fio.sbi, &sum, newaddr, fio.old_blkaddr, in move_data_block()
1411 f2fs_up_write(&fio.sbi->io_order_lock); in move_data_block()
1447 .sbi = F2FS_I_SB(inode), in move_data_page()
1495 static int gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, in gc_data_segment() argument
1499 struct super_block *sb = sbi->sb; in gc_data_segment()
1505 unsigned int usable_blks_in_seg = f2fs_usable_blks_in_seg(sbi, segno); in gc_data_segment()
1507 start_addr = START_BLOCK(sbi, segno); in gc_data_segment()
1525 if ((gc_type == BG_GC && has_not_enough_free_secs(sbi, 0, 0)) || in gc_data_segment()
1526 (!force_migrate && get_valid_blocks(sbi, segno, true) == in gc_data_segment()
1527 CAP_BLKS_PER_SEC(sbi))) in gc_data_segment()
1530 if (check_valid_map(sbi, segno, off) == 0) in gc_data_segment()
1534 f2fs_ra_meta_pages(sbi, NAT_BLOCK_OFFSET(nid), 1, in gc_data_segment()
1540 f2fs_ra_node_page(sbi, nid); in gc_data_segment()
1545 if (!is_alive(sbi, entry, &dni, start_addr + off, &nofs)) in gc_data_segment()
1549 f2fs_ra_node_page(sbi, dni.ino); in gc_data_segment()
1570 set_sbi_flag(sbi, SBI_NEED_FSCK); in gc_data_segment()
1571 f2fs_err_ratelimited(sbi, in gc_data_segment()
1587 sbi->skipped_gc_rwsem++; in gc_data_segment()
1628 sbi->skipped_gc_rwsem++; in gc_data_segment()
1633 sbi->skipped_gc_rwsem++; in gc_data_segment()
1661 stat_inc_data_blk_count(sbi, 1, gc_type); in gc_data_segment()
1671 static int __get_victim(struct f2fs_sb_info *sbi, unsigned int *victim, in __get_victim() argument
1674 struct sit_info *sit_i = SIT_I(sbi); in __get_victim()
1678 ret = f2fs_get_victim(sbi, victim, gc_type, NO_CHECK_TYPE, LFS, 0); in __get_victim()
1683 static int do_garbage_collect(struct f2fs_sb_info *sbi, in do_garbage_collect() argument
1692 unsigned int end_segno = start_segno + SEGS_PER_SEC(sbi); in do_garbage_collect()
1694 unsigned char type = IS_DATASEG(get_seg_entry(sbi, segno)->type) ? in do_garbage_collect()
1699 if (__is_large_section(sbi)) in do_garbage_collect()
1700 end_segno = rounddown(end_segno, SEGS_PER_SEC(sbi)); in do_garbage_collect()
1707 if (f2fs_sb_has_blkzoned(sbi)) in do_garbage_collect()
1708 end_segno -= SEGS_PER_SEC(sbi) - in do_garbage_collect()
1709 f2fs_usable_segs_in_sec(sbi, segno); in do_garbage_collect()
1711 sanity_check_seg_type(sbi, get_seg_entry(sbi, segno)->type); in do_garbage_collect()
1714 if (__is_large_section(sbi)) in do_garbage_collect()
1715 f2fs_ra_meta_pages(sbi, GET_SUM_BLOCK(sbi, segno), in do_garbage_collect()
1720 sum_page = f2fs_get_sum_page(sbi, segno++); in do_garbage_collect()
1726 sum_page = find_get_page(META_MAPPING(sbi), in do_garbage_collect()
1727 GET_SUM_BLOCK(sbi, segno)); in do_garbage_collect()
1741 sum_page = find_get_page(META_MAPPING(sbi), in do_garbage_collect()
1742 GET_SUM_BLOCK(sbi, segno)); in do_garbage_collect()
1745 if (get_valid_blocks(sbi, segno, false) == 0) in do_garbage_collect()
1747 if (gc_type == BG_GC && __is_large_section(sbi) && in do_garbage_collect()
1748 migrated >= sbi->migration_granularity) in do_garbage_collect()
1750 if (!PageUptodate(sum_page) || unlikely(f2fs_cp_error(sbi))) in do_garbage_collect()
1755 f2fs_err(sbi, "Inconsistent segment (%u) type [%d, %d] in SSA and SIT", in do_garbage_collect()
1757 set_sbi_flag(sbi, SBI_NEED_FSCK); in do_garbage_collect()
1758 f2fs_stop_checkpoint(sbi, false, in do_garbage_collect()
1771 submitted += gc_node_segment(sbi, sum->entries, segno, in do_garbage_collect()
1774 submitted += gc_data_segment(sbi, sum->entries, gc_list, in do_garbage_collect()
1778 stat_inc_gc_seg_count(sbi, data_type, gc_type); in do_garbage_collect()
1779 sbi->gc_reclaimed_segs[sbi->gc_mode]++; in do_garbage_collect()
1784 get_valid_blocks(sbi, segno, false) == 0) in do_garbage_collect()
1787 if (__is_large_section(sbi)) in do_garbage_collect()
1788 sbi->next_victim_seg[gc_type] = in do_garbage_collect()
1795 f2fs_submit_merged_write(sbi, data_type); in do_garbage_collect()
1800 stat_inc_gc_sec_count(sbi, data_type, gc_type); in do_garbage_collect()
1805 int f2fs_gc(struct f2fs_sb_info *sbi, struct f2fs_gc_control *gc_control) in f2fs_gc() argument
1819 trace_f2fs_gc_begin(sbi->sb, gc_type, gc_control->no_bg_gc, in f2fs_gc()
1821 get_pages(sbi, F2FS_DIRTY_NODES), in f2fs_gc()
1822 get_pages(sbi, F2FS_DIRTY_DENTS), in f2fs_gc()
1823 get_pages(sbi, F2FS_DIRTY_IMETA), in f2fs_gc()
1824 free_sections(sbi), in f2fs_gc()
1825 free_segments(sbi), in f2fs_gc()
1826 reserved_segments(sbi), in f2fs_gc()
1827 prefree_segments(sbi)); in f2fs_gc()
1829 cpc.reason = __get_cp_reason(sbi); in f2fs_gc()
1831 sbi->skipped_gc_rwsem = 0; in f2fs_gc()
1832 if (unlikely(!(sbi->sb->s_flags & SB_ACTIVE))) { in f2fs_gc()
1836 if (unlikely(f2fs_cp_error(sbi))) { in f2fs_gc()
1842 if (has_not_enough_free_secs(sbi, 0, 0)) { in f2fs_gc()
1850 if (prefree_segments(sbi)) { in f2fs_gc()
1851 stat_inc_cp_call_count(sbi, TOTAL_CALL); in f2fs_gc()
1852 ret = f2fs_write_checkpoint(sbi, &cpc); in f2fs_gc()
1866 ret = __get_victim(sbi, &segno, gc_type); in f2fs_gc()
1870 f2fs_pinned_section_exists(DIRTY_I(sbi))) { in f2fs_gc()
1871 f2fs_unpin_all_sections(sbi, false); in f2fs_gc()
1877 seg_freed = do_garbage_collect(sbi, segno, &gc_list, gc_type, in f2fs_gc()
1881 if (seg_freed == f2fs_usable_segs_in_sec(sbi, segno)) { in f2fs_gc()
1887 sbi->cur_victim_sec = NULL_SEGNO; in f2fs_gc()
1889 if (has_enough_free_secs(sbi, sec_freed, 0)) { in f2fs_gc()
1895 if (sbi->skipped_gc_rwsem) in f2fs_gc()
1900 stat_inc_cp_call_count(sbi, TOTAL_CALL); in f2fs_gc()
1901 ret = f2fs_write_checkpoint(sbi, &cpc); in f2fs_gc()
1904 } else if (has_enough_free_secs(sbi, 0, 0)) { in f2fs_gc()
1908 __get_secs_required(sbi, NULL, &upper_secs, NULL); in f2fs_gc()
1914 if (free_sections(sbi) <= upper_secs + NR_GC_CHECKPOINT_SECS && in f2fs_gc()
1915 prefree_segments(sbi)) { in f2fs_gc()
1916 stat_inc_cp_call_count(sbi, TOTAL_CALL); in f2fs_gc()
1917 ret = f2fs_write_checkpoint(sbi, &cpc); in f2fs_gc()
1928 SIT_I(sbi)->last_victim[ALLOC_NEXT] = 0; in f2fs_gc()
1929 SIT_I(sbi)->last_victim[FLUSH_DEVICE] = gc_control->victim_segno; in f2fs_gc()
1932 f2fs_unpin_all_sections(sbi, true); in f2fs_gc()
1934 trace_f2fs_gc_end(sbi->sb, ret, total_freed, total_sec_freed, in f2fs_gc()
1935 get_pages(sbi, F2FS_DIRTY_NODES), in f2fs_gc()
1936 get_pages(sbi, F2FS_DIRTY_DENTS), in f2fs_gc()
1937 get_pages(sbi, F2FS_DIRTY_IMETA), in f2fs_gc()
1938 free_sections(sbi), in f2fs_gc()
1939 free_segments(sbi), in f2fs_gc()
1940 reserved_segments(sbi), in f2fs_gc()
1941 prefree_segments(sbi)); in f2fs_gc()
1943 f2fs_up_write(&sbi->gc_lock); in f2fs_gc()
1964 static void init_atgc_management(struct f2fs_sb_info *sbi) in init_atgc_management() argument
1966 struct atgc_management *am = &sbi->am; in init_atgc_management()
1968 if (test_opt(sbi, ATGC) && in init_atgc_management()
1969 SIT_I(sbi)->elapsed_time >= DEF_GC_THREAD_AGE_THRESHOLD) in init_atgc_management()
1982 void f2fs_build_gc_manager(struct f2fs_sb_info *sbi) in f2fs_build_gc_manager() argument
1984 sbi->gc_pin_file_threshold = DEF_GC_FAILED_PINNED_FILES; in f2fs_build_gc_manager()
1987 if (f2fs_is_multi_device(sbi) && !__is_large_section(sbi)) in f2fs_build_gc_manager()
1988 SIT_I(sbi)->last_victim[ALLOC_NEXT] = in f2fs_build_gc_manager()
1989 GET_SEGNO(sbi, FDEV(0).end_blk) + 1; in f2fs_build_gc_manager()
1991 init_atgc_management(sbi); in f2fs_build_gc_manager()
1994 int f2fs_gc_range(struct f2fs_sb_info *sbi, in f2fs_gc_range() argument
2001 for (segno = start_seg; segno <= end_seg; segno += SEGS_PER_SEC(sbi)) { in f2fs_gc_range()
2007 do_garbage_collect(sbi, segno, &gc_list, FG_GC, in f2fs_gc_range()
2011 if (!dry_run && get_valid_blocks(sbi, segno, true)) in f2fs_gc_range()
2014 !get_valid_blocks(sbi, segno, true) && --gc_secs == 0) in f2fs_gc_range()
2024 static int free_segment_range(struct f2fs_sb_info *sbi, in free_segment_range() argument
2034 MAIN_SECS(sbi) -= secs; in free_segment_range()
2035 start = MAIN_SECS(sbi) * SEGS_PER_SEC(sbi); in free_segment_range()
2036 end = MAIN_SEGS(sbi) - 1; in free_segment_range()
2038 mutex_lock(&DIRTY_I(sbi)->seglist_lock); in free_segment_range()
2040 if (SIT_I(sbi)->last_victim[gc_mode] >= start) in free_segment_range()
2041 SIT_I(sbi)->last_victim[gc_mode] = 0; in free_segment_range()
2044 if (sbi->next_victim_seg[gc_type] >= start) in free_segment_range()
2045 sbi->next_victim_seg[gc_type] = NULL_SEGNO; in free_segment_range()
2046 mutex_unlock(&DIRTY_I(sbi)->seglist_lock); in free_segment_range()
2050 f2fs_allocate_segment_for_resize(sbi, type, start, end); in free_segment_range()
2053 err = f2fs_gc_range(sbi, start, end, dry_run, 0); in free_segment_range()
2057 stat_inc_cp_call_count(sbi, TOTAL_CALL); in free_segment_range()
2058 err = f2fs_write_checkpoint(sbi, &cpc); in free_segment_range()
2062 next_inuse = find_next_inuse(FREE_I(sbi), end + 1, start); in free_segment_range()
2064 f2fs_err(sbi, "segno %u should be free but still inuse!", in free_segment_range()
2066 f2fs_bug_on(sbi, 1); in free_segment_range()
2069 MAIN_SECS(sbi) += secs; in free_segment_range()
2073 static void update_sb_metadata(struct f2fs_sb_info *sbi, int secs) in update_sb_metadata() argument
2075 struct f2fs_super_block *raw_sb = F2FS_RAW_SUPER(sbi); in update_sb_metadata()
2080 int segs = secs * SEGS_PER_SEC(sbi); in update_sb_metadata()
2082 f2fs_down_write(&sbi->sb_lock); in update_sb_metadata()
2093 (long long)(segs << sbi->log_blocks_per_seg)); in update_sb_metadata()
2094 if (f2fs_is_multi_device(sbi)) { in update_sb_metadata()
2095 int last_dev = sbi->s_ndevs - 1; in update_sb_metadata()
2103 f2fs_up_write(&sbi->sb_lock); in update_sb_metadata()
2106 static void update_fs_metadata(struct f2fs_sb_info *sbi, int secs) in update_fs_metadata() argument
2108 int segs = secs * SEGS_PER_SEC(sbi); in update_fs_metadata()
2109 long long blks = (long long)segs << sbi->log_blocks_per_seg; in update_fs_metadata()
2111 le64_to_cpu(F2FS_CKPT(sbi)->user_block_count); in update_fs_metadata()
2113 SM_I(sbi)->segment_count = (int)SM_I(sbi)->segment_count + segs; in update_fs_metadata()
2114 MAIN_SEGS(sbi) = (int)MAIN_SEGS(sbi) + segs; in update_fs_metadata()
2115 MAIN_SECS(sbi) += secs; in update_fs_metadata()
2116 FREE_I(sbi)->free_sections = (int)FREE_I(sbi)->free_sections + secs; in update_fs_metadata()
2117 FREE_I(sbi)->free_segments = (int)FREE_I(sbi)->free_segments + segs; in update_fs_metadata()
2118 F2FS_CKPT(sbi)->user_block_count = cpu_to_le64(user_block_count + blks); in update_fs_metadata()
2120 if (f2fs_is_multi_device(sbi)) { in update_fs_metadata()
2121 int last_dev = sbi->s_ndevs - 1; in update_fs_metadata()
2129 div_u64(blks, sbi->blocks_per_blkz); in update_fs_metadata()
2136 struct f2fs_sb_info *sbi = F2FS_I_SB(file_inode(filp)); in f2fs_resize_fs() local
2143 old_block_count = le64_to_cpu(F2FS_RAW_SUPER(sbi)->block_count); in f2fs_resize_fs()
2147 if (f2fs_is_multi_device(sbi)) { in f2fs_resize_fs()
2148 int last_dev = sbi->s_ndevs - 1; in f2fs_resize_fs()
2151 if (block_count + (last_segs << sbi->log_blocks_per_seg) <= in f2fs_resize_fs()
2157 div_u64_rem(block_count, BLKS_PER_SEC(sbi), &rem); in f2fs_resize_fs()
2164 if (is_sbi_flag_set(sbi, SBI_NEED_FSCK)) { in f2fs_resize_fs()
2165 f2fs_err(sbi, "Should run fsck to repair first."); in f2fs_resize_fs()
2169 if (test_opt(sbi, DISABLE_CHECKPOINT)) { in f2fs_resize_fs()
2170 f2fs_err(sbi, "Checkpoint should be enabled."); in f2fs_resize_fs()
2179 secs = div_u64(shrunk_blocks, BLKS_PER_SEC(sbi)); in f2fs_resize_fs()
2182 if (!f2fs_down_write_trylock(&sbi->gc_lock)) { in f2fs_resize_fs()
2188 f2fs_lock_op(sbi); in f2fs_resize_fs()
2190 spin_lock(&sbi->stat_lock); in f2fs_resize_fs()
2191 if (shrunk_blocks + valid_user_blocks(sbi) + in f2fs_resize_fs()
2192 sbi->current_reserved_blocks + sbi->unusable_block_count + in f2fs_resize_fs()
2193 F2FS_OPTION(sbi).root_reserved_blocks > sbi->user_block_count) in f2fs_resize_fs()
2195 spin_unlock(&sbi->stat_lock); in f2fs_resize_fs()
2200 err = free_segment_range(sbi, secs, true); in f2fs_resize_fs()
2203 f2fs_unlock_op(sbi); in f2fs_resize_fs()
2204 f2fs_up_write(&sbi->gc_lock); in f2fs_resize_fs()
2210 err = freeze_super(sbi->sb, FREEZE_HOLDER_USERSPACE); in f2fs_resize_fs()
2214 if (f2fs_readonly(sbi->sb)) { in f2fs_resize_fs()
2215 err = thaw_super(sbi->sb, FREEZE_HOLDER_USERSPACE); in f2fs_resize_fs()
2221 f2fs_down_write(&sbi->gc_lock); in f2fs_resize_fs()
2222 f2fs_down_write(&sbi->cp_global_sem); in f2fs_resize_fs()
2224 spin_lock(&sbi->stat_lock); in f2fs_resize_fs()
2225 if (shrunk_blocks + valid_user_blocks(sbi) + in f2fs_resize_fs()
2226 sbi->current_reserved_blocks + sbi->unusable_block_count + in f2fs_resize_fs()
2227 F2FS_OPTION(sbi).root_reserved_blocks > sbi->user_block_count) in f2fs_resize_fs()
2230 sbi->user_block_count -= shrunk_blocks; in f2fs_resize_fs()
2231 spin_unlock(&sbi->stat_lock); in f2fs_resize_fs()
2235 set_sbi_flag(sbi, SBI_IS_RESIZEFS); in f2fs_resize_fs()
2236 err = free_segment_range(sbi, secs, false); in f2fs_resize_fs()
2240 update_sb_metadata(sbi, -secs); in f2fs_resize_fs()
2242 err = f2fs_commit_super(sbi, false); in f2fs_resize_fs()
2244 update_sb_metadata(sbi, secs); in f2fs_resize_fs()
2248 update_fs_metadata(sbi, -secs); in f2fs_resize_fs()
2249 clear_sbi_flag(sbi, SBI_IS_RESIZEFS); in f2fs_resize_fs()
2250 set_sbi_flag(sbi, SBI_IS_DIRTY); in f2fs_resize_fs()
2252 stat_inc_cp_call_count(sbi, TOTAL_CALL); in f2fs_resize_fs()
2253 err = f2fs_write_checkpoint(sbi, &cpc); in f2fs_resize_fs()
2255 update_fs_metadata(sbi, secs); in f2fs_resize_fs()
2256 update_sb_metadata(sbi, secs); in f2fs_resize_fs()
2257 f2fs_commit_super(sbi, false); in f2fs_resize_fs()
2260 clear_sbi_flag(sbi, SBI_IS_RESIZEFS); in f2fs_resize_fs()
2262 set_sbi_flag(sbi, SBI_NEED_FSCK); in f2fs_resize_fs()
2263 f2fs_err(sbi, "resize_fs failed, should run fsck to repair!"); in f2fs_resize_fs()
2265 spin_lock(&sbi->stat_lock); in f2fs_resize_fs()
2266 sbi->user_block_count += shrunk_blocks; in f2fs_resize_fs()
2267 spin_unlock(&sbi->stat_lock); in f2fs_resize_fs()
2270 f2fs_up_write(&sbi->cp_global_sem); in f2fs_resize_fs()
2271 f2fs_up_write(&sbi->gc_lock); in f2fs_resize_fs()
2272 thaw_super(sbi->sb, FREEZE_HOLDER_USERSPACE); in f2fs_resize_fs()