diff options
| -rw-r--r-- | mm/slab_common.c | 97 |
1 files changed, 48 insertions, 49 deletions
diff --git a/mm/slab_common.c b/mm/slab_common.c index aa3ca5bb01b5..8cf8b4962d6c 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c | |||
| @@ -23,49 +23,17 @@ enum slab_state slab_state; | |||
| 23 | LIST_HEAD(slab_caches); | 23 | LIST_HEAD(slab_caches); |
| 24 | DEFINE_MUTEX(slab_mutex); | 24 | DEFINE_MUTEX(slab_mutex); |
| 25 | 25 | ||
| 26 | /* | 26 | #ifdef CONFIG_DEBUG_VM |
| 27 | * kmem_cache_create - Create a cache. | 27 | static int kmem_cache_sanity_check(const char *name, size_t size) |
| 28 | * @name: A string which is used in /proc/slabinfo to identify this cache. | ||
| 29 | * @size: The size of objects to be created in this cache. | ||
| 30 | * @align: The required alignment for the objects. | ||
| 31 | * @flags: SLAB flags | ||
| 32 | * @ctor: A constructor for the objects. | ||
| 33 | * | ||
| 34 | * Returns a ptr to the cache on success, NULL on failure. | ||
| 35 | * Cannot be called within a interrupt, but can be interrupted. | ||
| 36 | * The @ctor is run when new pages are allocated by the cache. | ||
| 37 | * | ||
| 38 | * The flags are | ||
| 39 | * | ||
| 40 | * %SLAB_POISON - Poison the slab with a known test pattern (a5a5a5a5) | ||
| 41 | * to catch references to uninitialised memory. | ||
| 42 | * | ||
| 43 | * %SLAB_RED_ZONE - Insert `Red' zones around the allocated memory to check | ||
| 44 | * for buffer overruns. | ||
| 45 | * | ||
| 46 | * %SLAB_HWCACHE_ALIGN - Align the objects in this cache to a hardware | ||
| 47 | * cacheline. This can be beneficial if you're counting cycles as closely | ||
| 48 | * as davem. | ||
| 49 | */ | ||
| 50 | |||
| 51 | struct kmem_cache *kmem_cache_create(const char *name, size_t size, size_t align, | ||
| 52 | unsigned long flags, void (*ctor)(void *)) | ||
| 53 | { | 28 | { |
| 54 | struct kmem_cache *s = NULL; | 29 | struct kmem_cache *s = NULL; |
| 55 | 30 | ||
| 56 | #ifdef CONFIG_DEBUG_VM | ||
| 57 | if (!name || in_interrupt() || size < sizeof(void *) || | 31 | if (!name || in_interrupt() || size < sizeof(void *) || |
| 58 | size > KMALLOC_MAX_SIZE) { | 32 | size > KMALLOC_MAX_SIZE) { |
| 59 | printk(KERN_ERR "kmem_cache_create(%s) integrity check" | 33 | pr_err("kmem_cache_create(%s) integrity check failed\n", name); |
| 60 | " failed\n", name); | 34 | return -EINVAL; |
| 61 | goto out; | ||
| 62 | } | 35 | } |
| 63 | #endif | ||
| 64 | 36 | ||
| 65 | get_online_cpus(); | ||
| 66 | mutex_lock(&slab_mutex); | ||
| 67 | |||
| 68 | #ifdef CONFIG_DEBUG_VM | ||
| 69 | list_for_each_entry(s, &slab_caches, list) { | 37 | list_for_each_entry(s, &slab_caches, list) { |
| 70 | char tmp; | 38 | char tmp; |
| 71 | int res; | 39 | int res; |
| @@ -77,36 +45,67 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size, size_t align | |||
| 77 | */ | 45 | */ |
| 78 | res = probe_kernel_address(s->name, tmp); | 46 | res = probe_kernel_address(s->name, tmp); |
| 79 | if (res) { | 47 | if (res) { |
| 80 | printk(KERN_ERR | 48 | pr_err("Slab cache with size %d has lost its name\n", |
| 81 | "Slab cache with size %d has lost its name\n", | ||
| 82 | s->object_size); | 49 | s->object_size); |
| 83 | continue; | 50 | continue; |
| 84 | } | 51 | } |
| 85 | 52 | ||
| 86 | if (!strcmp(s->name, name)) { | 53 | if (!strcmp(s->name, name)) { |
| 87 | printk(KERN_ERR "kmem_cache_create(%s): Cache name" | 54 | pr_err("%s (%s): Cache name already exists.\n", |
| 88 | " already exists.\n", | 55 | __func__, name); |
| 89 | name); | ||
| 90 | dump_stack(); | 56 | dump_stack(); |
| 91 | s = NULL; | 57 | s = NULL; |
| 92 | goto oops; | 58 | return -EINVAL; |
| 93 | } | 59 | } |
| 94 | } | 60 | } |
| 95 | 61 | ||
| 96 | WARN_ON(strchr(name, ' ')); /* It confuses parsers */ | 62 | WARN_ON(strchr(name, ' ')); /* It confuses parsers */ |
| 63 | return 0; | ||
| 64 | } | ||
| 65 | #else | ||
| 66 | static inline int kmem_cache_sanity_check(const char *name, size_t size) | ||
| 67 | { | ||
| 68 | return 0; | ||
| 69 | } | ||
| 97 | #endif | 70 | #endif |
| 98 | 71 | ||
| 99 | s = __kmem_cache_create(name, size, align, flags, ctor); | 72 | /* |
| 73 | * kmem_cache_create - Create a cache. | ||
| 74 | * @name: A string which is used in /proc/slabinfo to identify this cache. | ||
| 75 | * @size: The size of objects to be created in this cache. | ||
| 76 | * @align: The required alignment for the objects. | ||
| 77 | * @flags: SLAB flags | ||
| 78 | * @ctor: A constructor for the objects. | ||
| 79 | * | ||
| 80 | * Returns a ptr to the cache on success, NULL on failure. | ||
| 81 | * Cannot be called within a interrupt, but can be interrupted. | ||
| 82 | * The @ctor is run when new pages are allocated by the cache. | ||
| 83 | * | ||
| 84 | * The flags are | ||
| 85 | * | ||
| 86 | * %SLAB_POISON - Poison the slab with a known test pattern (a5a5a5a5) | ||
| 87 | * to catch references to uninitialised memory. | ||
| 88 | * | ||
| 89 | * %SLAB_RED_ZONE - Insert `Red' zones around the allocated memory to check | ||
| 90 | * for buffer overruns. | ||
| 91 | * | ||
| 92 | * %SLAB_HWCACHE_ALIGN - Align the objects in this cache to a hardware | ||
| 93 | * cacheline. This can be beneficial if you're counting cycles as closely | ||
| 94 | * as davem. | ||
| 95 | */ | ||
| 96 | |||
| 97 | struct kmem_cache *kmem_cache_create(const char *name, size_t size, size_t align, | ||
| 98 | unsigned long flags, void (*ctor)(void *)) | ||
| 99 | { | ||
| 100 | struct kmem_cache *s = NULL; | ||
| 100 | 101 | ||
| 101 | #ifdef CONFIG_DEBUG_VM | 102 | get_online_cpus(); |
| 102 | oops: | 103 | mutex_lock(&slab_mutex); |
| 103 | #endif | 104 | if (kmem_cache_sanity_check(name, size) == 0) |
| 105 | s = __kmem_cache_create(name, size, align, flags, ctor); | ||
| 104 | mutex_unlock(&slab_mutex); | 106 | mutex_unlock(&slab_mutex); |
| 105 | put_online_cpus(); | 107 | put_online_cpus(); |
| 106 | 108 | ||
| 107 | #ifdef CONFIG_DEBUG_VM | ||
| 108 | out: | ||
| 109 | #endif | ||
| 110 | if (!s && (flags & SLAB_PANIC)) | 109 | if (!s && (flags & SLAB_PANIC)) |
| 111 | panic("kmem_cache_create: Failed to create slab '%s'\n", name); | 110 | panic("kmem_cache_create: Failed to create slab '%s'\n", name); |
| 112 | 111 | ||
