Skip to content

Commit 4127c65

Browse files
rgushchintorvalds
authored andcommitted
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. 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>
1 parent 37d5985 commit 4127c65

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

include/linux/memcontrol.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,18 +1531,6 @@ static inline bool memcg_kmem_enabled(void)
15311531
return static_branch_likely(&memcg_kmem_enabled_key);
15321532
}
15331533

1534-
static inline bool memcg_kmem_bypass(void)
1535-
{
1536-
if (in_interrupt())
1537-
return true;
1538-
1539-
/* Allow remote memcg charging in kthread contexts. */
1540-
if ((!current->mm || (current->flags & PF_KTHREAD)) &&
1541-
!current->active_memcg)
1542-
return true;
1543-
return false;
1544-
}
1545-
15461534
static inline int memcg_kmem_charge_page(struct page *page, gfp_t gfp,
15471535
int order)
15481536
{

mm/memcontrol.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,6 +1090,19 @@ static __always_inline struct mem_cgroup *get_active_memcg(void)
10901090
return memcg;
10911091
}
10921092

1093+
static __always_inline bool memcg_kmem_bypass(void)
1094+
{
1095+
/* Allow remote memcg charging from any context. */
1096+
if (unlikely(active_memcg()))
1097+
return false;
1098+
1099+
/* Memcg to charge can't be determined. */
1100+
if (in_interrupt() || !current->mm || (current->flags & PF_KTHREAD))
1101+
return true;
1102+
1103+
return false;
1104+
}
1105+
10931106
/**
10941107
* If active memcg is set, do not fallback to current->mm->memcg.
10951108
*/

0 commit comments

Comments
 (0)