[PATCH bpf-next v4 0/6] mm: bpf kfuncs to access memcg data

Roman Gushchin posted 6 patches 1 month, 2 weeks ago
MAINTAINERS                                   |   9 +
include/linux/memcontrol.h                    |  20 ++
mm/Makefile                                   |   3 +
mm/bpf_memcontrol.c                           | 193 +++++++++++++++
mm/memcontrol-v1.h                            |   1 -
mm/memcontrol.c                               |  16 ++
.../testing/selftests/bpf/cgroup_iter_memcg.h |  18 ++
.../bpf/prog_tests/cgroup_iter_memcg.c        | 223 ++++++++++++++++++
.../selftests/bpf/progs/cgroup_iter_memcg.c   |  39 +++
9 files changed, 521 insertions(+), 1 deletion(-)
create mode 100644 mm/bpf_memcontrol.c
create mode 100644 tools/testing/selftests/bpf/cgroup_iter_memcg.h
create mode 100644 tools/testing/selftests/bpf/prog_tests/cgroup_iter_memcg.c
create mode 100644 tools/testing/selftests/bpf/progs/cgroup_iter_memcg.c
[PATCH bpf-next v4 0/6] mm: bpf kfuncs to access memcg data
Posted by Roman Gushchin 1 month, 2 weeks ago
Introduce kfuncs to simplify the access to the memcg data.
These kfuncs can be used to accelerate monitoring use cases and
for implementing custom OOM policies once BPF OOM is landed.

This patchset was separated out from the BPF OOM patchset to simplify
the logistics and accelerate the landing of the part which is useful
by itself. No functional changes since BPF OOM v2.

v4:
  - refactored memcg vm event and stat item idx checks (by Alexei)

v3:
  - dropped redundant kfuncs flags (by Alexei)
  - fixed kdocs warnings (by Alexei)
  - merged memcg stats access patches into one (by Alexei)
  - restored root memcg usage reporting, added a comment
  - added checks for enum boundaries
  - added Shakeel and JP as co-maintainers (by Shakeel)

v2:
  - added mem_cgroup_disabled() checks (by Shakeel B.)
  - added special handling of the root memcg in bpf_mem_cgroup_usage()
  (by Shakeel B.)
  - minor fixes in the kselftest (by Shakeel B.)
  - added a MAINTAINERS entry (by Shakeel B.)

v1:
  https://lore.kernel.org/bpf/87ike29s5r.fsf@linux.dev/T/#t


JP Kobryn (1):
  bpf: selftests: selftests for memcg stat kfuncs

Roman Gushchin (5):
  mm: declare memcg_page_state_output() in memcontrol.h
  mm: introduce BPF kfuncs to deal with memcg pointers
  mm: introduce bpf_get_root_mem_cgroup() BPF kfunc
  mm: introduce BPF kfuncs to access memcg statistics and events
  MAINTAINERS: add an entry for MM BPF extensions

 MAINTAINERS                                   |   9 +
 include/linux/memcontrol.h                    |  20 ++
 mm/Makefile                                   |   3 +
 mm/bpf_memcontrol.c                           | 193 +++++++++++++++
 mm/memcontrol-v1.h                            |   1 -
 mm/memcontrol.c                               |  16 ++
 .../testing/selftests/bpf/cgroup_iter_memcg.h |  18 ++
 .../bpf/prog_tests/cgroup_iter_memcg.c        | 223 ++++++++++++++++++
 .../selftests/bpf/progs/cgroup_iter_memcg.c   |  39 +++
 9 files changed, 521 insertions(+), 1 deletion(-)
 create mode 100644 mm/bpf_memcontrol.c
 create mode 100644 tools/testing/selftests/bpf/cgroup_iter_memcg.h
 create mode 100644 tools/testing/selftests/bpf/prog_tests/cgroup_iter_memcg.c
 create mode 100644 tools/testing/selftests/bpf/progs/cgroup_iter_memcg.c

-- 
2.52.0
Re: [PATCH bpf-next v4 0/6] mm: bpf kfuncs to access memcg data
Posted by Yafang Shao 1 month, 2 weeks ago
On Tue, Dec 23, 2025 at 12:43 PM Roman Gushchin
<roman.gushchin@linux.dev> wrote:
>
> Introduce kfuncs to simplify the access to the memcg data.
> These kfuncs can be used to accelerate monitoring use cases and
> for implementing custom OOM policies once BPF OOM is landed.
>
> This patchset was separated out from the BPF OOM patchset to simplify
> the logistics and accelerate the landing of the part which is useful
> by itself. No functional changes since BPF OOM v2.

Hello Roman,

Thanks for driving the BPF-MM upstreaming work—this is great progress.

Would it be possible to upstream the bpf_st_ops and cgroups patch as a
standalone series as well? [0]

