Skip to content

Commit 50d53d7

Browse files
lizf-ostorvalds
authored andcommitted
memcg: fix memcg_kmem_bypass() for remote memcg charging
While trying to use remote memcg charging in an out-of-tree kernel module I found it's not working, because the current thread is a workqueue thread. As we will probably encounter this issue in the future as the users of memalloc_use_memcg() grow, and it's nothing wrong for this usage, it's better we fix it now. Signed-off-by: Zefan Li <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Reviewed-by: Roman Gushchin <[email protected]> Reviewed-by: Shakeel Butt <[email protected]> Acked-by: Johannes Weiner <[email protected]> Acked-by: Michal Hocko <[email protected]> Cc: Vladimir Davydov <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Linus Torvalds <[email protected]>
1 parent 4b82ab4 commit 50d53d7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

mm/memcontrol.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2852,7 +2852,12 @@ static void memcg_schedule_kmem_cache_create(struct mem_cgroup *memcg,
28522852

28532853
static inline bool memcg_kmem_bypass(void)
28542854
{
2855-
if (in_interrupt() || !current->mm || (current->flags & PF_KTHREAD))
2855+
if (in_interrupt())
2856+
return true;
2857+
2858+
/* Allow remote memcg charging in kthread contexts. */
2859+
if ((!current->mm || (current->flags & PF_KTHREAD)) &&
2860+
!current->active_memcg)
28562861
return true;
28572862
return false;
28582863
}

0 commit comments

Comments
 (0)