linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/memcontrol: fix wrong statistics in memory.stat
@ 2019-07-03  1:22 Yafang Shao
  2019-07-03  3:50 ` Shakeel Butt
  0 siblings, 1 reply; 6+ messages in thread
From: Yafang Shao @ 2019-07-03  1:22 UTC (permalink / raw)
  To: akpm; +Cc: linux-mm, Yafang Shao, Shakeel Butt, Michal Hocko, Yafang Shao

When we calculate total statistics for memcg1_stats and memcg1_events, we
use the the index 'i' in the for loop as the events index.
Actually we should use memcg1_stats[i] and memcg1_events[i] as the
events index.

Fixes: 8de7ecc6483b ("memcg: reduce memcg tree traversals for stats collection")
Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
Cc: Shakeel Butt <shakeelb@google.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Yafang Shao <shaoyafang@didiglobal.com>
---
 mm/memcontrol.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 3ee806b..2ad94d0 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3528,12 +3528,13 @@ static int memcg_stat_show(struct seq_file *m, void *v)
 		if (memcg1_stats[i] == MEMCG_SWAP && !do_memsw_account())
 			continue;
 		seq_printf(m, "total_%s %llu\n", memcg1_stat_names[i],
-			   (u64)memcg_page_state(memcg, i) * PAGE_SIZE);
+			   (u64)memcg_page_state(memcg, memcg1_stats[i]) *
+			   PAGE_SIZE);
 	}
 
 	for (i = 0; i < ARRAY_SIZE(memcg1_events); i++)
 		seq_printf(m, "total_%s %llu\n", memcg1_event_names[i],
-			   (u64)memcg_events(memcg, i));
+			   (u64)memcg_events(memcg, memcg1_events[i]));
 
 	for (i = 0; i < NR_LRU_LISTS; i++)
 		seq_printf(m, "total_%s %llu\n", mem_cgroup_lru_names[i],
-- 
1.8.3.1


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

* Re: [PATCH] mm/memcontrol: fix wrong statistics in memory.stat
  2019-07-03  1:22 [PATCH] mm/memcontrol: fix wrong statistics in memory.stat Yafang Shao
@ 2019-07-03  3:50 ` Shakeel Butt
  2019-07-03  3:51   ` Shakeel Butt
  2019-07-03  4:27   ` Yafang Shao
  0 siblings, 2 replies; 6+ messages in thread
From: Shakeel Butt @ 2019-07-03  3:50 UTC (permalink / raw)
  To: Yafang Shao; +Cc: Andrew Morton, Linux MM, Michal Hocko, Yafang Shao

+Johannes Weiner

On Tue, Jul 2, 2019 at 6:23 PM Yafang Shao <laoar.shao@gmail.com> wrote:
>
> When we calculate total statistics for memcg1_stats and memcg1_events, we
> use the the index 'i' in the for loop as the events index.
> Actually we should use memcg1_stats[i] and memcg1_events[i] as the
> events index.
>
> Fixes: 8de7ecc6483b ("memcg: reduce memcg tree traversals for stats collection")

Actually it fixes 42a300353577 ("mm: memcontrol: fix recursive
statistics correctness & scalabilty").

> Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
> Cc: Shakeel Butt <shakeelb@google.com>
> Cc: Michal Hocko <mhocko@suse.com>
> Cc: Yafang Shao <shaoyafang@didiglobal.com>
> ---
>  mm/memcontrol.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 3ee806b..2ad94d0 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -3528,12 +3528,13 @@ static int memcg_stat_show(struct seq_file *m, void *v)
>                 if (memcg1_stats[i] == MEMCG_SWAP && !do_memsw_account())
>                         continue;
>                 seq_printf(m, "total_%s %llu\n", memcg1_stat_names[i],
> -                          (u64)memcg_page_state(memcg, i) * PAGE_SIZE);
> +                          (u64)memcg_page_state(memcg, memcg1_stats[i]) *
> +                          PAGE_SIZE);

It seems like I made the above very subtle in 8de7ecc6483b and
Johannes missed this subtlety in 42a300353577 (and I missed it in the
review).

>         }
>
>         for (i = 0; i < ARRAY_SIZE(memcg1_events); i++)
>                 seq_printf(m, "total_%s %llu\n", memcg1_event_names[i],
> -                          (u64)memcg_events(memcg, i));
> +                          (u64)memcg_events(memcg, memcg1_events[i]));
>
>         for (i = 0; i < NR_LRU_LISTS; i++)
>                 seq_printf(m, "total_%s %llu\n", mem_cgroup_lru_names[i],
> --
> 1.8.3.1
>

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


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

* Re: [PATCH] mm/memcontrol: fix wrong statistics in memory.stat
  2019-07-03  3:50 ` Shakeel Butt
@ 2019-07-03  3:51   ` Shakeel Butt
  2019-07-03  4:27   ` Yafang Shao
  1 sibling, 0 replies; 6+ messages in thread
From: Shakeel Butt @ 2019-07-03  3:51 UTC (permalink / raw)
  To: Yafang Shao, Johannes Weiner
  Cc: Andrew Morton, Linux MM, Michal Hocko, Yafang Shao

+Johannes for real

On Tue, Jul 2, 2019 at 8:50 PM Shakeel Butt <shakeelb@google.com> wrote:
>
> +Johannes Weiner
>
> On Tue, Jul 2, 2019 at 6:23 PM Yafang Shao <laoar.shao@gmail.com> wrote:
> >
> > When we calculate total statistics for memcg1_stats and memcg1_events, we
> > use the the index 'i' in the for loop as the events index.
> > Actually we should use memcg1_stats[i] and memcg1_events[i] as the
> > events index.
> >
> > Fixes: 8de7ecc6483b ("memcg: reduce memcg tree traversals for stats collection")
>
> Actually it fixes 42a300353577 ("mm: memcontrol: fix recursive
> statistics correctness & scalabilty").
>
> > Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
> > Cc: Shakeel Butt <shakeelb@google.com>
> > Cc: Michal Hocko <mhocko@suse.com>
> > Cc: Yafang Shao <shaoyafang@didiglobal.com>
> > ---
> >  mm/memcontrol.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> > index 3ee806b..2ad94d0 100644
> > --- a/mm/memcontrol.c
> > +++ b/mm/memcontrol.c
> > @@ -3528,12 +3528,13 @@ static int memcg_stat_show(struct seq_file *m, void *v)
> >                 if (memcg1_stats[i] == MEMCG_SWAP && !do_memsw_account())
> >                         continue;
> >                 seq_printf(m, "total_%s %llu\n", memcg1_stat_names[i],
> > -                          (u64)memcg_page_state(memcg, i) * PAGE_SIZE);
> > +                          (u64)memcg_page_state(memcg, memcg1_stats[i]) *
> > +                          PAGE_SIZE);
>
> It seems like I made the above very subtle in 8de7ecc6483b and
> Johannes missed this subtlety in 42a300353577 (and I missed it in the
> review).
>
> >         }
> >
> >         for (i = 0; i < ARRAY_SIZE(memcg1_events); i++)
> >                 seq_printf(m, "total_%s %llu\n", memcg1_event_names[i],
> > -                          (u64)memcg_events(memcg, i));
> > +                          (u64)memcg_events(memcg, memcg1_events[i]));
> >
> >         for (i = 0; i < NR_LRU_LISTS; i++)
> >                 seq_printf(m, "total_%s %llu\n", mem_cgroup_lru_names[i],
> > --
> > 1.8.3.1
> >
>
> Reviewed-by: Shakeel Butt <shakeelb@google.com>


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

* Re: [PATCH] mm/memcontrol: fix wrong statistics in memory.stat
  2019-07-03  3:50 ` Shakeel Butt
  2019-07-03  3:51   ` Shakeel Butt
@ 2019-07-03  4:27   ` Yafang Shao
  2019-07-03  5:16     ` Shakeel Butt
  1 sibling, 1 reply; 6+ messages in thread
From: Yafang Shao @ 2019-07-03  4:27 UTC (permalink / raw)
  To: Shakeel Butt; +Cc: Andrew Morton, Linux MM, Michal Hocko, Yafang Shao

On Wed, Jul 3, 2019 at 11:50 AM Shakeel Butt <shakeelb@google.com> wrote:
>
> +Johannes Weiner
>
> On Tue, Jul 2, 2019 at 6:23 PM Yafang Shao <laoar.shao@gmail.com> wrote:
> >
> > When we calculate total statistics for memcg1_stats and memcg1_events, we
> > use the the index 'i' in the for loop as the events index.
> > Actually we should use memcg1_stats[i] and memcg1_events[i] as the
> > events index.
> >
> > Fixes: 8de7ecc6483b ("memcg: reduce memcg tree traversals for stats collection")
>
> Actually it fixes 42a300353577 ("mm: memcontrol: fix recursive
> statistics correctness & scalabilty").
>

Hi Shakeel,

In 8de7ecc6483b, this code was changed from memcg_page_state(mi,
memcg1_stats[i]) to acc.stat[i].

-               for_each_mem_cgroup_tree(mi, memcg)
-                       val += memcg_page_state(mi, memcg1_stats[i]) *
-                       PAGE_SIZE;
-               seq_printf(m, "total_%s %llu\n", memcg1_stat_names[i], val);
+               seq_printf(m, "total_%s %llu\n", memcg1_stat_names[i],
+                          (u64)acc.stat[i] * PAGE_SIZE);

In 42a300353577, this code was changed from acc.vmstats[i] to
memcg_events(memcg, i).
-                          (u64)acc.vmstats[i] * PAGE_SIZE);
+                          (u64)memcg_page_state(memcg, i) * PAGE_SIZE);

So seems this issue was introduced in 8de7ecc6483b, isn't it ?


> > Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
> > Cc: Shakeel Butt <shakeelb@google.com>
> > Cc: Michal Hocko <mhocko@suse.com>
> > Cc: Yafang Shao <shaoyafang@didiglobal.com>
> > ---
> >  mm/memcontrol.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> > index 3ee806b..2ad94d0 100644
> > --- a/mm/memcontrol.c
> > +++ b/mm/memcontrol.c
> > @@ -3528,12 +3528,13 @@ static int memcg_stat_show(struct seq_file *m, void *v)
> >                 if (memcg1_stats[i] == MEMCG_SWAP && !do_memsw_account())
> >                         continue;
> >                 seq_printf(m, "total_%s %llu\n", memcg1_stat_names[i],
> > -                          (u64)memcg_page_state(memcg, i) * PAGE_SIZE);
> > +                          (u64)memcg_page_state(memcg, memcg1_stats[i]) *
> > +                          PAGE_SIZE);
>
> It seems like I made the above very subtle in 8de7ecc6483b and
> Johannes missed this subtlety in 42a300353577 (and I missed it in the
> review).
>
> >         }
> >
> >         for (i = 0; i < ARRAY_SIZE(memcg1_events); i++)
> >                 seq_printf(m, "total_%s %llu\n", memcg1_event_names[i],
> > -                          (u64)memcg_events(memcg, i));
> > +                          (u64)memcg_events(memcg, memcg1_events[i]));
> >
> >         for (i = 0; i < NR_LRU_LISTS; i++)
> >                 seq_printf(m, "total_%s %llu\n", mem_cgroup_lru_names[i],
> > --
> > 1.8.3.1
> >
>
> Reviewed-by: Shakeel Butt <shakeelb@google.com>


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

* Re: [PATCH] mm/memcontrol: fix wrong statistics in memory.stat
  2019-07-03  4:27   ` Yafang Shao
@ 2019-07-03  5:16     ` Shakeel Butt
  2019-07-03  5:56       ` Yafang Shao
  0 siblings, 1 reply; 6+ messages in thread
From: Shakeel Butt @ 2019-07-03  5:16 UTC (permalink / raw)
  To: Yafang Shao; +Cc: Andrew Morton, Linux MM, Michal Hocko, Yafang Shao

On Tue, Jul 2, 2019 at 9:28 PM Yafang Shao <laoar.shao@gmail.com> wrote:
>
> On Wed, Jul 3, 2019 at 11:50 AM Shakeel Butt <shakeelb@google.com> wrote:
> >
> > +Johannes Weiner
> >
> > On Tue, Jul 2, 2019 at 6:23 PM Yafang Shao <laoar.shao@gmail.com> wrote:
> > >
> > > When we calculate total statistics for memcg1_stats and memcg1_events, we
> > > use the the index 'i' in the for loop as the events index.
> > > Actually we should use memcg1_stats[i] and memcg1_events[i] as the
> > > events index.
> > >
> > > Fixes: 8de7ecc6483b ("memcg: reduce memcg tree traversals for stats collection")
> >
> > Actually it fixes 42a300353577 ("mm: memcontrol: fix recursive
> > statistics correctness & scalabilty").
> >
>
> Hi Shakeel,
>
> In 8de7ecc6483b, this code was changed from memcg_page_state(mi,
> memcg1_stats[i]) to acc.stat[i].
>
> -               for_each_mem_cgroup_tree(mi, memcg)
> -                       val += memcg_page_state(mi, memcg1_stats[i]) *
> -                       PAGE_SIZE;
> -               seq_printf(m, "total_%s %llu\n", memcg1_stat_names[i], val);
> +               seq_printf(m, "total_%s %llu\n", memcg1_stat_names[i],
> +                          (u64)acc.stat[i] * PAGE_SIZE);
>
> In 42a300353577, this code was changed from acc.vmstats[i] to
> memcg_events(memcg, i).
> -                          (u64)acc.vmstats[i] * PAGE_SIZE);
> +                          (u64)memcg_page_state(memcg, i) * PAGE_SIZE);
>
> So seems this issue was introduced in 8de7ecc6483b, isn't it ?
>
>

