mm: memcontrol: do not recurse in direct reclaim
[firefly-linux-kernel-4.4.55.git] / mm / memcontrol.c
index 6b90d184e9c0eaa59332c4e393884472423e6e39..5d9c8a3136bc0404e086487b7b4a87a102a2fe2c 100644 (file)
@@ -2055,6 +2055,15 @@ retry:
                     current->flags & PF_EXITING))
                goto force;
 
+       /*
+        * Prevent unbounded recursion when reclaim operations need to
+        * allocate memory. This might exceed the limits temporarily,
+        * but we prefer facilitating memory reclaim and getting back
+        * under the limit over triggering OOM kills in these cases.
+        */
+       if (unlikely(current->flags & PF_MEMALLOC))
+               goto force;
+
        if (unlikely(task_in_memcg_oom(current)))
                goto nomem;