linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: ChaosEsque Team <chaosesqueteam@gmail.com>
To: Roman Gushchin <roman.gushchin@linux.dev>
Cc: linux-mm@kvack.org, bpf@vger.kernel.org,
	 Suren Baghdasaryan <surenb@google.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Michal Hocko <mhocko@suse.com>,
	 David Rientjes <rientjes@google.com>,
	Matt Bobrowski <mattbobrowski@google.com>,
	 Song Liu <song@kernel.org>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Alexei Starovoitov <ast@kernel.org>,
	 Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 07/14] mm: allow specifying custom oom constraint for bpf triggers
Date: Thu, 2 Oct 2025 12:37:25 -0400	[thread overview]
Message-ID: <CALC8CXfcJjoHyZAiHm1meGtKf9CAbgnmhy4fxMqaa5Gb_ZHvwQ@mail.gmail.com> (raw)
In-Reply-To: <20250818170136.209169-8-roman.gushchin@linux.dev>

Roman Gushchin...
RUSSKIEEEEEE

On Mon, Aug 18, 2025 at 1:05 PM Roman Gushchin <roman.gushchin@linux.dev> wrote:
>
> Currently there is a hard-coded list of possible oom constraints:
> NONE, CPUSET, MEMORY_POLICY & MEMCG. Add a new one: CONSTRAINT_BPF.
> Also, add an ability to specify a custom constraint name
> when calling bpf_out_of_memory(). If an empty string is passed
> as an argument, CONSTRAINT_BPF is displayed.
>
> The resulting output in dmesg will look like this:
>
> [  315.224875] kworker/u17:0 invoked oom-killer: gfp_mask=0x0(), order=0, oom_score_adj=0
>                oom_policy=default
> [  315.226532] CPU: 1 UID: 0 PID: 74 Comm: kworker/u17:0 Not tainted 6.16.0-00015-gf09eb0d6badc #102 PREEMPT(full)
> [  315.226534] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.17.0-5.fc42 04/01/2014
> [  315.226536] Workqueue: bpf_psi_wq bpf_psi_handle_event_fn
> [  315.226542] Call Trace:
> [  315.226545]  <TASK>
> [  315.226548]  dump_stack_lvl+0x4d/0x70
> [  315.226555]  dump_header+0x59/0x1c6
> [  315.226561]  oom_kill_process.cold+0x8/0xef
> [  315.226565]  out_of_memory+0x111/0x5c0
> [  315.226577]  bpf_out_of_memory+0x6f/0xd0
> [  315.226580]  ? srso_alias_return_thunk+0x5/0xfbef5
> [  315.226589]  bpf_prog_3018b0cf55d2c6bb_handle_psi_event+0x5d/0x76
> [  315.226594]  bpf__bpf_psi_ops_handle_psi_event+0x47/0xa7
> [  315.226599]  bpf_psi_handle_event_fn+0x63/0xb0
> [  315.226604]  process_one_work+0x1fc/0x580
> [  315.226616]  ? srso_alias_return_thunk+0x5/0xfbef5
> [  315.226624]  worker_thread+0x1d9/0x3b0
> [  315.226629]  ? __pfx_worker_thread+0x10/0x10
> [  315.226632]  kthread+0x128/0x270
> [  315.226637]  ? lock_release+0xd4/0x2d0
> [  315.226645]  ? __pfx_kthread+0x10/0x10
> [  315.226649]  ret_from_fork+0x81/0xd0
> [  315.226652]  ? __pfx_kthread+0x10/0x10
> [  315.226655]  ret_from_fork_asm+0x1a/0x30
> [  315.226667]  </TASK>
> [  315.239745] memory: usage 42240kB, limit 9007199254740988kB, failcnt 0
> [  315.240231] swap: usage 0kB, limit 0kB, failcnt 0
> [  315.240585] Memory cgroup stats for /cgroup-test-work-dir673/oom_test/cg2:
> [  315.240603] anon 42897408
> [  315.241317] file 0
> [  315.241493] kernel 98304
> ...
> [  315.255946] Tasks state (memory values in pages):
> [  315.256292] [  pid  ]   uid  tgid total_vm      rss rss_anon rss_file rss_shmem pgtables_bytes swapents oom_score_adj name
> [  315.257107] [    675]     0   675   162013    10969    10712      257         0   155648        0             0 test_progs
> [  315.257927] oom-kill:constraint=CONSTRAINT_BPF_PSI_MEM,nodemask=(null),cpuset=/,mems_allowed=0,oom_memcg=/cgroup-test-work-dir673/oom_test/cg2,task_memcg=/cgroup-test-work-dir673/oom_test/cg2,task=test_progs,pid=675,uid=0
> [  315.259371] Memory cgroup out of memory: Killed process 675 (test_progs) total-vm:648052kB, anon-rss:42848kB, file-rss:1028kB, shmem-rss:0kB, UID:0 pgtables:152kB oom_score_adj:0
>
> Signed-off-by: Roman Gushchin <roman.gushchin@linux.dev>
> ---
>  include/linux/oom.h |  4 ++++
>  mm/oom_kill.c       | 38 +++++++++++++++++++++++++++++---------
>  2 files changed, 33 insertions(+), 9 deletions(-)
>
> diff --git a/include/linux/oom.h b/include/linux/oom.h
> index ef453309b7ea..4b04944b42de 100644
> --- a/include/linux/oom.h
> +++ b/include/linux/oom.h
> @@ -19,6 +19,7 @@ enum oom_constraint {
>         CONSTRAINT_CPUSET,
>         CONSTRAINT_MEMORY_POLICY,
>         CONSTRAINT_MEMCG,
> +       CONSTRAINT_BPF,
>  };
>
>  /*
> @@ -58,6 +59,9 @@ struct oom_control {
>
>         /* Policy name */
>         const char *bpf_policy_name;
> +
> +       /* BPF-specific constraint name */
> +       const char *bpf_constraint;
>  #endif
>  };
>
> diff --git a/mm/oom_kill.c b/mm/oom_kill.c
> index df409f0fac45..67afcd43a5f7 100644
> --- a/mm/oom_kill.c
> +++ b/mm/oom_kill.c
> @@ -240,13 +240,6 @@ long oom_badness(struct task_struct *p, unsigned long totalpages)
>         return points;
>  }
>
> -static const char * const oom_constraint_text[] = {
> -       [CONSTRAINT_NONE] = "CONSTRAINT_NONE",
> -       [CONSTRAINT_CPUSET] = "CONSTRAINT_CPUSET",
> -       [CONSTRAINT_MEMORY_POLICY] = "CONSTRAINT_MEMORY_POLICY",
> -       [CONSTRAINT_MEMCG] = "CONSTRAINT_MEMCG",
> -};
> -
>  static const char *oom_policy_name(struct oom_control *oc)
>  {
>  #ifdef CONFIG_BPF_SYSCALL
> @@ -256,6 +249,27 @@ static const char *oom_policy_name(struct oom_control *oc)
>         return "default";
>  }
>
> +static const char *oom_constraint_text(struct oom_control *oc)
> +{
> +       switch (oc->constraint) {
> +       case CONSTRAINT_NONE:
> +               return "CONSTRAINT_NONE";
> +       case CONSTRAINT_CPUSET:
> +               return "CONSTRAINT_CPUSET";
> +       case CONSTRAINT_MEMORY_POLICY:
> +               return "CONSTRAINT_MEMORY_POLICY";
> +       case CONSTRAINT_MEMCG:
> +               return "CONSTRAINT_MEMCG";
> +#ifdef CONFIG_BPF_SYSCALL
> +       case CONSTRAINT_BPF:
> +               return oc->bpf_constraint ? : "CONSTRAINT_BPF";
> +#endif
> +       default:
> +               WARN_ON_ONCE(1);
> +               return "";
> +       }
> +}
> +
>  /*
>   * Determine the type of allocation constraint.
>   */
> @@ -267,6 +281,9 @@ static enum oom_constraint constrained_alloc(struct oom_control *oc)
>         bool cpuset_limited = false;
>         int nid;
>
> +       if (oc->constraint == CONSTRAINT_BPF)
> +               return CONSTRAINT_BPF;
> +
>         if (is_memcg_oom(oc)) {
>                 oc->totalpages = mem_cgroup_get_max(oc->memcg) ?: 1;
>                 return CONSTRAINT_MEMCG;
> @@ -458,7 +475,7 @@ static void dump_oom_victim(struct oom_control *oc, struct task_struct *victim)
>  {
>         /* one line summary of the oom killer context. */
>         pr_info("oom-kill:constraint=%s,nodemask=%*pbl",
> -                       oom_constraint_text[oc->constraint],
> +                       oom_constraint_text(oc),
>                         nodemask_pr_args(oc->nodemask));
>         cpuset_print_current_mems_allowed();
>         mem_cgroup_print_oom_context(oc->memcg, victim);
> @@ -1344,11 +1361,14 @@ __bpf_kfunc int bpf_oom_kill_process(struct oom_control *oc,
>   * Returns a negative value if an error has been occurred.
>   */
>  __bpf_kfunc int bpf_out_of_memory(struct mem_cgroup *memcg__nullable,
> -                                 int order, bool wait_on_oom_lock)
> +                                 int order, bool wait_on_oom_lock,
> +                                 const char *constraint_text__nullable)
>  {
>         struct oom_control oc = {
>                 .memcg = memcg__nullable,
>                 .order = order,
> +               .constraint = CONSTRAINT_BPF,
> +               .bpf_constraint = constraint_text__nullable,
>         };
>         int ret;
>
> --
> 2.50.1
>
>


  reply	other threads:[~2025-10-02 16:32 UTC|newest]

Thread overview: 83+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-18 17:01 [PATCH v1 00/14] mm: BPF OOM Roman Gushchin
2025-08-18 17:01 ` [PATCH v1 01/14] mm: introduce bpf struct ops for OOM handling Roman Gushchin
2025-08-19  4:09   ` Suren Baghdasaryan
2025-08-19 20:06     ` Roman Gushchin
2025-08-20 19:34       ` Suren Baghdasaryan
2025-08-20 19:52         ` Roman Gushchin
2025-08-20 20:01           ` Suren Baghdasaryan
2025-08-26 16:23         ` Amery Hung
2025-08-20 11:28   ` Kumar Kartikeya Dwivedi
2025-08-21  0:24     ` Roman Gushchin
2025-08-21  0:36       ` Kumar Kartikeya Dwivedi
2025-08-21  2:22         ` Roman Gushchin
2025-08-21 15:54           ` Suren Baghdasaryan
2025-08-22 19:27       ` Martin KaFai Lau
2025-08-25 17:00         ` Roman Gushchin
2025-08-26 18:01           ` Martin KaFai Lau
2025-08-26 19:52             ` Alexei Starovoitov
2025-08-27 18:28               ` Roman Gushchin
2025-09-02 17:31               ` Roman Gushchin
2025-09-02 22:30                 ` Martin KaFai Lau
2025-09-02 23:36                   ` Roman Gushchin
2025-10-04  2:00                   ` Roman Gushchin
2025-10-06 23:21                     ` Andrii Nakryiko
2025-10-06 23:52                       ` Roman Gushchin
2025-10-06 23:57                         ` Andrii Nakryiko
2025-10-07  0:41                           ` Roman Gushchin
2025-10-08  1:07                             ` Song Liu
2025-10-08  2:15                               ` Roman Gushchin
2025-10-08  7:03                                 ` Song Liu
2025-10-08 17:02                                   ` Roman Gushchin
2025-10-07  2:25                     ` Martin KaFai Lau
2025-09-03  0:29                 ` Tejun Heo
2025-09-03 23:30                   ` Roman Gushchin
2025-09-04  6:39                     ` Tejun Heo
2025-09-04 14:32                       ` Roman Gushchin
2025-09-04 16:26                         ` Alexei Starovoitov
2025-09-04 16:58                           ` Tejun Heo
2025-08-26 16:56   ` Amery Hung
2025-08-18 17:01 ` [PATCH v1 02/14] bpf: mark struct oom_control's memcg field as TRUSTED_OR_NULL Roman Gushchin
2025-08-20  9:17   ` Kumar Kartikeya Dwivedi
2025-08-20 22:32     ` Roman Gushchin
2025-08-18 17:01 ` [PATCH v1 03/14] mm: introduce bpf_oom_kill_process() bpf kfunc Roman Gushchin
2025-08-18 17:01 ` [PATCH v1 04/14] mm: introduce bpf kfuncs to deal with memcg pointers Roman Gushchin
2025-08-20  9:21   ` Kumar Kartikeya Dwivedi
2025-08-20 22:43     ` Roman Gushchin
2025-08-20 23:33       ` Kumar Kartikeya Dwivedi
2025-08-18 17:01 ` [PATCH v1 05/14] mm: introduce bpf_get_root_mem_cgroup() bpf kfunc Roman Gushchin
2025-08-20  9:25   ` Kumar Kartikeya Dwivedi
2025-08-20 22:45     ` Roman Gushchin
2025-08-18 17:01 ` [PATCH v1 06/14] mm: introduce bpf_out_of_memory() " Roman Gushchin
2025-08-19  4:09   ` Suren Baghdasaryan
2025-08-19 20:16     ` Roman Gushchin
2025-08-20  9:34   ` Kumar Kartikeya Dwivedi
2025-08-20 22:59     ` Roman Gushchin
2025-08-18 17:01 ` [PATCH v1 07/14] mm: allow specifying custom oom constraint for bpf triggers Roman Gushchin
2025-10-02 16:37   ` ChaosEsque Team [this message]
2025-08-18 17:01 ` [PATCH v1 08/14] mm: introduce bpf_task_is_oom_victim() kfunc Roman Gushchin
2025-08-18 17:01 ` [PATCH v1 09/14] bpf: selftests: introduce read_cgroup_file() helper Roman Gushchin
2025-08-18 17:01 ` [PATCH v1 10/14] bpf: selftests: bpf OOM handler test Roman Gushchin
2025-08-20  9:33   ` Kumar Kartikeya Dwivedi
2025-08-20 22:49     ` Roman Gushchin
2025-08-20 20:23   ` Andrii Nakryiko
2025-08-21  0:10     ` Roman Gushchin
2025-08-18 17:01 ` [PATCH v1 11/14] sched: psi: refactor psi_trigger_create() Roman Gushchin
2025-08-19  4:09   ` Suren Baghdasaryan
2025-08-19 20:28     ` Roman Gushchin
2025-08-18 17:01 ` [PATCH v1 12/14] sched: psi: implement psi trigger handling using bpf Roman Gushchin
2025-08-19  4:11   ` Suren Baghdasaryan
2025-08-19 22:31     ` Roman Gushchin
2025-08-19 23:31       ` Roman Gushchin
2025-08-20 23:56         ` Suren Baghdasaryan
2025-08-26 17:03   ` Amery Hung
2025-08-18 17:01 ` [PATCH v1 13/14] sched: psi: implement bpf_psi_create_trigger() kfunc Roman Gushchin
2025-08-20 20:30   ` Andrii Nakryiko
2025-08-21  0:36     ` Roman Gushchin
2025-08-22 19:13       ` Andrii Nakryiko
2025-08-22 19:57       ` Martin KaFai Lau
2025-08-25 16:56         ` Roman Gushchin
2025-08-18 17:01 ` [PATCH v1 14/14] bpf: selftests: psi struct ops test Roman Gushchin
2025-08-19  4:08 ` [PATCH v1 00/14] mm: BPF OOM Suren Baghdasaryan
2025-08-19 19:52   ` Roman Gushchin
2025-08-20 21:06 ` Shakeel Butt
2025-08-21  0:01   ` Roman Gushchin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CALC8CXfcJjoHyZAiHm1meGtKf9CAbgnmhy4fxMqaa5Gb_ZHvwQ@mail.gmail.com \
    --to=chaosesqueteam@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mattbobrowski@google.com \
    --cc=memxor@gmail.com \
    --cc=mhocko@suse.com \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=song@kernel.org \
    --cc=surenb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox