Linux 4.6-rc6
[cris-mirror.git] / mm / failslab.c
blobb0fac98cd9388941db02a3985d98b32d37b307dd
1 #include <linux/fault-inject.h>
2 #include <linux/slab.h>
3 #include <linux/mm.h>
4 #include "slab.h"
6 static struct {
7 struct fault_attr attr;
8 bool ignore_gfp_reclaim;
9 bool cache_filter;
10 } failslab = {
11 .attr = FAULT_ATTR_INITIALIZER,
12 .ignore_gfp_reclaim = true,
13 .cache_filter = false,
16 bool should_failslab(struct kmem_cache *s, gfp_t gfpflags)
18 /* No fault-injection for bootstrap cache */
19 if (unlikely(s == kmem_cache))
20 return false;
22 if (gfpflags & __GFP_NOFAIL)
23 return false;
25 if (failslab.ignore_gfp_reclaim && (gfpflags & __GFP_RECLAIM))
26 return false;
28 if (failslab.cache_filter && !(s->flags & SLAB_FAILSLAB))
29 return false;
31 return should_fail(&failslab.attr, s->object_size);
34 static int __init setup_failslab(char *str)
36 return setup_fault_attr(&failslab.attr, str);
38 __setup("failslab=", setup_failslab);
40 #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
41 static int __init failslab_debugfs_init(void)
43 struct dentry *dir;
44 umode_t mode = S_IFREG | S_IRUSR | S_IWUSR;
46 dir = fault_create_debugfs_attr("failslab", NULL, &failslab.attr);
47 if (IS_ERR(dir))
48 return PTR_ERR(dir);
50 if (!debugfs_create_bool("ignore-gfp-wait", mode, dir,
51 &failslab.ignore_gfp_reclaim))
52 goto fail;
53 if (!debugfs_create_bool("cache-filter", mode, dir,
54 &failslab.cache_filter))
55 goto fail;
57 return 0;
58 fail:
59 debugfs_remove_recursive(dir);
61 return -ENOMEM;
64 late_initcall(failslab_debugfs_init);
66 #endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */