linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Vlastimil Babka <vbabka@suse.cz>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: Christoph Lameter <cl@gentwo.org>,
	David Rientjes <rientjes@google.com>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	Harry Yoo <harry.yoo@oracle.com>,
	Eric Biggers <ebiggers@kernel.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [PATCH 3/7] mempool: add error injection support
Date: Tue, 11 Nov 2025 14:52:31 +0100	[thread overview]
Message-ID: <20251111135300.752962-4-hch@lst.de> (raw)
In-Reply-To: <20251111135300.752962-1-hch@lst.de>

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>
---
 mm/mempool.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/mm/mempool.c b/mm/mempool.c
index 1f4701713203..76ba4d5e656f 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 <linux/fault-inject.h>
 #include <linux/mm.h>
 #include <linux/slab.h>
 #include <linux/highmem.h>
@@ -20,6 +20,15 @@
 #include <linux/writeback.h>
 #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 pool %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);
-- 
2.47.3



  parent reply	other threads:[~2025-11-11 13:53 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-11 13:52 mempool_alloc_bulk and various mempool improvements Christoph Hellwig
2025-11-11 13:52 ` [PATCH 1/7] fault-inject: make enum fault_flags available unconditionally Christoph Hellwig
2025-11-11 13:52 ` [PATCH 2/7] mempool: update kerneldoc comments Christoph Hellwig
2025-11-11 13:52 ` Christoph Hellwig [this message]
2025-11-11 13:52 ` [PATCH 4/7] mempool: factor out a mempool_adjust_gfp helper Christoph Hellwig
2025-11-11 13:52 ` [PATCH 5/7] mempool: factor out a mempool_alloc_from_pool helper Christoph Hellwig
2025-11-11 13:52 ` [PATCH 6/7] mempool: fix a wakeup race when sleeping for elements Christoph Hellwig
2025-11-12 10:53   ` Vlastimil Babka
2025-11-12 15:38     ` Christoph Hellwig
2025-11-11 13:52 ` [PATCH 7/7] mempool: add mempool_{alloc,free}_bulk Christoph Hellwig
2025-11-12 12:20   ` Vlastimil Babka
2025-11-12 15:47     ` Christoph Hellwig
2025-11-12 15:56       ` Vlastimil Babka
2025-11-12 15:58         ` Christoph Hellwig
2025-11-12 12:22 ` mempool_alloc_bulk and various mempool improvements Vlastimil Babka
2025-11-12 15:50   ` Christoph Hellwig
2025-11-12 15:57     ` Vlastimil Babka
2025-11-12 17:34     ` Eric Biggers
2025-11-13  5:52       ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251111135300.752962-4-hch@lst.de \
    --to=hch@lst.de \
    --cc=akpm@linux-foundation.org \
    --cc=cl@gentwo.org \
    --cc=ebiggers@kernel.org \
    --cc=harry.yoo@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=vbabka@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox