Skip to content

Commit b77fc08

Browse files
Christoph Hellwigtehcaster
authored andcommitted
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>
1 parent 5c82978 commit b77fc08

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

mm/mempool.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* started by Ingo Molnar, Copyright (C) 2001
1010
* debugging by David Rientjes, Copyright (C) 2015
1111
*/
12-
12+
#include <linux/fault-inject.h>
1313
#include <linux/mm.h>
1414
#include <linux/slab.h>
1515
#include <linux/highmem.h>
@@ -20,6 +20,15 @@
2020
#include <linux/writeback.h>
2121
#include "slab.h"
2222

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);
31+
2332
#ifdef CONFIG_SLUB_DEBUG_ON
2433
static void poison_error(mempool_t *pool, void *element, size_t size,
2534
size_t byte)
@@ -404,9 +413,15 @@ void *mempool_alloc_noprof(mempool_t *pool, gfp_t gfp_mask)
404413
gfp_temp = gfp_mask & ~(__GFP_DIRECT_RECLAIM|__GFP_IO);
405414

406415
repeat_alloc:
416+
if (should_fail_ex(&fail_mempool_alloc, 1, FAULT_NOWARN)) {
417+
pr_info("forcing mempool usage for %pS\n",
418+
(void *)_RET_IP_);
419+
element = NULL;
420+
} else {
421+
element = pool->alloc(gfp_temp, pool->pool_data);
422+
}
407423

408-
element = pool->alloc(gfp_temp, pool->pool_data);
409-
if (likely(element != NULL))
424+
if (likely(element))
410425
return element;
411426

412427
spin_lock_irqsave(&pool->lock, flags);

0 commit comments

Comments
 (0)