From: Michal Hocko <mhocko@suse.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Chuyi Zhou <zhouchuyi@bytedance.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
muchun.song@linux.dev, bpf <bpf@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
wuyun.abel@bytedance.com, robin.lu@bytedance.com
Subject: Re: [RFC PATCH v2 1/5] mm, oom: Introduce bpf_oom_evaluate_task
Date: Tue, 22 Aug 2023 12:39:30 +0200 [thread overview]
Message-ID: <ZOSQYrFb2xleB83o@dhcp22.suse.cz> (raw)
In-Reply-To: <CAADnVQK=7NWbRtJyRJAqy5JwZHRB7s7hCNeGqixjLa4vB609XQ@mail.gmail.com>
On Wed 16-08-23 19:07:10, Alexei Starovoitov wrote:
> On Thu, Aug 10, 2023 at 1:13 AM Chuyi Zhou <zhouchuyi@bytedance.com> wrote:
> > static int oom_evaluate_task(struct task_struct *task, void *arg)
> > {
> > struct oom_control *oc = arg;
> > @@ -317,6 +339,26 @@ static int oom_evaluate_task(struct task_struct *task, void *arg)
> > if (!is_memcg_oom(oc) && !oom_cpuset_eligible(task, oc))
> > goto next;
> >
> > + /*
> > + * If task is allocating a lot of memory and has been marked to be
> > + * killed first if it triggers an oom, then select it.
> > + */
> > + if (oom_task_origin(task)) {
> > + points = LONG_MAX;
> > + goto select;
> > + }
> > +
> > + switch (bpf_oom_evaluate_task(task, oc)) {
> > + case BPF_EVAL_ABORT:
> > + goto abort; /* abort search process */
> > + case BPF_EVAL_NEXT:
> > + goto next; /* ignore the task */
> > + case BPF_EVAL_SELECT:
> > + goto select; /* select the task */
> > + default:
> > + break; /* No BPF policy */
> > + }
> > +
>
> I think forcing bpf prog to look at every task is going to be limiting
> long term.
> It's more flexible to invoke bpf prog from out_of_memory()
> and if it doesn't choose a task then fallback to select_bad_process().
> I believe that's what Roman was proposing.
> bpf can choose to iterate memcg or it might have some side knowledge
> that there are processes that can be set as oc->chosen right away,
> so it can skip the iteration.
This is certainly possible but I am worried this will lead to a lot of
duplication. There are common tasks that all/most oom victim selection
implementations should do. First of all they should make sure that the
victim is belonging to the oom domain. Arguably it should be also aware
of ongoing oom victim tear down to prevent from overkilling. Proper oom
victim reference counting handling. Most people are not even aware of
those things. Do we really want all those to be re-invented - most
likely incorrectly?
Advantage of reusing oom_evaluate_task is that all that can be avoided.
Iterating over tasks with a pre-defined oom-victim sure sounds like
unnecessary and wasted CPU cycles but if you want to prevent
over-killing this is still necessary. As the oom killer can be invoked
really rapidly (before the victim has a chance to die) I believe this is
a very useful feature.
--
Michal Hocko
SUSE Labs
next prev parent reply other threads:[~2023-08-22 10:39 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-10 8:13 [RFC PATCH v2 0/5] mm: Select victim using bpf_oom_evaluate_task Chuyi Zhou
2023-08-10 8:13 ` [RFC PATCH v2 1/5] mm, oom: Introduce bpf_oom_evaluate_task Chuyi Zhou
2023-08-17 2:07 ` Alexei Starovoitov
2023-08-17 2:51 ` Chuyi Zhou
2023-08-17 3:22 ` Alexei Starovoitov
2023-08-18 3:30 ` Chuyi Zhou
2023-08-18 4:34 ` Alexei Starovoitov
2023-08-22 10:39 ` Michal Hocko [this message]
2023-09-13 1:18 ` Bixuan Cui
2023-09-13 8:00 ` Chuyi Zhou
2023-09-13 11:24 ` Bixuan Cui
2023-08-10 8:13 ` [RFC PATCH v2 2/5] mm: Add policy_name to identify OOM policies Chuyi Zhou
2023-08-14 20:51 ` Jonathan Corbet
2023-08-15 2:28 ` Chuyi Zhou
2023-09-14 12:02 ` Bixuan Cui
2023-09-14 12:50 ` [External] " Chuyi Zhou
2023-09-15 2:28 ` Bixuan Cui
2023-09-15 3:31 ` Chuyi Zhou
2023-09-14 12:04 ` Bixuan Cui
2023-08-10 8:13 ` [RFC PATCH v2 3/5] mm: Add a tracepoint when OOM victim selection is failed Chuyi Zhou
2023-08-16 11:54 ` Alan Maguire
2023-08-10 8:13 ` [RFC PATCH v2 4/5] bpf: Add a OOM policy test Chuyi Zhou
2023-08-16 11:53 ` Alan Maguire
2023-08-16 12:31 ` Chuyi Zhou
2023-08-16 13:49 ` Alan Maguire
2023-08-16 14:34 ` Chuyi Zhou
2023-09-28 11:35 ` Charlley Green
2023-09-13 7:55 ` Bixuan Cui
2023-08-10 8:13 ` [RFC PATCH v2 5/5] bpf: Add a BPF OOM policy Doc Chuyi Zhou
2023-08-16 15:49 ` [PATCH RFC v2 0/5] mm: Select victim using bpf_oom_evaluate_task Yosry Ahmed
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=ZOSQYrFb2xleB83o@dhcp22.suse.cz \
--to=mhocko@suse.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=muchun.song@linux.dev \
--cc=robin.lu@bytedance.com \
--cc=roman.gushchin@linux.dev \
--cc=wuyun.abel@bytedance.com \
--cc=zhouchuyi@bytedance.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
all inboxes | Powered by JetHome®