]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
mm: kmem: enable kernel memcg accounting from interrupt contexts
authorRoman Gushchin <guro@fb.com>
Sat, 17 Oct 2020 23:13:53 +0000 (16:13 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sun, 18 Oct 2020 16:27:09 +0000 (09:27 -0700)
If a memcg to charge can be determined (using remote charging API), there
are no reasons to exclude allocations made from an interrupt context from
the accounting.

Such allocations will pass even if the resulting memcg size will exceed
the hard limit, but it will affect the application of the memory pressure
and an inability to put the workload under the limit will eventually
trigger the OOM.

To use active_memcg() helper, memcg_kmem_bypass() is moved back to
memcontrol.c.

Signed-off-by: Roman Gushchin <guro@fb.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Shakeel Butt <shakeelb@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>
Link: http://lkml.kernel.org/r/20200827225843.1270629-5-guro@fb.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/memcontrol.h
mm/memcontrol.c

index 6ef4a552e09d3ebfc0e1f0a0ca51d6efafdce480..e391e3c56de56f44ee7fe3f351ffe246e45dcbd7 100644 (file)
@@ -1531,18 +1531,6 @@ static inline bool memcg_kmem_enabled(void)
        return static_branch_likely(&memcg_kmem_enabled_key);
 }
 
-static inline bool memcg_kmem_bypass(void)
-{
-       if (in_interrupt())
-               return true;
-
-       /* Allow remote memcg charging in kthread contexts. */
-       if ((!current->mm || (current->flags & PF_KTHREAD)) &&
-            !current->active_memcg)
-               return true;
-       return false;
-}
-
 static inline int memcg_kmem_charge_page(struct page *page, gfp_t gfp,
                                         int order)
 {
index a3318b66e41ee3e04b7b2f81f144d684a56998e4..3a24e3b619f567efc5f0c5625974c0da854edcae 100644 (file)
@@ -1090,6 +1090,19 @@ static __always_inline struct mem_cgroup *get_active_memcg(void)
        return memcg;
 }
 
+static __always_inline bool memcg_kmem_bypass(void)
+{
+       /* Allow remote memcg charging from any context. */
+       if (unlikely(active_memcg()))
+               return false;
+
+       /* Memcg to charge can't be determined. */
+       if (in_interrupt() || !current->mm || (current->flags & PF_KTHREAD))
+               return true;
+
+       return false;
+}
+
 /**
  * If active memcg is set, do not fallback to current->mm->memcg.
  */