Re: [PATCH 1/3] bpf: Factor out nonsleepable arena allocation logic

[email protected]
Newsgroups org.kernel.vger.bpf
Message-ID <ab19f87e539597f549ca944d08d3185bc9f788d9265890f01482c4c1285c83ab@mail.kernel.org>
> commit 434fc482ce1027a7af536690a218094b882f2ad2
> Author: Emil Tsalapatis <[email protected]>
> Date:   Mon Aug 24 04:25:28 2026 -0400
>
>     bpf: Factor out nonsleepable arena allocation logic
>
>     The bpf_arena_alloc_pages() is supposed to transparently choose whether
>     to use _nolock() allocation variants or not depending on the caller's
>     context. This is implemented internally by testing the context a
>     __bpf_alloc_page call is made in. However, the implementation of
>     bpf_arena_alloc_pages() forces the use of the _nolock() variants by
>     calling __bpf_alloc_page after disabling IRQs by taking a spinlock.
>     This in turn causes spurious allocation failures for some workloads
>     like scx schedulers due to ZONE_NORMAL falling below the minimum
>     watermark, even though the caller is sleepable could wait until
>     there is memory available.

This isn't a bug, but could this sentence be reworded (e.g. "even though a
sleepable caller could wait until memory becomes available") so the
motivation reads cleanly?

> diff --git a/kernel/bpf/arena.c b/kernel/bpf/arena.c
> index 7b6847200b43..da356989786a 100644
> --- a/kernel/bpf/arena.c
> +++ b/kernel/bpf/arena.c
> @@ -661,68 +661,57 @@ static u64 clear_lo32(u64 val)
>  	return val & ~(u64)~0U;
>  }
>
> -/*
> - * Allocate pages and vmap them into kernel vmalloc area.
> - * Later the pages will be mmaped into user space vma.
> - */
> -static long arena_alloc_pages(struct bpf_arena *arena, long uaddr, long page_cnt, int node_id,
> -			      bool sleepable)
> +
> +static int arena_adjust_tree(struct bpf_arena *arena, long uaddr, long page_cnt, long *pgoff)
> +{
> +	int ret;
> +
> +	/* Special case where user is requesting specific range. */
> +	if (uaddr) {
> +		ret = is_range_tree_set(&arena->rt, *pgoff, page_cnt);
> +		if (ret)
> +			return ret;
> +		return range_tree_clear(&arena->rt, *pgoff, page_cnt);
> +	}
> +
> +	ret = range_tree_find(&arena->rt, page_cnt);
> +	if (ret < 0)
> +		return ret;
> +
> +	*pgoff = ret;
> +
> +	return range_tree_clear(&arena->rt, *pgoff, page_cnt);
> +}
> +
> +static long arena_alloc_pages_internal(struct bpf_arena *arena, long page_cnt,
> +		long uaddr, long pgoff, int node_id, bool sleepable)

This isn't a bug, but would it read better to keep the existing
(uaddr, page_cnt) argument order in arena_alloc_pages_internal() so all
three functions agree, given both parameters are plain long?

arena_adjust_tree() uses (uaddr, page_cnt) and arena_alloc_pages() also
uses (uaddr, page_cnt), but arena_alloc_pages_internal() uses
(page_cnt, uaddr).


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/32709208315
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.