Re: [PATCH bpf-next] bpf: Add a retry after refilling the free list when unit_alloc() fails

From: Kumar Kartikeya Dwivedi
Date: Thu Feb 13 2025 - 04:06:48 EST


On Thu, 13 Feb 2025 at 09:42, Changwoo Min <changwoo@xxxxxxxxxx> wrote:
>
> Hello Song,
>
> Thank you for the review!
>
> On 25. 2. 13. 03:33, Song Liu wrote:
> > On Wed, Feb 12, 2025 at 12:49 AM Changwoo Min <changwoo@xxxxxxxxxx> wrote:
> >>
> >> When there is no entry in the free list (c->free_llist), unit_alloc()
> >> fails even when there is available memory in the system, causing allocation
> >> failure in various BPF calls -- such as bpf_mem_alloc() and
> >> bpf_cpumask_create().
> >>
> >> Such allocation failure can happen, especially when a BPF program tries many
> >> allocations -- more than a delta between high and low watermarks -- in an
> >> IRQ-disabled context.
> >
> > Can we add a selftests for this scenario?
>
> It would be a bit tricky to create an IRQ-disabled case in a BPF
> program. However, I think it will be possible to reproduce the
> allocation failure issue when allocating sufficiently enough
> small allocations.

You can also make use of recently introduced
bpf_local_irq_{save,restore} in the selftest.

>
> [...]
>