linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: memcontrol: fix get_active_memcg return value
@ 2021-02-23  9:11 Muchun Song
  2021-02-23 15:18 ` Shakeel Butt
  2021-02-23 15:35 ` Roman Gushchin
  0 siblings, 2 replies; 3+ messages in thread
From: Muchun Song @ 2021-02-23  9:11 UTC (permalink / raw)
  To: hannes, mhocko, vdavydov.dev, akpm, guro, shakeelb
  Cc: cgroups, linux-mm, linux-kernel, Muchun Song

We use a global percpu int_active_memcg variable to store the remote
memcg when we are in the interrupt context. But get_active_memcg always
return the current->active_memcg or root_mem_cgroup. The remote memcg
(set in the interrupt context) is ignored. This is not what we want.
So fix it.

Fixes: 37d5985c003d ("mm: kmem: prepare remote memcg charging infra for interrupt contexts")
Signed-off-by: Muchun Song <songmuchun@bytedance.com>
---
 mm/memcontrol.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index be6bc5044150..bbe25655f7eb 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1061,13 +1061,9 @@ static __always_inline struct mem_cgroup *get_active_memcg(void)
 
 	rcu_read_lock();
 	memcg = active_memcg();
-	if (memcg) {
-		/* current->active_memcg must hold a ref. */
-		if (WARN_ON_ONCE(!css_tryget(&memcg->css)))
-			memcg = root_mem_cgroup;
-		else
-			memcg = current->active_memcg;
-	}
+	/* remote memcg must hold a ref. */
+	if (memcg && WARN_ON_ONCE(!css_tryget(&memcg->css)))
+		memcg = root_mem_cgroup;
 	rcu_read_unlock();
 
 	return memcg;
-- 
2.11.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm: memcontrol: fix get_active_memcg return value
  2021-02-23  9:11 [PATCH] mm: memcontrol: fix get_active_memcg return value Muchun Song
@ 2021-02-23 15:18 ` Shakeel Butt
  2021-02-23 15:35 ` Roman Gushchin
  1 sibling, 0 replies; 3+ messages in thread
From: Shakeel Butt @ 2021-02-23 15:18 UTC (permalink / raw)
  To: Muchun Song, stable
  Cc: Johannes Weiner, Michal Hocko, Vladimir Davydov, Andrew Morton,
	Roman Gushchin, Cgroups, Linux MM, LKML

On Tue, Feb 23, 2021 at 1:14 AM Muchun Song <songmuchun@bytedance.com> wrote:
>
> We use a global percpu int_active_memcg variable to store the remote
> memcg when we are in the interrupt context. But get_active_memcg always
> return the current->active_memcg or root_mem_cgroup. The remote memcg
> (set in the interrupt context) is ignored. This is not what we want.
> So fix it.
>
> Fixes: 37d5985c003d ("mm: kmem: prepare remote memcg charging infra for interrupt contexts")
> Signed-off-by: Muchun Song <songmuchun@bytedance.com>

Good catch.
Cc: stable@vger.kernel.org

Reviewed-by: Shakeel Butt <shakeelb@google.com>

> ---
>  mm/memcontrol.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index be6bc5044150..bbe25655f7eb 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -1061,13 +1061,9 @@ static __always_inline struct mem_cgroup *get_active_memcg(void)
>
>         rcu_read_lock();
>         memcg = active_memcg();
> -       if (memcg) {
> -               /* current->active_memcg must hold a ref. */
> -               if (WARN_ON_ONCE(!css_tryget(&memcg->css)))
> -                       memcg = root_mem_cgroup;
> -               else
> -                       memcg = current->active_memcg;
> -       }
> +       /* remote memcg must hold a ref. */
> +       if (memcg && WARN_ON_ONCE(!css_tryget(&memcg->css)))
> +               memcg = root_mem_cgroup;
>         rcu_read_unlock();
>
>         return memcg;
> --
> 2.11.0
>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm: memcontrol: fix get_active_memcg return value
  2021-02-23  9:11 [PATCH] mm: memcontrol: fix get_active_memcg return value Muchun Song
  2021-02-23 15:18 ` Shakeel Butt
@ 2021-02-23 15:35 ` Roman Gushchin
  1 sibling, 0 replies; 3+ messages in thread
From: Roman Gushchin @ 2021-02-23 15:35 UTC (permalink / raw)
  To: Muchun Song
  Cc: hannes, mhocko, vdavydov.dev, akpm, shakeelb, cgroups, linux-mm,
	linux-kernel

On Tue, Feb 23, 2021 at 05:11:01PM +0800, Muchun Song wrote:
> We use a global percpu int_active_memcg variable to store the remote
> memcg when we are in the interrupt context. But get_active_memcg always
> return the current->active_memcg or root_mem_cgroup. The remote memcg
> (set in the interrupt context) is ignored. This is not what we want.
> So fix it.
> 
> Fixes: 37d5985c003d ("mm: kmem: prepare remote memcg charging infra for interrupt contexts")
> Signed-off-by: Muchun Song <songmuchun@bytedance.com>
> ---
>  mm/memcontrol.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index be6bc5044150..bbe25655f7eb 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -1061,13 +1061,9 @@ static __always_inline struct mem_cgroup *get_active_memcg(void)
>  
>  	rcu_read_lock();
>  	memcg = active_memcg();
> -	if (memcg) {
> -		/* current->active_memcg must hold a ref. */
> -		if (WARN_ON_ONCE(!css_tryget(&memcg->css)))
> -			memcg = root_mem_cgroup;
> -		else
> -			memcg = current->active_memcg;
> -	}
> +	/* remote memcg must hold a ref. */
> +	if (memcg && WARN_ON_ONCE(!css_tryget(&memcg->css)))
> +		memcg = root_mem_cgroup;

Ouch, this is a good one!

Reviewed-by: Roman Gushchin <guro@fb.com>

Thank you!


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-02-23 15:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-23  9:11 [PATCH] mm: memcontrol: fix get_active_memcg return value Muchun Song
2021-02-23 15:18 ` Shakeel Butt
2021-02-23 15:35 ` Roman Gushchin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).