From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.69 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796245461; b=0g6t4jWuuPnf2J7Oi2biDJXA9tFjk+o0aG3j+2qQ+cyT4KxqT8zIcsemKCT91A7B2qj0 J0yEue056/jIdpVRi4nnFTN4623s4e6/JfYl4aFP+dXRbIKCp3aaVs/KIjRETs3LlmyvM 5kPXBFEdR4a81Qy/y4mjr7pQaxU+HWNQIKxQGDOrMHLxPWkA2sgadCKXqcUoIG/mFjYcW CXYrTMTuL/AgzcTqxDWfcG8Gpz5Xj5yGxACcgNWRO9Lcd00/WinGC0uiKWAFH+VMMcB9x QGdmN4f6IkxsydB2ujwfuFAMfa2Zx63QI+3/XPiNRNy2Jv/RqMD5jTLqLli4lKMHc3A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796245461; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:Mime-Version: X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=QNZI17mDOdo6WEUcc15Rhg+NFlB7qgT8+Ggv1+EHWxI=; b=d4gqWq/8k4XL1CAS4ikLWRjusneExUFHRm9YVTcPCDWb+875Ncm5Iy32uLuapbqr8Qus RIk+fTUChmWaWZH3aIlKI0P0Ly0ix8v7CrBhk7avCd/tB/WdwxcIQI/u4xoA4v+WnTfbq a9Hj73H0R1yPJaBHpMcElGSEOY0oXnGGFcL/QfrSpAFf8Zz3eRsgSjpRwLIriGzW3oebP YDIfH3a4pdYZkIal44qZbh9EyBjySGbU8hxe2WwWT9U2qqVQ6ulXxAxdzFRsSd9eDT11a Sb+eb3CJq6LzyUcqdVzIoqbnZlfwO1TbKPmkoIs3d0E2Q6VgK/6jn3kG1ev3wfp9sFw== 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=cC7gkZJ9; arc=none smtp.remote-ip=209.85.210.69 Received: from mail-ot1-f69.google.com (mail-ot1-f69.google.com [209.85.210.69]) (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 50559606A32D for ; Wed, 2 Dec 2026 21:04:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 50559606A32D 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=cC7gkZJ9 Received: by mail-ot1-f69.google.com with SMTP id 46e09a7af769-8632a144987so8617708a34.2 for ; Wed, 02 Dec 2026 13:04:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796245459; x=1796850259; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=QNZI17mDOdo6WEUcc15Rhg+NFlB7qgT8+Ggv1+EHWxI=; b=cC7gkZJ9LjQZ0H+V/Smt2LXGQsd+UEvKq9AlBnM0q64y7hYl9vpyROyUnxV4OySP01 NqU9PmqhnSHTNTpY3Zo9CbNCCSvEbLBa0+Dl5EhcQsY3jtV25zcyppmghBgQQK4NAcHI +fP2Zd58OniIo+GeFl1hznM6dTBUTbIzqdOH6m3kPbbRNTT3IFb438WG0FMiqkkxb7HU cUto91hc+huSicwaUN/AJkecnWBb+t7xUW7HapIOPi8ufzz5PXYjp+N2CqpqWct/AzPo 2PNu4fTjxgZzigkPR/uHcmKcPzuEoYAjQ/V/P/9XV5RO6AGayJodyDGmA79VXd07WNLR N5aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796245459; x=1796850259; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=QNZI17mDOdo6WEUcc15Rhg+NFlB7qgT8+Ggv1+EHWxI=; b=wTctV7khgoL8IZX4bSTMUnt3/y58VYN73CVimhmLDqmoHAo8VHjf5vUGYlha/Z7wTy CQoJjX5Ulwti1teSicsdvq/TNw2MswkRjpDCvp7TpcWf5IaetolxIMctkt8xN55UkO2g xSH0UD9xS8X0XHEotgNfKTC7rK9PJH09Hg8QV2rlXAvQzTKUM286CgNfD3P4TI7X19bs Kevei2jydZk39oDrU/aTXaeBN79zTHSIfJBiTLdRs/buSGR6g2K17pM+SPJGx3z0r5jD ZU/5l0ir8nR6UTTZFundkX4bEQoRWCPmQxiMIbidIKmeQPkHrPMkW1TSDYUkyl1D2Xf5 JLsw== X-Forwarded-Encrypted: i=1; AL+hErGRYnun2f70X/JgjoXdDYY/QBOaQFyV4c7VEA1NRBzaCl6DXJBIsqV81EEZZyt0FIUj9ohy5GjW4jB2+0o=@vger.kernel.org X-Gm-Message-State: APuU4Z91nyWyRnNojD8ovfKg63RVbYINtE4nMESlMP1EnJOdQlrL0Axf 1h20+1ySdlMTznFLeciVi8+Z25S3FjLK8rbA3r+FlIFOIdQlVo1D8w8HoyL2Of4oZcZCLKtDjg/ vlO3T6OljJA== X-Received: from iowb19.prod.google.com ([2002:a05:6602:14d3:b0:9c7:bd0f:3947]) (user=bgardon job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6808:1484:b0:4b3:7b31:8df7 with SMTP id 5614622812f47-57a0a93091bmr44408406b6e.14.1796245458882; Wed, 02 Dec 2026 13:04:18 -0800 (PST) Date: Wed, 2 Dec 2026 13:03:50 -0800 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 X-Mailer: git-send-email 2.56.1.911.g883d8bcb20-goog Message-ID: <20261202210415.517651-1-bgardon@google.com> Subject: [PATCH bpf-next v4 00/17] mm: BPF OOM 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 Content-Type: text/plain; charset="UTF-8" Note: I am taking over this patch series from Roman Gushchin. This series adds support for BPF OOM handling and proactive OOM prevention. One might want this to: 1) Implement custom reactive OOM handling policies with smarter, application-specific victim selection. 2) Add greater NUMA awareness to task selection. 3) Create proactive OOM prevention policies, which terminate tasks before a kernel OOM is invoked, to preserve memory QoS. This creates a generic cgroup struct_ops interface, which is invoked before the kernel's OOM selector. A policy linked to the struct_ops can select which task to terminate, or expand a memory cgroup's hard limit to resolve the OOM non-destructively. Earlier proposals [1] have augmented the in-kernel task badness heuristic, but this series goes farther, leaving policy entirely up to the BPF program. Past attempts to standardize a single memory-cgroup-aware OOM policy [2] have shown that selection depends heavily on workloads and cgroup hierarchy layout. A BPF interface will provide flexibility while keeping the kernel OOM handler as a relatively simple and reliable fallback. To prevent OOMs in the first place, PSI-driven userspace daemons such as oomd [3] and systemd-oomd [4] terminate processes before thrashing or hard stalls, while leaving the kernel OOM handler as a last resort. Moving some of that logic into BPF avoids deploying and monitoring a separate privileged daemon that must itself survive severe memory pressure. It also unifies OOM accounting and logging, and gives policies direct access to kernel memcg and task state. Series Overview --------------- - Patch 1: Preparation: mark struct oom_control::memcg as TRUSTED_OR_NULL in the BPF verifier. - Patches 2-5: Reactive BPF OOM infrastructure: CGROUP_OOM_OPS struct_ops, bpf_oom_kill_process(), bpf_out_of_memory(), and cgroup hierarchy handling selftest. - Patches 6-10: PSI integration: psi_avgs_work_tp tracepoint, psi_group::cgroup_id, allowing bpf_out_of_memory() from tp_btf/psi_avgs_work_tp, and PSI selftest. - Patch 11: A systemd-oomd style BPF OOM policy example and selftest. - Patches 12-14: Allow proactive BPF policies to directly terminate chosen tasks without falling back to select_bad_process(). This complements bpf_out_of_memory(), which runs the full out_of_memory() path and delegates selection to attached bpf_oom_ops handlers or the in-kernel selection algorithm. - Patches 15-16: Allow OOM handlers to resolve memcg OOMs by raising memory.max, as suggested by Michal Hocko. - Patch 17: Documentation/bpf/bpf_oom.rst | 138 ++++++++ Documentation/bpf/index.rst | 1 + MAINTAINERS | 4 + 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/memcontrol.h | 27 ++ include/linux/oom.h | 39 +++ include/linux/psi_types.h | 6 + include/trace/events/psi.h | 19 ++ kernel/bpf/cgroup.c | 1 + kernel/bpf/verifier.c | 5 + kernel/sched/psi.c | 7 + mm/Makefile | 3 + mm/bpf_memcontrol.c | 24 ++ mm/bpf_oom.c | 187 +++++++++++ mm/memcontrol-v1.c | 16 + mm/memcontrol-v1.h | 6 + mm/memcontrol.c | 38 +++ mm/oom_kill.c | 313 ++++++++++++++++++- tools/testing/selftests/bpf/config | 1 + .../selftests/bpf/prog_tests/memory_holder.h | 158 ++++++++++ tools/testing/selftests/bpf/prog_tests/test_oom.c | 218 +++++++++++++ .../selftests/bpf/prog_tests/test_oom_kfunc_neg.c | 79 +++++ .../bpf/prog_tests/test_oom_proactive_kill.c | 119 +++++++ .../selftests/bpf/prog_tests/test_oom_raise_max.c | 135 ++++++++ tools/testing/selftests/bpf/prog_tests/test_oomd.c | 274 ++++++++++++++++ tools/testing/selftests/bpf/prog_tests/test_psi.c | 107 +++++++ tools/testing/selftests/bpf/progs/test_oom.c | 132 ++++++++ .../selftests/bpf/progs/test_oom_fail_ops_oom.c | 21 ++ .../bpf/progs/test_oom_fail_ops_proactive.c | 23 ++ .../selftests/bpf/progs/test_oom_fail_syscall.c | 15 + .../selftests/bpf/progs/test_oom_proactive_kill.c | 46 +++ .../selftests/bpf/progs/test_oom_proactive_kill.h | 12 + .../selftests/bpf/progs/test_oom_raise_max.c | 55 ++++ .../selftests/bpf/progs/test_oom_raise_max.h | 10 + tools/testing/selftests/bpf/progs/test_oomd.c | 346 +++++++++++++++++++++ tools/testing/selftests/bpf/progs/test_oomd.h | 33 ++ tools/testing/selftests/bpf/progs/test_psi.c | 88 ++++++ 40 files changed, 2760 insertions(+), 8 deletions(-) -- 2.56.1.911.g883d8bcb20-goog