Re: [PATCH v2 06/23] mm: introduce BPF struct ops for OOM handling
From: Song Liu
Date: Tue Oct 28 2025 - 17:33:55 EST
On Mon, Oct 27, 2025 at 4:18 PM Roman Gushchin <roman.gushchin@xxxxxxxxx> wrote:
[...]
> +
> +struct bpf_oom_ops {
> + /**
> + * @handle_out_of_memory: Out of memory bpf handler, called before
> + * the in-kernel OOM killer.
> + * @ctx: Execution context
> + * @oc: OOM control structure
> + *
> + * Should return 1 if some memory was freed up, otherwise
> + * the in-kernel OOM killer is invoked.
> + */
> + int (*handle_out_of_memory)(struct bpf_oom_ctx *ctx, struct oom_control *oc);
> +
> + /**
> + * @handle_cgroup_offline: Cgroup offline callback
> + * @ctx: Execution context
> + * @cgroup_id: Id of deleted cgroup
> + *
> + * Called if the cgroup with the attached bpf_oom_ops is deleted.
> + */
> + void (*handle_cgroup_offline)(struct bpf_oom_ctx *ctx, u64 cgroup_id);
handle_out_of_memory() and handle_cgroup_offline() takes bpf_oom_ctx,
which is just cgroup_id for now. Shall we pass in struct mem_cgroup, which
should be easier to use?
Thanks,
Song
> +
> + /**
> + * @name: BPF OOM policy name
> + */
> + char name[BPF_OOM_NAME_MAX_LEN];
> +};
> +
> +#ifdef CONFIG_BPF_SYSCALL
> +/**
> + * @bpf_handle_oom: handle out of memory condition using bpf
> + * @oc: OOM control structure
> + *
> + * Returns true if some memory was freed.
> + */
> +bool bpf_handle_oom(struct oom_control *oc);
> +