diff options
author | Joonsoo Kim <iamjoonsoo.kim@lge.com> | 2014-10-09 18:26:00 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-10-09 22:25:50 -0400 |
commit | 07f361b2bee38896df8be17d8c3f8af3f3610606 (patch) | |
tree | 11a32316c31f5b85551cfce61a5d99d08e1af55d | |
parent | 3aa24f519e48e0db0ccf198d1b766a61d9463ce6 (diff) |
mm/slab_common: move kmem_cache definition to internal header
We don't need to keep kmem_cache definition in include/linux/slab.h if we
don't need to inline kmem_cache_size(). According to my code inspection,
this function is only called at lc_create() in lib/lru_cache.c which may
be called at initialization phase of something, so we don't need to inline
it. Therfore, move it to slab_common.c and move kmem_cache definition to
internal header.
After this change, we can change kmem_cache definition easily without full
kernel build. For instance, we can turn on/off CONFIG_SLUB_STATS without
full kernel build.
[akpm@linux-foundation.org: export kmem_cache_size() to modules]
[rdunlap@infradead.org: add header files to fix kmemcheck.c build errors]
Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Acked-by: Christoph Lameter <cl@linux.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | include/linux/slab.h | 42 | ||||
-rw-r--r-- | mm/kmemcheck.c | 1 | ||||
-rw-r--r-- | mm/slab.h | 35 | ||||
-rw-r--r-- | mm/slab_common.c | 9 |
4 files changed, 46 insertions, 41 deletions
diff --git a/include/linux/slab.h b/include/linux/slab.h index 1d9abb7d22a0..9062e4ad1787 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h | |||
@@ -158,31 +158,6 @@ size_t ksize(const void *); | |||
158 | #define ARCH_KMALLOC_MINALIGN __alignof__(unsigned long long) | 158 | #define ARCH_KMALLOC_MINALIGN __alignof__(unsigned long long) |
159 | #endif | 159 | #endif |
160 | 160 | ||
161 | #ifdef CONFIG_SLOB | ||
162 | /* | ||
163 | * Common fields provided in kmem_cache by all slab allocators | ||
164 | * This struct is either used directly by the allocator (SLOB) | ||
165 | * or the allocator must include definitions for all fields | ||
166 | * provided in kmem_cache_common in their definition of kmem_cache. | ||
167 | * | ||
168 | * Once we can do anonymous structs (C11 standard) we could put a | ||
169 | * anonymous struct definition in these allocators so that the | ||
170 | * separate allocations in the kmem_cache structure of SLAB and | ||
171 | * SLUB is no longer needed. | ||
172 | */ | ||
173 | struct kmem_cache { | ||
174 | unsigned int object_size;/* The original size of the object */ | ||
175 | unsigned int size; /* The aligned/padded/added on size */ | ||
176 | unsigned int align; /* Alignment as calculated */ | ||
177 | unsigned long flags; /* Active flags on the slab */ | ||
178 | const char *name; /* Slab name for sysfs */ | ||
179 | int refcount; /* Use counter */ | ||
180 | void (*ctor)(void *); /* Called on object slot creation */ | ||
181 | struct list_head list; /* List of all slab caches on the system */ | ||
182 | }; | ||
183 | |||
184 | #endif /* CONFIG_SLOB */ | ||
185 | |||
186 | /* | 161 | /* |
187 | * Kmalloc array related definitions | 162 | * Kmalloc array related definitions |
188 | */ | 163 | */ |
@@ -363,14 +338,6 @@ kmem_cache_alloc_node_trace(struct kmem_cache *s, | |||
363 | } | 338 | } |
364 | #endif /* CONFIG_TRACING */ | 339 | #endif /* CONFIG_TRACING */ |
365 | 340 | ||
366 | #ifdef CONFIG_SLAB | ||
367 | #include <linux/slab_def.h> | ||
368 | #endif | ||
369 | |||
370 | #ifdef CONFIG_SLUB | ||
371 | #include <linux/slub_def.h> | ||
372 | #endif | ||
373 | |||
374 | extern void *kmalloc_order(size_t size, gfp_t flags, unsigned int order); | 341 | extern void *kmalloc_order(size_t size, gfp_t flags, unsigned int order); |
375 | 342 | ||
376 | #ifdef CONFIG_TRACING | 343 | #ifdef CONFIG_TRACING |
@@ -650,14 +617,7 @@ static inline void *kzalloc_node(size_t size, gfp_t flags, int node) | |||
650 | return kmalloc_node(size, flags | __GFP_ZERO, node); | 617 | return kmalloc_node(size, flags | __GFP_ZERO, node); |
651 | } | 618 | } |
652 | 619 | ||
653 | /* | 620 | unsigned int kmem_cache_size(struct kmem_cache *s); |
654 | * Determine the size of a slab object | ||
655 | */ | ||
656 | static inline unsigned int kmem_cache_size(struct kmem_cache *s) | ||
657 | { | ||
658 | return s->object_size; | ||
659 | } | ||
660 | |||
661 | void __init kmem_cache_init_late(void); | 621 | void __init kmem_cache_init_late(void); |
662 | 622 | ||
663 | #endif /* _LINUX_SLAB_H */ | 623 | #endif /* _LINUX_SLAB_H */ |
diff --git a/mm/kmemcheck.c b/mm/kmemcheck.c index fd814fd61319..cab58bb592d8 100644 --- a/mm/kmemcheck.c +++ b/mm/kmemcheck.c | |||
@@ -2,6 +2,7 @@ | |||
2 | #include <linux/mm_types.h> | 2 | #include <linux/mm_types.h> |
3 | #include <linux/mm.h> | 3 | #include <linux/mm.h> |
4 | #include <linux/slab.h> | 4 | #include <linux/slab.h> |
5 | #include "slab.h" | ||
5 | #include <linux/kmemcheck.h> | 6 | #include <linux/kmemcheck.h> |
6 | 7 | ||
7 | void kmemcheck_alloc_shadow(struct page *page, int order, gfp_t flags, int node) | 8 | void kmemcheck_alloc_shadow(struct page *page, int order, gfp_t flags, int node) |
@@ -4,6 +4,41 @@ | |||
4 | * Internal slab definitions | 4 | * Internal slab definitions |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #ifdef CONFIG_SLOB | ||
8 | /* | ||
9 | * Common fields provided in kmem_cache by all slab allocators | ||
10 | * This struct is either used directly by the allocator (SLOB) | ||
11 | * or the allocator must include definitions for all fields | ||
12 | * provided in kmem_cache_common in their definition of kmem_cache. | ||
13 | * | ||
14 | * Once we can do anonymous structs (C11 standard) we could put a | ||
15 | * anonymous struct definition in these allocators so that the | ||
16 | * separate allocations in the kmem_cache structure of SLAB and | ||
17 | * SLUB is no longer needed. | ||
18 | */ | ||
19 | struct kmem_cache { | ||
20 | unsigned int object_size;/* The original size of the object */ | ||
21 | unsigned int size; /* The aligned/padded/added on size */ | ||
22 | unsigned int align; /* Alignment as calculated */ | ||
23 | unsigned long flags; /* Active flags on the slab */ | ||
24 | const char *name; /* Slab name for sysfs */ | ||
25 | int refcount; /* Use counter */ | ||
26 | void (*ctor)(void *); /* Called on object slot creation */ | ||
27 | struct list_head list; /* List of all slab caches on the system */ | ||
28 | }; | ||
29 | |||
30 | #endif /* CONFIG_SLOB */ | ||
31 | |||
32 | #ifdef CONFIG_SLAB | ||
33 | #include <linux/slab_def.h> | ||
34 | #endif | ||
35 | |||
36 | #ifdef CONFIG_SLUB | ||
37 | #include <linux/slub_def.h> | ||
38 | #endif | ||
39 | |||
40 | #include <linux/memcontrol.h> | ||
41 | |||
7 | /* | 42 | /* |
8 | * State of the slab allocator. | 43 | * State of the slab allocator. |
9 | * | 44 | * |
diff --git a/mm/slab_common.c b/mm/slab_common.c index cabb842c4e7c..d7d8ffd0c306 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c | |||
@@ -30,6 +30,15 @@ LIST_HEAD(slab_caches); | |||
30 | DEFINE_MUTEX(slab_mutex); | 30 | DEFINE_MUTEX(slab_mutex); |
31 | struct kmem_cache *kmem_cache; | 31 | struct kmem_cache *kmem_cache; |
32 | 32 | ||
33 | /* | ||
34 | * Determine the size of a slab object | ||
35 | */ | ||
36 | unsigned int kmem_cache_size(struct kmem_cache *s) | ||
37 | { | ||
38 | return s->object_size; | ||
39 | } | ||
40 | EXPORT_SYMBOL(kmem_cache_size); | ||
41 | |||
33 | #ifdef CONFIG_DEBUG_VM | 42 | #ifdef CONFIG_DEBUG_VM |
34 | static int kmem_cache_sanity_check(const char *name, size_t size) | 43 | static int kmem_cache_sanity_check(const char *name, size_t size) |
35 | { | 44 | { |