linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: memcontrol: correct the NR_ANON_THPS counter of hierarchical memcg
@ 2020-10-26 14:26 zhongjiang-ali
  2020-10-26 14:47 ` Johannes Weiner
  2020-10-26 14:47 ` Michal Hocko
  0 siblings, 2 replies; 5+ messages in thread
From: zhongjiang-ali @ 2020-10-26 14:26 UTC (permalink / raw)
  To: hannes, mhocko, vdavydov.dev, akpm; +Cc: linux-mm

memcg_page_state will get the specified number in hierarchical memcg,
It should multiply by HPAGE_PMD_NR rather than an page if the item is
NR_ANON_THPS.

Fixes: 468c398233da ("mm: memcontrol: switch to native NR_ANON_THPS counter")
Signed-off-by: zhongjiang-ali <zhongjiang-ali@linux.alibaba.com>
---
 mm/memcontrol.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 3a24e3b..c27898e 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4110,11 +4110,17 @@ static int memcg_stat_show(struct seq_file *m, void *v)
 			   (u64)memsw * PAGE_SIZE);
 
 	for (i = 0; i < ARRAY_SIZE(memcg1_stats); i++) {
+		unsigned long nr;
+
 		if (memcg1_stats[i] == MEMCG_SWAP && !do_memsw_account())
 			continue;
+		nr = memcg_page_state(memcg, memcg1_stats[i]);
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
+		if (memcg1_stats[i] == NR_ANON_THPS)
+			nr *= HPAGE_PMD_NR;
+#endif
 		seq_printf(m, "total_%s %llu\n", memcg1_stat_names[i],
-			   (u64)memcg_page_state(memcg, memcg1_stats[i]) *
-			   PAGE_SIZE);
+						nr * PAGE_SIZE);
 	}
 
 	for (i = 0; i < ARRAY_SIZE(memcg1_events); i++)
-- 
1.8.3.1



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

* Re: [PATCH] mm: memcontrol: correct the NR_ANON_THPS counter of hierarchical memcg
  2020-10-26 14:26 [PATCH] mm: memcontrol: correct the NR_ANON_THPS counter of hierarchical memcg zhongjiang-ali
@ 2020-10-26 14:47 ` Johannes Weiner
  2020-10-26 14:47 ` Michal Hocko
  1 sibling, 0 replies; 5+ messages in thread
From: Johannes Weiner @ 2020-10-26 14:47 UTC (permalink / raw)
  To: zhongjiang-ali; +Cc: mhocko, vdavydov.dev, akpm, linux-mm

On Mon, Oct 26, 2020 at 10:26:35PM +0800, zhongjiang-ali wrote:
> memcg_page_state will get the specified number in hierarchical memcg,
> It should multiply by HPAGE_PMD_NR rather than an page if the item is
> NR_ANON_THPS.
> 
> Fixes: 468c398233da ("mm: memcontrol: switch to native NR_ANON_THPS counter")
> Signed-off-by: zhongjiang-ali <zhongjiang-ali@linux.alibaba.com>

Acked-by: Johannes Weiner <hannes@cmpxchg.org>


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

