aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/fork.c
diff options
context:
space:
mode:
authorOleg Nesterov <oleg@tv-sign.ru>2006-03-28 19:11:12 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2006-03-28 21:36:42 -0500
commitaa1757f90bea3f598b6e5d04d922a6a60200f1da (patch)
tree4f8f3804b2595031d0b84de7086dc28375290f0d /kernel/fork.c
parent1f09f9749cdde4e69f95d62d96d2e03f50b3353c (diff)
[PATCH] convert sighand_cache to use SLAB_DESTROY_BY_RCU
This patch borrows a clever Hugh's 'struct anon_vma' trick. Without tasklist_lock held we can't trust task->sighand until we locked it and re-checked that it is still the same. But this means we don't need to defer 'kmem_cache_free(sighand)'. We can return the memory to slab immediately, all we need is to be sure that sighand->siglock can't dissapear inside rcu protected section. To do so we need to initialize ->siglock inside ctor function, SLAB_DESTROY_BY_RCU does the rest. Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'kernel/fork.c')
-rw-r--r--kernel/fork.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/kernel/fork.c b/kernel/fork.c
index 0c32e28cdc5f..33ffb5bf0dbc 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -786,14 +786,6 @@ int unshare_files(void)
786 786
787EXPORT_SYMBOL(unshare_files); 787EXPORT_SYMBOL(unshare_files);
788 788
789void sighand_free_cb(struct rcu_head *rhp)
790{
791 struct sighand_struct *sp;
792
793 sp = container_of(rhp, struct sighand_struct, rcu);
794 kmem_cache_free(sighand_cachep, sp);
795}
796
797static inline int copy_sighand(unsigned long clone_flags, struct task_struct * tsk) 789static inline int copy_sighand(unsigned long clone_flags, struct task_struct * tsk)
798{ 790{
799 struct sighand_struct *sig; 791 struct sighand_struct *sig;
@@ -806,7 +798,6 @@ static inline int copy_sighand(unsigned long clone_flags, struct task_struct * t
806 rcu_assign_pointer(tsk->sighand, sig); 798 rcu_assign_pointer(tsk->sighand, sig);
807 if (!sig) 799 if (!sig)
808 return -ENOMEM; 800 return -ENOMEM;
809 spin_lock_init(&sig->siglock);
810 atomic_set(&sig->count, 1); 801 atomic_set(&sig->count, 1);
811 memcpy(sig->action, current->sighand->action, sizeof(sig->action)); 802 memcpy(sig->action, current->sighand->action, sizeof(sig->action));
812 return 0; 803 return 0;
@@ -1356,11 +1347,21 @@ long do_fork(unsigned long clone_flags,
1356#define ARCH_MIN_MMSTRUCT_ALIGN 0 1347#define ARCH_MIN_MMSTRUCT_ALIGN 0
1357#endif 1348#endif
1358 1349
1350static void sighand_ctor(void *data, kmem_cache_t *cachep, unsigned long flags)
1351{
1352 struct sighand_struct *sighand = data;
1353
1354 if ((flags & (SLAB_CTOR_VERIFY | SLAB_CTOR_CONSTRUCTOR)) ==
1355 SLAB_CTOR_CONSTRUCTOR)
1356 spin_lock_init(&sighand->siglock);
1357}
1358
1359void __init proc_caches_init(void) 1359void __init proc_caches_init(void)
1360{ 1360{
1361 sighand_cachep = kmem_cache_create("sighand_cache", 1361 sighand_cachep = kmem_cache_create("sighand_cache",
1362 sizeof(struct sighand_struct), 0, 1362 sizeof(struct sighand_struct), 0,
1363 SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL); 1363 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_DESTROY_BY_RCU,
1364 sighand_ctor, NULL);
1364 signal_cachep = kmem_cache_create("signal_cache", 1365 signal_cachep = kmem_cache_create("signal_cache",
1365 sizeof(struct signal_struct), 0, 1366 sizeof(struct signal_struct), 0,
1366 SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL); 1367 SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL);