diff options
author | Johannes Weiner <hannes@cmpxchg.org> | 2013-09-12 18:13:42 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-09-12 18:38:01 -0400 |
commit | 519e52473ebe9db5cdef44670d5a97f1fd53d721 (patch) | |
tree | 635fce64ff3658250745b9c8dfebd47e981a5b16 /include/linux | |
parent | 3a13c4d761b4b979ba8767f42345fed3274991b0 (diff) |
mm: memcg: enable memcg OOM killer only for user faults
System calls and kernel faults (uaccess, gup) can handle an out of memory
situation gracefully and just return -ENOMEM.
Enable the memcg OOM killer only for user faults, where it's really the
only option available.
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Michal Hocko <mhocko@suse.cz>
Cc: David Rientjes <rientjes@google.com>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: azurIt <azurit@pobox.sk>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux')
-rw-r--r-- | include/linux/memcontrol.h | 44 | ||||
-rw-r--r-- | include/linux/sched.h | 3 |
2 files changed, 47 insertions, 0 deletions
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index d4d1f9b0dbba..34ac6497d01a 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h | |||
@@ -151,6 +151,37 @@ extern void mem_cgroup_print_oom_info(struct mem_cgroup *memcg, | |||
151 | extern void mem_cgroup_replace_page_cache(struct page *oldpage, | 151 | extern void mem_cgroup_replace_page_cache(struct page *oldpage, |
152 | struct page *newpage); | 152 | struct page *newpage); |
153 | 153 | ||
154 | /** | ||
155 | * mem_cgroup_toggle_oom - toggle the memcg OOM killer for the current task | ||
156 | * @new: true to enable, false to disable | ||
157 | * | ||
158 | * Toggle whether a failed memcg charge should invoke the OOM killer | ||
159 | * or just return -ENOMEM. Returns the previous toggle state. | ||
160 | */ | ||
161 | static inline bool mem_cgroup_toggle_oom(bool new) | ||
162 | { | ||
163 | bool old; | ||
164 | |||
165 | old = current->memcg_oom.may_oom; | ||
166 | current->memcg_oom.may_oom = new; | ||
167 | |||
168 | return old; | ||
169 | } | ||
170 | |||
171 | static inline void mem_cgroup_enable_oom(void) | ||
172 | { | ||
173 | bool old = mem_cgroup_toggle_oom(true); | ||
174 | |||
175 | WARN_ON(old == true); | ||
176 | } | ||
177 | |||
178 | static inline void mem_cgroup_disable_oom(void) | ||
179 | { | ||
180 | bool old = mem_cgroup_toggle_oom(false); | ||
181 | |||
182 | WARN_ON(old == false); | ||
183 | } | ||
184 | |||
154 | #ifdef CONFIG_MEMCG_SWAP | 185 | #ifdef CONFIG_MEMCG_SWAP |
155 | extern int do_swap_account; | 186 | extern int do_swap_account; |
156 | #endif | 187 | #endif |
@@ -383,6 +414,19 @@ static inline void mem_cgroup_end_update_page_stat(struct page *page, | |||
383 | { | 414 | { |
384 | } | 415 | } |
385 | 416 | ||
417 | static inline bool mem_cgroup_toggle_oom(bool new) | ||
418 | { | ||
419 | return false; | ||
420 | } | ||
421 | |||
422 | static inline void mem_cgroup_enable_oom(void) | ||
423 | { | ||
424 | } | ||
425 | |||
426 | static inline void mem_cgroup_disable_oom(void) | ||
427 | { | ||
428 | } | ||
429 | |||
386 | static inline void mem_cgroup_inc_page_stat(struct page *page, | 430 | static inline void mem_cgroup_inc_page_stat(struct page *page, |
387 | enum mem_cgroup_page_stat_item idx) | 431 | enum mem_cgroup_page_stat_item idx) |
388 | { | 432 | { |
diff --git a/include/linux/sched.h b/include/linux/sched.h index 45f254dddafc..9ce1fa53031f 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h | |||
@@ -1393,6 +1393,9 @@ struct task_struct { | |||
1393 | unsigned long memsw_nr_pages; /* uncharged mem+swap usage */ | 1393 | unsigned long memsw_nr_pages; /* uncharged mem+swap usage */ |
1394 | } memcg_batch; | 1394 | } memcg_batch; |
1395 | unsigned int memcg_kmem_skip_account; | 1395 | unsigned int memcg_kmem_skip_account; |
1396 | struct memcg_oom_info { | ||
1397 | unsigned int may_oom:1; | ||
1398 | } memcg_oom; | ||
1396 | #endif | 1399 | #endif |
1397 | #ifdef CONFIG_UPROBES | 1400 | #ifdef CONFIG_UPROBES |
1398 | struct uprobe_task *utask; | 1401 | struct uprobe_task *utask; |