From: Hui Zhu <hui.zhu@linux.dev>
To: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
John Fastabend <john.fastabend@gmail.com>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Jiri Olsa <jolsa@kernel.org>,
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>,
JP Kobryn <jp.kobryn@linux.dev>,
Andrew Morton <akpm@linux-foundation.org>,
Shuah Khan <shuah@kernel.org>,
davem@davemloft.net, Jakub Kicinski <kuba@kernel.org>,
Jesper Dangaard Brouer <hawk@kernel.org>,
Stanislav Fomichev <sdf@fomichev.me>,
KP Singh <kpsingh@kernel.org>, Tao Chen <chen.dylane@linux.dev>,
Mykyta Yatsenko <yatsenko@meta.com>,
Leon Hwang <leon.hwang@linux.dev>,
Anton Protopopov <a.s.protopopov@gmail.com>,
Amery Hung <ameryhung@gmail.com>,
Tobias Klauser <tklauser@distanz.ch>,
Eyal Birger <eyal.birger@gmail.com>, Rong Tao <rongtao@cestc.cn>,
Hao Luo <haoluo@google.com>,
Peter Zijlstra <peterz@infradead.org>,
Miguel Ojeda <ojeda@kernel.org>,
Nathan Chancellor <nathan@kernel.org>,
Kees Cook <kees@kernel.org>, Tejun Heo <tj@kernel.org>,
Jeff Xu <jeffxu@chromium.org>,
mkoutny@suse.com, Jan Hendrik Farr <kernel@jfarr.cc>,
Christian Brauner <brauner@kernel.org>,
Randy Dunlap <rdunlap@infradead.org>,
Brian Gerst <brgerst@gmail.com>,
Masahiro Yamada <masahiroy@kernel.org>,
Willem de Bruijn <willemb@google.com>,
Jason Xing <kerneljasonxing@gmail.com>,
Paul Chaignon <paul.chaignon@gmail.com>,
Lance Yang <lance.yang@linux.dev>,
Jiayuan Chen <jiayuan.chen@linux.dev>,
Emil Tsalapatis <emil@etsalapatis.com>,
Ihor Solodrai <ihor.solodrai@linux.dev>,
Barry Song <baohua@kernel.org>, Geliang Tang <geliang@kernel.org>,
linux-kernel@vger.kernel.org, bpf@vger.kernel.org,
cgroups@vger.kernel.org, linux-mm@kvack.org,
netdev@vger.kernel.org, linux-kselftest@vger.kernel.org
Cc: Hui Zhu <zhuhui@kylinos.cn>
Subject: [RFC PATCH 0/2] memcg_ext: dynamic memory.low and memory.min protection
Date: Tue, 27 Oct 2026 17:11:58 +0800 [thread overview]
Message-ID: <cover.1793086858.git.zhuhui@kylinos.cn> (raw)
From: Hui Zhu <zhuhui@kylinos.cn>
This follows the memcg_ext RFC [1], which adds bpf_memcg_ops - a
struct_ops type attaching memory controller policy to a cgroup - and
one member, high_policy(). Its cover letter names dynamic protection
as future work; these two patches are that.
Why it matters: memory.low and memory.min protect a cgroup by a fixed
threshold and have no idea whether it is using the memory. A
high-priority cgroup that holds a large working set and then goes idle
keeps suppressing reclaim on its siblings, and that memory is wasted.
A policy program sees the real activity - page faults, charges - and
can grant or withdraw protection as it changes.
The hooks are not new: [2] proposed the same below-low and below-min
decision on its own memcg_bpf_ops type. Only the carrier changes
here. bpf_memcg_ops already supplies attach, the ancestor walk,
result combination and the re-entry guard, so protection costs two
members and one walk helper shared with high_policy().
Patch 1 adds low_policy() and min_policy(). A program gets a
read-only snapshot of the check the kernel is making - the memcg, the
reclaim target, the threshold and the usage - and returns a request;
BPF_MEMCG_PROT_BELOW, the only one so far, treats the cgroup as below
its threshold, so reclaim skips it and counts it in memory.events.
The kernel compares elow/emin first and asks BPF only when it found
the cgroup unprotected, and ORs the answers of the cgroup and every
ancestor, so a policy can only add protection, never take it away.
Patch 2 is the prog_tests runner: attach both policies to a child,
fault 8M of anonymous memory into it, reclaim from its parent, and
check that both hooks were consulted and that the ctx described the
check faithfully. Both answer NO_OPINION, so nothing about reclaim's
outcome is asserted. A working example that does answer BELOW, so
reclaim skips one cgroup and takes the memory from a sibling instead,
is maintained out of tree at [3], released under GPLv2.
[1] https://lore.kernel.org/all/20260921192559.2619635-1-shakeel.butt@linux.dev/
[2] https://lore.kernel.org/all/cover.1779760876.git.zhuhui@kylinos.cn/
[3] https://github.com/teawater/memcg-async-reclaim/tree/memcg_ext_plus
Hui Zhu (2):
memcg_ext: add memory.low and memory.min protection policies
selftests/bpf: Add bpf_memcg_ops protection test
include/linux/bpf_memcontrol.h | 104 ++++++++++-
include/linux/memcontrol.h | 23 ++-
mm/bpf_memcontrol.c | 162 ++++++++++++++----
.../bpf/prog_tests/memcg_ops_protection.c | 151 ++++++++++++++++
.../bpf/progs/memcg_ops_protection.c | 72 ++++++++
5 files changed, 470 insertions(+), 42 deletions(-)
create mode 100644 tools/testing/selftests/bpf/prog_tests/memcg_ops_protection.c
create mode 100644 tools/testing/selftests/bpf/progs/memcg_ops_protection.c
--
2.43.0
next reply other threads:[~2026-10-27 9:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-27 9:11 Hui Zhu [this message]
2026-10-27 9:11 ` [RFC PATCH 1/2] memcg_ext: add memory.low and memory.min protection policies Hui Zhu
2026-10-27 9:12 ` [RFC PATCH 2/2] selftests/bpf: Add bpf_memcg_ops protection test Hui Zhu
2026-10-27 18:17 ` [RFC PATCH 0/2] memcg_ext: dynamic memory.low and memory.min protection Tejun Heo
2026-10-28 10:27 ` 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=cover.1793086858.git.zhuhui@kylinos.cn \
--to=hui.zhu@linux.dev \
--cc=a.s.protopopov@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=ameryhung@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=baohua@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=brauner@kernel.org \
--cc=brgerst@gmail.com \
--cc=cgroups@vger.kernel.org \
--cc=chen.dylane@linux.dev \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=eyal.birger@gmail.com \
--cc=geliang@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=haoluo@google.com \
--cc=hawk@kernel.org \
--cc=ihor.solodrai@linux.dev \
--cc=jeffxu@chromium.org \
--cc=jiayuan.chen@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=jp.kobryn@linux.dev \
--cc=kees@kernel.org \
--cc=kernel@jfarr.cc \
--cc=kerneljasonxing@gmail.com \
--cc=kpsingh@kernel.org \
--cc=kuba@kernel.org \
--cc=lance.yang@linux.dev \
--cc=leon.hwang@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=martin.lau@linux.dev \
--cc=masahiroy@kernel.org \
--cc=memxor@gmail.com \
--cc=mhocko@kernel.org \
--cc=mkoutny@suse.com \
--cc=muchun.song@linux.dev \
--cc=nathan@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=paul.chaignon@gmail.com \
--cc=peterz@infradead.org \
--cc=rdunlap@infradead.org \
--cc=roman.gushchin@linux.dev \
--cc=rongtao@cestc.cn \
--cc=sdf@fomichev.me \
--cc=shakeel.butt@linux.dev \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=tj@kernel.org \
--cc=tklauser@distanz.ch \
--cc=willemb@google.com \
--cc=yatsenko@meta.com \
--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
all inboxes | Powered by JetHome®