2024-01-26 20:37:28

by T.J. Mercier

[permalink] [raw]
Subject: [PATCH] mm: memcg: Don't periodically flush stats when memcg is disabled

The root memcg is onlined even when memcg is disabled. When it's onlined
a 2 second periodic stat flush is started, but no stat flushing is
required when memcg is disabled because there can be no child memcgs.
Most calls to flush memcg stats are avoided when memcg is disabled as a
result of the mem_cgroup_disabled check [1] added in [2], but the
periodic flushing started in mem_cgroup_css_online is not. Skip it.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/mm/memcontrol.c?h=v6.8-rc1#n753
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=7d7ef0a4686abe43cd76a141b340a348f45ecdf2

Fixes: aa48e47e3906 ("memcg: infrastructure to flush memcg stats")
Reported-by: Minchan Kim <[email protected]>
Signed-off-by: T.J. Mercier <[email protected]>
---
mm/memcontrol.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index e4c8735e7c85..bad8f9dfc9ab 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -5586,7 +5586,7 @@ static int mem_cgroup_css_online(struct cgroup_subsys_state *css)
if (alloc_shrinker_info(memcg))
goto offline_kmem;

- if (unlikely(mem_cgroup_is_root(memcg)))
+ if (unlikely(mem_cgroup_is_root(memcg)) && !mem_cgroup_disabled())
queue_delayed_work(system_unbound_wq, &stats_flush_dwork,
FLUSH_TIME);
lru_gen_online_memcg(memcg);
--
2.43.0.429.g432eaa2c6b-goog



2024-01-26 21:02:47

by Shakeel Butt

[permalink] [raw]
Subject: Re: [PATCH] mm: memcg: Don't periodically flush stats when memcg is disabled

On Fri, Jan 26, 2024 at 12:34 PM T.J. Mercier <[email protected]> wrote:
>
> The root memcg is onlined even when memcg is disabled. When it's onlined
> a 2 second periodic stat flush is started, but no stat flushing is
> required when memcg is disabled because there can be no child memcgs.
> Most calls to flush memcg stats are avoided when memcg is disabled as a
> result of the mem_cgroup_disabled check [1] added in [2], but the

Remove [1] reference and instead of [2] add the actual commit reference.

> periodic flushing started in mem_cgroup_css_online is not. Skip it.
>
> [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/mm/memcontrol.c?h=v6.8-rc1#n753
> [2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=7d7ef0a4686abe43cd76a141b340a348f45ecdf2
>
> Fixes: aa48e47e3906 ("memcg: infrastructure to flush memcg stats")
> Reported-by: Minchan Kim <[email protected]>
> Signed-off-by: T.J. Mercier <[email protected]>

Acked-by: Shakeel Butt <[email protected]>

2024-01-26 21:07:50

by Johannes Weiner

[permalink] [raw]
Subject: Re: [PATCH] mm: memcg: Don't periodically flush stats when memcg is disabled

On Fri, Jan 26, 2024 at 08:33:52PM +0000, T.J. Mercier wrote:
> The root memcg is onlined even when memcg is disabled. When it's onlined
> a 2 second periodic stat flush is started, but no stat flushing is
> required when memcg is disabled because there can be no child memcgs.
> Most calls to flush memcg stats are avoided when memcg is disabled as a
> result of the mem_cgroup_disabled check [1] added in [2], but the
> periodic flushing started in mem_cgroup_css_online is not. Skip it.
>
> [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/mm/memcontrol.c?h=v6.8-rc1#n753
> [2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=7d7ef0a4686abe43cd76a141b340a348f45ecdf2
>
> Fixes: aa48e47e3906 ("memcg: infrastructure to flush memcg stats")
> Reported-by: Minchan Kim <[email protected]>
> Signed-off-by: T.J. Mercier <[email protected]>

With what Shakeel pointed out resolved:

Acked-by: Johannes Weiner <[email protected]>

2024-01-26 21:23:30

by T.J. Mercier

[permalink] [raw]
Subject: Re: [PATCH] mm: memcg: Don't periodically flush stats when memcg is disabled

On Fri, Jan 26, 2024 at 1:06 PM Johannes Weiner <[email protected]> wrote:
>
> On Fri, Jan 26, 2024 at 08:33:52PM +0000, T.J. Mercier wrote:
> > The root memcg is onlined even when memcg is disabled. When it's onlined
> > a 2 second periodic stat flush is started, but no stat flushing is
> > required when memcg is disabled because there can be no child memcgs.
> > Most calls to flush memcg stats are avoided when memcg is disabled as a
> > result of the mem_cgroup_disabled check [1] added in [2], but the
> > periodic flushing started in mem_cgroup_css_online is not. Skip it.
> >
> > [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/mm/memcontrol.c?h=v6.8-rc1#n753
> > [2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=7d7ef0a4686abe43cd76a141b340a348f45ecdf2
> >
> > Fixes: aa48e47e3906 ("memcg: infrastructure to flush memcg stats")
> > Reported-by: Minchan Kim <[email protected]>
> > Signed-off-by: T.J. Mercier <[email protected]>
>
> With what Shakeel pointed out resolved:
>
> Acked-by: Johannes Weiner <[email protected]>

Thanks Shakeel and Johannes. v2 is here, hopefully fixed up correctly:
https://lore.kernel.org/all/[email protected]/