Re: [PATCH] mempool: clarify behavior of mempool_alloc_preallocated()
From: Sebastian Andrzej Siewior
Date: Wed Oct 15 2025 - 15:27:20 EST
On 2025-10-15 11:52:24 [-0700], Vishal Moola (Oracle) wrote:
> > --- a/mm/mempool.c
> > +++ b/mm/mempool.c
> > @@ -461,8 +461,8 @@ EXPORT_SYMBOL(mempool_alloc_noprof);
> > * mempool_create().
> > *
> > * This function is similar to mempool_alloc, but it only attempts allocating
> > - * an element from the preallocated elements. It does not sleep and immediately
> > - * returns if no preallocated elements are available.
> > + * an element from the preallocated elements. It only takes a single spinlock_t
>
> Might it make more sense to say "It may sleep" instead of "takes a
> single spinlock_t"?
May sleep usually refers to something that can not be used in an
interrupt handler.
> I feel like the fact that we take a spinlock isn't the important part
> here (especially because we always drop it before returning).
It actually is. A spinlock_t can not be acquired in hardirq context or
when interrupts are explicitly disabled via local_irq_disable().
Therefore you should use the function in a local_irq_disable() section.
Sebastian