aboutsummaryrefslogtreecommitdiffstats
path: root/mm/slab.c
diff options
context:
space:
mode:
authorAkinobu Mita <akinobu.mita@gmail.com>2008-12-23 05:37:01 -0500
committerPekka Enberg <penberg@cs.helsinki.fi>2008-12-29 04:27:46 -0500
commit773ff60e841461cb1f9374a713ffcda029b8c317 (patch)
treec3691b5a82261a3d2c1861f2913774faac63fa96 /mm/slab.c
parent3c92ec8ae91ecf59d88c798301833d7cf83f2179 (diff)
SLUB: failslab support
Currently fault-injection capability for SLAB allocator is only available to SLAB. This patch makes it available to SLUB, too. [penberg@cs.helsinki.fi: unify slab and slub implementations] Cc: Christoph Lameter <cl@linux-foundation.org> Cc: Matt Mackall <mpm@selenic.com> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
Diffstat (limited to 'mm/slab.c')
-rw-r--r--mm/slab.c75
1 files changed, 5 insertions, 70 deletions
diff --git a/mm/slab.c b/mm/slab.c
index 09187517f9dc..c347dd8480cc 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -3106,79 +3106,14 @@ static void *cache_alloc_debugcheck_after(struct kmem_cache *cachep,
3106#define cache_alloc_debugcheck_after(a,b,objp,d) (objp) 3106#define cache_alloc_debugcheck_after(a,b,objp,d) (objp)
3107#endif 3107#endif
3108 3108
3109#ifdef CONFIG_FAILSLAB 3109static bool slab_should_failslab(struct kmem_cache *cachep, gfp_t flags)
3110
3111static struct failslab_attr {
3112
3113 struct fault_attr attr;
3114
3115 u32 ignore_gfp_wait;
3116#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
3117 struct dentry *ignore_gfp_wait_file;
3118#endif
3119
3120} failslab = {
3121 .attr = FAULT_ATTR_INITIALIZER,
3122 .ignore_gfp_wait = 1,
3123};
3124
3125static int __init setup_failslab(char *str)
3126{
3127 return setup_fault_attr(&failslab.attr, str);
3128}
3129__setup("failslab=", setup_failslab);
3130
3131static int should_failslab(struct kmem_cache *cachep, gfp_t flags)
3132{ 3110{
3133 if (cachep == &cache_cache) 3111 if (cachep == &cache_cache)
3134 return 0; 3112 return false;
3135 if (flags & __GFP_NOFAIL)
3136 return 0;
3137 if (failslab.ignore_gfp_wait && (flags & __GFP_WAIT))
3138 return 0;
3139 3113
3140 return should_fail(&failslab.attr, obj_size(cachep)); 3114 return should_failslab(obj_size(cachep), flags);
3141} 3115}
3142 3116
3143#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
3144
3145static int __init failslab_debugfs(void)
3146{
3147 mode_t mode = S_IFREG | S_IRUSR | S_IWUSR;
3148 struct dentry *dir;
3149 int err;
3150
3151 err = init_fault_attr_dentries(&failslab.attr, "failslab");
3152 if (err)
3153 return err;
3154 dir = failslab.attr.dentries.dir;
3155
3156 failslab.ignore_gfp_wait_file =
3157 debugfs_create_bool("ignore-gfp-wait", mode, dir,
3158 &failslab.ignore_gfp_wait);
3159
3160 if (!failslab.ignore_gfp_wait_file) {
3161 err = -ENOMEM;
3162 debugfs_remove(failslab.ignore_gfp_wait_file);
3163 cleanup_fault_attr_dentries(&failslab.attr);
3164 }
3165
3166 return err;
3167}
3168
3169late_initcall(failslab_debugfs);
3170
3171#endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */
3172
3173#else /* CONFIG_FAILSLAB */
3174
3175static inline int should_failslab(struct kmem_cache *cachep, gfp_t flags)
3176{
3177 return 0;
3178}
3179
3180#endif /* CONFIG_FAILSLAB */
3181
3182static inline void *____cache_alloc(struct kmem_cache *cachep, gfp_t flags) 3117static inline void *____cache_alloc(struct kmem_cache *cachep, gfp_t flags)
3183{ 3118{
3184 void *objp; 3119 void *objp;
@@ -3381,7 +3316,7 @@ __cache_alloc_node(struct kmem_cache *cachep, gfp_t flags, int nodeid,
3381 unsigned long save_flags; 3316 unsigned long save_flags;
3382 void *ptr; 3317 void *ptr;
3383 3318
3384 if (should_failslab(cachep, flags)) 3319 if (slab_should_failslab(cachep, flags))
3385 return NULL; 3320 return NULL;
3386 3321
3387 cache_alloc_debugcheck_before(cachep, flags); 3322 cache_alloc_debugcheck_before(cachep, flags);
@@ -3457,7 +3392,7 @@ __cache_alloc(struct kmem_cache *cachep, gfp_t flags, void *caller)
3457 unsigned long save_flags; 3392 unsigned long save_flags;
3458 void *objp; 3393 void *objp;
3459 3394
3460 if (should_failslab(cachep, flags)) 3395 if (slab_should_failslab(cachep, flags))
3461 return NULL; 3396 return NULL;
3462 3397
3463 cache_alloc_debugcheck_before(cachep, flags); 3398 cache_alloc_debugcheck_before(cachep, flags);