linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: memcontrol: fix percpu vmstats and vmevents flush
@ 2019-08-29 20:31 Shakeel Butt
  2019-08-29 20:40 ` Roman Gushchin
  2019-08-30  5:49 ` Michal Hocko
  0 siblings, 2 replies; 3+ messages in thread
From: Shakeel Butt @ 2019-08-29 20:31 UTC (permalink / raw)
  To: Roman Gushchin
  Cc: linux-mm, cgroups, linux-kernel, Shakeel Butt, Michal Hocko,
	Johannes Weiner, Vladimir Davydov, Andrew Morton, stable

Instead of using raw_cpu_read() use per_cpu() to read the actual data of
the corresponding cpu otherwise we will be reading the data of the
current cpu for the number of online CPUs.

Fixes: bb65f89b7d3d ("mm: memcontrol: flush percpu vmevents before releasing memcg")
Fixes: c350a99ea2b1 ("mm: memcontrol: flush percpu vmstats before releasing memcg")
Signed-off-by: Shakeel Butt <shakeelb@google.com>
Cc: Roman Gushchin <guro@fb.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: <stable@vger.kernel.org>
---

Note: The buggy patches were marked for stable therefore adding Cc to
stable.

 mm/memcontrol.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 26e2999af608..f4e60ee8b845 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3271,7 +3271,7 @@ static void memcg_flush_percpu_vmstats(struct mem_cgroup *memcg)
 
 	for_each_online_cpu(cpu)
 		for (i = 0; i < MEMCG_NR_STAT; i++)
-			stat[i] += raw_cpu_read(memcg->vmstats_percpu->stat[i]);
+			stat[i] += per_cpu(memcg->vmstats_percpu->stat[i], cpu);
 
 	for (mi = memcg; mi; mi = parent_mem_cgroup(mi))
 		for (i = 0; i < MEMCG_NR_STAT; i++)
@@ -3286,8 +3286,8 @@ static void memcg_flush_percpu_vmstats(struct mem_cgroup *memcg)
 
 		for_each_online_cpu(cpu)
 			for (i = 0; i < NR_VM_NODE_STAT_ITEMS; i++)
-				stat[i] += raw_cpu_read(
-					pn->lruvec_stat_cpu->count[i]);
+				stat[i] += per_cpu(
+					pn->lruvec_stat_cpu->count[i], cpu);
 
 		for (pi = pn; pi; pi = parent_nodeinfo(pi, node))
 			for (i = 0; i < NR_VM_NODE_STAT_ITEMS; i++)
@@ -3306,8 +3306,8 @@ static void memcg_flush_percpu_vmevents(struct mem_cgroup *memcg)
 
 	for_each_online_cpu(cpu)
 		for (i = 0; i < NR_VM_EVENT_ITEMS; i++)
-			events[i] += raw_cpu_read(
-				memcg->vmstats_percpu->events[i]);
+			events[i] += per_cpu(memcg->vmstats_percpu->events[i],
+					     cpu);
 
 	for (mi = memcg; mi; mi = parent_mem_cgroup(mi))
 		for (i = 0; i < NR_VM_EVENT_ITEMS; i++)
-- 
2.23.0.187.g17f5b7556c-goog



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

* Re: [PATCH] mm: memcontrol: fix percpu vmstats and vmevents flush
  2019-08-29 20:31 [PATCH] mm: memcontrol: fix percpu vmstats and vmevents flush Shakeel Butt
@ 2019-08-29 20:40 ` Roman Gushchin
  2019-08-30  5:49 ` Michal Hocko
  1 sibling, 0 replies; 3+ messages in thread
From: Roman Gushchin @ 2019-08-29 20:40 UTC (permalink / raw)
  To: Shakeel Butt
  Cc: linux-mm, cgroups, linux-kernel, Michal Hocko, Johannes Weiner,
	Vladimir Davydov, Andrew Morton, stable

On Thu, Aug 29, 2019 at 01:31:10PM -0700, Shakeel Butt wrote:
> Instead of using raw_cpu_read() use per_cpu() to read the actual data of
> the corresponding cpu otherwise we will be reading the data of the
> current cpu for the number of online CPUs.
> 
> Fixes: bb65f89b7d3d ("mm: memcontrol: flush percpu vmevents before releasing memcg")
> Fixes: c350a99ea2b1 ("mm: memcontrol: flush percpu vmstats before releasing memcg")
> Signed-off-by: Shakeel Butt <shakeelb@google.com>
> Cc: Roman Gushchin <guro@fb.com>
> Cc: Michal Hocko <mhocko@suse.com>
> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: <stable@vger.kernel.org>

Ouch, thanks Shakeel!

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


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

* Re: [PATCH] mm: memcontrol: fix percpu vmstats and vmevents flush
  2019-08-29 20:31 [PATCH] mm: memcontrol: fix percpu vmstats and vmevents flush Shakeel Butt
  2019-08-29 20:40 ` Roman Gushchin
@ 2019-08-30  5:49 ` Michal Hocko
  1 sibling, 0 replies; 3+ messages in thread
From: Michal Hocko @ 2019-08-30  5:49 UTC (permalink / raw)
  To: Shakeel Butt
  Cc: Roman Gushchin, linux-mm, cgroups, linux-kernel, Johannes Weiner,
	Vladimir Davydov, Andrew Morton, stable

On Thu 29-08-19 13:31:10, Shakeel Butt wrote:
> Instead of using raw_cpu_read() use per_cpu() to read the actual data of
> the corresponding cpu otherwise we will be reading the data of the
> current cpu for the number of online CPUs.
> 
> Fixes: bb65f89b7d3d ("mm: memcontrol: flush percpu vmevents before releasing memcg")
> Fixes: c350a99ea2b1 ("mm: memcontrol: flush percpu vmstats before releasing memcg")
> Signed-off-by: Shakeel Butt <shakeelb@google.com>
> Cc: Roman Gushchin <guro@fb.com>
> Cc: Michal Hocko <mhocko@suse.com>
> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: <stable@vger.kernel.org>

Ups, missed that when reviewing. Sorry about that.

Acked-by: Michal Hocko <mhocko@suse.com>

> ---
> 
> Note: The buggy patches were marked for stable therefore adding Cc to
> stable.
> 
>  mm/memcontrol.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 26e2999af608..f4e60ee8b845 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -3271,7 +3271,7 @@ static void memcg_flush_percpu_vmstats(struct mem_cgroup *memcg)
>  
>  	for_each_online_cpu(cpu)
>  		for (i = 0; i < MEMCG_NR_STAT; i++)
> -			stat[i] += raw_cpu_read(memcg->vmstats_percpu->stat[i]);
> +			stat[i] += per_cpu(memcg->vmstats_percpu->stat[i], cpu);
>  
>  	for (mi = memcg; mi; mi = parent_mem_cgroup(mi))
>  		for (i = 0; i < MEMCG_NR_STAT; i++)
> @@ -3286,8 +3286,8 @@ static void memcg_flush_percpu_vmstats(struct mem_cgroup *memcg)
>  
>  		for_each_online_cpu(cpu)
>  			for (i = 0; i < NR_VM_NODE_STAT_ITEMS; i++)
> -				stat[i] += raw_cpu_read(
> -					pn->lruvec_stat_cpu->count[i]);
> +				stat[i] += per_cpu(
> +					pn->lruvec_stat_cpu->count[i], cpu);
>  
>  		for (pi = pn; pi; pi = parent_nodeinfo(pi, node))
>  			for (i = 0; i < NR_VM_NODE_STAT_ITEMS; i++)
> @@ -3306,8 +3306,8 @@ static void memcg_flush_percpu_vmevents(struct mem_cgroup *memcg)
>  
>  	for_each_online_cpu(cpu)
>  		for (i = 0; i < NR_VM_EVENT_ITEMS; i++)
> -			events[i] += raw_cpu_read(
> -				memcg->vmstats_percpu->events[i]);
> +			events[i] += per_cpu(memcg->vmstats_percpu->events[i],
> +					     cpu);
>  
>  	for (mi = memcg; mi; mi = parent_mem_cgroup(mi))
>  		for (i = 0; i < NR_VM_EVENT_ITEMS; i++)
> -- 
> 2.23.0.187.g17f5b7556c-goog
> 

-- 
Michal Hocko
SUSE Labs


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

end of thread, other threads:[~2019-08-30  5:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-29 20:31 [PATCH] mm: memcontrol: fix percpu vmstats and vmevents flush Shakeel Butt
2019-08-29 20:40 ` Roman Gushchin
2019-08-30  5:49 ` Michal Hocko

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).