mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Hui Zhu <hui.zhu@linux.dev>
Cc: 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>, 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,
	Hui Zhu <zhuhui@kylinos.cn>
Subject: Re: [RFC PATCH 0/2] memcg_ext: dynamic memory.low and memory.min protection
Date: Wed, 28 Oct 2026 07:19:04 -1000	[thread overview]
Message-ID: <5572f45165fa3ec7d16e1d17eb2c3fb6@kernel.org> (raw)
In-Reply-To: <c652f3e6198b143fcf29f5540a769228f3d8470c@linux.dev>

Hello, Hui.

On Wed, Oct 28, 2026 at 10:27:33AM +0000, Hui Zhu wrote:
> memory.low is a request, and what reclaim honors is elow, which
> page_counter_calculate_protection() derives on each pass from the
> parent's elow, the siblings' requests and the tree's usage.  At the
> first level below the reclaim root that comes out equal to what was
> written, and there the knob is enough.  Deeper down it is capped by the
> parent's budget and shared out between siblings according to what they
> claimed and what they use, so what a cgroup wrote and what it ends up
> with can differ.  As far as I can tell none of that is visible from
> userspace: memory.low reads back the declared value, and I could not
> find anything that exports elow.
...
> So the derived value seems to be usable only where it is derived,
> inside the check, and that is where low_policy() sits: it is evaluated
> per pass and is handed that pass's own inputs - the memcg, the reclaim
> target, the elow just computed, the usage - instead of being state that
> is read at the check.

The visibility of effective values is a problem of wider scope, not an
argument for implementing bpf struct_ops. There were discussions in the
past on whether we could expose some meaningful effective value. They
didn't lead to anything conclusive, and we may yet find a way to expose
something more useful.

Also, the hook doesn't use elow to decide anything. mem_cgroup_below_low()
and below_min() return true as long as elow or emin covers the usage.
They ask the policies only once the usage exceeds it, and the only
answer a policy can give is BELOW, which makes reclaim skip the cgroup.
So, what the hook buys in the nested case isn't access to the per-pass
elow. It lets a cgroup escape the ceiling that its parent's protection
imposes on the subtree.

Some of that may be innate to nested protection semantics. One
shortcoming may be that there's no way for a parent to "passthrough" in
terms of protection, because there's no way for a parent to be neutral.
If its memory.low is too low, that's the ceiling for the whole
subhierarchy. If it's set high, the subtree gets the total protection
one way or another. There may be arguments for a different semantics
which changes the shape of the protection.

However, it doesn't make sense to let a BPF program escape the parent's
policy, and, again, none of this is an argument for adding bpf
struct_ops.

> The other half is what a policy can key on.  memory.low has one
> dimension, bytes.  A policy program is not limited to the ctx it is
> handed; it can also use state that other BPF programs keep, so
> protection can be a function of activity rather than of size - a
> workingset refault rate, for instance.  [1] reads those counters from
> BPF and acts on them; it drives reclaim rather than answering a
> protection hook, but the signal it reads is the one such a policy would
> want.  The limit is on the output rather than the input: the hook
> returns a boolean, so it cannot grant anything memory.low cannot.

These signals are all available to userspace. The workingset refault
counters are in memory.stat, PSI is in memory.pressure, and whatever
state other BPF programs keep sits in BPF maps which userspace can read.
So, the inputs aren't the difference. What's left is how quickly and how
often the protection gets adjusted.

That may be an argument, but nothing so far shows that struct_ops is
needed for it. Can you demonstrate a realistic and useful scenario which
can't be achieved from userspace but can be with struct_ops?

Thanks.

--
tejun

      reply	other threads:[~2026-10-28 17:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-27  9:11 Hui Zhu
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
2026-10-28 17:19     ` Tejun Heo [this message]

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=5572f45165fa3ec7d16e1d17eb2c3fb6@kernel.org \
    --to=tj@kernel.org \
    --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=hui.zhu@linux.dev \
    --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=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®