[PATCH -mm 3/3] proc: make task_sig() lockless
From: Oleg Nesterov
Date: Mon Mar 22 2010 - 14:43:12 EST
Now that task->signal can't go away and collect_sigign_sigcatch()
is rcu-safe, task_sig() doesn't need ->siglock.
Remove lock_task_sighand() and unnecessary sigemptyset's, move
collect_sigign_sigcatch() under rcu_read_lock().
Of course, this means we read pending/blocked/etc nonatomically,
but I hope this is OK for fs/proc.
Probably we can change do_task_stat() to avod ->siglock too, except
we can't get tty_nr lockless.
Also, remove the "is this correct?" comment. I think it is safe
to dereference __task_cred(p)->user under rcu lock. In any case,
->siglock can't help to protect cred->user.
Signed-off-by: Oleg Nesterov <oleg@xxxxxxxxxx>
---
fs/proc/array.c | 26 ++++++++++----------------
1 file changed, 10 insertions(+), 16 deletions(-)
--- 34-rc1/fs/proc/array.c~PROC_3_TASK_SIG_DONT_USE_SIGLOCK 2010-03-22 17:39:42.000000000 +0100
+++ 34-rc1/fs/proc/array.c 2010-03-22 18:36:13.000000000 +0100
@@ -257,30 +257,24 @@ static void collect_sigign_sigcatch(stru
static inline void task_sig(struct seq_file *m, struct task_struct *p)
{
- unsigned long flags;
sigset_t pending, shpending, blocked, ignored, caught;
int num_threads = 0;
unsigned long qsize = 0;
unsigned long qlim = 0;
- sigemptyset(&pending);
- sigemptyset(&shpending);
- sigemptyset(&blocked);
sigemptyset(&ignored);
sigemptyset(&caught);
- if (lock_task_sighand(p, &flags)) {
- pending = p->pending.signal;
- shpending = p->signal->shared_pending.signal;
- blocked = p->blocked;
- collect_sigign_sigcatch(p, &ignored, &caught);
- num_threads = get_nr_threads(p);
- rcu_read_lock(); /* FIXME: is this correct? */
- qsize = atomic_read(&__task_cred(p)->user->sigpending);
- rcu_read_unlock();
- qlim = task_rlimit(p, RLIMIT_SIGPENDING);
- unlock_task_sighand(p, &flags);
- }
+ blocked = p->blocked;
+ pending = p->pending.signal;
+ shpending = p->signal->shared_pending.signal;
+ qlim = task_rlimit(p, RLIMIT_SIGPENDING);
+ num_threads = get_nr_threads(p);
+
+ rcu_read_lock();
+ collect_sigign_sigcatch(p, &ignored, &caught);
+ qsize = atomic_read(&__task_cred(p)->user->sigpending);
+ rcu_read_unlock();
seq_printf(m, "Threads:\t%d\n", num_threads);
seq_printf(m, "SigQ:\t%lu/%lu\n", qsize, qlim);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/