diff options
| author | Ingo Molnar <mingo@elte.hu> | 2006-01-08 04:01:37 -0500 |
|---|---|---|
| committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-01-08 23:13:40 -0500 |
| commit | e56d090310d7625ecb43a1eeebd479f04affb48b (patch) | |
| tree | 2f479215dff4a2d8f3a9ed85200a5bc4f51534be /kernel | |
| parent | 4369ef3c3e9d3bd9b879580678778f558d481e90 (diff) | |
[PATCH] RCU signal handling
RCU tasklist_lock and RCU signal handling: send signals RCU-read-locked
instead of tasklist_lock read-locked. This is a scalability improvement on
SMP and a preemption-latency improvement under PREEMPT_RCU.
Signed-off-by: Paul E. McKenney <paulmck@us.ibm.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Acked-by: William Irwin <wli@holomorphy.com>
Cc: Roland McGrath <roland@redhat.com>
Cc: 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')
| -rw-r--r-- | kernel/exit.c | 1 | ||||
| -rw-r--r-- | kernel/fork.c | 10 | ||||
| -rw-r--r-- | kernel/pid.c | 22 | ||||
| -rw-r--r-- | kernel/rcupdate.c | 1 | ||||
| -rw-r--r-- | kernel/sched.c | 7 | ||||
| -rw-r--r-- | kernel/signal.c | 97 |
6 files changed, 111 insertions, 27 deletions
diff --git a/kernel/exit.c b/kernel/exit.c index ee515683b9..c73a7eb26d 100644 --- a/kernel/exit.c +++ b/kernel/exit.c | |||
| @@ -72,7 +72,6 @@ repeat: | |||
| 72 | __ptrace_unlink(p); | 72 | __ptrace_unlink(p); |
| 73 | BUG_ON(!list_empty(&p->ptrace_list) || !list_empty(&p->ptrace_children)); | 73 | BUG_ON(!list_empty(&p->ptrace_list) || !list_empty(&p->ptrace_children)); |
| 74 | __exit_signal(p); | 74 | __exit_signal(p); |
| 75 | __exit_sighand(p); | ||
| 76 | /* | 75 | /* |
| 77 | * Note that the fastpath in sys_times depends on __exit_signal having | 76 | * Note that the fastpath in sys_times depends on __exit_signal having |
| 78 | * updated the counters before a task is removed from the tasklist of | 77 | * updated the counters before a task is removed from the tasklist of |
diff --git a/kernel/fork.c b/kernel/fork.c index fb8572a422..7fe3adfa65 100644 --- a/kernel/fork.c +++ b/kernel/fork.c | |||
| @@ -743,6 +743,14 @@ int unshare_files(void) | |||
| 743 | 743 | ||
| 744 | EXPORT_SYMBOL(unshare_files); | 744 | EXPORT_SYMBOL(unshare_files); |
| 745 | 745 | ||
| 746 | void sighand_free_cb(struct rcu_head *rhp) | ||
| 747 | { | ||
| 748 | struct sighand_struct *sp; | ||
| 749 | |||
| 750 | sp = container_of(rhp, struct sighand_struct, rcu); | ||
| 751 | kmem_cache_free(sighand_cachep, sp); | ||
| 752 | } | ||
| 753 | |||
| 746 | static inline int copy_sighand(unsigned long clone_flags, struct task_struct * tsk) | 754 | static inline int copy_sighand(unsigned long clone_flags, struct task_struct * tsk) |
| 747 | { | 755 | { |
| 748 | struct sighand_struct *sig; | 756 | struct sighand_struct *sig; |
| @@ -752,7 +760,7 @@ static inline int copy_sighand(unsigned long clone_flags, struct task_struct * t | |||
| 752 | return 0; | 760 | return 0; |
| 753 | } | 761 | } |
| 754 | sig = kmem_cache_alloc(sighand_cachep, GFP_KERNEL); | 762 | sig = kmem_cache_alloc(sighand_cachep, GFP_KERNEL); |
| 755 | tsk->sighand = sig; | 763 | rcu_assign_pointer(tsk->sighand, sig); |
| 756 | if (!sig) | 764 | if (!sig) |
| 757 | return -ENOMEM; | 765 | return -ENOMEM; |
| 758 | spin_lock_init(&sig->siglock); | 766 | spin_lock_init(&sig->siglock); |
diff --git a/kernel/pid.c b/kernel/pid.c index edba31c681..1acc072469 100644 --- a/kernel/pid.c +++ b/kernel/pid.c | |||
| @@ -136,7 +136,7 @@ struct pid * fastcall find_pid(enum pid_type type, int nr) | |||
| 136 | struct hlist_node *elem; | 136 | struct hlist_node *elem; |
| 137 | struct pid *pid; | 137 | struct pid *pid; |
| 138 | 138 | ||
| 139 | hlist_for_each_entry(pid, elem, | 139 | hlist_for_each_entry_rcu(pid, elem, |
| 140 | &pid_hash[type][pid_hashfn(nr)], pid_chain) { | 140 | &pid_hash[type][pid_hashfn(nr)], pid_chain) { |
| 141 | if (pid->nr == nr) | 141 | if (pid->nr == nr) |
| 142 | return pid; | 142 | return pid; |
| @@ -150,15 +150,15 @@ int fastcall attach_pid(task_t *task, enum pid_type type, int nr) | |||
| 150 | 150 | ||
| 151 | task_pid = &task->pids[type]; | 151 | task_pid = &task->pids[type]; |
| 152 | pid = find_pid(type, nr); | 152 | pid = find_pid(type, nr); |
| 153 | task_pid->nr = nr; | ||
| 153 | if (pid == NULL) { | 154 | if (pid == NULL) { |
| 154 | hlist_add_head(&task_pid->pid_chain, | ||
| 155 | &pid_hash[type][pid_hashfn(nr)]); | ||
| 156 | INIT_LIST_HEAD(&task_pid->pid_list); | 155 | INIT_LIST_HEAD(&task_pid->pid_list); |
| 156 | hlist_add_head_rcu(&task_pid->pid_chain, | ||
| 157 | &pid_hash[type][pid_hashfn(nr)]); | ||
| 157 | } else { | 158 | } else { |
| 158 | INIT_HLIST_NODE(&task_pid->pid_chain); | 159 | INIT_HLIST_NODE(&task_pid->pid_chain); |
| 159 | list_add_tail(&task_pid->pid_list, &pid->pid_list); | 160 | list_add_tail_rcu(&task_pid->pid_list, &pid->pid_list); |
| 160 | } | 161 | } |
| 161 | task_pid->nr = nr; | ||
| 162 | 162 | ||
| 163 | return 0; | 163 | return 0; |
| 164 | } | 164 | } |
| @@ -170,20 +170,20 @@ static fastcall int __detach_pid(task_t *task, enum pid_type type) | |||
| 170 | 170 | ||
| 171 | pid = &task->pids[type]; | 171 | pid = &task->pids[type]; |
| 172 | if (!hlist_unhashed(&pid->pid_chain)) { | 172 | if (!hlist_unhashed(&pid->pid_chain)) { |
| 173 | hlist_del(&pid->pid_chain); | ||
| 174 | 173 | ||
| 175 | if (list_empty(&pid->pid_list)) | 174 | if (list_empty(&pid->pid_list)) { |
| 176 | nr = pid->nr; | 175 | nr = pid->nr; |
| 177 | else { | 176 | hlist_del_rcu(&pid->pid_chain); |
| 177 | } else { | ||
| 178 | pid_next = list_entry(pid->pid_list.next, | 178 | pid_next = list_entry(pid->pid_list.next, |
| 179 | struct pid, pid_list); | 179 | struct pid, pid_list); |
| 180 | /* insert next pid from pid_list to hash */ | 180 | /* insert next pid from pid_list to hash */ |
| 181 | hlist_add_head(&pid_next->pid_chain, | 181 | hlist_replace_rcu(&pid->pid_chain, |
| 182 | &pid_hash[type][pid_hashfn(pid_next->nr)]); | 182 | &pid_next->pid_chain); |
| 183 | } | 183 | } |
| 184 | } | 184 | } |
| 185 | 185 | ||
| 186 | list_del(&pid->pid_list); | 186 | list_del_rcu(&pid->pid_list); |
| 187 | pid->nr = 0; | 187 | pid->nr = 0; |
| 188 | 188 | ||
| 189 | return nr; | 189 | return nr; |
diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c index c9afc61240..0a669bd2f6 100644 --- a/kernel/rcupdate.c +++ b/kernel/rcupdate.c | |||
| @@ -35,6 +35,7 @@ | |||
| 35 | #include <linux/init.h> | 35 | #include <linux/init.h> |
| 36 | #include <linux/spinlock.h> | 36 | #include <linux/spinlock.h> |
| 37 | #include <linux/smp.h> | 37 | #include <linux/smp.h> |
| 38 | #include <linux/rcupdate.h> | ||
| 38 | #include <linux/interrupt.h> | 39 | #include <linux/interrupt.h> |
| 39 | #include <linux/sched.h> | 40 | #include <linux/sched.h> |
| 40 | #include <asm/atomic.h> | 41 | #include <asm/atomic.h> |
diff --git a/kernel/sched.c b/kernel/sched.c index 6f46c94cc2..9273309115 100644 --- a/kernel/sched.c +++ b/kernel/sched.c | |||
| @@ -176,6 +176,13 @@ static unsigned int task_timeslice(task_t *p) | |||
| 176 | #define task_hot(p, now, sd) ((long long) ((now) - (p)->last_ran) \ | 176 | #define task_hot(p, now, sd) ((long long) ((now) - (p)->last_ran) \ |
| 177 | < (long long) (sd)->cache_hot_time) | 177 | < (long long) (sd)->cache_hot_time) |
| 178 | 178 | ||
| 179 | void __put_task_struct_cb(struct rcu_head *rhp) | ||
| 180 | { | ||
| 181 | __put_task_struct(container_of(rhp, struct task_struct, rcu)); | ||
| 182 | } | ||
| 183 | |||
| 184 | EXPORT_SYMBOL_GPL(__put_task_struct_cb); | ||
| 185 | |||
| 179 | /* | 186 | /* |
| 180 | * These are the runqueue data structures: | 187 | * These are the runqueue data structures: |
| 181 | */ | 188 | */ |
diff --git a/kernel/signal.c b/kernel/signal.c index d7611f189e..64737c72da 100644 --- a/kernel/signal.c +++ b/kernel/signal.c | |||
| @@ -329,13 +329,20 @@ void __exit_sighand(struct task_struct *tsk) | |||
| 329 | /* Ok, we're done with the signal handlers */ | 329 | /* Ok, we're done with the signal handlers */ |
| 330 | tsk->sighand = NULL; | 330 | tsk->sighand = NULL; |
| 331 | if (atomic_dec_and_test(&sighand->count)) | 331 | if (atomic_dec_and_test(&sighand->count)) |
| 332 | kmem_cache_free(sighand_cachep, sighand); | 332 | sighand_free(sighand); |
| 333 | } | 333 | } |
| 334 | 334 | ||
| 335 | void exit_sighand(struct task_struct *tsk) | 335 | void exit_sighand(struct task_struct *tsk) |
| 336 | { | 336 | { |
| 337 | write_lock_irq(&tasklist_lock); | 337 | write_lock_irq(&tasklist_lock); |
| 338 | __exit_sighand(tsk); | 338 | rcu_read_lock(); |
| 339 | if (tsk->sighand != NULL) { | ||
| 340 | struct sighand_struct *sighand = rcu_dereference(tsk->sighand); | ||
| 341 | spin_lock(&sighand->siglock); | ||
| 342 | __exit_sighand(tsk); | ||
| 343 | spin_unlock(&sighand->siglock); | ||
| 344 | } | ||
| 345 | rcu_read_unlock(); | ||
| 339 | write_unlock_irq(&tasklist_lock); | 346 | write_unlock_irq(&tasklist_lock); |
| 340 | } | 347 | } |
| 341 | 348 | ||
| @@ -345,12 +352,14 @@ void exit_sighand(struct task_struct *tsk) | |||
| 345 | void __exit_signal(struct task_struct *tsk) | 352 | void __exit_signal(struct task_struct *tsk) |
| 346 | { | 353 | { |
| 347 | struct signal_struct * sig = tsk->signal; | 354 | struct signal_struct * sig = tsk->signal; |
| 348 | struct sighand_struct * sighand = tsk->sighand; | 355 | struct sighand_struct * sighand; |
| 349 | 356 | ||
| 350 | if (!sig) | 357 | if (!sig) |
| 351 | BUG(); | 358 | BUG(); |
| 352 | if (!atomic_read(&sig->count)) | 359 | if (!atomic_read(&sig->count)) |
| 353 | BUG(); | 360 | BUG(); |
| 361 | rcu_read_lock(); | ||
| 362 | sighand = rcu_dereference(tsk->sighand); | ||
| 354 | spin_lock(&sighand->siglock); | 363 | spin_lock(&sighand->siglock); |
| 355 | posix_cpu_timers_exit(tsk); | 364 | posix_cpu_timers_exit(tsk); |
| 356 | if (atomic_dec_and_test(&sig->count)) { | 365 | if (atomic_dec_and_test(&sig->count)) { |
| @@ -358,6 +367,7 @@ void __exit_signal(struct task_struct *tsk) | |||
| 358 | if (tsk == sig->curr_target) | 367 | if (tsk == sig->curr_target) |
| 359 | sig->curr_target = next_thread(tsk); | 368 | sig->curr_target = next_thread(tsk); |
| 360 | tsk->signal = NULL; | 369 | tsk->signal = NULL; |
| 370 | __exit_sighand(tsk); | ||
| 361 | spin_unlock(&sighand->siglock); | 371 | spin_unlock(&sighand->siglock); |
| 362 | flush_sigqueue(&sig->shared_pending); | 372 | flush_sigqueue(&sig->shared_pending); |
| 363 | } else { | 373 | } else { |
| @@ -389,9 +399,11 @@ void __exit_signal(struct task_struct *tsk) | |||
| 389 | sig->nvcsw += tsk->nvcsw; | 399 | sig->nvcsw += tsk->nvcsw; |
| 390 | sig->nivcsw += tsk->nivcsw; | 400 | sig->nivcsw += tsk->nivcsw; |
| 391 | sig->sched_time += tsk->sched_time; | 401 | sig->sched_time += tsk->sched_time; |
| 402 | __exit_sighand(tsk); | ||
| 392 | spin_unlock(&sighand->siglock); | 403 | spin_unlock(&sighand->siglock); |
