fs/f2fs/gc.c
Source file repositories/reference/linux-study-clean/fs/f2fs/gc.c
File Facts
- System
- Linux kernel
- Corpus path
fs/f2fs/gc.c- Extension
.c- Size
- 62258 bytes
- Lines
- 2427
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/fs.hlinux/module.hlinux/init.hlinux/f2fs_fs.hlinux/kthread.hlinux/delay.hlinux/freezer.hlinux/sched/signal.hlinux/random.hlinux/sched/mm.hf2fs.hnode.hsegment.hgc.hiostat.htrace/events/f2fs.h
Detected Declarations
function gc_thread_funcfunction f2fs_start_gc_threadfunction f2fs_stop_gc_threadfunction select_gc_typefunction select_policyfunction get_max_costfunction check_bg_victimsfunction get_cb_costfunction get_gc_costfunction count_bitsfunction f2fs_check_victim_treefunction __insert_victim_entryfunction add_victim_entryfunction atgc_lookup_victimfunction atssr_lookup_victimfunction lookup_victim_by_agefunction release_victim_entryfunction list_for_each_entry_safefunction f2fs_pin_sectionfunction f2fs_pinned_section_existsfunction f2fs_section_is_pinnedfunction f2fs_unpin_all_sectionsfunction f2fs_gc_pinned_controlfunction f2fs_get_victimfunction add_gc_inodefunction put_gc_inodefunction list_for_each_entry_safefunction check_valid_mapfunction gc_node_segmentfunction f2fs_start_bidx_of_nodefunction is_alivefunction ra_data_blockfunction move_data_blockfunction move_data_pagefunction gc_data_segmentfunction __get_victimfunction do_garbage_collectfunction f2fs_gcfunction prefree_segmentsfunction f2fs_create_garbage_collection_cachefunction f2fs_destroy_garbage_collection_cachefunction init_atgc_managementfunction f2fs_build_gc_managerfunction f2fs_gc_rangefunction free_segment_rangefunction update_sb_metadatafunction update_fs_metadatafunction f2fs_resize_fs
Annotated Snippet
if (test_opt(sbi, GC_MERGE) && waitqueue_active(fggc_wq)) {
foreground = true;
gc_control.one_time = false;
} else if (f2fs_sb_has_blkzoned(sbi)) {
gc_control.one_time = true;
}
/* give it a try one time */
if (gc_th->gc_wake)
gc_th->gc_wake = false;
if (f2fs_readonly(sbi->sb)) {
stat_other_skip_bggc_count(sbi);
continue;
}
if (kthread_should_stop())
break;
if (sbi->sb->s_writers.frozen >= SB_FREEZE_WRITE) {
increase_sleep_time(gc_th, &wait_ms);
stat_other_skip_bggc_count(sbi);
continue;
}
if (time_to_inject(sbi, FAULT_CHECKPOINT))
f2fs_stop_checkpoint(sbi, false,
STOP_CP_REASON_FAULT_INJECT);
if (!sb_start_write_trylock(sbi->sb)) {
stat_other_skip_bggc_count(sbi);
continue;
}
/*
* [GC triggering condition]
* 0. GC is not conducted currently.
* 1. There are enough dirty segments.
* 2. IO subsystem is idle by checking the # of writeback pages.
* 3. IO subsystem is idle by checking the # of requests in
* bdev's request list.
*
* Note) We have to avoid triggering GCs frequently.
* Because it is possible that some segments can be
* invalidated soon after by user update or deletion.
* So, I'd like to wait some time to collect dirty segments.
*/
if (sbi->gc_mode == GC_URGENT_HIGH ||
sbi->gc_mode == GC_URGENT_MID) {
wait_ms = gc_th->urgent_sleep_time;
f2fs_down_write_trace(&sbi->gc_lock, &gc_control.lc);
goto do_gc;
}
if (foreground) {
f2fs_down_write_trace(&sbi->gc_lock, &gc_control.lc);
goto do_gc;
} else if (!f2fs_down_write_trylock_trace(&sbi->gc_lock,
&gc_control.lc)) {
stat_other_skip_bggc_count(sbi);
goto next;
}
if (!is_idle(sbi, GC_TIME)) {
increase_sleep_time(gc_th, &wait_ms);
f2fs_up_write_trace(&sbi->gc_lock, &gc_control.lc);
stat_io_skip_bggc_count(sbi);
goto next;
}
if (f2fs_sb_has_blkzoned(sbi)) {
if (has_enough_free_blocks(sbi,
gc_th->no_zoned_gc_percent)) {
wait_ms = gc_th->no_gc_sleep_time;
f2fs_up_write_trace(&sbi->gc_lock,
&gc_control.lc);
goto next;
}
if (wait_ms == gc_th->no_gc_sleep_time)
wait_ms = gc_th->max_sleep_time;
}
if (need_to_boost_gc(sbi)) {
decrease_sleep_time(gc_th, &wait_ms);
if (f2fs_sb_has_blkzoned(sbi))
gc_boost = true;
} else {
increase_sleep_time(gc_th, &wait_ms);
}
do_gc:
stat_inc_gc_call_count(sbi, foreground ?
Annotation
- Immediate include surface: `linux/fs.h`, `linux/module.h`, `linux/init.h`, `linux/f2fs_fs.h`, `linux/kthread.h`, `linux/delay.h`, `linux/freezer.h`, `linux/sched/signal.h`.
- Detected declarations: `function gc_thread_func`, `function f2fs_start_gc_thread`, `function f2fs_stop_gc_thread`, `function select_gc_type`, `function select_policy`, `function get_max_cost`, `function check_bg_victims`, `function get_cb_cost`, `function get_gc_cost`, `function count_bits`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.