mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jonathan Corbet <corbet@lwn.net>
To: Chuyi Zhou <zhouchuyi@bytedance.com>,
	hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev,
	ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	muchun.song@linux.dev
Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
	wuyun.abel@bytedance.com, robin.lu@bytedance.com,
	Chuyi Zhou <zhouchuyi@bytedance.com>
Subject: Re: [RFC PATCH v2 2/5] mm: Add policy_name to identify OOM policies
Date: Mon, 14 Aug 2023 14:51:15 -0600	[thread overview]
Message-ID: <87h6p1uz3w.fsf@meer.lwn.net> (raw)
In-Reply-To: <20230810081319.65668-3-zhouchuyi@bytedance.com>

Chuyi Zhou <zhouchuyi@bytedance.com> writes:

> This patch adds a new metadata policy_name in oom_control and report it
> in dump_header(), so we can know what has been the selection policy. In
> BPF program, we can call kfunc set_oom_policy_name to set the current
> user-defined policy name. The in-kernel policy_name is "default".
>
> Signed-off-by: Chuyi Zhou <zhouchuyi@bytedance.com>
> ---
>  include/linux/oom.h |  7 +++++++
>  mm/oom_kill.c       | 42 +++++++++++++++++++++++++++++++++++++++---
>  2 files changed, 46 insertions(+), 3 deletions(-)

So I have a possibly dumb question here...

> diff --git a/include/linux/oom.h b/include/linux/oom.h
> index 7d0c9c48a0c5..69d0f2ec6ea6 100644
> --- a/include/linux/oom.h
> +++ b/include/linux/oom.h
> @@ -22,6 +22,10 @@ enum oom_constraint {
>  	CONSTRAINT_MEMCG,
>  };
>  
> +enum {
> +	POLICY_NAME_LEN = 16,
> +};

We've defined our name length, fine...

>  /*
>   * Details of the page allocation that triggered the oom killer that are used to
>   * determine what should be killed.
> @@ -52,6 +56,9 @@ struct oom_control {
>  
>  	/* Used to print the constraint info. */
>  	enum oom_constraint constraint;
> +
> +	/* Used to report the policy info. */
> +	char policy_name[POLICY_NAME_LEN];
>  };

...that is the length of the array, appended to the structure...

>  extern struct mutex oom_lock;
> diff --git a/mm/oom_kill.c b/mm/oom_kill.c
> index 255c9ef1d808..3239dcdba4d7 100644
> --- a/mm/oom_kill.c
> +++ b/mm/oom_kill.c
> @@ -443,6 +443,35 @@ static int dump_task(struct task_struct *p, void *arg)
>  	return 0;
>  }
>  
> +__bpf_kfunc void set_oom_policy_name(struct oom_control *oc, const char *src, size_t sz)
> +{
> +	memset(oc->policy_name, 0, sizeof(oc->policy_name));
> +
> +	if (sz > POLICY_NAME_LEN)
> +		sz = POLICY_NAME_LEN;
> +
> +	memcpy(oc->policy_name, src, sz);
> +}

This truncates the name, possibly leaving it without a terminating NUL
character, right?

> +__diag_push();
> +__diag_ignore_all("-Wmissing-prototypes",
> +		  "kfuncs which will be used in BPF programs");
> +
> +__weak noinline void bpf_set_policy_name(struct oom_control *oc)
> +{
> +}
> +
> +__diag_pop();
> +
> +BTF_SET8_START(bpf_oom_policy_kfunc_ids)
> +BTF_ID_FLAGS(func, set_oom_policy_name)
> +BTF_SET8_END(bpf_oom_policy_kfunc_ids)
> +
> +static const struct btf_kfunc_id_set bpf_oom_policy_kfunc_set = {
> +	.owner          = THIS_MODULE,
> +	.set            = &bpf_oom_policy_kfunc_ids,
> +};
> +
>  /**
>   * dump_tasks - dump current memory state of all system tasks
>   * @oc: pointer to struct oom_control
> @@ -484,8 +513,8 @@ static void dump_oom_summary(struct oom_control *oc, struct task_struct *victim)
>  
>  static void dump_header(struct oom_control *oc, struct task_struct *p)
>  {
> -	pr_warn("%s invoked oom-killer: gfp_mask=%#x(%pGg), order=%d, oom_score_adj=%hd\n",
> -		current->comm, oc->gfp_mask, &oc->gfp_mask, oc->order,
> +	pr_warn("%s invoked oom-killer: gfp_mask=%#x(%pGg), order=%d, policy_name=%s, oom_score_adj=%hd\n",
> +		current->comm, oc->gfp_mask, &oc->gfp_mask, oc->order, oc->policy_name,

...and if the policy name is unterminated, this print will run off the
end of the structure.

Am I missing something here?

Thanks,

jon


  reply	other threads:[~2023-08-14 20:52 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
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 [this message]
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=87h6p1uz3w.fsf@meer.lwn.net \
    --to=corbet@lwn.net \
    --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=mhocko@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®