blob: 79171b4a58269986491198403a322d6c2a7dc814 [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>
Akinobu Mita773ff602008-12-23 19:37:01 +09003
4static struct {
5 struct fault_attr attr;
Mel Gorman71baba42015-11-06 16:28:28 -08006 bool ignore_gfp_reclaim;
Viresh Kumar621a5f72015-09-26 15:04:07 -07007 bool cache_filter;
Akinobu Mita773ff602008-12-23 19:37:01 +09008} failslab = {
9 .attr = FAULT_ATTR_INITIALIZER,
Mel Gorman71baba42015-11-06 16:28:28 -080010 .ignore_gfp_reclaim = true,
Viresh Kumar621a5f72015-09-26 15:04:07 -070011 .cache_filter = false,
Akinobu Mita773ff602008-12-23 19:37:01 +090012};
13
Dmitry Monakhov4c13dd32010-02-26 09:36:12 +030014bool should_failslab(size_t size, gfp_t gfpflags, unsigned long cache_flags)
Akinobu Mita773ff602008-12-23 19:37:01 +090015{
16 if (gfpflags & __GFP_NOFAIL)
17 return false;
18
Mel Gorman71baba42015-11-06 16:28:28 -080019 if (failslab.ignore_gfp_reclaim && (gfpflags & __GFP_RECLAIM))
Akinobu Mita773ff602008-12-23 19:37:01 +090020 return false;
21
Dmitry Monakhov4c13dd32010-02-26 09:36:12 +030022 if (failslab.cache_filter && !(cache_flags & SLAB_FAILSLAB))
23 return false;
24
Akinobu Mita773ff602008-12-23 19:37:01 +090025 return should_fail(&failslab.attr, size);
26}
27
28static int __init setup_failslab(char *str)
29{
30 return setup_fault_attr(&failslab.attr, str);
31}
32__setup("failslab=", setup_failslab);
33
34#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
Akinobu Mita773ff602008-12-23 19:37:01 +090035static int __init failslab_debugfs_init(void)
36{
Akinobu Mitadd48c082011-08-03 16:21:01 -070037 struct dentry *dir;
Al Virof4ae40a2011-07-24 04:33:43 -040038 umode_t mode = S_IFREG | S_IRUSR | S_IWUSR;
Akinobu Mita773ff602008-12-23 19:37:01 +090039
Akinobu Mitadd48c082011-08-03 16:21:01 -070040 dir = fault_create_debugfs_attr("failslab", NULL, &failslab.attr);
41 if (IS_ERR(dir))
42 return PTR_ERR(dir);
Akinobu Mita773ff602008-12-23 19:37:01 +090043
Akinobu Mitadd48c082011-08-03 16:21:01 -070044 if (!debugfs_create_bool("ignore-gfp-wait", mode, dir,
Mel Gorman71baba42015-11-06 16:28:28 -080045 &failslab.ignore_gfp_reclaim))
Akinobu Mita810f09b2011-07-26 16:09:02 -070046 goto fail;
Akinobu Mitadd48c082011-08-03 16:21:01 -070047 if (!debugfs_create_bool("cache-filter", mode, dir,
Akinobu Mita810f09b2011-07-26 16:09:02 -070048 &failslab.cache_filter))
49 goto fail;
Akinobu Mita773ff602008-12-23 19:37:01 +090050
Akinobu Mita810f09b2011-07-26 16:09:02 -070051 return 0;
52fail:
Akinobu Mitadd48c082011-08-03 16:21:01 -070053 debugfs_remove_recursive(dir);
Dmitry Monakhov4c13dd32010-02-26 09:36:12 +030054
Akinobu Mita810f09b2011-07-26 16:09:02 -070055 return -ENOMEM;
Akinobu Mita773ff602008-12-23 19:37:01 +090056}
57
58late_initcall(failslab_debugfs_init);
59
60#endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */