aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Lameter <clameter@sgi.com>2007-05-06 17:49:57 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-05-07 15:12:55 -0400
commit0a31bd5f2bbb6473ef9d24f0063ca91cfa678b64 (patch)
treea945e829bf6bf7a93bf844b2ee9f2a3a2fa17c5d
parent5af60839909b8e3b28ca7cd7912fa0b23475617f (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>
-rw-r--r--block/cfq-iosched.c6
-rw-r--r--fs/aio.c6
-rw-r--r--fs/bio.c3
-rw-r--r--fs/dcache.c8
-rw-r--r--include/linux/slab.h12
-rw-r--r--kernel/delayacct.c6
-rw-r--r--kernel/pid.c4
-rw-r--r--kernel/signal.c6
-rw-r--r--kernel/taskstats.c4
9 files changed, 23 insertions, 32 deletions
diff --git a/block/cfq-iosched.c b/block/cfq-iosched.c
index 64df3fa303b0..baef5fc7cff8 100644
--- a/block/cfq-iosched.c
+++ b/block/cfq-iosched.c
@@ -2090,13 +2090,11 @@ static void cfq_slab_kill(void)
2090 2090
2091static int __init cfq_slab_setup(void) 2091static int __init cfq_slab_setup(void)
2092{ 2092{
2093 cfq_pool = kmem_cache_create("cfq_pool", sizeof(struct cfq_queue), 0, 0, 2093 cfq_pool = KMEM_CACHE(cfq_queue, 0);
2094 NULL, NULL);
2095 if (!cfq_pool) 2094 if (!cfq_pool)
2096 goto fail; 2095 goto fail;
2097 2096
2098 cfq_ioc_pool = kmem_cache_create("cfq_ioc_pool", 2097 cfq_ioc_pool = KMEM_CACHE(cfq_io_context, 0);
2099 sizeof(struct cfq_io_context), 0, 0, NULL, NULL);
2100 if (!cfq_ioc_pool) 2098 if (!cfq_ioc_pool)
2101 goto fail; 2099 goto fail;
2102 2100
diff --git a/fs/aio.c b/fs/aio.c
index e4598d6d49dd..b97ab8028b6d 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -68,10 +68,8 @@ static void aio_queue_work(struct kioctx *);
68 */ 68 */
69static int __init aio_setup(void) 69static int __init aio_setup(void)
70{ 70{
71 kiocb_cachep = kmem_cache_create("kiocb", sizeof(struct kiocb), 71 kiocb_cachep = KMEM_CACHE(kiocb, SLAB_HWCACHE_ALIGN|SLAB_PANIC);
72 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL); 72 kioctx_cachep = KMEM_CACHE(kioctx,SLAB_HWCACHE_ALIGN|SLAB_PANIC);
73 kioctx_cachep = kmem_cache_create("kioctx", sizeof(struct kioctx),
74 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL);
75 73
76 aio_wq = create_workqueue("aio"); 74 aio_wq = create_workqueue("aio");
77 75
diff --git a/fs/bio.c b/fs/bio.c
index 693940da4090..093345f00128 100644
--- a/fs/bio.c
+++ b/fs/bio.c
@@ -1193,8 +1193,7 @@ static void __init biovec_init_slabs(void)
1193 1193
1194static int __init init_bio(void) 1194static int __init init_bio(void)
1195{ 1195{
1196 bio_slab = kmem_cache_create("bio", sizeof(struct bio), 0, 1196 bio_slab = KMEM_CACHE(bio, SLAB_HWCACHE_ALIGN|SLAB_PANIC);
1197 SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL);
1198 1197
1199 biovec_init_slabs(); 1198 biovec_init_slabs();
1200 1199
diff --git a/fs/dcache.c b/fs/dcache.c
index d68631f18df1..d1bf5d8aeb5a 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -2052,12 +2052,8 @@ static void __init dcache_init(unsigned long mempages)
2052 * but it is probably not worth it because of the cache nature 2052 * but it is probably not worth it because of the cache nature
2053 * of the dcache. 2053 * of the dcache.
2054 */ 2054 */
2055 dentry_cache = kmem_cache_create("dentry_cache", 2055 dentry_cache = KMEM_CACHE(dentry,
2056 sizeof(struct dentry), 2056 SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|SLAB_MEM_SPREAD);
2057 0,
2058 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
2059 SLAB_MEM_SPREAD),
2060 NULL, NULL);
2061 2057
2062 set_shrinker(DEFAULT_SEEKS, shrink_dcache_memory); 2058 set_shrinker(DEFAULT_SEEKS, shrink_dcache_memory);
2063 2059
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 *);
57const char *kmem_cache_name(struct kmem_cache *); 57const char *kmem_cache_name(struct kmem_cache *);
58int kmem_ptr_validate(struct kmem_cache *cachep, const void *ptr); 58int 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
61extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node); 73extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
62#else 74#else
diff --git a/kernel/delayacct.c b/kernel/delayacct.c
index 766d5912b26a..c0148ae992c4 100644
--- a/kernel/delayacct.c
+++ b/kernel/delayacct.c
@@ -31,11 +31,7 @@ __setup("nodelayacct", delayacct_setup_disable);
31 31
32void delayacct_init(void) 32void delayacct_init(void)
33{ 33{
34 delayacct_cache = kmem_cache_create("delayacct_cache", 34 delayacct_cache = KMEM_CACHE(task_delay_info, SLAB_PANIC);
35 sizeof(struct task_delay_info),
36 0,
37 SLAB_PANIC,
38 NULL, NULL);
39 delayacct_tsk_init(&init_task); 35 delayacct_tsk_init(&init_task);
40} 36}
41 37
diff --git a/kernel/pid.c b/kernel/pid.c
index 78f2aee90f54..9c80bc23d6b8 100644
--- a/kernel/pid.c
+++ b/kernel/pid.c
@@ -412,7 +412,5 @@ void __init pidmap_init(void)
412 set_bit(0, init_pid_ns.pidmap[0].page); 412 set_bit(0, init_pid_ns.pidmap[0].page);
413 atomic_dec(&init_pid_ns.pidmap[0].nr_free); 413 atomic_dec(&init_pid_ns.pidmap[0].nr_free);
414 414
415 pid_cachep = kmem_cache_create("pid", sizeof(struct pid), 415 pid_cachep = KMEM_CACHE(pid, SLAB_PANIC);
416 __alignof__(struct pid),
417 SLAB_PANIC, NULL, NULL);
418} 416}
diff --git a/kernel/signal.c b/kernel/signal.c
index 3670225ecbc0..2b4087d545a3 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -2636,9 +2636,5 @@ __attribute__((weak)) const char *arch_vma_name(struct vm_area_struct *vma)
2636 2636
2637void __init signals_init(void) 2637void __init signals_init(void)
2638{ 2638{
2639 sigqueue_cachep = 2639 sigqueue_cachep = KMEM_CACHE(sigqueue, SLAB_PANIC);
2640 kmem_cache_create("sigqueue",
2641 sizeof(struct sigqueue),
2642 __alignof__(struct sigqueue),
2643 SLAB_PANIC, NULL, NULL);
2644} 2640}
diff --git a/kernel/taskstats.c b/kernel/taskstats.c
index ad7d2392cb0e..906cae771585 100644
--- a/kernel/taskstats.c
+++ b/kernel/taskstats.c
@@ -524,9 +524,7 @@ void __init taskstats_init_early(void)
524{ 524{
525 unsigned int i; 525 unsigned int i;
526 526
527 taskstats_cache = kmem_cache_create("taskstats_cache", 527 taskstats_cache = KMEM_CACHE(taskstats, SLAB_PANIC);
528 sizeof(struct taskstats),
529 0, SLAB_PANIC, NULL, NULL);
530 for_each_possible_cpu(i) { 528 for_each_possible_cpu(i) {
531 INIT_LIST_HEAD(&(per_cpu(listener_array, i).list)); 529 INIT_LIST_HEAD(&(per_cpu(listener_array, i).list));
532 init_rwsem(&(per_cpu(listener_array, i).sem)); 530 init_rwsem(&(per_cpu(listener_array, i).sem));