blob: b0fac98cd9388941db02a3985d98b32d37b307dd [file] [log] [blame]
Akinobu Mita773ff602008-12-23 19:37:01 +09001#include <linux/fault-inject.h>
Dmitry Monakhov4c13dd32010-02-26 09:36:12 +03002#include <linux/slab.h>
Jesper Dangaard Brouerfab99632016-03-15 14:53:38 -07003#include <linux/mm.h>
4#include "slab.h"
Akinobu Mita773ff602008-12-23 19:37:01 +09005
6static struct {
7 struct fault_attr attr;
Mel Gorman71baba42015-11-06 16:28:28 -08008 bool ignore_gfp_reclaim;
Viresh Kumar621a5f72015-09-26 15:04:07 -07009 bool cache_filter;
Akinobu Mita773ff602008-12-23 19:37:01 +090010} failslab = {
11 .attr = FAULT_ATTR_INITIALIZER,
Mel Gorman71baba42015-11-06 16:28:28 -080012 .ignore_gfp_reclaim = true,
Viresh Kumar621a5f72015-09-26 15:04:07 -070013 .cache_filter = false,
Akinobu Mita773ff602008-12-23 19:37:01 +090014};
15
Jesper Dangaard Brouerfab99632016-03-15 14:53:38 -070016bool should_failslab(struct kmem_cache *s, gfp_t gfpflags)
Akinobu Mita773ff602008-12-23 19:37:01 +090017{
Jesper Dangaard Brouerfab99632016-03-15 14:53:38 -070018 /* No fault-injection for bootstrap cache */
19 if (unlikely(s == kmem_cache))
20 return false;
21
Akinobu Mita773ff602008-12-23 19:37:01 +090022 if (gfpflags & __GFP_NOFAIL)
23 return false;
24
Mel Gorman71baba42015-11-06 16:28:28 -080025 if (failslab.ignore_gfp_reclaim && (gfpflags & __GFP_RECLAIM))
Akinobu Mita773ff602008-12-23 19:37:01 +090026 return false;
27
Jesper Dangaard Brouerfab99632016-03-15 14:53:38 -070028 if (failslab.cache_filter && !(s->flags & SLAB_FAILSLAB))
Dmitry Monakhov4c13dd32010-02-26 09:36:12 +030029 return false;
30
Jesper Dangaard Brouerfab99632016-03-15 14:53:38 -070031 return should_fail(&failslab.attr, s->object_size);
Akinobu Mita773ff602008-12-23 19:37:01 +090032}
33
34static int __init setup_failslab(char *str)
35{
36 return setup_fault_attr(&failslab.attr, str);
37}
38__setup("failslab=", setup_failslab);
39
40#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
Akinobu Mita773ff602008-12-23 19:37:01 +090041static int __init failslab_debugfs_init(void)
42{
Akinobu Mitadd48c082011-08-03 16:21:01 -070043 struct dentry *dir;
Al Virof4ae40a62011-07-24 04:33:43 -040044 umode_t mode = S_IFREG | S_IRUSR | S_IWUSR;
Akinobu Mita773ff602008-12-23 19:37:01 +090045
Akinobu Mitadd48c082011-08-03 16:21:01 -070046 dir = fault_create_debugfs_attr("failslab", NULL, &failslab.attr);
47 if (IS_ERR(dir))
48 return PTR_ERR(dir);
Akinobu Mita773ff602008-12-23 19:37:01 +090049
Akinobu Mitadd48c082011-08-03 16:21:01 -070050 if (!debugfs_create_bool("ignore-gfp-wait", mode, dir,
Mel Gorman71baba42015-11-06 16:28:28 -080051 &failslab.ignore_gfp_reclaim))
Akinobu Mita810f09b2011-07-26 16:09:02 -070052 goto fail;
Akinobu Mitadd48c082011-08-03 16:21:01 -070053 if (!debugfs_create_bool("cache-filter", mode, dir,
Akinobu Mita810f09b2011-07-26 16:09:02 -070054 &failslab.cache_filter))
55 goto fail;
Akinobu Mita773ff602008-12-23 19:37:01 +090056
Akinobu Mita810f09b2011-07-26 16:09:02 -070057 return 0;
58fail:
Akinobu Mitadd48c082011-08-03 16:21:01 -070059 debugfs_remove_recursive(dir);
Dmitry Monakhov4c13dd32010-02-26 09:36:12 +030060
Akinobu Mita810f09b2011-07-26 16:09:02 -070061 return -ENOMEM;
Akinobu Mita773ff602008-12-23 19:37:01 +090062}
63
64late_initcall(failslab_debugfs_init);
65
66#endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */