[PATCH] pids: kill PIDTYPE_TGID

This patch kills PIDTYPE_TGID pid_type thus saving one hash table in
kernel/pid.c and speeding up subthreads create/destroy a bit. It is also a
preparation for the further tref/pids rework.

This patch adds 'struct list_head thread_group' to 'struct task_struct'
instead.

We don't detach group leader from PIDTYPE_PID namespace until another
thread inherits it's ->pid == ->tgid, so we are safe wrt premature
free_pidmap(->tgid) call.

Currently there are no users of find_task_by_pid_type(PIDTYPE_TGID).
Should the need arise, we can use find_task_by_pid()->group_leader.

Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
Acked-By: Eric Biederman <ebiederm@xmission.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

Oleg Nesterov and committed by
Linus Torvalds
47e65328 88531f72

+12 -14
-1
include/linux/pid.h
··· 4 4 enum pid_type 5 5 { 6 6 PIDTYPE_PID, 7 - PIDTYPE_TGID, 8 7 PIDTYPE_PGID, 9 8 PIDTYPE_SID, 10 9 PIDTYPE_MAX
+8 -3
include/linux/sched.h
··· 752 752 753 753 /* PID/PID hash table linkage. */ 754 754 struct pid pids[PIDTYPE_MAX]; 755 + struct list_head thread_group; 755 756 756 757 struct completion *vfork_done; /* for vfork() */ 757 758 int __user *set_child_tid; /* CLONE_CHILD_SETTID */ ··· 1193 1192 #define while_each_thread(g, t) \ 1194 1193 while ((t = next_thread(t)) != g) 1195 1194 1196 - extern task_t * FASTCALL(next_thread(const task_t *p)); 1197 - 1198 1195 #define thread_group_leader(p) (p->pid == p->tgid) 1196 + 1197 + static inline task_t *next_thread(task_t *p) 1198 + { 1199 + return list_entry(rcu_dereference(p->thread_group.next), 1200 + task_t, thread_group); 1201 + } 1199 1202 1200 1203 static inline int thread_group_empty(task_t *p) 1201 1204 { 1202 - return list_empty(&p->pids[PIDTYPE_TGID].pid_list); 1205 + return list_empty(&p->thread_group); 1203 1206 } 1204 1207 1205 1208 #define delay_group_leader(p) \
+1 -9
kernel/exit.c
··· 51 51 { 52 52 nr_threads--; 53 53 detach_pid(p, PIDTYPE_PID); 54 - detach_pid(p, PIDTYPE_TGID); 55 54 if (thread_group_leader(p)) { 56 55 detach_pid(p, PIDTYPE_PGID); 57 56 detach_pid(p, PIDTYPE_SID); ··· 58 59 list_del_init(&p->tasks); 59 60 __get_cpu_var(process_counts)--; 60 61 } 61 - 62 + list_del_rcu(&p->thread_group); 62 63 remove_parent(p); 63 64 } 64 65 ··· 962 963 { 963 964 do_exit((error_code&0xff)<<8); 964 965 } 965 - 966 - task_t fastcall *next_thread(const task_t *p) 967 - { 968 - return pid_task(p->pids[PIDTYPE_TGID].pid_list.next, PIDTYPE_TGID); 969 - } 970 - 971 - EXPORT_SYMBOL(next_thread); 972 966 973 967 /* 974 968 * Take down every thread in the group. This is called by fatal signals
+3 -1
kernel/fork.c
··· 1112 1112 * We dont wake it up yet. 1113 1113 */ 1114 1114 p->group_leader = p; 1115 + INIT_LIST_HEAD(&p->thread_group); 1115 1116 INIT_LIST_HEAD(&p->ptrace_children); 1116 1117 INIT_LIST_HEAD(&p->ptrace_list); 1117 1118 ··· 1166 1165 retval = -EAGAIN; 1167 1166 goto bad_fork_cleanup_namespace; 1168 1167 } 1168 + 1169 1169 p->group_leader = current->group_leader; 1170 + list_add_tail_rcu(&p->thread_group, &p->group_leader->thread_group); 1170 1171 1171 1172 if (current->signal->group_stop_count > 0) { 1172 1173 /* ··· 1216 1213 list_add_tail(&p->tasks, &init_task.tasks); 1217 1214 __get_cpu_var(process_counts)++; 1218 1215 } 1219 - attach_pid(p, PIDTYPE_TGID, p->tgid); 1220 1216 attach_pid(p, PIDTYPE_PID, p->pid); 1221 1217 nr_threads++; 1222 1218 }