1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 28ac773b4SAlexey Dobriyan #ifndef __INCLUDE_LINUX_OOM_H 38ac773b4SAlexey Dobriyan #define __INCLUDE_LINUX_OOM_H 48ac773b4SAlexey Dobriyan 55a3135c2SDavid Rientjes 63f07c014SIngo Molnar #include <linux/sched/signal.h> 7172acf60SDavid Rientjes #include <linux/types.h> 84365a567SKAMEZAWA Hiroyuki #include <linux/nodemask.h> 9607ca46eSDavid Howells #include <uapi/linux/oom.h> 106b31d595SMichal Hocko #include <linux/sched/coredump.h> /* MMF_* */ 116b31d595SMichal Hocko #include <linux/mm.h> /* VM_FAULT* */ 12172acf60SDavid Rientjes 13172acf60SDavid Rientjes struct zonelist; 14172acf60SDavid Rientjes struct notifier_block; 1574bcbf40SAndrew Morton struct mem_cgroup; 1674bcbf40SAndrew Morton struct task_struct; 17172acf60SDavid Rientjes 18ef8444eaSyuzhoujian enum oom_constraint { 19ef8444eaSyuzhoujian CONSTRAINT_NONE, 20ef8444eaSyuzhoujian CONSTRAINT_CPUSET, 21ef8444eaSyuzhoujian CONSTRAINT_MEMORY_POLICY, 22ef8444eaSyuzhoujian CONSTRAINT_MEMCG, 23ef8444eaSyuzhoujian }; 24ef8444eaSyuzhoujian 258989e4c7SDavid Rientjes /* 268989e4c7SDavid Rientjes * Details of the page allocation that triggered the oom killer that are used to 278989e4c7SDavid Rientjes * determine what should be killed. 288989e4c7SDavid Rientjes */ 296e0fc46dSDavid Rientjes struct oom_control { 308989e4c7SDavid Rientjes /* Used to determine cpuset */ 316e0fc46dSDavid Rientjes struct zonelist *zonelist; 328989e4c7SDavid Rientjes 338989e4c7SDavid Rientjes /* Used to determine mempolicy */ 346e0fc46dSDavid Rientjes nodemask_t *nodemask; 358989e4c7SDavid Rientjes 362a966b77SVladimir Davydov /* Memory cgroup in which oom is invoked, or NULL for global oom */ 372a966b77SVladimir Davydov struct mem_cgroup *memcg; 382a966b77SVladimir Davydov 398989e4c7SDavid Rientjes /* Used to determine cpuset and node locality requirement */ 408989e4c7SDavid Rientjes const gfp_t gfp_mask; 418989e4c7SDavid Rientjes 428989e4c7SDavid Rientjes /* 438989e4c7SDavid Rientjes * order == -1 means the oom kill is required by sysrq, otherwise only 448989e4c7SDavid Rientjes * for display purposes. 458989e4c7SDavid Rientjes */ 468989e4c7SDavid Rientjes const int order; 476e0fc46dSDavid Rientjes 487c5f64f8SVladimir Davydov /* Used by oom implementation, do not set */ 497c5f64f8SVladimir Davydov unsigned long totalpages; 507c5f64f8SVladimir Davydov struct task_struct *chosen; 519066e5cfSYafang Shao long chosen_points; 52ef8444eaSyuzhoujian 53ef8444eaSyuzhoujian /* Used to print the constraint info. */ 54ef8444eaSyuzhoujian enum oom_constraint constraint; 559cbb78bbSDavid Rientjes }; 569cbb78bbSDavid Rientjes 57dc56401fSJohannes Weiner extern struct mutex oom_lock; 5867197a4fSSuren Baghdasaryan extern struct mutex oom_adj_mutex; 59dc56401fSJohannes Weiner set_current_oom_origin(void)60e1e12d2fSDavid Rientjesstatic inline void set_current_oom_origin(void) 61e1e12d2fSDavid Rientjes { 62c96fc2d8STetsuo Handa current->signal->oom_flag_origin = true; 63e1e12d2fSDavid Rientjes } 64e1e12d2fSDavid Rientjes clear_current_oom_origin(void)65e1e12d2fSDavid Rientjesstatic inline void clear_current_oom_origin(void) 66e1e12d2fSDavid Rientjes { 67c96fc2d8STetsuo Handa current->signal->oom_flag_origin = false; 68e1e12d2fSDavid Rientjes } 69e1e12d2fSDavid Rientjes oom_task_origin(const struct task_struct * p)70e1e12d2fSDavid Rientjesstatic inline bool oom_task_origin(const struct task_struct *p) 71e1e12d2fSDavid Rientjes { 72c96fc2d8STetsuo Handa return p->signal->oom_flag_origin; 73e1e12d2fSDavid Rientjes } 7472788c38SDavid Rientjes tsk_is_oom_victim(struct task_struct * tsk)75862e3073SMichal Hockostatic inline bool tsk_is_oom_victim(struct task_struct * tsk) 76862e3073SMichal Hocko { 77862e3073SMichal Hocko return tsk->signal->oom_mm; 78862e3073SMichal Hocko } 79862e3073SMichal Hocko 806b31d595SMichal Hocko /* 816b31d595SMichal Hocko * Checks whether a page fault on the given mm is still reliable. 826b31d595SMichal Hocko * This is no longer true if the oom reaper started to reap the 836b31d595SMichal Hocko * address space which is reflected by MMF_UNSTABLE flag set in 846b31d595SMichal Hocko * the mm. At that moment any !shared mapping would lose the content 856b31d595SMichal Hocko * and could cause a memory corruption (zero pages instead of the 866b31d595SMichal Hocko * original content). 876b31d595SMichal Hocko * 886b31d595SMichal Hocko * User should call this before establishing a page table entry for 896b31d595SMichal Hocko * a !shared mapping and under the proper page table lock. 906b31d595SMichal Hocko * 916b31d595SMichal Hocko * Return 0 when the PF is safe VM_FAULT_SIGBUS otherwise. 926b31d595SMichal Hocko */ check_stable_address_space(struct mm_struct * mm)932b740303SSouptick Joarderstatic inline vm_fault_t check_stable_address_space(struct mm_struct *mm) 946b31d595SMichal Hocko { 956b31d595SMichal Hocko if (unlikely(test_bit(MMF_UNSTABLE, &mm->flags))) 966b31d595SMichal Hocko return VM_FAULT_SIGBUS; 976b31d595SMichal Hocko return 0; 986b31d595SMichal Hocko } 996b31d595SMichal Hocko 1009066e5cfSYafang Shao long oom_badness(struct task_struct *p, 101a7f638f9SDavid Rientjes unsigned long totalpages); 1025695be14SMichal Hocko 1036e0fc46dSDavid Rientjes extern bool out_of_memory(struct oom_control *oc); 10416e95196SJohannes Weiner 10538531201STetsuo Handa extern void exit_oom_victim(void); 10616e95196SJohannes Weiner 1075a3135c2SDavid Rientjes extern int register_oom_notifier(struct notifier_block *nb); 1085a3135c2SDavid Rientjes extern int unregister_oom_notifier(struct notifier_block *nb); 1095a3135c2SDavid Rientjes 1107d2e7a22SMichal Hocko extern bool oom_killer_disable(signed long timeout); 111c32b3cbeSMichal Hocko extern void oom_killer_enable(void); 1128e4228e1SDavid Rientjes 113158e0a2dSKAMEZAWA Hiroyuki extern struct task_struct *find_lock_task_mm(struct task_struct *p); 114158e0a2dSKAMEZAWA Hiroyuki 1155a3135c2SDavid Rientjes #endif /* _INCLUDE_LINUX_OOM_H */ 116