@@ -380,6 +380,19 @@ int mempool_resize(mempool_t *pool, int new_min_nr)
380380}
381381EXPORT_SYMBOL (mempool_resize );
382382
383+ /*
384+ * Adjust the gfp flags for mempool allocations, as we never want to dip into
385+ * the global emergency reserves or retry in the page allocator.
386+ *
387+ * The first pass also doesn't want to go reclaim, but the next passes do, so
388+ * return a separate subset for that first iteration.
389+ */
390+ static inline gfp_t mempool_adjust_gfp (gfp_t * gfp_mask )
391+ {
392+ * gfp_mask |= __GFP_NOMEMALLOC | __GFP_NORETRY | __GFP_NOWARN ;
393+ return * gfp_mask & ~(__GFP_DIRECT_RECLAIM | __GFP_IO );
394+ }
395+
383396/**
384397 * mempool_alloc - allocate an element from a memory pool
385398 * @pool: pointer to the memory pool
@@ -398,20 +411,14 @@ EXPORT_SYMBOL(mempool_resize);
398411 */
399412void * mempool_alloc_noprof (mempool_t * pool , gfp_t gfp_mask )
400413{
414+ gfp_t gfp_temp = mempool_adjust_gfp (& gfp_mask );
401415 void * element ;
402416 unsigned long flags ;
403417 wait_queue_entry_t wait ;
404- gfp_t gfp_temp ;
405418
406419 VM_WARN_ON_ONCE (gfp_mask & __GFP_ZERO );
407420 might_alloc (gfp_mask );
408421
409- gfp_mask |= __GFP_NOMEMALLOC ; /* don't allocate emergency reserves */
410- gfp_mask |= __GFP_NORETRY ; /* don't loop in __alloc_pages */
411- gfp_mask |= __GFP_NOWARN ; /* failures are OK */
412-
413- gfp_temp = gfp_mask & ~(__GFP_DIRECT_RECLAIM |__GFP_IO );
414-
415422repeat_alloc :
416423 if (should_fail_ex (& fail_mempool_alloc , 1 , FAULT_NOWARN )) {
417424 pr_info ("forcing mempool usage for %pS\n" ,
0 commit comments