Skip to content

Commit 47e6532

Browse files
Oleg NesterovLinus Torvalds
authored andcommitted
[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 <[email protected]> Acked-By: Eric Biederman <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 88531f7 commit 47e6532

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-14
lines changed

include/linux/pid.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
enum pid_type
55
{
66
PIDTYPE_PID,
7-
PIDTYPE_TGID,
87
PIDTYPE_PGID,
98
PIDTYPE_SID,
109
PIDTYPE_MAX

include/linux/sched.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,7 @@ struct task_struct {
752752

753753
/* PID/PID hash table linkage. */
754754
struct pid pids[PIDTYPE_MAX];
755+
struct list_head thread_group;
755756

756757
struct completion *vfork_done; /* for vfork() */
757758
int __user *set_child_tid; /* CLONE_CHILD_SETTID */
@@ -1192,13 +1193,17 @@ extern void wait_task_inactive(task_t * p);
11921193
#define while_each_thread(g, t) \
11931194
while ((t = next_thread(t)) != g)
11941195

1195-
extern task_t * FASTCALL(next_thread(const task_t *p));
1196-
11971196
#define thread_group_leader(p) (p->pid == p->tgid)
11981197

1198+
static inline task_t *next_thread(task_t *p)
1199+
{
1200+
return list_entry(rcu_dereference(p->thread_group.next),
1201+
task_t, thread_group);
1202+
}
1203+
11991204
static inline int thread_group_empty(task_t *p)
12001205
{
1201-
return list_empty(&p->pids[PIDTYPE_TGID].pid_list);
1206+
return list_empty(&p->thread_group);
12021207
}
12031208

12041209
#define delay_group_leader(p) \

kernel/exit.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,14 @@ static void __unhash_process(struct task_struct *p)
5151
{
5252
nr_threads--;
5353
detach_pid(p, PIDTYPE_PID);
54-
detach_pid(p, PIDTYPE_TGID);
5554
if (thread_group_leader(p)) {
5655
detach_pid(p, PIDTYPE_PGID);
5756
detach_pid(p, PIDTYPE_SID);
5857

5958
list_del_init(&p->tasks);
6059
__get_cpu_var(process_counts)--;
6160
}
62-
61+
list_del_rcu(&p->thread_group);
6362
remove_parent(p);
6463
}
6564

@@ -964,13 +963,6 @@ asmlinkage long sys_exit(int error_code)
964963
do_exit((error_code&0xff)<<8);
965964
}
966965

967-
task_t fastcall *next_thread(const task_t *p)
968-
{
969-
return pid_task(p->pids[PIDTYPE_TGID].pid_list.next, PIDTYPE_TGID);
970-
}
971-
972-
EXPORT_SYMBOL(next_thread);
973-
974966
/*
975967
* Take down every thread in the group. This is called by fatal signals
976968
* as well as by sys_exit_group (below).

kernel/fork.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,7 @@ static task_t *copy_process(unsigned long clone_flags,
11121112
* We dont wake it up yet.
11131113
*/
11141114
p->group_leader = p;
1115+
INIT_LIST_HEAD(&p->thread_group);
11151116
INIT_LIST_HEAD(&p->ptrace_children);
11161117
INIT_LIST_HEAD(&p->ptrace_list);
11171118

@@ -1165,7 +1166,9 @@ static task_t *copy_process(unsigned long clone_flags,
11651166
retval = -EAGAIN;
11661167
goto bad_fork_cleanup_namespace;
11671168
}
1169+
11681170
p->group_leader = current->group_leader;
1171+
list_add_tail_rcu(&p->thread_group, &p->group_leader->thread_group);
11691172

11701173
if (current->signal->group_stop_count > 0) {
11711174
/*
@@ -1213,7 +1216,6 @@ static task_t *copy_process(unsigned long clone_flags,
12131216
list_add_tail(&p->tasks, &init_task.tasks);
12141217
__get_cpu_var(process_counts)++;
12151218
}
1216-
attach_pid(p, PIDTYPE_TGID, p->tgid);
12171219
attach_pid(p, PIDTYPE_PID, p->pid);
12181220
nr_threads++;
12191221
}

0 commit comments

Comments
 (0)