While the upstreaming of BPF-THP is currently stalled, we are actively
experimenting with more BPF-MM related features—like BPF-based NUMA
balancing—on our production servers. This work is a great fit for
per-cgroup tuning via BPF, and having your bpf_st_ops and cgroups
changes upstream would be very helpful for these efforts.

[0] https://lore.kernel.org/bpf/CAADnVQJGiH_yF=AoFSRy4zh20uneJgBfqGshubLM6aVq069Fhg@mail.gmail.com/

-- 
Regards
Yafang
Re: [PATCH bpf-next v4 0/6] mm: bpf kfuncs to access memcg data
Posted by Roman Gushchin 1 month, 2 weeks ago
Yafang Shao <laoar.shao@gmail.com> writes:

> On Tue, Dec 23, 2025 at 12:43 PM Roman Gushchin
> <roman.gushchin@linux.dev> wrote:
>>
>> Introduce kfuncs to simplify the access to the memcg data.
>> These kfuncs can be used to accelerate monitoring use cases and
>> for implementing custom OOM policies once BPF OOM is landed.
>>
>> This patchset was separated out from the BPF OOM patchset to simplify
>> the logistics and accelerate the landing of the part which is useful
>> by itself. No functional changes since BPF OOM v2.
>
> Hello Roman,
>
> Thanks for driving the BPF-MM upstreaming work—this is great progress.
>
> Would it be possible to upstream the bpf_st_ops and cgroups patch as a
> standalone series as well? [0]

Hello Yafang,

this is in my plan for next few weeks: I'll probably try to upstream
it altogether with bpfoom, but if there will be any delays with bpfoom,
we can split the patchset further.

Thanks!
Re: [PATCH bpf-next v4 0/6] mm: bpf kfuncs to access memcg data
Posted by Shakeel Butt 1 month, 2 weeks ago
On Mon, Dec 22, 2025 at 08:41:50PM -0800, Roman Gushchin wrote:
> Introduce kfuncs to simplify the access to the memcg data.
> These kfuncs can be used to accelerate monitoring use cases and
> for implementing custom OOM policies once BPF OOM is landed.
> 
> This patchset was separated out from the BPF OOM patchset to simplify
> the logistics and accelerate the landing of the part which is useful
> by itself. No functional changes since BPF OOM v2.

For the series:

Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
Re: [PATCH bpf-next v4 0/6] mm: bpf kfuncs to access memcg data
Posted by Alexei Starovoitov 1 month, 2 weeks ago
On Mon, Dec 22, 2025 at 6:42 PM Roman Gushchin <roman.gushchin@linux.dev> wrote:
>
> Introduce kfuncs to simplify the access to the memcg data.
> These kfuncs can be used to accelerate monitoring use cases and
> for implementing custom OOM policies once BPF OOM is landed.
>
> This patchset was separated out from the BPF OOM patchset to simplify
> the logistics and accelerate the landing of the part which is useful
> by itself. No functional changes since BPF OOM v2.
>
> v4:
>   - refactored memcg vm event and stat item idx checks (by Alexei)

Applied yesterday.

pw-bot seems to be completely broken. No notifications for the last few days.
Re: [PATCH bpf-next v4 0/6] mm: bpf kfuncs to access memcg data
Posted by Konstantin Ryabitsev 1 month, 2 weeks ago
On Tue, Dec 23, 2025 at 09:25:35AM -1000, Alexei Starovoitov wrote:
> > v4:
> >   - refactored memcg vm event and stat item idx checks (by Alexei)
> 
> Applied yesterday.
> 
> pw-bot seems to be completely broken. No notifications for the last few days.

It was postfix, actually, but it managed to fail in a way that didn't show up
on monitoring. It should be in a happier place now. Thanks for the heads-up.

-K
Re: [PATCH bpf-next v4 0/6] mm: bpf kfuncs to access memcg data
Posted by Roman Gushchin 1 month, 2 weeks ago
Alexei Starovoitov <alexei.starovoitov@gmail.com> writes:

> On Mon, Dec 22, 2025 at 6:42 PM Roman Gushchin <roman.gushchin@linux.dev> wrote:
>>
>> Introduce kfuncs to simplify the access to the memcg data.
>> These kfuncs can be used to accelerate monitoring use cases and
>> for implementing custom OOM policies once BPF OOM is landed.
>>
>> This patchset was separated out from the BPF OOM patchset to simplify
>> the logistics and accelerate the landing of the part which is useful
>> by itself. No functional changes since BPF OOM v2.
>>
>> v4:
>>   - refactored memcg vm event and stat item idx checks (by Alexei)
>
> Applied yesterday.

Thank you!

> pw-bot seems to be completely broken. No notifications for the last few days.

Yep, also there were some infra issues in the ci output... Something
about git being unavailable.