From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.200 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796245464; b=zfBMDuKhIPJhADfF6f/wMy8aQ13j9uoLv/uM5fb03kvFxe8vIcmrc0sN5ulnpWAxjtM9 2zXoB1N28GBk4vxDGOU8E8KIEKg/nXqsJhgW4sQpyM4MH7g13NeUPSXCqiaCPsNcXQo9Q 2LFjTGdqPF8iOrCB9HahhuKMqMe+QHQ21LCFMnjJJLrXCrKysO3zBsuRt0mElMrDkFpDf 7n3kdWxCD9FXywVYSbYhnuLIoOP5g/iOW0H5AFIU9ESKygwKCs7VU/31kcPEQCVxs0Ytq Mto2GPh+A45BPVN4p6gTUMb/dx7i7P5fKRR+OIXGJnj2OQjDbcve7Pu3LzTNgWMvtIg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796245464; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=EOEvwod4YRJNQWt7wyGUJZgqZtC/v7KT98qk5YXqI2w=; b=Aolc+umGXf7lzSXfbgg76EvmDsORNIMH7SaJQxHOgwfpjcVy66660MO4joc+cc3ainRb MYCrGnDzc5FWNlSLOf/BkmYVA1sBxKiR7zeZuJOlo/H/WenuXYqfCinRC/3Tkl+mcIhYM 01oknTk1Kg0wB+w0J+f1rHthwHesY/lcvhJdCK0aJZphzA97FN1ekwz2V9/pVoWSbkAYR 49Ul+dgiQ9wxiZR3SHfwcu2W8fzbSwI6Td8KJkbQ5Ev3L/qC/L+IfcTA7uEFJeWOhneem qAy9SQerTSnfeOsbLjRu/Ffy1JzkMH/q0TgVnRkpXgUy/pk+yWUpRF/axt6GQbMkPuw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--bgardon.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=gCrS9BDd; arc=none smtp.remote-ip=209.85.167.200 Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3DA84606A32F for ; Wed, 2 Dec 2026 21:04:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3DA84606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--bgardon.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=gCrS9BDd Received: by mail-oi1-f200.google.com with SMTP id 5614622812f47-4dc57e2a3f2so16997365b6e.0 for ; Wed, 02 Dec 2026 13:04:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796245463; x=1796850263; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=EOEvwod4YRJNQWt7wyGUJZgqZtC/v7KT98qk5YXqI2w=; b=gCrS9BDduNlNU3+NIqOqjYOxDhNlceqFbrUxAYlh3TAhFf9v/oQRV1iLcptI+/USoB w6eELi0I6uY7HKQWgGrq9E+EukBemVitZUzzjsckPEKA3U4/QmRzXqnkWOP470OjNMwr K+xPswHQupwyhtPklzDP4GIJ9+UY/SE8MXzxxsQC8JMn2WLbWqWOuAWX1ij8zU71HLWk DfqPdycptL3i9eGpsqSxNA97U2H9GAHuNWMcmehxq5f/Nr5ayTI70ZL3D0Cgxo0qyBd9 N5lQCeMOcpE1u242w7YdieURSn5P9L4d+Dk8EVlcH+WpgeYLgpb3V3eyFf26ISU7VLsE vXBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796245463; x=1796850263; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=EOEvwod4YRJNQWt7wyGUJZgqZtC/v7KT98qk5YXqI2w=; b=OLBB2qU4OrzpasPAAtYV4oMwGlNAEH932UcKfPPZGo1/JCeJEdu0YVaUoV4S0/aud6 u7yh8ium26k+X8epo6Yp+HxnmjA/EASYbmhB+raAgWa+PSWg6fWVOcQ6FMvgBPAnFJkY tk+YIG1ci1u06959L25xp4IPq8NfTtsgQvwc91ga94eUeUw0c5rZevXdCaN3uPMV4QfV uSo6wFgZFWokjQhYdVzdm6WJKzUAX69ZLlAjq7216rODkSuZiYOYD/NNERyCCqcQZFna 6ev2+vvWurQcmglYoPPfDr775orL/7wLUJ0FxiORLMXn804UrDxaMmgsWppXGtGQZ1YZ 8ymQ== X-Forwarded-Encrypted: i=1; AL+hErFA7FbvsxIw+2qEnSgWuf3/95edkTDMqpIkcUe4Fc4e5e07ye2YQPUMMr0qc8NzbDEVkU8D7vtV@vger.kernel.org X-Gm-Message-State: APuU4Z+2zkiSKxnnsjsRxUg4yZ2BXaQEvcY/8ZKmSNwyNnK/944SHs5u 7+LHmnm4apwcb/AvVTveinFl+KC3dNqiuvTRZMDq+zkYZjBTzLIcbRjwtpNEfifrL5uNKCTlfRS p9fkiycYKWQ== X-Received: from ioxg23.prod.google.com ([2002:a05:6602:737:b0:9c7:5697:9ad7]) (user=bgardon job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6808:13c5:b0:573:52b1:bb00 with SMTP id 5614622812f47-57a09910c41mr47675603b6e.39.1796245462706; Wed, 02 Dec 2026 13:04:22 -0800 (PST) Date: Wed, 2 Dec 2026 13:03:52 -0800 In-Reply-To: <20261202210415.517651-1-bgardon@google.com> X-Mailing-List: cgroups@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261202210415.517651-1-bgardon@google.com> X-Mailer: git-send-email 2.56.1.911.g883d8bcb20-goog Message-ID: <20261202210415.517651-3-bgardon@google.com> Subject: [PATCH bpf-next v4 02/17] mm, bpf: introduce BPF OOM struct ops From: Ben Gardon To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Andrew Morton , Johannes Weiner , Michal Hocko , Shakeel Butt , Roman Gushchin , Tejun Heo Cc: JP Kobryn , Eduard Zingerman , Kumar Kartikeya Dwivedi , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Ihor Solodrai , David Rientjes , Suren Baghdasaryan , Josh Don , Sweet Tea Dorminy , Chuyi Zhou , Yafang Shao , benbwgardon@gmail.com, bpf@vger.kernel.org, linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Ben Gardon , John Fastabend , Michal Hocko Content-Type: text/plain; charset="UTF-8" From: Roman Gushchin Introduce cgroup BPF struct_ops (bpf_oom_ops, attach type CGROUP_OOM_OPS) for implementing custom OOM policies. Policies can be attached to a cgroup via bpf_map__attach_cgroup_opts(). Root cgroup attachments cover system-wide OOMs as well as fallback from descendant cgroups. By default, effective handlers run from the OOMing memory cgroup upward toward the root unless an ancestor attaches with BPF_F_PREORDER. The handle_out_of_memory callback receives the oom_control describing the OOM scope and the cgroup where the policy is attached. Returning a positive value signals that the OOM condition has been handled. This could be by terminating a task, expanding a memcg limit, or backing off while a previously selected task exits. Returning <= 0 delegates to the next handler in the effective chain and ultimately to the in-kernel OOM handler. SysRq-triggered OOMs bypass BPF handlers so SysRq-f remains a failsafe. Existing heuristics and sysctls such as panic_on_oom and sysctl_oom_kill_allocating_task continue to run prior to bpf_handle_oom(). Signed-off-by: Roman Gushchin Co-developed-by: Ben Gardon Signed-off-by: Ben Gardon --- v3 -> v4: - Adopted mainline cgroup struct_ops attachment (CGROUP_OOM_OPS) and changed handle_out_of_memory() to receive (struct oom_control *, struct cgroup *). - Dropped oc->bpf_memory_freed dual-reporting check so handlers can return > 0 to back off while an existing selected task exits; treat only positive returns (> 0) as handled so negative errnos delegate. - Bypassed bpf_handle_oom() on SysRq-triggered OOMs (is_sysrq_oom(oc)). - Added .validate callback requiring handle_out_of_memory, validated ops->name via bpf_obj_name_cpy(), switched bpf_oom_func_proto() to curated bpf_base_func_proto() (blocking user-copy/stack helpers), walked up offline cgroups to the nearest online ancestor, and encapsulated sleepable RCU Tasks Trace locking in bpf-cgroup.h. v3: https://lore.kernel.org/all/20260127024421.494929-8-roman.gushchin@linux.dev/ MAINTAINERS | 2 + include/linux/bpf-cgroup-defs.h | 1 + include/linux/bpf-cgroup.h | 16 ++- include/linux/bpf.h | 1 + include/linux/bpf_oom.h | 44 ++++++++ include/linux/oom.h | 17 +++ kernel/bpf/cgroup.c | 1 + mm/Makefile | 3 + mm/bpf_oom.c | 187 ++++++++++++++++++++++++++++++++ mm/oom_kill.c | 10 ++ 10 files changed, 280 insertions(+), 2 deletions(-) create mode 100644 include/linux/bpf_oom.h create mode 100644 mm/bpf_oom.c diff --git a/MAINTAINERS b/MAINTAINERS index b430b29e3878..d4ef52c5594b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -5177,7 +5177,9 @@ M: Shakeel Butt L: bpf@vger.kernel.org L: linux-mm@kvack.org S: Maintained +F: include/linux/bpf_oom.h F: mm/bpf_memcontrol.c +F: mm/bpf_oom.c BPF [MISC] L: bpf@vger.kernel.org diff --git a/include/linux/bpf-cgroup-defs.h b/include/linux/bpf-cgroup-defs.h index 671f27ba6a62..ff650a422e36 100644 --- a/include/linux/bpf-cgroup-defs.h +++ b/include/linux/bpf-cgroup-defs.h @@ -48,6 +48,7 @@ enum cgroup_bpf_attach_type { CGROUP_UNIX_GETSOCKNAME, CGROUP_INET_SOCK_RELEASE, CGROUP_TCP_SOCK_OPS, + CGROUP_OOM_OPS, CGROUP_LSM_START, CGROUP_LSM_END = CGROUP_LSM_START + CGROUP_LSM_NUM - 1, MAX_CGROUP_BPF_ATTACH_TYPE diff --git a/include/linux/bpf-cgroup.h b/include/linux/bpf-cgroup.h index 0b63c2cc1399..13a74791be46 100644 --- a/include/linux/bpf-cgroup.h +++ b/include/linux/bpf-cgroup.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -112,14 +113,25 @@ struct bpf_prog_list { u32 flags; }; +static inline void bpf_cgroup_struct_ops_lock_sleepable(void) +{ + rcu_read_lock_trace(); +} + +static inline void bpf_cgroup_struct_ops_unlock_sleepable(void) +{ + rcu_read_unlock_trace(); +} + #define bpf_cgroup_struct_ops_foreach(var, item, cgrp, atype) \ - for (item = rcu_dereference((cgrp)->bpf.effective[atype])->items;\ + for (item = rcu_dereference_check((cgrp)->bpf.effective[atype], \ + rcu_read_lock_trace_held())->items;\ ((var) = READ_ONCE(item->kdata)); \ item++) static inline bool cgroup_bpf_is_struct_ops_atype(enum cgroup_bpf_attach_type atype) { - return atype == CGROUP_TCP_SOCK_OPS; + return atype == CGROUP_TCP_SOCK_OPS || atype == CGROUP_OOM_OPS; } void cgroup_bpf_struct_ops_register(int atype, u32 type_id, void *cfi_stubs, bool mult_trace); int cgroup_bpf_struct_ops_attach(struct bpf_map *map, const union bpf_attr *attr); diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 96e249bd00fb..82f99b92c481 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -2761,6 +2761,7 @@ struct bpf_prog_array_item { }; union { struct bpf_cgroup_storage *cgroup_storage[MAX_BPF_CGROUP_STORAGE_TYPE]; + struct cgroup *cgroup; u64 bpf_cookie; }; }; diff --git a/include/linux/bpf_oom.h b/include/linux/bpf_oom.h new file mode 100644 index 000000000000..23e3131a12be --- /dev/null +++ b/include/linux/bpf_oom.h @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#ifndef __BPF_OOM_H +#define __BPF_OOM_H + +struct cgroup; +struct oom_control; + +#define BPF_OOM_NAME_MAX_LEN 64 + +/** + * struct bpf_oom_ops - BPF operations for customizing OOM handling + */ +struct bpf_oom_ops { + /** + * @handle_out_of_memory: Out of memory BPF handler, invoked before the + * in-kernel OOM selector. + * + * Receives @oc describing the OOM scope/constraint and @cgrp where this + * policy instance is attached. Return a positive value (> 0) if the + * OOM event was handled (either by freeing/expanding memory or + * backing off for an already-exiting task), or <= 0 to defer to the + * next handler in the hierarchy and ultimately the in-kernel OOM + * handler. + */ + int (*handle_out_of_memory)(struct oom_control *oc, + struct cgroup *cgrp); + + /** + * @name: BPF OOM policy name logged in OOM reports. + */ + char name[BPF_OOM_NAME_MAX_LEN]; +}; + +#if defined(CONFIG_CGROUP_BPF) && defined(CONFIG_MEMCG) +bool bpf_handle_oom(struct oom_control *oc); +#else +static inline bool bpf_handle_oom(struct oom_control *oc) +{ + return false; +} +#endif + +#endif /* __BPF_OOM_H */ diff --git a/include/linux/oom.h b/include/linux/oom.h index 00da05d227e6..ca3192c42533 100644 --- a/include/linux/oom.h +++ b/include/linux/oom.h @@ -51,8 +51,25 @@ struct oom_control { /* Used to print the constraint info. */ enum oom_constraint constraint; + +#if defined(CONFIG_CGROUP_BPF) && defined(CONFIG_MEMCG) + /* Active BPF OOM handler name */ + const char *bpf_handler_name; +#endif }; +#if defined(CONFIG_CGROUP_BPF) && defined(CONFIG_MEMCG) +static inline const char *oom_handler_name(const struct oom_control *oc) +{ + return oc->bpf_handler_name; +} +#else +static inline const char *oom_handler_name(const struct oom_control *oc) +{ + return NULL; +} +#endif + extern struct mutex oom_lock; extern struct mutex oom_adj_mutex; diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c index e4e680dfb63d..dba22e99197d 100644 --- a/kernel/bpf/cgroup.c +++ b/kernel/bpf/cgroup.c @@ -572,6 +572,7 @@ static void prog_list_init_item(struct bpf_prog_list *pl, struct bpf_prog_array_ { if (prog_list_is_struct_ops(pl)) { item->kdata = bpf_struct_ops_map_kdata(pl->link->map); + item->cgroup = pl->link->cgroup; return; } diff --git a/mm/Makefile b/mm/Makefile index 2a3ec53d62ee..66b53e569eed 100644 --- a/mm/Makefile +++ b/mm/Makefile @@ -107,6 +107,9 @@ obj-$(CONFIG_MEMCG) += memcontrol.o vmpressure.o ifdef CONFIG_BPF_SYSCALL obj-$(CONFIG_MEMCG) += bpf_memcontrol.o endif +ifdef CONFIG_CGROUP_BPF +obj-$(CONFIG_MEMCG) += bpf_oom.o +endif obj-$(CONFIG_CGROUP_HUGETLB) += hugetlb_cgroup.o obj-$(CONFIG_GUP_TEST) += gup_test.o obj-$(CONFIG_DMAPOOL_TEST) += dmapool_test.o diff --git a/mm/bpf_oom.c b/mm/bpf_oom.c new file mode 100644 index 000000000000..bc0838d55335 --- /dev/null +++ b/mm/bpf_oom.c @@ -0,0 +1,187 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * BPF-driven OOM killer customization + * + * Author: Roman Gushchin + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +static int bpf_ops_handle_oom(struct bpf_oom_ops *bpf_oom_ops, + struct cgroup *cgrp, + struct oom_control *oc) +{ + int ret; + + oc->bpf_handler_name = &bpf_oom_ops->name[0]; + pagefault_disable(); + ret = bpf_oom_ops->handle_out_of_memory(oc, cgrp); + pagefault_enable(); + oc->bpf_handler_name = NULL; + + return ret; +} + +static struct cgroup *bpf_oom_cgroup(struct mem_cgroup *memcg) +{ + if (cgroup_subsys_on_dfl(memory_cgrp_subsys) && !mem_cgroup_disabled()) { + struct cgroup *cgrp; + + memcg = memcg ?: root_mem_cgroup; + cgrp = READ_ONCE(memcg->css.cgroup); + if (cgrp->root == &cgrp_dfl_root) + return cgrp; + } + + /* + * Fall back to the cgroup v2 root when memory cgroups are disabled or + * mounted on cgroup v1 (cgroup BPF only attaches to the v2 hierarchy). + */ + return &cgrp_dfl_root.cgrp; +} + +/** + * bpf_handle_oom() - Invoke attached cgroup BPF OOM policies + * @oc: OOM control structure describing the OOM event + * + * Return: true if a BPF policy handled the OOM, false to fall back to the + * in-kernel OOM handler. + */ +bool bpf_handle_oom(struct oom_control *oc) +{ + const struct bpf_prog_array_item *item; + struct bpf_oom_ops *bpf_oom_ops; + struct cgroup *cgrp; + int ret = 0; + + lockdep_assert_held(&oom_lock); + + if (!cgroup_bpf_enabled(CGROUP_OOM_OPS)) + return false; + + cgrp = bpf_oom_cgroup(oc->memcg); + + bpf_cgroup_struct_ops_lock_sleepable(); + while (cgrp && !(READ_ONCE(cgrp->self.flags) & CSS_ONLINE)) + cgrp = cgroup_parent(cgrp); + if (!cgrp) + goto out_unlock; + + bpf_cgroup_struct_ops_foreach(bpf_oom_ops, item, cgrp, CGROUP_OOM_OPS) { + ret = bpf_ops_handle_oom(bpf_oom_ops, item->cgroup, oc); + if (ret > 0) + break; + } + +out_unlock: + bpf_cgroup_struct_ops_unlock_sleepable(); + + return ret > 0; +} + +static int __handle_out_of_memory(struct oom_control *oc, + struct cgroup *cgrp) +{ + return 0; +} + +static struct bpf_oom_ops __bpf_oom_ops = { + .handle_out_of_memory = __handle_out_of_memory, +}; + +static const struct bpf_func_proto * +bpf_oom_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) +{ + switch (func_id) { + case BPF_FUNC_copy_from_user: + case BPF_FUNC_copy_from_user_task: + case BPF_FUNC_get_task_stack: + return NULL; + default: + return bpf_base_func_proto(func_id, prog); + } +} + +static bool bpf_oom_ops_is_valid_access(int off, int size, + enum bpf_access_type type, + const struct bpf_prog *prog, + struct bpf_insn_access_aux *info) +{ + return bpf_tracing_btf_ctx_access(off, size, type, prog, info); +} + +static const struct bpf_verifier_ops bpf_oom_verifier_ops = { + .get_func_proto = bpf_oom_func_proto, + .is_valid_access = bpf_oom_ops_is_valid_access, +}; + +static int bpf_oom_ops_check_member(const struct btf_type *t, + const struct btf_member *member, + const struct bpf_prog *prog) +{ + return 0; +} + +static int bpf_oom_ops_init_member(const struct btf_type *t, + const struct btf_member *member, + void *kdata, const void *udata) +{ + const struct bpf_oom_ops *uops = udata; + struct bpf_oom_ops *ops = kdata; + u32 moff = __btf_member_bit_offset(t, member) / 8; + + switch (moff) { + case offsetof(struct bpf_oom_ops, name): + if (uops->name[0]) { + if (bpf_obj_name_cpy(ops->name, uops->name, + sizeof(ops->name)) <= 0) + return -EINVAL; + } else { + strscpy_pad(ops->name, "bpf_defined_policy", + sizeof(ops->name)); + } + return 1; + } + return 0; +} + +static int bpf_oom_ops_validate(void *kdata) +{ + struct bpf_oom_ops *ops = kdata; + + if (!ops->handle_out_of_memory) + return -EINVAL; + + return 0; +} + +static int bpf_oom_ops_init(struct btf *btf) +{ + return 0; +} + +static struct bpf_struct_ops bpf_oom_bpf_ops = { + .verifier_ops = &bpf_oom_verifier_ops, + .check_member = bpf_oom_ops_check_member, + .init_member = bpf_oom_ops_init_member, + .validate = bpf_oom_ops_validate, + .init = bpf_oom_ops_init, + .name = "bpf_oom_ops", + .cgroup_atype = CGROUP_OOM_OPS, + .owner = THIS_MODULE, + .cfi_stubs = &__bpf_oom_ops, + .free_after_mult_rcu_gp = true, +}; + +static int __init bpf_oom_struct_ops_init(void) +{ + return register_bpf_struct_ops(&bpf_oom_bpf_ops, bpf_oom_ops); +} +late_initcall(bpf_oom_struct_ops_init); diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 5d48bd862c27..fa9088c965b6 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -45,6 +45,7 @@ #include #include #include +#include #include #include "internal.h" @@ -451,6 +452,8 @@ static void dump_header(struct oom_control *oc) pr_warn("%s invoked oom-killer: gfp_mask=%#x(%pGg), order=%d, oom_score_adj=%d\n", current->comm, oc->gfp_mask, &oc->gfp_mask, oc->order, current->signal->oom_score_adj); + if (oom_handler_name(oc)) + pr_warn("oom bpf handler: %s\n", oom_handler_name(oc)); if (!IS_ENABLED(CONFIG_COMPACTION) && oc->order) pr_warn("COMPACTION is disabled!!!\n"); @@ -1145,6 +1148,13 @@ bool out_of_memory(struct oom_control *oc) return true; } + /* + * Let BPF handle the OOM first unless triggered via SysRq, which + * skips to the kernel OOM handler. + */ + if (!is_sysrq_oom(oc) && bpf_handle_oom(oc)) + return true; + select_bad_process(oc); /* Found nothing?!?! */ if (!oc->chosen) { -- 2.56.1.911.g883d8bcb20-goog