mm/oom_kill.c
Source file repositories/reference/linux-study-clean/mm/oom_kill.c
File Facts
- System
- Linux kernel
- Corpus path
mm/oom_kill.c- Extension
.c- Size
- 34311 bytes
- Lines
- 1258
- Domain
- Core OS
- Bucket
- Memory Management
- Inferred role
- Core OS: syscall or user/kernel boundary
- Status
- core 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.
- Defines or participates in a user/kernel boundary; inspect argument validation, copy_from_user/copy_to_user, credentials, and dispatch target.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/oom.hlinux/mm.hlinux/err.hlinux/gfp.hlinux/sched.hlinux/sched/mm.hlinux/sched/task.hlinux/sched/debug.hlinux/swap.hlinux/syscalls.hlinux/timex.hlinux/jiffies.hlinux/cpuset.hlinux/export.hlinux/notifier.hlinux/memcontrol.hlinux/mempolicy.hlinux/security.hlinux/ptrace.hlinux/freezer.hlinux/ftrace.hlinux/ratelimit.hlinux/kthread.hlinux/init.hlinux/mmu_notifier.hlinux/cred.hlinux/nmi.hasm/tlb.hinternal.hslab.htrace/events/oom.h
Detected Declarations
syscall process_mreleasefunction is_memcg_oomfunction oom_cpuset_eligiblefunction oom_cpuset_eligiblefunction kthread_use_mmfunction for_each_threadfunction is_sysrq_oomfunction oom_unkillable_taskfunction memoryfunction oom_badnessfunction mm_flags_testfunction constrained_allocfunction get_page_from_freelistfunction oom_evaluate_taskfunction select_bad_processfunction dump_taskfunction dump_tasksfunction for_each_processfunction dump_oom_victimfunction dump_headerfunction process_shares_mmfunction for_each_threadfunction __oom_reap_task_mmfunction oom_reap_task_mmfunction oom_reap_taskfunction oom_reaperfunction wake_oom_reaperfunction queue_oom_reaperfunction oom_initfunction queue_oom_reaperfunction exit_oom_victimfunction oom_killer_enablefunction oom_killer_disablefunction __task_will_free_memfunction task_will_free_memfunction __oom_kill_processfunction oom_kill_memcg_memberfunction oom_kill_processfunction check_panic_on_oomfunction register_oom_notifierfunction unregister_oom_notifierfunction taskfunction pagefault_out_of_memorymodule init oom_initexport register_oom_notifierexport unregister_oom_notifier
Annotated Snippet
SYSCALL_DEFINE2(process_mrelease, int, pidfd, unsigned int, flags)
{
#ifdef CONFIG_MMU
struct mm_struct *mm = NULL;
struct task_struct *task;
struct task_struct *p;
unsigned int f_flags;
bool reap = false;
long ret = 0;
if (flags)
return -EINVAL;
task = pidfd_get_task(pidfd, &f_flags);
if (IS_ERR(task))
return PTR_ERR(task);
/*
* Make sure to choose a thread which still has a reference to mm
* during the group exit
*/
p = find_lock_task_mm(task);
if (!p) {
ret = -ESRCH;
goto put_task;
}
mm = p->mm;
mmgrab(mm);
if (task_will_free_mem(p))
reap = true;
else {
/* Error only if the work has not been done already */
if (!mm_flags_test(MMF_OOM_SKIP, mm))
ret = -EINVAL;
}
task_unlock(p);
if (!reap)
goto drop_mm;
if (mmap_read_lock_killable(mm)) {
ret = -EINTR;
goto drop_mm;
}
/*
* Check MMF_OOM_SKIP again under mmap_read_lock protection to ensure
* possible change in exit_mmap is seen
*/
if (!mm_flags_test(MMF_OOM_SKIP, mm) && !__oom_reap_task_mm(mm))
ret = -EAGAIN;
mmap_read_unlock(mm);
drop_mm:
mmdrop(mm);
put_task:
put_task_struct(task);
return ret;
#else
return -ENOSYS;
#endif /* CONFIG_MMU */
}
Annotation
- Immediate include surface: `linux/oom.h`, `linux/mm.h`, `linux/err.h`, `linux/gfp.h`, `linux/sched.h`, `linux/sched/mm.h`, `linux/sched/task.h`, `linux/sched/debug.h`.
- Detected declarations: `syscall process_mrelease`, `function is_memcg_oom`, `function oom_cpuset_eligible`, `function oom_cpuset_eligible`, `function kthread_use_mm`, `function for_each_thread`, `function is_sysrq_oom`, `function oom_unkillable_task`, `function memory`, `function oom_badness`.
- Atlas domain: Core OS / Memory Management.
- Implementation status: core implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.