[PATCH bpf-next v3 10/17] mm: introduce bpf_task_is_oom_victim() kfunc

From: Roman Gushchin

Date: Mon Jan 26 2026 - 21:54:34 EST


Export tsk_is_oom_victim() helper as a BPF kfunc.
It's very useful to avoid redundant oom kills.

Signed-off-by: Roman Gushchin <roman.gushchin@xxxxxxxxx>
Suggested-by: Michal Hocko <mhocko@xxxxxxxx>
---
mm/oom_kill.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)

diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 8f63a370b8f5..53f9f9674658 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -1381,10 +1381,24 @@ __bpf_kfunc int bpf_out_of_memory(struct mem_cgroup *memcg__nullable,
return ret;
}

+/**
+ * bpf_task_is_oom_victim - Check if the task has been marked as an OOM victim
+ * @task: task to check
+ *
+ * Returns true if the task has been previously selected by the OOM killer
+ * to be killed. It's expected that the task will be destroyed soon and some
+ * memory will be freed, so maybe no additional actions required.
+ */
+__bpf_kfunc bool bpf_task_is_oom_victim(struct task_struct *task)
+{
+ return tsk_is_oom_victim(task);
+}
+
__bpf_kfunc_end_defs();

BTF_KFUNCS_START(bpf_oom_kfuncs)
BTF_ID_FLAGS(func, bpf_oom_kill_process, KF_SLEEPABLE)
+BTF_ID_FLAGS(func, bpf_task_is_oom_victim)
BTF_KFUNCS_END(bpf_oom_kfuncs)

BTF_ID_LIST_SINGLE(bpf_oom_ops_ids, struct, bpf_oom_ops)
--
2.52.0