> mempool_alloc() should only be called with GFP_ATOMIC when> it is not safe to wait. Passing __GFP_NOFAIL to kmalloc()> says that it is safe to wait indefinitely. So this code is> inconsistent.> > Clearly it is OK to wait indefinitely in this code, and> mempool_alloc() is able to do that. So just use> mempool_alloc, and allow it to sleep. If no memory is> available it will wait for something to be returned to the> pool, and will retry a normal allocation regularly.

The region hash code is buggy anyway, because it may allocate more entries than the size of the pool and not give them back.

That kmalloc was introduced in the commit c06aad854 to work around a deadlock due to incorrect mempool usage.

Your patch slightly increases the probability of the deadlock because mempool_alloc does all allocations with __GFP_NOMEMALLOC, so it uses higher limit than kmalloc(GFP_NOIO).