diff --git a/mm/mempool.c b/mm/mempool.c index 1f4701713203..5cf59779cc3d 100644 --- a/mm/mempool.c +++ b/mm/mempool.c @@ -9,7 +9,7 @@ * started by Ingo Molnar, Copyright (C) 2001 * debugging by David Rientjes, Copyright (C) 2015 */ - +#include #include #include #include @@ -20,6 +20,15 @@ #include #include "slab.h" +static DECLARE_FAULT_ATTR(fail_mempool_alloc); + +static int __init mempool_faul_inject_init(void) +{ + return PTR_ERR_OR_ZERO(fault_create_debugfs_attr("fail_mempool_alloc", + NULL, &fail_mempool_alloc)); +} +late_initcall(mempool_faul_inject_init); + #ifdef CONFIG_SLUB_DEBUG_ON static void poison_error(mempool_t *pool, void *element, size_t size, size_t byte) @@ -404,9 +413,15 @@ void *mempool_alloc_noprof(mempool_t *pool, gfp_t gfp_mask) gfp_temp = gfp_mask & ~(__GFP_DIRECT_RECLAIM|__GFP_IO); repeat_alloc: + if (should_fail_ex(&fail_mempool_alloc, 1, FAULT_NOWARN)) { + pr_info("forcing mempool usage for %pS\n", + (void *)_RET_IP_); + element = NULL; + } else { + element = pool->alloc(gfp_temp, pool->pool_data); + } - element = pool->alloc(gfp_temp, pool->pool_data); - if (likely(element != NULL)) + if (likely(element)) return element; spin_lock_irqsave(&pool->lock, flags);