That's the reason I said 8de7ecc6483b made it subtle but not wrong.
Check accumulate_memcg_tree() in 8de7ecc6483b, the memcg_page_state()
and memcg_events() are called with correct index but saved at 'i'
index in acc array.


> > > Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
> > > Cc: Shakeel Butt <shakeelb@google.com>
> > > Cc: Michal Hocko <mhocko@suse.com>
> > > Cc: Yafang Shao <shaoyafang@didiglobal.com>
> > > ---
> > >  mm/memcontrol.c | 5 +++--
> > >  1 file changed, 3 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> > > index 3ee806b..2ad94d0 100644
> > > --- a/mm/memcontrol.c
> > > +++ b/mm/memcontrol.c
> > > @@ -3528,12 +3528,13 @@ static int memcg_stat_show(struct seq_file *m, void *v)
> > >                 if (memcg1_stats[i] == MEMCG_SWAP && !do_memsw_account())
> > >                         continue;
> > >                 seq_printf(m, "total_%s %llu\n", memcg1_stat_names[i],
> > > -                          (u64)memcg_page_state(memcg, i) * PAGE_SIZE);
> > > +                          (u64)memcg_page_state(memcg, memcg1_stats[i]) *
> > > +                          PAGE_SIZE);
> >
> > It seems like I made the above very subtle in 8de7ecc6483b and
> > Johannes missed this subtlety in 42a300353577 (and I missed it in the
> > review).
> >
> > >         }
> > >
> > >         for (i = 0; i < ARRAY_SIZE(memcg1_events); i++)
> > >                 seq_printf(m, "total_%s %llu\n", memcg1_event_names[i],
> > > -                          (u64)memcg_events(memcg, i));
> > > +                          (u64)memcg_events(memcg, memcg1_events[i]));
> > >
> > >         for (i = 0; i < NR_LRU_LISTS; i++)
> > >                 seq_printf(m, "total_%s %llu\n", mem_cgroup_lru_names[i],
> > > --
> > > 1.8.3.1
> > >
> >
> > Reviewed-by: Shakeel Butt <shakeelb@google.com>


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

* Re: [PATCH] mm/memcontrol: fix wrong statistics in memory.stat
  2019-07-03  5:16     ` Shakeel Butt
@ 2019-07-03  5:56       ` Yafang Shao
  0 siblings, 0 replies; 6+ messages in thread
From: Yafang Shao @ 2019-07-03  5:56 UTC (permalink / raw)
  To: Shakeel Butt; +Cc: Andrew Morton, Linux MM, Michal Hocko, Yafang Shao

On Wed, Jul 3, 2019 at 1:17 PM Shakeel Butt <shakeelb@google.com> wrote:
>
> On Tue, Jul 2, 2019 at 9:28 PM Yafang Shao <laoar.shao@gmail.com> wrote:
> >
> > On Wed, Jul 3, 2019 at 11:50 AM Shakeel Butt <shakeelb@google.com> wrote:
> > >
> > > +Johannes Weiner
> > >
> > > On Tue, Jul 2, 2019 at 6:23 PM Yafang Shao <laoar.shao@gmail.com> wrote:
> > > >
> > > > When we calculate total statistics for memcg1_stats and memcg1_events, we
> > > > use the the index 'i' in the for loop as the events index.
> > > > Actually we should use memcg1_stats[i] and memcg1_events[i] as the
> > > > events index.
> > > >
> > > > Fixes: 8de7ecc6483b ("memcg: reduce memcg tree traversals for stats collection")
> > >
> > > Actually it fixes 42a300353577 ("mm: memcontrol: fix recursive
> > > statistics correctness & scalabilty").
> > >
> >
> > Hi Shakeel,
> >
> > In 8de7ecc6483b, this code was changed from memcg_page_state(mi,
> > memcg1_stats[i]) to acc.stat[i].
> >
> > -               for_each_mem_cgroup_tree(mi, memcg)
> > -                       val += memcg_page_state(mi, memcg1_stats[i]) *
> > -                       PAGE_SIZE;
> > -               seq_printf(m, "total_%s %llu\n", memcg1_stat_names[i], val);
> > +               seq_printf(m, "total_%s %llu\n", memcg1_stat_names[i],
> > +                          (u64)acc.stat[i] * PAGE_SIZE);
> >
> > In 42a300353577, this code was changed from acc.vmstats[i] to
> > memcg_events(memcg, i).
> > -                          (u64)acc.vmstats[i] * PAGE_SIZE);
> > +                          (u64)memcg_page_state(memcg, i) * PAGE_SIZE);
> >
> > So seems this issue was introduced in 8de7ecc6483b, isn't it ?
> >
> >
>
> That's the reason I said 8de7ecc6483b made it subtle but not wrong.
> Check accumulate_memcg_tree() in 8de7ecc6483b, the memcg_page_state()
> and memcg_events() are called with correct index but saved at 'i'
> index in acc array.
>

