linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] mm: memcg/slab: Fix root memcg vmstats
@ 2020-11-10  3:10 Muchun Song
  2020-11-10 15:20 ` Shakeel Butt
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Muchun Song @ 2020-11-10  3:10 UTC (permalink / raw)
  To: hannes, mhocko, vdavydov.dev, akpm, cl, penberg, rientjes,
	iamjoonsoo.kim, shakeelb, guro, vbabka, laoar.shao, songmuchun,
	chris
  Cc: linux-kernel, cgroups, linux-mm

If we reparent the slab objects to the root memcg, when we free
the slab object, we need to update the per-memcg vmstats to keep
it correct for the root memcg. Now this at least affects the vmstat
of NR_KERNEL_STACK_KB for !CONFIG_VMAP_STACK when the thread stack
size is smaller than the PAGE_SIZE.

Fixes: ec9f02384f60 ("mm: workingset: fix vmstat counters for shadow nodes")
Signed-off-by: Muchun Song <songmuchun@bytedance.com>
Acked-by: Roman Gushchin <guro@fb.com>
---
 v1->v2:
 - Just resend the patch.

 mm/memcontrol.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 2dde734df7d1..bbd40c5af61e 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -875,8 +875,13 @@ void __mod_lruvec_kmem_state(void *p, enum node_stat_item idx, int val)
 	rcu_read_lock();
 	memcg = mem_cgroup_from_obj(p);
 
-	/* Untracked pages have no memcg, no lruvec. Update only the node */
-	if (!memcg || memcg == root_mem_cgroup) {
+	/*
+	 * Untracked pages have no memcg, no lruvec. Update only the
+	 * node. If we reparent the slab objects to the root memcg,
+	 * when we free the slab object, we need to update the per-memcg
+	 * vmstats to keep it correct for the root memcg.
+	 */
+	if (!memcg) {
 		__mod_node_page_state(pgdat, idx, val);
 	} else {
 		lruvec = mem_cgroup_lruvec(memcg, pgdat);
-- 
2.20.1



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

* Re: [PATCH v2] mm: memcg/slab: Fix root memcg vmstats
  2020-11-10  3:10 [PATCH v2] mm: memcg/slab: Fix root memcg vmstats Muchun Song
@ 2020-11-10 15:20 ` Shakeel Butt
  2020-11-10 15:23 ` Johannes Weiner
  2020-11-10 18:57 ` David Rientjes
  2 siblings, 0 replies; 4+ messages in thread
From: Shakeel Butt @ 2020-11-10 15:20 UTC (permalink / raw)
  To: Muchun Song
  Cc: Johannes Weiner, Michal Hocko, Vladimir Davydov, Andrew Morton,
	Christoph Lameter, Pekka Enberg, David Rientjes, Joonsoo Kim,
	Roman Gushchin, Vlastimil Babka, Yafang Shao, Chris Down, LKML,
	Cgroups, Linux MM

On Mon, Nov 9, 2020 at 7:10 PM Muchun Song <songmuchun@bytedance.com> wrote:
>
> If we reparent the slab objects to the root memcg, when we free
> the slab object, we need to update the per-memcg vmstats to keep
> it correct for the root memcg. Now this at least affects the vmstat
> of NR_KERNEL_STACK_KB for !CONFIG_VMAP_STACK when the thread stack
> size is smaller than the PAGE_SIZE.
>
> Fixes: ec9f02384f60 ("mm: workingset: fix vmstat counters for shadow nodes")
> Signed-off-by: Muchun Song <songmuchun@bytedance.com>
> Acked-by: Roman Gushchin <guro@fb.com>

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


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

* Re: [PATCH v2] mm: memcg/slab: Fix root memcg vmstats
  2020-11-10  3:10 [PATCH v2] mm: memcg/slab: Fix root memcg vmstats Muchun Song
  2020-11-10 15:20 ` Shakeel Butt
@ 2020-11-10 15:23 ` Johannes Weiner
  2020-11-10 18:57 ` David Rientjes
  2 siblings, 0 replies; 4+ messages in thread
From: Johannes Weiner @ 2020-11-10 15:23 UTC (permalink / raw)
  To: Muchun Song
  Cc: mhocko, vdavydov.dev, akpm, cl, penberg, rientjes,
	iamjoonsoo.kim, shakeelb, guro, vbabka, laoar.shao, chris,
	linux-kernel, cgroups, linux-mm

On Tue, Nov 10, 2020 at 11:10:15AM +0800, Muchun Song wrote:
> If we reparent the slab objects to the root memcg, when we free
> the slab object, we need to update the per-memcg vmstats to keep
> it correct for the root memcg. Now this at least affects the vmstat
> of NR_KERNEL_STACK_KB for !CONFIG_VMAP_STACK when the thread stack
> size is smaller than the PAGE_SIZE.
> 
> Fixes: ec9f02384f60 ("mm: workingset: fix vmstat counters for shadow nodes")
> Signed-off-by: Muchun Song <songmuchun@bytedance.com>
> Acked-by: Roman Gushchin <guro@fb.com>

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


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

* Re: [PATCH v2] mm: memcg/slab: Fix root memcg vmstats
  2020-11-10  3:10 [PATCH v2] mm: memcg/slab: Fix root memcg vmstats Muchun Song
  2020-11-10 15:20 ` Shakeel Butt
  2020-11-10 15:23 ` Johannes Weiner
@ 2020-11-10 18:57 ` David Rientjes
  2 siblings, 0 replies; 4+ messages in thread
From: David Rientjes @ 2020-11-10 18:57 UTC (permalink / raw)
  To: Muchun Song
  Cc: hannes, mhocko, vdavydov.dev, Andrew Morton, cl, penberg,
	iamjoonsoo.kim, shakeelb, guro, Vlastimil Babka, laoar.shao,
	chris, linux-kernel, cgroups, linux-mm

On Tue, 10 Nov 2020, Muchun Song wrote:

> If we reparent the slab objects to the root memcg, when we free
> the slab object, we need to update the per-memcg vmstats to keep
> it correct for the root memcg. Now this at least affects the vmstat
> of NR_KERNEL_STACK_KB for !CONFIG_VMAP_STACK when the thread stack
> size is smaller than the PAGE_SIZE.
> 
> Fixes: ec9f02384f60 ("mm: workingset: fix vmstat counters for shadow nodes")
> Signed-off-by: Muchun Song <songmuchun@bytedance.com>
> Acked-by: Roman Gushchin <guro@fb.com>

Acked-by: David Rientjes <rientjes@google.com>

I assume that without this fix that the root memcg's vmstat would always 
be inflated if we reparented?  If that's accurate, perhaps this is 
deserving of a

Cc: stable@vger.kernel.org # 5.3+


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

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

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-10  3:10 [PATCH v2] mm: memcg/slab: Fix root memcg vmstats Muchun Song
2020-11-10 15:20 ` Shakeel Butt
2020-11-10 15:23 ` Johannes Weiner
2020-11-10 18:57 ` David Rientjes

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