linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] failslab for SLUB
@ 2008-12-23 10:37 Akinobu Mita
  2008-12-23 13:00 ` Pekka J Enberg
  0 siblings, 1 reply; 6+ messages in thread
From: Akinobu Mita @ 2008-12-23 10:37 UTC (permalink / raw)
  To: linux-kernel
  Cc: Christoph Lameter, Pekka Enberg, Matt Mackall, linux-mm, akpm

Currently fault-injection capability for SLAB allocator is only available
to SLAB. This patch makes it available to SLUB, too.

Cc: Christoph Lameter <cl@linux-foundation.org>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: Matt Mackall <mpm@selenic.com>
Cc: linux-mm@kvack.org
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
---
 lib/Kconfig.debug |    1 
 mm/slub.c         |   66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+)

Index: 2.6-rc/mm/slub.c
===================================================================
--- 2.6-rc.orig/mm/slub.c
+++ 2.6-rc/mm/slub.c
@@ -24,6 +24,7 @@
 #include <linux/kallsyms.h>
 #include <linux/memory.h>
 #include <linux/math64.h>
+#include <linux/fault-inject.h>
 
 /*
  * Lock order:
@@ -1573,6 +1574,68 @@ debug:
 	goto unlock_out;
 }
 
+#ifdef CONFIG_FAILSLAB
+
+static struct {
+	struct fault_attr attr;
+	u32 ignore_gfp_wait;
+#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
+	struct dentry *ignore_gfp_wait_file;
+#endif
+} failslub = {
+	.attr = FAULT_ATTR_INITIALIZER,
+	.ignore_gfp_wait = 1,
+};
+
+static bool should_failslub(struct kmem_cache *s, gfp_t gfpflags)
+{
+	if (gfpflags & __GFP_NOFAIL)
+		return false;
+	if (failslub.ignore_gfp_wait && (gfpflags & __GFP_WAIT))
+		return false;
+
+	return should_fail(&failslub.attr, s->objsize);
+}
+
+#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
+
+static int __init failslub_debugfs(void)
+{
+	mode_t mode = S_IFREG | S_IRUSR | S_IWUSR;
+	struct dentry *dir;
+	int err;
+
+	err = init_fault_attr_dentries(&failslub.attr, "failslab");
+	if (err)
+		return err;
+	dir = failslub.attr.dentries.dir;
+
+	failslub.ignore_gfp_wait_file =
+		debugfs_create_bool("ignore-gfp-wait", mode, dir,
+				      &failslub.ignore_gfp_wait);
+
+	if (!failslub.ignore_gfp_wait_file) {
+		err = -ENOMEM;
+		debugfs_remove(failslub.ignore_gfp_wait_file);
+		cleanup_fault_attr_dentries(&failslub.attr);
+	}
+
+	return err;
+}
+
+late_initcall(failslub_debugfs);
+
+#endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */
+
+#else /* CONFIG_FAILSLAB */
+
+static inline bool should_failslub(struct kmem_cache *cachep, gfp_t flags)
+{
+	return false;
+}
+
+#endif /* CONFIG_FAILSLAB */
+
 /*
  * Inlined fastpath so that allocation functions (kmalloc, kmem_cache_alloc)
  * have the fastpath folded into their functions. So no function call
@@ -1591,6 +1654,9 @@ static __always_inline void *slab_alloc(
 	unsigned long flags;
 	unsigned int objsize;
 
+	if (should_failslub(s, gfpflags))
+		return NULL;
+
 	local_irq_save(flags);
 	c = get_cpu_slab(s, smp_processor_id());
 	objsize = c->objsize;
Index: 2.6-rc/lib/Kconfig.debug
===================================================================
--- 2.6-rc.orig/lib/Kconfig.debug
+++ 2.6-rc/lib/Kconfig.debug
@@ -699,6 +699,7 @@ config FAULT_INJECTION
 config FAILSLAB
 	bool "Fault-injection capability for kmalloc"
 	depends on FAULT_INJECTION
+	depends on SLAB || SLUB
 	help
 	  Provide fault-injection capability for kmalloc.
 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-12-23 15:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-23 10:37 [PATCH] failslab for SLUB Akinobu Mita
2008-12-23 13:00 ` Pekka J Enberg
2008-12-23 13:29   ` Akinobu Mita
2008-12-23 14:43   ` Johannes Weiner
2008-12-23 14:44     ` Pekka Enberg
2008-12-23 15:22       ` Johannes Weiner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox