Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm: add a helper function to check may oom condition

Use helper function to check if we need to deal with oom condition.

Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
Acked-by: David Rientjes <rientjes@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Qiang Huang and committed by
Linus Torvalds
b9921ecd 9c2606b7

+7 -9
+5
include/linux/oom.h
··· 82 82 oom_killer_disabled = false; 83 83 } 84 84 85 + static inline bool oom_gfp_allowed(gfp_t gfp_mask) 86 + { 87 + return (gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY); 88 + } 89 + 85 90 extern struct task_struct *find_lock_task_mm(struct task_struct *p); 86 91 87 92 /* sysctls */
+1 -8
mm/memcontrol.c
··· 2984 2984 struct res_counter *fail_res; 2985 2985 struct mem_cgroup *_memcg; 2986 2986 int ret = 0; 2987 - bool may_oom; 2988 2987 2989 2988 ret = res_counter_charge(&memcg->kmem, size, &fail_res); 2990 2989 if (ret) 2991 2990 return ret; 2992 2991 2993 - /* 2994 - * Conditions under which we can wait for the oom_killer. Those are 2995 - * the same conditions tested by the core page allocator 2996 - */ 2997 - may_oom = (gfp & __GFP_FS) && !(gfp & __GFP_NORETRY); 2998 - 2999 2992 _memcg = memcg; 3000 2993 ret = __mem_cgroup_try_charge(NULL, gfp, size >> PAGE_SHIFT, 3001 - &_memcg, may_oom); 2994 + &_memcg, oom_gfp_allowed(gfp)); 3002 2995 3003 2996 if (ret == -EINTR) { 3004 2997 /*
+1 -1
mm/page_alloc.c
··· 2593 2593 * running out of options and have to consider going OOM 2594 2594 */ 2595 2595 if (!did_some_progress) { 2596 - if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY)) { 2596 + if (oom_gfp_allowed(gfp_mask)) { 2597 2597 if (oom_killer_disabled) 2598 2598 goto nopage; 2599 2599 /* Coredumps can quickly deplete all memory reserves */