diff options
author | Jesper Dangaard Brouer <brouer@redhat.com> | 2016-03-15 17:53:38 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-03-15 19:55:16 -0400 |
commit | fab9963a69dbd71304357dbfe4ec5345f14cebdd (patch) | |
tree | 369f7f82b5f17d426ccaddc4295d6568f7647068 | |
parent | 11c7aec2a9b4e685bbf6a15148e7841b3525fc0c (diff) |
mm: fault-inject take over bootstrap kmem_cache check
Remove the SLAB specific function slab_should_failslab(), by moving the
check against fault-injection for the bootstrap slab, into the shared
function should_failslab() (used by both SLAB and SLUB).
This is a step towards sharing alloc_hook's between SLUB and SLAB.
This bootstrap slab "kmem_cache" is used for allocating struct
kmem_cache objects to the allocator itself.
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: Christoph Lameter <cl@linux.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Vladimir Davydov <vdavydov@virtuozzo.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | include/linux/fault-inject.h | 5 | ||||
-rw-r--r-- | mm/failslab.c | 12 | ||||
-rw-r--r-- | mm/slab.c | 12 | ||||
-rw-r--r-- | mm/slab.h | 2 |
4 files changed, 14 insertions, 17 deletions
diff --git a/include/linux/fault-inject.h b/include/linux/fault-inject.h index 3159a7dba034..9f4956d8601c 100644 --- a/include/linux/fault-inject.h +++ b/include/linux/fault-inject.h | |||
@@ -62,10 +62,9 @@ static inline struct dentry *fault_create_debugfs_attr(const char *name, | |||
62 | #endif /* CONFIG_FAULT_INJECTION */ | 62 | #endif /* CONFIG_FAULT_INJECTION */ |
63 | 63 | ||
64 | #ifdef CONFIG_FAILSLAB | 64 | #ifdef CONFIG_FAILSLAB |
65 | extern bool should_failslab(size_t size, gfp_t gfpflags, unsigned long flags); | 65 | extern bool should_failslab(struct kmem_cache *s, gfp_t gfpflags); |
66 | #else | 66 | #else |
67 | static inline bool should_failslab(size_t size, gfp_t gfpflags, | 67 | static inline bool should_failslab(struct kmem_cache *s, gfp_t gfpflags) |
68 | unsigned long flags) | ||
69 | { | 68 | { |
70 | return false; | 69 | return false; |
71 | } | 70 | } |
diff --git a/mm/failslab.c b/mm/failslab.c index 79171b4a5826..b0fac98cd938 100644 --- a/mm/failslab.c +++ b/mm/failslab.c | |||
@@ -1,5 +1,7 @@ | |||
1 | #include <linux/fault-inject.h> | 1 | #include <linux/fault-inject.h> |
2 | #include <linux/slab.h> | 2 | #include <linux/slab.h> |
3 | #include <linux/mm.h> | ||
4 | #include "slab.h" | ||
3 | 5 | ||
4 | static struct { | 6 | static struct { |
5 | struct fault_attr attr; | 7 | struct fault_attr attr; |
@@ -11,18 +13,22 @@ static struct { | |||
11 | .cache_filter = false, | 13 | .cache_filter = false, |
12 | }; | 14 | }; |
13 | 15 | ||
14 | bool should_failslab(size_t size, gfp_t gfpflags, unsigned long cache_flags) | 16 | bool should_failslab(struct kmem_cache *s, gfp_t gfpflags) |
15 | { | 17 | { |
18 | /* No fault-injection for bootstrap cache */ | ||
19 | if (unlikely(s == kmem_cache)) | ||
20 | return false; | ||
21 | |||
16 | if (gfpflags & __GFP_NOFAIL) | 22 | if (gfpflags & __GFP_NOFAIL) |
17 | return false; | 23 | return false; |
18 | 24 | ||
19 | if (failslab.ignore_gfp_reclaim && (gfpflags & __GFP_RECLAIM)) | 25 | if (failslab.ignore_gfp_reclaim && (gfpflags & __GFP_RECLAIM)) |
20 | return false; | 26 | return false; |
21 | 27 | ||
22 | if (failslab.cache_filter && !(cache_flags & SLAB_FAILSLAB)) | 28 | if (failslab.cache_filter && !(s->flags & SLAB_FAILSLAB)) |
23 | return false; | 29 | return false; |
24 | 30 | ||
25 | return should_fail(&failslab.attr, size); | 31 | return should_fail(&failslab.attr, s->object_size); |
26 | } | 32 | } |
27 | 33 | ||
28 | static int __init setup_failslab(char *str) | 34 | static int __init setup_failslab(char *str) |
@@ -2926,14 +2926,6 @@ static void *cache_alloc_debugcheck_after(struct kmem_cache *cachep, | |||
2926 | #define cache_alloc_debugcheck_after(a,b,objp,d) (objp) | 2926 | #define cache_alloc_debugcheck_after(a,b,objp,d) (objp) |
2927 | #endif | 2927 | #endif |
2928 | 2928 | ||
2929 | static bool slab_should_failslab(struct kmem_cache *cachep, gfp_t flags) | ||
2930 | { | ||
2931 | if (unlikely(cachep == kmem_cache)) | ||
2932 | return false; | ||
2933 | |||
2934 | return should_failslab(cachep->object_size, flags, cachep->flags); | ||
2935 | } | ||
2936 | |||
2937 | static inline void *____cache_alloc(struct kmem_cache *cachep, gfp_t flags) | 2929 | static inline void *____cache_alloc(struct kmem_cache *cachep, gfp_t flags) |
2938 | { | 2930 | { |
2939 | void *objp; | 2931 | void *objp; |
@@ -3155,7 +3147,7 @@ slab_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid, | |||
3155 | 3147 | ||
3156 | lockdep_trace_alloc(flags); | 3148 | lockdep_trace_alloc(flags); |
3157 | 3149 | ||
3158 | if (slab_should_failslab(cachep, flags)) | 3150 | if (should_failslab(cachep, flags)) |
3159 | return NULL; | 3151 | return NULL; |
3160 | 3152 | ||
3161 | cachep = memcg_kmem_get_cache(cachep, flags); | 3153 | cachep = memcg_kmem_get_cache(cachep, flags); |
@@ -3243,7 +3235,7 @@ slab_alloc(struct kmem_cache *cachep, gfp_t flags, unsigned long caller) | |||
3243 | 3235 | ||
3244 | lockdep_trace_alloc(flags); | 3236 | lockdep_trace_alloc(flags); |
3245 | 3237 | ||
3246 | if (slab_should_failslab(cachep, flags)) | 3238 | if (should_failslab(cachep, flags)) |
3247 | return NULL; | 3239 | return NULL; |
3248 | 3240 | ||
3249 | cachep = memcg_kmem_get_cache(cachep, flags); | 3241 | cachep = memcg_kmem_get_cache(cachep, flags); |
@@ -360,7 +360,7 @@ static inline struct kmem_cache *slab_pre_alloc_hook(struct kmem_cache *s, | |||
360 | lockdep_trace_alloc(flags); | 360 | lockdep_trace_alloc(flags); |
361 | might_sleep_if(gfpflags_allow_blocking(flags)); | 361 | might_sleep_if(gfpflags_allow_blocking(flags)); |
362 | 362 | ||
363 | if (should_failslab(s->object_size, flags, s->flags)) | 363 | if (should_failslab(s, flags)) |
364 | return NULL; | 364 | return NULL; |
365 | 365 | ||
366 | return memcg_kmem_get_cache(s, flags); | 366 | return memcg_kmem_get_cache(s, flags); |