blob: 49a3031fda50d1156bf0f67e77fea5ae2161537f [file] [log] [blame]
Alexey Dobriyan8ac773b2006-10-19 23:28:32 -07001#ifndef __INCLUDE_LINUX_OOM_H
2#define __INCLUDE_LINUX_OOM_H
3
David Rientjesa63d83f2010-08-09 17:19:46 -07004/*
David Rientjes51b1bd22010-08-09 17:19:47 -07005 * /proc/<pid>/oom_adj is deprecated, see
6 * Documentation/feature-removal-schedule.txt.
7 *
David Rientjesa63d83f2010-08-09 17:19:46 -07008 * /proc/<pid>/oom_adj set to -17 protects from the oom-killer
9 */
Alexey Dobriyan8ac773b2006-10-19 23:28:32 -070010#define OOM_DISABLE (-17)
11/* inclusive */
12#define OOM_ADJUST_MIN (-16)
13#define OOM_ADJUST_MAX 15
14
David Rientjesa63d83f2010-08-09 17:19:46 -070015/*
16 * /proc/<pid>/oom_score_adj set to OOM_SCORE_ADJ_MIN disables oom killing for
17 * pid.
18 */
19#define OOM_SCORE_ADJ_MIN (-1000)
20#define OOM_SCORE_ADJ_MAX 1000
21
David Rientjes5a3135c22007-10-16 23:25:53 -070022#ifdef __KERNEL__
23
David Rientjesa63d83f2010-08-09 17:19:46 -070024#include <linux/sched.h>
David Rientjes172acf62007-10-16 23:25:59 -070025#include <linux/types.h>
KAMEZAWA Hiroyuki4365a562009-12-15 16:45:33 -080026#include <linux/nodemask.h>
David Rientjes172acf62007-10-16 23:25:59 -070027
28struct zonelist;
29struct notifier_block;
Andrew Morton74bcbf42010-08-09 17:19:43 -070030struct mem_cgroup;
31struct task_struct;
David Rientjes172acf62007-10-16 23:25:59 -070032
David Rientjes70e24bd2007-10-16 23:25:53 -070033/*
34 * Types of limitations to the nodes from which allocations may occur
35 */
36enum oom_constraint {
37 CONSTRAINT_NONE,
38 CONSTRAINT_CPUSET,
39 CONSTRAINT_MEMORY_POLICY,
David Rientjes309ed882010-08-09 17:18:54 -070040 CONSTRAINT_MEMCG,
David Rientjes70e24bd2007-10-16 23:25:53 -070041};
42
David Rientjes9cbb78b2012-07-31 16:43:44 -070043enum oom_scan_t {
44 OOM_SCAN_OK, /* scan thread and find its badness */
45 OOM_SCAN_CONTINUE, /* do not consider thread for oom kill */
46 OOM_SCAN_ABORT, /* abort the iteration and return */
47 OOM_SCAN_SELECT, /* always select this thread first */
48};
49
David Rientjes43362a42011-10-31 17:07:18 -070050extern void compare_swap_oom_score_adj(int old_val, int new_val);
David Rientjes72788c32011-05-24 17:11:40 -070051extern int test_set_oom_score_adj(int new_val);
52
David Rientjesa7f638f2012-05-29 15:06:47 -070053extern unsigned long oom_badness(struct task_struct *p,
54 struct mem_cgroup *memcg, const nodemask_t *nodemask,
55 unsigned long totalpages);
David Rientjes9cbb78b2012-07-31 16:43:44 -070056extern void oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
57 unsigned int points, unsigned long totalpages,
58 struct mem_cgroup *memcg, nodemask_t *nodemask,
59 const char *message);
60
Minchan Kimff321fe2010-08-09 17:18:57 -070061extern int try_set_zonelist_oom(struct zonelist *zonelist, gfp_t gfp_flags);
Mel Gormandd1a2392008-04-28 02:12:17 -070062extern void clear_zonelist_oom(struct zonelist *zonelist, gfp_t gfp_flags);
David Rientjes098d7f12007-10-16 23:25:55 -070063
David Rientjes876aafb2012-07-31 16:43:48 -070064extern void check_panic_on_oom(enum oom_constraint constraint, gfp_t gfp_mask,
65 int order, const nodemask_t *nodemask);
66
David Rientjes9cbb78b2012-07-31 16:43:44 -070067extern enum oom_scan_t oom_scan_process_thread(struct task_struct *task,
68 unsigned long totalpages, const nodemask_t *nodemask,
69 bool force_kill);
David Rientjes62ce1c72012-07-31 16:43:39 -070070extern void mem_cgroup_out_of_memory(struct mem_cgroup *memcg, gfp_t gfp_mask,
71 int order);
David Rientjes9cbb78b2012-07-31 16:43:44 -070072
KAMEZAWA Hiroyuki4365a562009-12-15 16:45:33 -080073extern void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,
David Rientjes08ab9b12012-03-21 16:34:04 -070074 int order, nodemask_t *mask, bool force_kill);
David Rientjes5a3135c22007-10-16 23:25:53 -070075extern int register_oom_notifier(struct notifier_block *nb);
76extern int unregister_oom_notifier(struct notifier_block *nb);
77
Alexey Dobriyan1a8670a2009-09-21 17:03:09 -070078extern bool oom_killer_disabled;
79
80static inline void oom_killer_disable(void)
81{
82 oom_killer_disabled = true;
83}
84
85static inline void oom_killer_enable(void)
86{
87 oom_killer_disabled = false;
88}
David Rientjes8e4228e2010-08-09 17:18:56 -070089
KAMEZAWA Hiroyuki158e0a22010-08-10 18:03:00 -070090extern struct task_struct *find_lock_task_mm(struct task_struct *p);
91
David Rientjes8e4228e2010-08-09 17:18:56 -070092/* sysctls */
93extern int sysctl_oom_dump_tasks;
94extern int sysctl_oom_kill_allocating_task;
95extern int sysctl_panic_on_oom;
David Rientjes5a3135c22007-10-16 23:25:53 -070096#endif /* __KERNEL__*/
97#endif /* _INCLUDE_LINUX_OOM_H */