mm: add a helper function to check may oom condition
authorQiang Huang <h.huangqiang@huawei.com>
Tue, 12 Nov 2013 23:07:22 +0000 (15:07 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 13 Nov 2013 03:09:04 +0000 (12:09 +0900)
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>
include/linux/oom.h
mm/memcontrol.c
mm/page_alloc.c

index da60007075b509b864d386b3d9092c77aec97c64..4cd62677feb9eaf8f9a4647231663a8d7a42f986 100644 (file)
@@ -82,6 +82,11 @@ static inline void oom_killer_enable(void)
        oom_killer_disabled = false;
 }
 
+static inline bool oom_gfp_allowed(gfp_t gfp_mask)
+{
+       return (gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY);
+}
+
 extern struct task_struct *find_lock_task_mm(struct task_struct *p);
 
 /* sysctls */
index 13b9d0f221b8460ae3c361dd51d22ae969e78325..3427de9897a59b63a66ccc916ef4d87759cfbbfb 100644 (file)
@@ -2984,21 +2984,14 @@ static int memcg_charge_kmem(struct mem_cgroup *memcg, gfp_t gfp, u64 size)
        struct res_counter *fail_res;
        struct mem_cgroup *_memcg;
        int ret = 0;
-       bool may_oom;
 
        ret = res_counter_charge(&memcg->kmem, size, &fail_res);
        if (ret)
                return ret;
 
-       /*
-        * Conditions under which we can wait for the oom_killer. Those are
-        * the same conditions tested by the core page allocator
-        */
-       may_oom = (gfp & __GFP_FS) && !(gfp & __GFP_NORETRY);
-
        _memcg = memcg;
        ret = __mem_cgroup_try_charge(NULL, gfp, size >> PAGE_SHIFT,
-                                     &_memcg, may_oom);
+                                     &_memcg, oom_gfp_allowed(gfp));
 
        if (ret == -EINTR)  {
                /*
index 3d1d75a6629f6161681227668378877f060c8746..e0412c026e0da066d8a3b9b533ae60407e7d1cd4 100644 (file)
@@ -2593,7 +2593,7 @@ rebalance:
         * running out of options and have to consider going OOM
         */
        if (!did_some_progress) {
-               if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY)) {
+               if (oom_gfp_allowed(gfp_mask)) {
                        if (oom_killer_disabled)
                                goto nopage;
                        /* Coredumps can quickly deplete all memory reserves */