Commit | Line | Data |
---|---|---|
8ac773b4 AD |
1 | #ifndef __INCLUDE_LINUX_OOM_H |
2 | #define __INCLUDE_LINUX_OOM_H | |
3 | ||
5a3135c2 | 4 | |
a63d83f4 | 5 | #include <linux/sched.h> |
172acf60 | 6 | #include <linux/types.h> |
4365a567 | 7 | #include <linux/nodemask.h> |
607ca46e | 8 | #include <uapi/linux/oom.h> |
172acf60 DR |
9 | |
10 | struct zonelist; | |
11 | struct notifier_block; | |
74bcbf40 AM |
12 | struct mem_cgroup; |
13 | struct task_struct; | |
172acf60 | 14 | |
6e0fc46d DR |
15 | struct oom_control { |
16 | struct zonelist *zonelist; | |
17 | nodemask_t *nodemask; | |
18 | gfp_t gfp_mask; | |
19 | int order; | |
6e0fc46d DR |
20 | }; |
21 | ||
70e24bdf DR |
22 | /* |
23 | * Types of limitations to the nodes from which allocations may occur | |
24 | */ | |
25 | enum oom_constraint { | |
26 | CONSTRAINT_NONE, | |
27 | CONSTRAINT_CPUSET, | |
28 | CONSTRAINT_MEMORY_POLICY, | |
309ed882 | 29 | CONSTRAINT_MEMCG, |
70e24bdf DR |
30 | }; |
31 | ||
9cbb78bb DR |
32 | enum oom_scan_t { |
33 | OOM_SCAN_OK, /* scan thread and find its badness */ | |
34 | OOM_SCAN_CONTINUE, /* do not consider thread for oom kill */ | |
35 | OOM_SCAN_ABORT, /* abort the iteration and return */ | |
36 | OOM_SCAN_SELECT, /* always select this thread first */ | |
37 | }; | |
38 | ||
e1e12d2f DR |
39 | /* Thread is the potential origin of an oom condition; kill first on oom */ |
40 | #define OOM_FLAG_ORIGIN ((__force oom_flags_t)0x1) | |
41 | ||
dc56401f JW |
42 | extern struct mutex oom_lock; |
43 | ||
e1e12d2f DR |
44 | static inline void set_current_oom_origin(void) |
45 | { | |
46 | current->signal->oom_flags |= OOM_FLAG_ORIGIN; | |
47 | } | |
48 | ||
49 | static inline void clear_current_oom_origin(void) | |
50 | { | |
51 | current->signal->oom_flags &= ~OOM_FLAG_ORIGIN; | |
52 | } | |
53 | ||
54 | static inline bool oom_task_origin(const struct task_struct *p) | |
55 | { | |
56 | return !!(p->signal->oom_flags & OOM_FLAG_ORIGIN); | |
57 | } | |
72788c38 | 58 | |
16e95196 | 59 | extern void mark_oom_victim(struct task_struct *tsk); |
49550b60 | 60 | |
a7f638f9 DR |
61 | extern unsigned long oom_badness(struct task_struct *p, |
62 | struct mem_cgroup *memcg, const nodemask_t *nodemask, | |
63 | unsigned long totalpages); | |
5695be14 MH |
64 | |
65 | extern int oom_kills_count(void); | |
66 | extern void note_oom_kill(void); | |
6e0fc46d | 67 | extern void oom_kill_process(struct oom_control *oc, struct task_struct *p, |
9cbb78bb | 68 | unsigned int points, unsigned long totalpages, |
6e0fc46d | 69 | struct mem_cgroup *memcg, const char *message); |
9cbb78bb | 70 | |
6e0fc46d DR |
71 | extern void check_panic_on_oom(struct oom_control *oc, |
72 | enum oom_constraint constraint, | |
2415b9f5 | 73 | struct mem_cgroup *memcg); |
876aafbf | 74 | |
6e0fc46d DR |
75 | extern enum oom_scan_t oom_scan_process_thread(struct oom_control *oc, |
76 | struct task_struct *task, unsigned long totalpages); | |
9cbb78bb | 77 | |
6e0fc46d | 78 | extern bool out_of_memory(struct oom_control *oc); |
16e95196 JW |
79 | |
80 | extern void exit_oom_victim(void); | |
81 | ||
5a3135c2 DR |
82 | extern int register_oom_notifier(struct notifier_block *nb); |
83 | extern int unregister_oom_notifier(struct notifier_block *nb); | |
84 | ||
1a8670a2 | 85 | extern bool oom_killer_disabled; |
c32b3cbe MH |
86 | extern bool oom_killer_disable(void); |
87 | extern void oom_killer_enable(void); | |
8e4228e1 | 88 | |
158e0a2d KH |
89 | extern struct task_struct *find_lock_task_mm(struct task_struct *p); |
90 | ||
d003f371 ON |
91 | static inline bool task_will_free_mem(struct task_struct *task) |
92 | { | |
93 | /* | |
94 | * A coredumping process may sleep for an extended period in exit_mm(), | |
95 | * so the oom killer cannot assume that the process will promptly exit | |
96 | * and release memory. | |
97 | */ | |
98 | return (task->flags & PF_EXITING) && | |
99 | !(task->signal->flags & SIGNAL_GROUP_COREDUMP); | |
100 | } | |
101 | ||
8e4228e1 DR |
102 | /* sysctls */ |
103 | extern int sysctl_oom_dump_tasks; | |
104 | extern int sysctl_oom_kill_allocating_task; | |
105 | extern int sysctl_panic_on_oom; | |
5a3135c2 | 106 | #endif /* _INCLUDE_LINUX_OOM_H */ |