* [PATCH v2] mm: memcg-v1: fix memsw and TCP failcnt accounting
@ 2026-08-11 3:08 Guopeng Zhang
2026-08-11 4:13 ` Tao Cui
2026-08-11 4:31 ` Shakeel Butt
0 siblings, 2 replies; 3+ messages in thread
From: Guopeng Zhang @ 2026-08-11 3:08 UTC (permalink / raw)
To: hannes, mhocko, akpm
Cc: roman.gushchin, shakeel.butt, muchun.song, cgroups, linux-mm,
linux-kernel, Guopeng Zhang, Michal Hocko
From: Guopeng Zhang <zhangguopeng@kylinos.cn>
Commit 0e2759afcaf9 ("page_counter: track failcnt only for legacy
cgroups") made failcnt accounting conditional on track_failcnt. It
enabled the flag for memcg->memory, but not for memcg->memsw or
memcg->tcpmem.
Consequently, memory.memsw.failcnt remains zero when the memory+swap
limit is hit. memory.kmem.tcp.limit_in_bytes still sets
memcg->tcpmem.max, but TCP charge failures are not reflected in
memory.kmem.tcp.failcnt.
Enable failcnt accounting for both v1 counters.
To reproduce memory.memsw.failcnt:
CG=/sys/fs/cgroup/memory/memsw-test
LIMIT=33554432
mkdir "$CG"
echo "$LIMIT" > "$CG/memory.limit_in_bytes"
echo "$LIMIT" > "$CG/memory.memsw.limit_in_bytes"
Start a child process in the cgroup and make it allocate and touch 96 MiB
of memory, causing a memcg OOM.
cat "$CG/memory.memsw.failcnt"
Without the patch, memory.memsw.failcnt is 0. With the patch,
memory.memsw.failcnt is greater than 0.
To reproduce memory.kmem.tcp.failcnt:
CG=/sys/fs/cgroup/memory/tcpmem-test
LIMIT=65536
mkdir "$CG"
echo "$LIMIT" > "$CG/memory.kmem.tcp.limit_in_bytes"
Start a child process in the cgroup, create a TCP socket, and reserve
1 MiB of socket memory with SO_RESERVE_MEM. The reservation fails with
ENOMEM.
cat "$CG/memory.kmem.tcp.failcnt"
Without the patch, memory.kmem.tcp.failcnt is 0. With the patch,
memory.kmem.tcp.failcnt is greater than 0.
Closes: https://sashiko.dev/#/patchset/20260810074247.52747-1-guopeng.zhang@linux.dev?part=1
Fixes: 0e2759afcaf9 ("page_counter: track failcnt only for legacy cgroups")
Cc: stable@vger.kernel.org
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Guopeng Zhang <zhangguopeng@kylinos.cn>
---
Changes in v2:
- Enable failcnt tracking for tcpmem as suggested by Johannes Weiner.
- Add the memory.kmem.tcp.failcnt reproducer and test result.
- Update the subject and changelog to cover both counters.
- Add Cc: stable@vger.kernel.org and the received Acked-by tags.
Link to v1: https://lore.kernel.org/r/20260810074247.52747-1-guopeng.zhang@linux.dev
mm/memcontrol.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 70806373d5a9..17da1f43b7d3 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4235,9 +4235,11 @@ mem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css)
#ifdef CONFIG_MEMCG_V1
WRITE_ONCE(memcg->swappiness, mem_cgroup_swappiness(parent));
memcg->memory.track_failcnt = !memcg_on_dfl;
+ memcg->memsw.track_failcnt = !memcg_on_dfl;
WRITE_ONCE(memcg->oom_kill_disable, READ_ONCE(parent->oom_kill_disable));
page_counter_init(&memcg->kmem, &parent->kmem, false);
page_counter_init(&memcg->tcpmem, &parent->tcpmem, false);
+ memcg->tcpmem.track_failcnt = !memcg_on_dfl;
#endif
} else {
init_memcg_stats();
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v2] mm: memcg-v1: fix memsw and TCP failcnt accounting
2026-08-11 3:08 [PATCH v2] mm: memcg-v1: fix memsw and TCP failcnt accounting Guopeng Zhang
@ 2026-08-11 4:13 ` Tao Cui
2026-08-11 4:31 ` Shakeel Butt
1 sibling, 0 replies; 3+ messages in thread
From: Tao Cui @ 2026-08-11 4:13 UTC (permalink / raw)
To: Guopeng Zhang, hannes, mhocko, akpm
Cc: cui.tao, roman.gushchin, shakeel.butt, muchun.song, cgroups,
linux-mm, linux-kernel, Guopeng Zhang, Michal Hocko
在 2026/8/11 11:08, Guopeng Zhang 写道:
> From: Guopeng Zhang <zhangguopeng@kylinos.cn>
>
> Commit 0e2759afcaf9 ("page_counter: track failcnt only for legacy
> cgroups") made failcnt accounting conditional on track_failcnt. It
> enabled the flag for memcg->memory, but not for memcg->memsw or
> memcg->tcpmem.
>
> Consequently, memory.memsw.failcnt remains zero when the memory+swap
> limit is hit. memory.kmem.tcp.limit_in_bytes still sets
> memcg->tcpmem.max, but TCP charge failures are not reflected in
> memory.kmem.tcp.failcnt.
>
> Enable failcnt accounting for both v1 counters.
>
> To reproduce memory.memsw.failcnt:
>
> CG=/sys/fs/cgroup/memory/memsw-test
> LIMIT=33554432
> mkdir "$CG"
> echo "$LIMIT" > "$CG/memory.limit_in_bytes"
> echo "$LIMIT" > "$CG/memory.memsw.limit_in_bytes"
>
> Start a child process in the cgroup and make it allocate and touch 96 MiB
> of memory, causing a memcg OOM.
>
> cat "$CG/memory.memsw.failcnt"
>
> Without the patch, memory.memsw.failcnt is 0. With the patch,
> memory.memsw.failcnt is greater than 0.
>
> To reproduce memory.kmem.tcp.failcnt:
>
> CG=/sys/fs/cgroup/memory/tcpmem-test
> LIMIT=65536
> mkdir "$CG"
> echo "$LIMIT" > "$CG/memory.kmem.tcp.limit_in_bytes"
>
> Start a child process in the cgroup, create a TCP socket, and reserve
> 1 MiB of socket memory with SO_RESERVE_MEM. The reservation fails with
> ENOMEM.
>
> cat "$CG/memory.kmem.tcp.failcnt"
>
> Without the patch, memory.kmem.tcp.failcnt is 0. With the patch,
> memory.kmem.tcp.failcnt is greater than 0.
>
> Closes: https://sashiko.dev/#/patchset/20260810074247.52747-1-guopeng.zhang@linux.dev?part=1
> Fixes: 0e2759afcaf9 ("page_counter: track failcnt only for legacy cgroups")
> Cc: stable@vger.kernel.org
> Acked-by: Johannes Weiner <hannes@cmpxchg.org>
> Acked-by: Michal Hocko <mhocko@suse.com>
> Signed-off-by: Guopeng Zhang <zhangguopeng@kylinos.cn>
> ---
> Changes in v2:
> - Enable failcnt tracking for tcpmem as suggested by Johannes Weiner.
> - Add the memory.kmem.tcp.failcnt reproducer and test result.
> - Update the subject and changelog to cover both counters.
> - Add Cc: stable@vger.kernel.org and the received Acked-by tags.
>
> Link to v1: https://lore.kernel.org/r/20260810074247.52747-1-guopeng.zhang@linux.dev
>
> mm/memcontrol.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 70806373d5a9..17da1f43b7d3 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -4235,9 +4235,11 @@ mem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css)
> #ifdef CONFIG_MEMCG_V1
> WRITE_ONCE(memcg->swappiness, mem_cgroup_swappiness(parent));
> memcg->memory.track_failcnt = !memcg_on_dfl;
> + memcg->memsw.track_failcnt = !memcg_on_dfl;
> WRITE_ONCE(memcg->oom_kill_disable, READ_ONCE(parent->oom_kill_disable));
> page_counter_init(&memcg->kmem, &parent->kmem, false);
> page_counter_init(&memcg->tcpmem, &parent->tcpmem, false);
> + memcg->tcpmem.track_failcnt = !memcg_on_dfl;
> #endif
> } else {
> init_memcg_stats();
Reviewed-by: Tao Cui <cuitao@kylinos.cn>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH v2] mm: memcg-v1: fix memsw and TCP failcnt accounting
2026-08-11 3:08 [PATCH v2] mm: memcg-v1: fix memsw and TCP failcnt accounting Guopeng Zhang
2026-08-11 4:13 ` Tao Cui
@ 2026-08-11 4:31 ` Shakeel Butt
1 sibling, 0 replies; 3+ messages in thread
From: Shakeel Butt @ 2026-08-11 4:31 UTC (permalink / raw)
To: Guopeng Zhang
Cc: hannes, mhocko, akpm, roman.gushchin, muchun.song, cgroups,
linux-mm, linux-kernel, Guopeng Zhang, Michal Hocko
On Tue, Aug 11, 2026 at 11:08:43AM +0800, Guopeng Zhang wrote:
> From: Guopeng Zhang <zhangguopeng@kylinos.cn>
>
> Commit 0e2759afcaf9 ("page_counter: track failcnt only for legacy
> cgroups") made failcnt accounting conditional on track_failcnt. It
> enabled the flag for memcg->memory, but not for memcg->memsw or
> memcg->tcpmem.
>
> Consequently, memory.memsw.failcnt remains zero when the memory+swap
> limit is hit. memory.kmem.tcp.limit_in_bytes still sets
> memcg->tcpmem.max, but TCP charge failures are not reflected in
> memory.kmem.tcp.failcnt.
>
> Enable failcnt accounting for both v1 counters.
>
> To reproduce memory.memsw.failcnt:
>
> CG=/sys/fs/cgroup/memory/memsw-test
> LIMIT=33554432
> mkdir "$CG"
> echo "$LIMIT" > "$CG/memory.limit_in_bytes"
> echo "$LIMIT" > "$CG/memory.memsw.limit_in_bytes"
>
> Start a child process in the cgroup and make it allocate and touch 96 MiB
> of memory, causing a memcg OOM.
>
> cat "$CG/memory.memsw.failcnt"
>
> Without the patch, memory.memsw.failcnt is 0. With the patch,
> memory.memsw.failcnt is greater than 0.
>
> To reproduce memory.kmem.tcp.failcnt:
>
> CG=/sys/fs/cgroup/memory/tcpmem-test
> LIMIT=65536
> mkdir "$CG"
> echo "$LIMIT" > "$CG/memory.kmem.tcp.limit_in_bytes"
>
> Start a child process in the cgroup, create a TCP socket, and reserve
> 1 MiB of socket memory with SO_RESERVE_MEM. The reservation fails with
> ENOMEM.
>
> cat "$CG/memory.kmem.tcp.failcnt"
>
> Without the patch, memory.kmem.tcp.failcnt is 0. With the patch,
> memory.kmem.tcp.failcnt is greater than 0.
>
> Closes: https://sashiko.dev/#/patchset/20260810074247.52747-1-guopeng.zhang@linux.dev?part=1
> Fixes: 0e2759afcaf9 ("page_counter: track failcnt only for legacy cgroups")
> Cc: stable@vger.kernel.org
> Acked-by: Johannes Weiner <hannes@cmpxchg.org>
> Acked-by: Michal Hocko <mhocko@suse.com>
> Signed-off-by: Guopeng Zhang <zhangguopeng@kylinos.cn>
Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-08-11 4:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-11 3:08 [PATCH v2] mm: memcg-v1: fix memsw and TCP failcnt accounting Guopeng Zhang
2026-08-11 4:13 ` Tao Cui
2026-08-11 4:31 ` Shakeel Butt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox