From: "JP Kobryn (Meta)" <inwardvessel@gmail.com>
To: Hui Zhu <hui.zhu@linux.dev>, Johannes Weiner <hannes@cmpxchg.org>,
Michal Hocko <mhocko@kernel.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Shakeel Butt <shakeel.butt@linux.dev>,
Muchun Song <muchun.song@linux.dev>,
Andrew Morton <akpm@linux-foundation.org>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>, Shuah Khan <shuah@kernel.org>,
Hui Zhu <zhuhui@kylinos.cn>,
cgroups@vger.kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, bpf@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: Re: [PATCH bpf-next 2/3] mm/memcontrol: Return error when accessing kmem with nokmem
Date: Thu, 12 Feb 2026 16:38:54 -0800 [thread overview]
Message-ID: <51bbd728-c712-4601-8a4a-7c602c67fe75@gmail.com> (raw)
In-Reply-To: <733422f72ccbac94126ae67b9e49f4a3d460b76a.1770883926.git.zhuhui@kylinos.cn>
On 2/12/26 12:23 AM, Hui Zhu wrote:
> From: Hui Zhu <zhuhui@kylinos.cn>
>
> When running tests on hosts with cgroup.memory=nokmem enabled for
> performance reasons, test_kmem always gets a value of 0 for kmem
> statistics.
>
> Since BPF programs cannot easily determine whether kmem is enabled,
> add a check in memcg_stat_item_valid() to return an error when
> attempting to access MEMCG_KMEM statistics while kmem accounting
> is disabled via cgroup_memory_nokmem.
>
> This prevents BPF programs from silently receiving zero values and
> allows them to properly handle the case where kmem accounting is
> unavailable.
>
> Signed-off-by: Hui Zhu <zhuhui@kylinos.cn>
> ---
> mm/memcontrol.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 129eed3ff5bb..4d8419623d1c 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -667,7 +667,8 @@ unsigned long memcg_page_state(struct mem_cgroup *memcg, int idx)
>
> bool memcg_stat_item_valid(int idx)
> {
> - if ((u32)idx >= MEMCG_NR_STAT)
> + if ((u32)idx >= MEMCG_NR_STAT ||
> + (cgroup_memory_nokmem && (u32)idx == MEMCG_KMEM))
> return false;
It's still a valid stat though, right? When it's disabled the value will
just remain zero. I don't think this is necessary.
next prev parent reply other threads:[~2026-02-13 0:39 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-12 8:23 [PATCH bpf-next 0/3] Fix test_cgroup_iter_memcg issues found during back-porting Hui Zhu
2026-02-12 8:23 ` [PATCH bpf-next 1/3] selftests/bpf: Check bpf_mem_cgroup_page_state return value Hui Zhu
2026-02-12 8:50 ` bot+bpf-ci
2026-02-12 9:23 ` hui.zhu
2026-02-13 0:14 ` JP Kobryn
2026-02-13 7:29 ` hui.zhu
2026-02-12 8:23 ` [PATCH bpf-next 2/3] mm/memcontrol: Return error when accessing kmem with nokmem Hui Zhu
2026-02-13 0:38 ` JP Kobryn (Meta) [this message]
2026-02-12 8:23 ` [PATCH bpf-next 3/3] selftests/bpf: Skip test_kmem when cgroup.memory=nokmem Hui Zhu
2026-02-13 0:41 ` JP Kobryn (Meta)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=51bbd728-c712-4601-8a4a-7c602c67fe75@gmail.com \
--to=inwardvessel@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=cgroups@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=hannes@cmpxchg.org \
--cc=haoluo@google.com \
--cc=hui.zhu@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=martin.lau@linux.dev \
--cc=mhocko@kernel.org \
--cc=muchun.song@linux.dev \
--cc=roman.gushchin@linux.dev \
--cc=sdf@fomichev.me \
--cc=shakeel.butt@linux.dev \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
--cc=zhuhui@kylinos.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox