kernel/sched/fair.c
Source file repositories/reference/linux-study-clean/kernel/sched/fair.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/sched/fair.c- Extension
.c- Size
- 429745 bytes
- Lines
- 15460
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/energy_model.hlinux/mmap_lock.hlinux/hugetlb_inline.hlinux/jiffies.hlinux/mm_api.hlinux/highmem.hlinux/spinlock_api.hlinux/cpumask_api.hlinux/lockdep_api.hlinux/softirq.hlinux/refcount_api.hlinux/topology.hlinux/sched/clock.hlinux/sched/cond_resched.hlinux/sched/cputime.hlinux/sched/isolation.hlinux/sched/nohz.hlinux/sched/prio.hlinux/cpuidle.hlinux/interrupt.hlinux/memory-tiers.hlinux/mempolicy.hlinux/mutex_api.hlinux/profile.hlinux/psi.hlinux/ratelimit.hlinux/task_work.hlinux/rbtree_augmented.hasm/switch_to.huapi/linux/sched/types.hsched.hstats.h
Detected Declarations
struct numa_groupstruct numa_statsstruct task_numa_envstruct energy_envstruct lb_envstruct sg_lb_statsstruct sd_lb_statsstruct sg_lb_statsenum numa_typeenum asym_fits_stateenum preempt_wakeup_actionenum fbq_typeenum group_typeenum migration_typeenum llc_migfunction setup_sched_thermal_decay_shiftfunction arch_asym_cpu_priorityfunction sched_fair_sysctl_initfunction update_load_addfunction update_load_subfunction update_load_setfunction get_update_sysctl_factorfunction update_sysctlfunction sched_init_granularityfunction __update_inv_weightfunction __calc_deltafunction __calc_deltafunction calc_delta_fairfunction list_add_leaf_cfs_rqfunction parentfunction list_del_leaf_cfs_rqfunction assert_list_leaf_cfs_rqfunction is_same_groupfunction find_matching_sefunction tg_is_idlefunction cfs_rq_is_idlefunction se_is_idlefunction list_add_leaf_cfs_rqfunction list_del_leaf_cfs_rqfunction find_matching_sefunction cfs_rq_is_idlefunction se_is_idlefunction max_vruntimefunction min_vruntimefunction entity_beforefunction entity_keyfunction v_ifunction __sum_w_vruntime_add
Annotated Snippet
struct numa_group {
refcount_t refcount;
spinlock_t lock; /* nr_tasks, tasks */
int nr_tasks;
pid_t gid;
int active_nodes;
struct rcu_head rcu;
unsigned long total_faults;
unsigned long max_faults_cpu;
/*
* faults[] array is split into two regions: faults_mem and faults_cpu.
*
* Faults_cpu is used to decide whether memory should move
* towards the CPU. As a consequence, these stats are weighted
* more by CPU use than by memory faults.
*/
unsigned long faults[];
};
/*
* For functions that can be called in multiple contexts that permit reading
* ->numa_group (see struct task_struct for locking rules).
*/
static struct numa_group *deref_task_numa_group(struct task_struct *p)
{
return rcu_dereference_check(p->numa_group, p == current ||
(lockdep_is_held(__rq_lockp(task_rq(p))) && !READ_ONCE(p->on_cpu)));
}
static struct numa_group *deref_curr_numa_group(struct task_struct *p)
{
return rcu_dereference_protected(p->numa_group, p == current);
}
static inline unsigned long group_faults_priv(struct numa_group *ng);
static inline unsigned long group_faults_shared(struct numa_group *ng);
static unsigned int task_nr_scan_windows(struct task_struct *p)
{
unsigned long rss = 0;
unsigned long nr_scan_pages;
/*
* Calculations based on RSS as non-present and empty pages are skipped
* by the PTE scanner and NUMA hinting faults should be trapped based
* on resident pages
*/
nr_scan_pages = MB_TO_PAGES(sysctl_numa_balancing_scan_size);
rss = get_mm_rss(p->mm);
if (!rss)
rss = nr_scan_pages;
rss = round_up(rss, nr_scan_pages);
return rss / nr_scan_pages;
}
/* For sanity's sake, never scan more PTEs than MAX_SCAN_WINDOW MB/sec. */
#define MAX_SCAN_WINDOW 2560
static unsigned int task_scan_min(struct task_struct *p)
{
unsigned int scan_size = READ_ONCE(sysctl_numa_balancing_scan_size);
unsigned int scan, floor;
unsigned int windows = 1;
if (scan_size < MAX_SCAN_WINDOW)
windows = MAX_SCAN_WINDOW / scan_size;
floor = 1000 / windows;
scan = sysctl_numa_balancing_scan_period_min / task_nr_scan_windows(p);
return max_t(unsigned int, floor, scan);
}
static unsigned int task_scan_start(struct task_struct *p)
{
unsigned long smin = task_scan_min(p);
unsigned long period = smin;
struct numa_group *ng;
/* Scale the maximum scan period with the amount of shared memory. */
rcu_read_lock();
ng = rcu_dereference_all(p->numa_group);
if (ng) {
unsigned long shared = group_faults_shared(ng);
unsigned long private = group_faults_priv(ng);
period *= refcount_read(&ng->refcount);
period *= shared + 1;
Annotation
- Immediate include surface: `linux/energy_model.h`, `linux/mmap_lock.h`, `linux/hugetlb_inline.h`, `linux/jiffies.h`, `linux/mm_api.h`, `linux/highmem.h`, `linux/spinlock_api.h`, `linux/cpumask_api.h`.
- Detected declarations: `struct numa_group`, `struct numa_stats`, `struct task_numa_env`, `struct energy_env`, `struct lb_env`, `struct sg_lb_stats`, `struct sd_lb_stats`, `struct sg_lb_stats`, `enum numa_type`, `enum asym_fits_state`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: integration 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.