Skip to content

Commit

Permalink
memcg: fix memcg_kmem_bypass() for remote memcg charging
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
lizf-os authored and torvalds committed Jun 2, 2020
1 parent 4b82ab4 commit 50d53d7
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion mm/memcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -2852,7 +2852,12 @@ static void memcg_schedule_kmem_cache_create(struct mem_cgroup *memcg,

static inline bool memcg_kmem_bypass(void)
{
if (in_interrupt() || !current->mm || (current->flags & PF_KTHREAD))
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;
}
Expand Down

0 comments on commit 50d53d7

Please sign in to comment.