Skip to content

Commit 3d24924

Browse files
Christoph Hellwigtehcaster
authored andcommitted
mempool: factor out a mempool_adjust_gfp helper
Add a helper to better isolate and document the gfp flags adjustments. Signed-off-by: Christoph Hellwig <hch@lst.de> Link: https://patch.msgid.link/20251113084022.1255121-6-hch@lst.de Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
1 parent b77fc08 commit 3d24924

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

mm/mempool.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,19 @@ int mempool_resize(mempool_t *pool, int new_min_nr)
380380
}
381381
EXPORT_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
*/
399412
void *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-
415422
repeat_alloc:
416423
if (should_fail_ex(&fail_mempool_alloc, 1, FAULT_NOWARN)) {
417424
pr_info("forcing mempool usage for %pS\n",

0 commit comments

Comments
 (0)