Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __INCLUDE_LINUX_OOM_H
0003 #define __INCLUDE_LINUX_OOM_H
0004 
0005 
0006 #include <linux/sched/signal.h>
0007 #include <linux/types.h>
0008 #include <linux/nodemask.h>
0009 #include <uapi/linux/oom.h>
0010 #include <linux/sched/coredump.h> /* MMF_* */
0011 #include <linux/mm.h> /* VM_FAULT* */
0012 
0013 struct zonelist;
0014 struct notifier_block;
0015 struct mem_cgroup;
0016 struct task_struct;
0017 
0018 enum oom_constraint {
0019     CONSTRAINT_NONE,
0020     CONSTRAINT_CPUSET,
0021     CONSTRAINT_MEMORY_POLICY,
0022     CONSTRAINT_MEMCG,
0023 };
0024 
0025 /*
0026  * Details of the page allocation that triggered the oom killer that are used to
0027  * determine what should be killed.
0028  */
0029 struct oom_control {
0030     /* Used to determine cpuset */
0031     struct zonelist *zonelist;
0032 
0033     /* Used to determine mempolicy */
0034     nodemask_t *nodemask;
0035 
0036     /* Memory cgroup in which oom is invoked, or NULL for global oom */
0037     struct mem_cgroup *memcg;
0038 
0039     /* Used to determine cpuset and node locality requirement */
0040     const gfp_t gfp_mask;
0041 
0042     /*
0043      * order == -1 means the oom kill is required by sysrq, otherwise only
0044      * for display purposes.
0045      */
0046     const int order;
0047 
0048     /* Used by oom implementation, do not set */
0049     unsigned long totalpages;
0050     struct task_struct *chosen;
0051     long chosen_points;
0052 
0053     /* Used to print the constraint info. */
0054     enum oom_constraint constraint;
0055 };
0056 
0057 extern struct mutex oom_lock;
0058 extern struct mutex oom_adj_mutex;
0059 
0060 static inline void set_current_oom_origin(void)
0061 {
0062     current->signal->oom_flag_origin = true;
0063 }
0064 
0065 static inline void clear_current_oom_origin(void)
0066 {
0067     current->signal->oom_flag_origin = false;
0068 }
0069 
0070 static inline bool oom_task_origin(const struct task_struct *p)
0071 {
0072     return p->signal->oom_flag_origin;
0073 }
0074 
0075 static inline bool tsk_is_oom_victim(struct task_struct * tsk)
0076 {
0077     return tsk->signal->oom_mm;
0078 }
0079 
0080 /*
0081  * Use this helper if tsk->mm != mm and the victim mm needs a special
0082  * handling. This is guaranteed to stay true after once set.
0083  */
0084 static inline bool mm_is_oom_victim(struct mm_struct *mm)
0085 {
0086     return test_bit(MMF_OOM_VICTIM, &mm->flags);
0087 }
0088 
0089 /*
0090  * Checks whether a page fault on the given mm is still reliable.
0091  * This is no longer true if the oom reaper started to reap the
0092  * address space which is reflected by MMF_UNSTABLE flag set in
0093  * the mm. At that moment any !shared mapping would lose the content
0094  * and could cause a memory corruption (zero pages instead of the
0095  * original content).
0096  *
0097  * User should call this before establishing a page table entry for
0098  * a !shared mapping and under the proper page table lock.
0099  *
0100  * Return 0 when the PF is safe VM_FAULT_SIGBUS otherwise.
0101  */
0102 static inline vm_fault_t check_stable_address_space(struct mm_struct *mm)
0103 {
0104     if (unlikely(test_bit(MMF_UNSTABLE, &mm->flags)))
0105         return VM_FAULT_SIGBUS;
0106     return 0;
0107 }
0108 
0109 bool __oom_reap_task_mm(struct mm_struct *mm);
0110 
0111 long oom_badness(struct task_struct *p,
0112         unsigned long totalpages);
0113 
0114 extern bool out_of_memory(struct oom_control *oc);
0115 
0116 extern void exit_oom_victim(void);
0117 
0118 extern int register_oom_notifier(struct notifier_block *nb);
0119 extern int unregister_oom_notifier(struct notifier_block *nb);
0120 
0121 extern bool oom_killer_disable(signed long timeout);
0122 extern void oom_killer_enable(void);
0123 
0124 extern struct task_struct *find_lock_task_mm(struct task_struct *p);
0125 
0126 #endif /* _INCLUDE_LINUX_OOM_H */