Re: [PATCH bpf-next v7 1/2] mm/bpf: Add bpf_proactive_reclaim kfunc

From: Andrew Morton

Date: Fri Sep 04 2026 - 14:37:39 EST


On Fri, 4 Sep 2026 18:20:19 +0800 "Hui Zhu" <hui.zhu@xxxxxxxxx> wrote:

> @@ -159,6 +160,74 @@ __bpf_kfunc void bpf_mem_cgroup_flush_stats(struct mem_cgroup *memcg)
> mem_cgroup_flush_stats(memcg);
> }
>
> +/*
> + * Reclaim must not recurse: try_to_free_mem_cgroup_pages() overwrites
> + * current->reclaim_state, so a nested call would corrupt the outer
> + * reclaim state. Reclaim windows are marked with PF_MEMALLOC;
> + * reclaim_state is also checked because it is installed slightly
> + * before PF_MEMALLOC.
> + */
> +static bool bpf_in_reclaim_context(void)
> +{
> + return (current->flags & PF_MEMALLOC) || current->reclaim_state;
> +}
> +

Would life improve if try_to_free_mem_cgroup_pages() didn't do that?
If try_to_free_mem_cgroup_pages() (or some variant of it) were to
permit nesting?

rs = new_thing(current, &sc.reclaim_state);
...
set_task_reclaim_state(current, rs);

?