From: Shakeel Butt <shakeel.butt@linux.dev>
To: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Hui Zhu <hui.zhu@linux.dev>,
Roman Gushchin <roman.gushchin@linux.dev>,
JP Kobryn <inwardvessel@gmail.com>,
Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Ihor Solodrai <ihor.solodrai@linux.dev>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Jiri Olsa <jolsa@kernel.org>,
Emil Tsalapatis <emil@etsalapatis.com>,
Shuah Khan <shuah@kernel.org>, Barry Song <baohua@kernel.org>,
Geliang Tang <geliang@kernel.org>,
linux-kernel@vger.kernel.org, bpf@vger.kernel.org,
linux-mm@kvack.org, linux-kselftest@vger.kernel.org,
Hui Zhu <zhuhui@kylinos.cn>
Subject: Re: [PATCH bpf-next v7 1/2] mm/bpf: Add bpf_proactive_reclaim kfunc
Date: Sat, 5 Sep 2026 09:28:46 -0700 [thread overview]
Message-ID: <apxB5tyglnSbqmEu@linux.dev> (raw)
In-Reply-To: <DL7CEX9EX781.23V26M3600JEI@gmail.com>
On Sat, Sep 05, 2026 at 01:23:39PM +0200, Kumar Kartikeya Dwivedi wrote:
> On Fri Sep 4, 2026 at 8:03 PM CEST, Andrew Morton wrote:
> > On Fri, 4 Sep 2026 18:20:19 +0800 "Hui Zhu" <hui.zhu@linux.dev> wrote:
> >
> >> @@ -159,6 +160,74 @@ __bpf_kfunc void bpf_mem_cgroup_flush_stats(struct mem_cgroup *memcg)
> >> mem_cgroup_flush_stats(memcg);
> >> }
> >>
> >> +/*
> >> + * Reclaim must not recurse: try_to_free_mem_cgroup_pages() overwrites
> >> + * current->reclaim_state, so a nested call would corrupt the outer
> >> + * reclaim state. Reclaim windows are marked with PF_MEMALLOC;
> >> + * reclaim_state is also checked because it is installed slightly
> >> + * before PF_MEMALLOC.
> >> + */
> >> +static bool bpf_in_reclaim_context(void)
> >> +{
> >> + return (current->flags & PF_MEMALLOC) || current->reclaim_state;
> >> +}
> >> +
> >
> > Would life improve if try_to_free_mem_cgroup_pages() didn't do that?
> > If try_to_free_mem_cgroup_pages() (or some variant of it) were to
> > permit nesting?
> >
> > rs = new_thing(current, &sc.reclaim_state);
> > ...
> > set_task_reclaim_state(current, rs);
> >
>
> My understanding is that given the current restrictions on where this kfunc can
> be called, this is mostly a defensive and shouldn't be firing (?). Given that,
> we can probably revisit this when such reentrancy is necessary, even though I
> doubt it would be the case in the future. It will at most be invoked from a wq
> callback or a kthread, so should be fine.
>
If with the current restrictions, this recursion can not happen then let's not
add this check here. We never want recursion/reentrancy here.
next prev parent reply other threads:[~2026-09-05 16:29 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-04 10:20 [PATCH bpf-next v7 0/2] bpf: BPF-driven proactive memcg reclaim Hui Zhu
2026-09-04 10:20 ` [PATCH bpf-next v7 1/2] mm/bpf: Add bpf_proactive_reclaim kfunc Hui Zhu
2026-09-04 10:36 ` sashiko-bot
2026-09-04 11:25 ` bot+bpf-ci
2026-09-04 18:03 ` Andrew Morton
2026-09-05 11:23 ` Kumar Kartikeya Dwivedi
2026-09-05 16:28 ` Shakeel Butt [this message]
2026-09-07 3:17 ` Hui Zhu
2026-09-04 10:20 ` [PATCH bpf-next v7 2/2] selftests/bpf: Add memcg async reclaim test Hui Zhu
2026-09-04 11:25 ` bot+bpf-ci
2026-09-05 11:24 ` [PATCH bpf-next v7 0/2] bpf: BPF-driven proactive memcg reclaim Kumar Kartikeya Dwivedi
2026-09-07 3:31 ` Hui Zhu
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=apxB5tyglnSbqmEu@linux.dev \
--to=shakeel.butt@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=baohua@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=geliang@kernel.org \
--cc=hui.zhu@linux.dev \
--cc=ihor.solodrai@linux.dev \
--cc=inwardvessel@gmail.com \
--cc=jolsa@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=memxor@gmail.com \
--cc=roman.gushchin@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.