Got it. Thanks for your explanation and review.

Thanks
Yafang

>
> > > > Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
> > > > Cc: Shakeel Butt <shakeelb@google.com>
> > > > Cc: Michal Hocko <mhocko@suse.com>
> > > > Cc: Yafang Shao <shaoyafang@didiglobal.com>
> > > > ---
> > > >  mm/memcontrol.c | 5 +++--
> > > >  1 file changed, 3 insertions(+), 2 deletions(-)
> > > >
> > > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> > > > index 3ee806b..2ad94d0 100644
> > > > --- a/mm/memcontrol.c
> > > > +++ b/mm/memcontrol.c
> > > > @@ -3528,12 +3528,13 @@ static int memcg_stat_show(struct seq_file *m, void *v)
> > > >                 if (memcg1_stats[i] == MEMCG_SWAP && !do_memsw_account())
> > > >                         continue;
> > > >                 seq_printf(m, "total_%s %llu\n", memcg1_stat_names[i],
> > > > -                          (u64)memcg_page_state(memcg, i) * PAGE_SIZE);
> > > > +                          (u64)memcg_page_state(memcg, memcg1_stats[i]) *
> > > > +                          PAGE_SIZE);
> > >
> > > It seems like I made the above very subtle in 8de7ecc6483b and
> > > Johannes missed this subtlety in 42a300353577 (and I missed it in the
> > > review).
> > >
> > > >         }
> > > >
> > > >         for (i = 0; i < ARRAY_SIZE(memcg1_events); i++)
> > > >                 seq_printf(m, "total_%s %llu\n", memcg1_event_names[i],
> > > > -                          (u64)memcg_events(memcg, i));
> > > > +                          (u64)memcg_events(memcg, memcg1_events[i]));
> > > >
> > > >         for (i = 0; i < NR_LRU_LISTS; i++)
> > > >                 seq_printf(m, "total_%s %llu\n", mem_cgroup_lru_names[i],
> > > > --
> > > > 1.8.3.1
> > > >
> > >
> > > Reviewed-by: Shakeel Butt <shakeelb@google.com>


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

end of thread, other threads:[~2019-07-03  5:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-03  1:22 [PATCH] mm/memcontrol: fix wrong statistics in memory.stat Yafang Shao
2019-07-03  3:50 ` Shakeel Butt
2019-07-03  3:51   ` Shakeel Butt
2019-07-03  4:27   ` Yafang Shao
2019-07-03  5:16     ` Shakeel Butt
2019-07-03  5:56       ` Yafang Shao

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