8fb67b9e6110094c0409bcd615e79b5a14aeddd1
[linux-2.6-block.git] / include / linux / oom.h
1 #ifndef __INCLUDE_LINUX_OOM_H
2 #define __INCLUDE_LINUX_OOM_H
3
4
5 #include <linux/sched.h>
6 #include <linux/types.h>
7 #include <linux/nodemask.h>
8 #include <uapi/linux/oom.h>
9
10 struct zonelist;
11 struct notifier_block;
12 struct mem_cgroup;
13 struct task_struct;
14
15 struct oom_control {
16         struct zonelist *zonelist;
17         nodemask_t      *nodemask;
18         gfp_t           gfp_mask;
19         int             order;
20 };
21
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,
29         CONSTRAINT_MEMCG,
30 };
31
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
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
42 extern struct mutex oom_lock;
43
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 }
58
59 extern void mark_oom_victim(struct task_struct *tsk);
60
61 extern unsigned long oom_badness(struct task_struct *p,
62                 struct mem_cgroup *memcg, const nodemask_t *nodemask,
63                 unsigned long totalpages);
64
65 extern int oom_kills_count(void);
66 extern void note_oom_kill(void);
67 extern void oom_kill_process(struct oom_control *oc, struct task_struct *p,
68                              unsigned int points, unsigned long totalpages,
69                              struct mem_cgroup *memcg, const char *message);
70
71 extern void check_panic_on_oom(struct oom_control *oc,
72                                enum oom_constraint constraint,
73                                struct mem_cgroup *memcg);
74
75 extern enum oom_scan_t oom_scan_process_thread(struct oom_control *oc,
76                 struct task_struct *task, unsigned long totalpages);
77
78 extern bool out_of_memory(struct oom_control *oc);
79
80 extern void exit_oom_victim(void);
81
82 extern int register_oom_notifier(struct notifier_block *nb);
83 extern int unregister_oom_notifier(struct notifier_block *nb);
84
85 extern bool oom_killer_disabled;
86 extern bool oom_killer_disable(void);
87 extern void oom_killer_enable(void);
88
89 extern struct task_struct *find_lock_task_mm(struct task_struct *p);
90
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
102 /* sysctls */
103 extern int sysctl_oom_dump_tasks;
104 extern int sysctl_oom_kill_allocating_task;
105 extern int sysctl_panic_on_oom;
106 #endif /* _INCLUDE_LINUX_OOM_H */