diff options
author | Christoph Lameter <clameter@sgi.com> | 2007-05-06 17:49:57 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-05-07 15:12:55 -0400 |
commit | 0a31bd5f2bbb6473ef9d24f0063ca91cfa678b64 (patch) | |
tree | a945e829bf6bf7a93bf844b2ee9f2a3a2fa17c5d /include/linux/slab.h | |
parent | 5af60839909b8e3b28ca7cd7912fa0b23475617f (diff) |
KMEM_CACHE(): simplify slab cache creation
This patch provides a new macro
KMEM_CACHE(<struct>, <flags>)
to simplify slab creation. KMEM_CACHE creates a slab with the name of the
struct, with the size of the struct and with the alignment of the struct.
Additional slab flags may be specified if necessary.
Example
struct test_slab {
int a,b,c;
struct list_head;
} __cacheline_aligned_in_smp;
test_slab_cache = KMEM_CACHE(test_slab, SLAB_PANIC)
will create a new slab named "test_slab" of the size sizeof(struct
test_slab) and aligned to the alignment of test slab. If it fails then we
panic.
Signed-off-by: Christoph Lameter <clameter@sgi.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/slab.h')
-rw-r--r-- | include/linux/slab.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/include/linux/slab.h b/include/linux/slab.h index a9befa50d3e3..e14b4c338b89 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h | |||
@@ -57,6 +57,18 @@ unsigned int kmem_cache_size(struct kmem_cache *); | |||
57 | const char *kmem_cache_name(struct kmem_cache *); | 57 | const char *kmem_cache_name(struct kmem_cache *); |
58 | int kmem_ptr_validate(struct kmem_cache *cachep, const void *ptr); | 58 | int kmem_ptr_validate(struct kmem_cache *cachep, const void *ptr); |
59 | 59 | ||
60 | /* | ||
61 | * Please use this macro to create slab caches. Simply specify the | ||
62 | * name of the structure and maybe some flags that are listed above. | ||
63 | * | ||
64 | * The alignment of the struct determines object alignment. If you | ||
65 | * f.e. add ____cacheline_aligned_in_smp to the struct declaration | ||
66 | * then the objects will be properly aligned in SMP configurations. | ||
67 | */ | ||
68 | #define KMEM_CACHE(__struct, __flags) kmem_cache_create(#__struct,\ | ||
69 | sizeof(struct __struct), __alignof__(struct __struct),\ | ||
70 | (__flags), NULL, NULL) | ||
71 | |||
60 | #ifdef CONFIG_NUMA | 72 | #ifdef CONFIG_NUMA |
61 | extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node); | 73 | extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node); |
62 | #else | 74 | #else |