From: Eric W. Biederman While we can currently walk through thread groups, process groups, and sessions with just the rcu_read_lock, this opens the door to walking the entire task list. We already have all of the other RCU guarantees so there is no cost in doing this, this should be enough so that proc can stop taking the tasklist lock during readdir. prev_task was killed because it has no users, and using it will miss new tasks when doing an rcu traversal. Signed-off-by: Eric W. Biederman Signed-off-by: Andrew Morton --- fs/exec.c | 2 +- include/linux/sched.h | 3 +-- kernel/exit.c | 2 +- kernel/fork.c | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff -puN fs/exec.c~task-make-task-list-manipulations-rcu-safe fs/exec.c --- devel/fs/exec.c~task-make-task-list-manipulations-rcu-safe 2006-03-16 02:09:13.000000000 -0800 +++ devel-akpm/fs/exec.c 2006-03-16 02:09:13.000000000 -0800 @@ -718,7 +718,7 @@ static int de_thread(struct task_struct attach_pid(current, PIDTYPE_PID, current->pid); attach_pid(current, PIDTYPE_PGID, current->signal->pgrp); attach_pid(current, PIDTYPE_SID, current->signal->session); - list_add_tail(¤t->tasks, &init_task.tasks); + list_add_tail_rcu(¤t->tasks, &init_task.tasks); current->parent = current->real_parent = leader->real_parent; leader->parent = leader->real_parent = child_reaper; diff -puN include/linux/sched.h~task-make-task-list-manipulations-rcu-safe include/linux/sched.h --- devel/include/linux/sched.h~task-make-task-list-manipulations-rcu-safe 2006-03-16 02:09:13.000000000 -0800 +++ devel-akpm/include/linux/sched.h 2006-03-16 02:09:13.000000000 -0800 @@ -1206,8 +1206,7 @@ extern void wait_task_inactive(task_t * #define remove_parent(p) list_del_init(&(p)->sibling) #define add_parent(p) list_add_tail(&(p)->sibling,&(p)->parent->children) -#define next_task(p) list_entry((p)->tasks.next, struct task_struct, tasks) -#define prev_task(p) list_entry((p)->tasks.prev, struct task_struct, tasks) +#define next_task(p) list_entry(rcu_dereference((p)->tasks.next), struct task_struct, tasks) #define for_each_process(p) \ for (p = &init_task ; (p = next_task(p)) != &init_task ; ) diff -puN kernel/exit.c~task-make-task-list-manipulations-rcu-safe kernel/exit.c --- devel/kernel/exit.c~task-make-task-list-manipulations-rcu-safe 2006-03-16 02:09:13.000000000 -0800 +++ devel-akpm/kernel/exit.c 2006-03-16 02:09:13.000000000 -0800 @@ -55,7 +55,7 @@ static void __unhash_process(struct task detach_pid(p, PIDTYPE_PGID); detach_pid(p, PIDTYPE_SID); - list_del_init(&p->tasks); + list_del_rcu(&p->tasks); __get_cpu_var(process_counts)--; } list_del_rcu(&p->thread_group); diff -puN kernel/fork.c~task-make-task-list-manipulations-rcu-safe kernel/fork.c --- devel/kernel/fork.c~task-make-task-list-manipulations-rcu-safe 2006-03-16 02:09:13.000000000 -0800 +++ devel-akpm/kernel/fork.c 2006-03-16 02:09:13.000000000 -0800 @@ -1215,7 +1215,7 @@ static task_t *copy_process(unsigned lon attach_pid(p, PIDTYPE_PGID, process_group(p)); attach_pid(p, PIDTYPE_SID, p->signal->session); - list_add_tail(&p->tasks, &init_task.tasks); + list_add_tail_rcu(&p->tasks, &init_task.tasks); __get_cpu_var(process_counts)++; } attach_pid(p, PIDTYPE_PID, p->pid); _