Re: [PATCH bpf-next v4 17/17] Documentation/bpf: Document BPF OOM handling and kfuncs
From: bot+bpf-ci
Date: Wed Dec 02 2026 - 16:58:39 EST
> Documentation/bpf: Document BPF OOM handling and kfuncs
TL;DR: Documentation-only issues in bpf_oom.rst: it may overstate
dump_header() suppression (no-victim path still dumps), implies multiple
supported tracepoints, and misplaces handler validation (attach, not load).
> diff --git a/Documentation/bpf/bpf_oom.rst b/Documentation/bpf/bpf_oom.rst
> new file mode 100644
> --- /dev/null
> +++ b/Documentation/bpf/bpf_oom.rst
> @@ -0,0 +1,138 @@
[ ... ]
> +2. **Proactive OOM invocation and termination** via BPF kfuncs callable
> + from ``BPF_PROG_TYPE_SYSCALL`` programs and select tracepoints (such as
> + ``tp_btf/psi_avgs_work_tp``) to trigger OOM handling or directly
> + terminate a chosen task without a separate userspace OOM daemon.
Is "select tracepoints (such as tp_btf/psi_avgs_work_tp)" accurate?
bpf_declare_oom_tracing_filter() in mm/oom_kill.c accepts exactly one
tracing attach point and returns -EACCES for any other:
prog->aux->attach_btf_id == bpf_oom_trace_ids[0]
Should the text name psi_avgs_work_tp as the only supported tracepoint
rather than implying a set?
[ ... ]
> +- ``handle_out_of_memory(oc, cgrp)``: Sleepable callback
> + (``SEC("struct_ops.s/handle_out_of_memory")``). ``oc`` is a read-only
> + ``struct oom_control *`` whose ``oc->memcg`` field is verified as
> + ``TRUSTED_OR_NULL`` (``NULL`` for global OOMs, trusted pointer for
> + memcg OOMs). ``cgrp`` is the cgroup where this policy instance is
> + attached. ``handle_out_of_memory`` is required and validated at map
> + load time.
Is "validated at map load time" correct?
bpf_oom_ops_validate() is the struct_ops .validate callback, which is only
called from __bpf_struct_ops_map_update_elem():
if (st_ops->validate) {
err = st_ops->validate(kdata);
That runs on BPF_MAP_UPDATE_ELEM of the struct_ops map, which libbpf issues
from bpf_map__attach_cgroup_opts() rather than from bpf_object__load().
An object that leaves handle_out_of_memory unset (or uses an invalid name)
loads successfully and fails with -EINVAL only at attach.
Could this say the check happens when the struct_ops map is updated or
attached?
[ ... ]
> +``int bpf_out_of_memory(struct mem_cgroup *memcg__nullable, int order, u64 flags)``
> + Acquires ``oom_lock`` (waiting interruptibly for fatal signals if
> + ``BPF_OOM_FLAGS_WAIT_ON_OOM_LOCK`` is set, else returning ``-EBUSY`` on
> + contention), accounts ``MEMCG_OOM`` for non-NULL ``memcg``, and runs
> + ``out_of_memory()``, invoking any attached ``bpf_oom_ops`` policies and
> + falling back to ``select_bad_process()`` if unhandled. Root ``memcg`` is
> + normalized to ``NULL``; dying memcgs return ``-EINVAL``. BPF-declared
> + OOMs do not panic the kernel if no eligible task exists, skip
> + ``sysctl_oom_kill_allocating_task``, and omit ``dump_header()`` noise.
Is the claim that BPF-declared OOMs omit dump_header() correct for the case
where no eligible task exists?
The suppression is only in oom_kill_process() and check_panic_on_oom().
The no-victim path in out_of_memory() still calls it unconditionally:
select_bad_process(oc);
/* Found nothing?!?! */
if (!oc->chosen) {
dump_header(oc);
pr_warn("Out of memory and no killable processes...\n");
...
if (!is_sysrq_oom(oc) && !is_memcg_oom(oc) &&
!is_bpf_declared_oom(oc))
panic("System is deadlocked on memory\n");
}
Only the panic is skipped there. If bpf_out_of_memory() is called on a
memcg whose tasks are all OOM_SCORE_ADJ_MIN (or that has no tasks) and no
bpf_oom_ops handler returns > 0, the full header, including dump_stack()
and meminfo, is printed on every call.
Should the documentation limit the dump_header() claim to the kill path, or
should out_of_memory() get an is_bpf_declared_oom() check before that
dump_header()?
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/46974333971