BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Hui Zhu" <hui.zhu@linux.dev>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH v13] mm/bpf: Add bpf_proactive_reclaim kfunc
Date: Mon, 21 Sep 2026 03:16:24 +0000	[thread overview]
Message-ID: <20260921031624.866B31F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260921030854.17858-1-hui.zhu@linux.dev>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] mm/bpf: anonymous swappiness enum is omitted from BTF
--

commit 1eb287ed1b56fa630faef31e3bfc3e5da668a9da
Author: Hui Zhu <zhuhui@kylinos.cn>

mm/bpf: Add bpf_proactive_reclaim kfunc

This commit adds the bpf_proactive_reclaim() kfunc to allow BPF programs
to proactively reclaim memory from a memory cgroup. It also converts
swappiness macros into an enum with the stated goal of emitting them into
BTF for use by BPF programs via vmlinux.h.

> diff --git a/mm/bpf_memcontrol.c b/mm/bpf_memcontrol.c
> index 716df49d76477..d8f579c285600 100644
> --- a/mm/bpf_memcontrol.c
> +++ b/mm/bpf_memcontrol.c

[ ... ]

> +/**
> + * bpf_proactive_reclaim - proactively reclaim memory from a memory cgroup
> + * @memcg: the target memory cgroup to reclaim from.
> + * @size: the amount of memory to reclaim, in bytes, clamped to
> + *        MEMCG_CHARGE_BATCH.
> + * @swappiness: the reclaim swappiness, in the range [MIN_SWAPPINESS,
> + *              MAX_SWAPPINESS], or one of the special modes: -1 to use
> + *              the memcg's own swappiness, or SWAPPINESS_ANON_ONLY to
> + *              reclaim only anon folios.
> + *
> + * Performs one proactive reclaim pass on @memcg, like a write to
> + * memory.reclaim but without retrying until @size is reached. Call it
> + * repeatedly to reclaim more than one batch.
> + *
> + * Only available to BPF_PROG_TYPE_SYSCALL, because other sleepable programs
> + * may run with filesystem locks held, which the reclaim path can deadlock
> + * on via filesystem shrinkers.
> + *
> + * Return: The amount of memory reclaimed, in bytes, or a negative error.
> + */
> +__bpf_kfunc long bpf_proactive_reclaim(struct mem_cgroup *memcg,
> +				       unsigned long size,
> +				       int swappiness)

[Severity: Medium]
Since the function signature uses int swappiness instead of an enum type,
will the compiler ever reference the newly added enum?

Without a reference in the signature, the enum is treated as purely internal
to the compilation unit and disconnected from the kfunc.

> +{
> +	unsigned long nr_reclaimed;
> +	unsigned long nr_pages;
> +
> +	if (swappiness != -1 && swappiness != SWAPPINESS_ANON_ONLY) {
> +		if (swappiness < MIN_SWAPPINESS || swappiness > MAX_SWAPPINESS)
> +			return -EINVAL;
> +	}

[ ... ]

> diff --git a/mm/internal.h b/mm/internal.h
> index 0434dfcfc36f1..4d426663ddd81 100644
> --- a/mm/internal.h
> +++ b/mm/internal.h

[ ... ]

>  #define MEMCG_RECLAIM_MAY_SWAP (1 << 1)
>  #define MEMCG_RECLAIM_PROACTIVE (1 << 2)
> -#define MIN_SWAPPINESS 0
> -#define MAX_SWAPPINESS 200
> +enum {
> +	MIN_SWAPPINESS = 0,
> +	MAX_SWAPPINESS = 200,
>  
> -/* Just reclaim from anon folios in proactive memory reclaim */
> -#define SWAPPINESS_ANON_ONLY (MAX_SWAPPINESS + 1)
> +	/* Just reclaim from anon folios in proactive memory reclaim */
> +	SWAPPINESS_ANON_ONLY = MAX_SWAPPINESS + 1,
> +};

[Severity: Medium]
The commit message states these are converted to an enum so that they are
emitted into BTF. Because this is an anonymous enum that isn't used to type
any variable or function argument, will it actually be preserved in DWARF/BTF?

It appears pahole omits completely unreferenced anonymous enums, meaning
these constants will not be emitted into vmlinux.h as intended.

Could we give this enum a name and use it in the bpf_proactive_reclaim()
signature to ensure it gets generated?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260921030854.17858-1-hui.zhu@linux.dev?part=1

  reply	other threads:[~2026-09-21  3:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-21  3:08 [PATCH v13] mm/bpf: Add bpf_proactive_reclaim kfunc Hui Zhu
2026-09-21  3:16 ` sashiko-bot [this message]
2026-09-21  6:56 ` Kumar Kartikeya Dwivedi
2026-09-21  7:00 ` patchwork-bot+netdevbpf

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=20260921031624.866B31F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=hui.zhu@linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    /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