Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mempool: add error injection support

Add a call to should_fail_ex that forces mempool to actually allocate
from the pool to stress the mempool implementation when enabled through
debugfs. By default should_fail{,_ex} prints a very verbose stack trace
that clutters the kernel log, slows down execution and triggers the
kernel bug detection in xfstests. Pass FAULT_NOWARN and print a
single-line message notating the caller instead so that full tests
can be run with fault injection.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Link: https://patch.msgid.link/20251113084022.1255121-5-hch@lst.de
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>

authored by

Christoph Hellwig and committed by
Vlastimil Babka
b77fc08e 5c829783

+18 -3
+18 -3
mm/mempool.c
··· 9 9 * started by Ingo Molnar, Copyright (C) 2001 10 10 * debugging by David Rientjes, Copyright (C) 2015 11 11 */ 12 - 12 + #include <linux/fault-inject.h> 13 13 #include <linux/mm.h> 14 14 #include <linux/slab.h> 15 15 #include <linux/highmem.h> ··· 19 19 #include <linux/mempool.h> 20 20 #include <linux/writeback.h> 21 21 #include "slab.h" 22 + 23 + static DECLARE_FAULT_ATTR(fail_mempool_alloc); 24 + 25 + static int __init mempool_faul_inject_init(void) 26 + { 27 + return PTR_ERR_OR_ZERO(fault_create_debugfs_attr("fail_mempool_alloc", 28 + NULL, &fail_mempool_alloc)); 29 + } 30 + late_initcall(mempool_faul_inject_init); 22 31 23 32 #ifdef CONFIG_SLUB_DEBUG_ON 24 33 static void poison_error(mempool_t *pool, void *element, size_t size, ··· 413 404 gfp_temp = gfp_mask & ~(__GFP_DIRECT_RECLAIM|__GFP_IO); 414 405 415 406 repeat_alloc: 407 + if (should_fail_ex(&fail_mempool_alloc, 1, FAULT_NOWARN)) { 408 + pr_info("forcing mempool usage for %pS\n", 409 + (void *)_RET_IP_); 410 + element = NULL; 411 + } else { 412 + element = pool->alloc(gfp_temp, pool->pool_data); 413 + } 416 414 417 - element = pool->alloc(gfp_temp, pool->pool_data); 418 - if (likely(element != NULL)) 415 + if (likely(element)) 419 416 return element; 420 417 421 418 spin_lock_irqsave(&pool->lock, flags);