blob: cb29085ded3714794a967f3c5455ddae6b2abe65 [file] [log] [blame]
Alexey Dobriyan8ac773b2006-10-19 23:28:32 -07001#ifndef __INCLUDE_LINUX_OOM_H
2#define __INCLUDE_LINUX_OOM_H
3
David Rientjes5a3135c22007-10-16 23:25:53 -07004
David Rientjesa63d83f2010-08-09 17:19:46 -07005#include <linux/sched.h>
David Rientjes172acf62007-10-16 23:25:59 -07006#include <linux/types.h>
KAMEZAWA Hiroyuki4365a562009-12-15 16:45:33 -08007#include <linux/nodemask.h>
David Howells607ca462012-10-13 10:46:48 +01008#include <uapi/linux/oom.h>
David Rientjes172acf62007-10-16 23:25:59 -07009
10struct zonelist;
11struct notifier_block;
Andrew Morton74bcbf42010-08-09 17:19:43 -070012struct mem_cgroup;
13struct task_struct;
David Rientjes172acf62007-10-16 23:25:59 -070014
David Rientjes6e0fc462015-09-08 15:00:36 -070015struct oom_control {
16 struct zonelist *zonelist;
17 nodemask_t *nodemask;
18 gfp_t gfp_mask;
19 int order;
20 bool force_kill;
21};
22
David Rientjes70e24bd2007-10-16 23:25:53 -070023/*
24 * Types of limitations to the nodes from which allocations may occur
25 */
26enum oom_constraint {
27 CONSTRAINT_NONE,
28 CONSTRAINT_CPUSET,
29 CONSTRAINT_MEMORY_POLICY,
David Rientjes309ed882010-08-09 17:18:54 -070030 CONSTRAINT_MEMCG,
David Rientjes70e24bd2007-10-16 23:25:53 -070031};
32
David Rientjes9cbb78b2012-07-31 16:43:44 -070033enum oom_scan_t {
34 OOM_SCAN_OK, /* scan thread and find its badness */
35 OOM_SCAN_CONTINUE, /* do not consider thread for oom kill */
36 OOM_SCAN_ABORT, /* abort the iteration and return */
37 OOM_SCAN_SELECT, /* always select this thread first */
38};
39
David Rientjese1e12d22012-12-11 16:02:56 -080040/* Thread is the potential origin of an oom condition; kill first on oom */
41#define OOM_FLAG_ORIGIN ((__force oom_flags_t)0x1)
42
Johannes Weinerdc564012015-06-24 16:57:19 -070043extern struct mutex oom_lock;
44
David Rientjese1e12d22012-12-11 16:02:56 -080045static inline void set_current_oom_origin(void)
46{
47 current->signal->oom_flags |= OOM_FLAG_ORIGIN;
48}
49
50static inline void clear_current_oom_origin(void)
51{
52 current->signal->oom_flags &= ~OOM_FLAG_ORIGIN;
53}
54
55static inline bool oom_task_origin(const struct task_struct *p)
56{
57 return !!(p->signal->oom_flags & OOM_FLAG_ORIGIN);
58}
David Rientjes72788c32011-05-24 17:11:40 -070059
Johannes Weiner16e95192015-06-24 16:57:07 -070060extern void mark_oom_victim(struct task_struct *tsk);
Michal Hocko49550b62015-02-11 15:26:12 -080061
David Rientjesa7f638f2012-05-29 15:06:47 -070062extern unsigned long oom_badness(struct task_struct *p,
63 struct mem_cgroup *memcg, const nodemask_t *nodemask,
64 unsigned long totalpages);
Michal Hocko5695be12014-10-20 18:12:32 +020065
66extern int oom_kills_count(void);
67extern void note_oom_kill(void);
David Rientjes6e0fc462015-09-08 15:00:36 -070068extern void oom_kill_process(struct oom_control *oc, struct task_struct *p,
David Rientjes9cbb78b2012-07-31 16:43:44 -070069 unsigned int points, unsigned long totalpages,
David Rientjes6e0fc462015-09-08 15:00:36 -070070 struct mem_cgroup *memcg, const char *message);
David Rientjes9cbb78b2012-07-31 16:43:44 -070071
David Rientjes6e0fc462015-09-08 15:00:36 -070072extern void check_panic_on_oom(struct oom_control *oc,
73 enum oom_constraint constraint,
Balasubramani Vivekanandan2415b9f2015-04-14 15:48:18 -070074 struct mem_cgroup *memcg);
David Rientjes876aafb2012-07-31 16:43:48 -070075
David Rientjes6e0fc462015-09-08 15:00:36 -070076extern enum oom_scan_t oom_scan_process_thread(struct oom_control *oc,
77 struct task_struct *task, unsigned long totalpages);
David Rientjes9cbb78b2012-07-31 16:43:44 -070078
David Rientjes6e0fc462015-09-08 15:00:36 -070079extern bool out_of_memory(struct oom_control *oc);
Johannes Weiner16e95192015-06-24 16:57:07 -070080
81extern void exit_oom_victim(void);
82
David Rientjes5a3135c22007-10-16 23:25:53 -070083extern int register_oom_notifier(struct notifier_block *nb);
84extern int unregister_oom_notifier(struct notifier_block *nb);
85
Alexey Dobriyan1a8670a2009-09-21 17:03:09 -070086extern bool oom_killer_disabled;
Michal Hockoc32b3cb2015-02-11 15:26:24 -080087extern bool oom_killer_disable(void);
88extern void oom_killer_enable(void);
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
Oleg Nesterovd003f372014-12-12 16:56:24 -080092static inline bool task_will_free_mem(struct task_struct *task)
93{
94 /*
95 * A coredumping process may sleep for an extended period in exit_mm(),
96 * so the oom killer cannot assume that the process will promptly exit
97 * and release memory.
98 */
99 return (task->flags & PF_EXITING) &&
100 !(task->signal->flags & SIGNAL_GROUP_COREDUMP);
101}
102
David Rientjes8e4228e2010-08-09 17:18:56 -0700103/* sysctls */
104extern int sysctl_oom_dump_tasks;
105extern int sysctl_oom_kill_allocating_task;
106extern int sysctl_panic_on_oom;
David Rientjes5a3135c22007-10-16 23:25:53 -0700107#endif /* _INCLUDE_LINUX_OOM_H */