diff options
author | Roman Gushchin <guro@fb.com> | 2020-09-17 11:57:54 +1000 |
---|---|---|
committer | Stephen Rothwell <sfr@canb.auug.org.au> | 2020-09-18 18:01:02 +1000 |
commit | 72304e768791c6c694cc8da09b5d2ecbe5fa18c8 (patch) | |
tree | f21d9d40131a3e08f2071bd8ab09ff6c247c0fc1 | |
parent | 33a6d3e8980fd2d95990b9d5ff78f7a82cd377b6 (diff) | |
download | linux-72304e768791c6c694cc8da09b5d2ecbe5fa18c8.tar.gz linux-72304e768791c6c694cc8da09b5d2ecbe5fa18c8.tar.xz |
mm: kmem: enable kernel memcg accounting from interrupt contexts
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.
Link: http://lkml.kernel.org/r/20200827225843.1270629-5-guro@fb.com
Signed-off-by: Roman Gushchin <guro@fb.com>
Reviewed-by: Shakeel Butt <shakeelb@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
-rw-r--r-- | include/linux/memcontrol.h | 12 | ||||
-rw-r--r-- | mm/memcontrol.c | 13 |
2 files changed, 13 insertions, 12 deletions
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 6ef4a552e09d..e391e3c56de5 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -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) { diff --git a/mm/memcontrol.c b/mm/memcontrol.c index e6338a81982c..0b3ca5749e4e 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -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. */ |