* Re: [PATCH] mm: memcontrol: correct the NR_ANON_THPS counter of hierarchical memcg
  2020-10-26 14:26 [PATCH] mm: memcontrol: correct the NR_ANON_THPS counter of hierarchical memcg zhongjiang-ali
  2020-10-26 14:47 ` Johannes Weiner
@ 2020-10-26 14:47 ` Michal Hocko
  2020-10-26 16:31   ` Johannes Weiner
  1 sibling, 1 reply; 5+ messages in thread
From: Michal Hocko @ 2020-10-26 14:47 UTC (permalink / raw)
  To: zhongjiang-ali; +Cc: hannes, vdavydov.dev, akpm, linux-mm

On Mon 26-10-20 22:26:35, zhongjiang-ali wrote:
> memcg_page_state will get the specified number in hierarchical memcg,
> It should multiply by HPAGE_PMD_NR rather than an page if the item is
> NR_ANON_THPS.

I am not sure which tree are you looking at but the current Linus tree
already does have this hunk.

> Fixes: 468c398233da ("mm: memcontrol: switch to native NR_ANON_THPS counter")
> Signed-off-by: zhongjiang-ali <zhongjiang-ali@linux.alibaba.com>
> ---
>  mm/memcontrol.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 3a24e3b..c27898e 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -4110,11 +4110,17 @@ static int memcg_stat_show(struct seq_file *m, void *v)
>  			   (u64)memsw * PAGE_SIZE);
>  
>  	for (i = 0; i < ARRAY_SIZE(memcg1_stats); i++) {
> +		unsigned long nr;
> +
>  		if (memcg1_stats[i] == MEMCG_SWAP && !do_memsw_account())
>  			continue;
> +		nr = memcg_page_state(memcg, memcg1_stats[i]);
> +#ifdef CONFIG_TRANSPARENT_HUGEPAGE
> +		if (memcg1_stats[i] == NR_ANON_THPS)
> +			nr *= HPAGE_PMD_NR;
> +#endif
>  		seq_printf(m, "total_%s %llu\n", memcg1_stat_names[i],
> -			   (u64)memcg_page_state(memcg, memcg1_stats[i]) *
> -			   PAGE_SIZE);
> +						nr * PAGE_SIZE);
>  	}
>  
>  	for (i = 0; i < ARRAY_SIZE(memcg1_events); i++)
> -- 
> 1.8.3.1

-- 
Michal Hocko
SUSE Labs


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

* Re: [PATCH] mm: memcontrol: correct the NR_ANON_THPS counter of hierarchical memcg
  2020-10-26 14:47 ` Michal Hocko
@ 2020-10-26 16:31   ` Johannes Weiner
  2020-10-26 18:43     ` Michal Hocko
  0 siblings, 1 reply; 5+ messages in thread
From: Johannes Weiner @ 2020-10-26 16:31 UTC (permalink / raw)
  To: Michal Hocko; +Cc: zhongjiang-ali, vdavydov.dev, akpm, linux-mm

On Mon, Oct 26, 2020 at 03:47:57PM +0100, Michal Hocko wrote:
> On Mon 26-10-20 22:26:35, zhongjiang-ali wrote:
> > memcg_page_state will get the specified number in hierarchical memcg,
> > It should multiply by HPAGE_PMD_NR rather than an page if the item is
> > NR_ANON_THPS.
> 
> I am not sure which tree are you looking at but the current Linus tree
> already does have this hunk.

This tripped up my pattern matching as well. You go to the code and
you see this bit already there. But it's only there for the local
stats, not the hierarchical stats, and the code for them is nearly
identical - except "%s" vs "total_%s" and memcg_page_state_local() vs
memcg_page_state().

Zhongjiang is updating the hierarchical stats a few lines below where
you see that hunk.


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

* Re: [PATCH] mm: memcontrol: correct the NR_ANON_THPS counter of hierarchical memcg
  2020-10-26 16:31   ` Johannes Weiner
@ 2020-10-26 18:43     ` Michal Hocko
  0 siblings, 0 replies; 5+ messages in thread
From: Michal Hocko @ 2020-10-26 18:43 UTC (permalink / raw)
  To: Johannes Weiner; +Cc: zhongjiang-ali, vdavydov.dev, akpm, linux-mm

On Mon 26-10-20 12:31:33, Johannes Weiner wrote:
> On Mon, Oct 26, 2020 at 03:47:57PM +0100, Michal Hocko wrote:
> > On Mon 26-10-20 22:26:35, zhongjiang-ali wrote:
> > > memcg_page_state will get the specified number in hierarchical memcg,
> > > It should multiply by HPAGE_PMD_NR rather than an page if the item is
> > > NR_ANON_THPS.
> > 
> > I am not sure which tree are you looking at but the current Linus tree
> > already does have this hunk.
> 
> This tripped up my pattern matching as well. You go to the code and
> you see this bit already there. But it's only there for the local
> stats, not the hierarchical stats, and the code for them is nearly
> identical - except "%s" vs "total_%s" and memcg_page_state_local() vs
> memcg_page_state().

You are right! Completely missed the total part. Thanks!

My bad!

> Zhongjiang is updating the hierarchical stats a few lines below where
> you see that hunk.

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

-- 
Michal Hocko
SUSE Labs


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

end of thread, other threads:[~2020-10-26 18:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-26 14:26 [PATCH] mm: memcontrol: correct the NR_ANON_THPS counter of hierarchical memcg zhongjiang-ali
2020-10-26 14:47 ` Johannes Weiner
2020-10-26 14:47 ` Michal Hocko
2020-10-26 16:31   ` Johannes Weiner
2020-10-26 18:43     ` 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).