Skip to content

Commit

Permalink
[PATCH] pids: kill PIDTYPE_TGID
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Oleg Nesterov authored and Linus Torvalds committed Mar 29, 2006
1 parent 88531f7 commit 47e6532
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
1 change: 0 additions & 1 deletion include/linux/pid.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
enum pid_type
{
PIDTYPE_PID,
PIDTYPE_TGID,
PIDTYPE_PGID,
PIDTYPE_SID,
PIDTYPE_MAX
Expand Down
11 changes: 8 additions & 3 deletions include/linux/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ struct task_struct {

/* PID/PID hash table linkage. */
struct pid pids[PIDTYPE_MAX];
struct list_head thread_group;

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

extern task_t * FASTCALL(next_thread(const task_t *p));

#define thread_group_leader(p) (p->pid == p->tgid)

static inline task_t *next_thread(task_t *p)
{
return list_entry(rcu_dereference(p->thread_group.next),
task_t, thread_group);
}

static inline int thread_group_empty(task_t *p)
{
return list_empty(&p->pids[PIDTYPE_TGID].pid_list);
return list_empty(&p->thread_group);
}

#define delay_group_leader(p) \
Expand Down
10 changes: 1 addition & 9 deletions kernel/exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,14 @@ static void __unhash_process(struct task_struct *p)
{
nr_threads--;
detach_pid(p, PIDTYPE_PID);
detach_pid(p, PIDTYPE_TGID);
if (thread_group_leader(p)) {
detach_pid(p, PIDTYPE_PGID);
detach_pid(p, PIDTYPE_SID);

list_del_init(&p->tasks);
__get_cpu_var(process_counts)--;
}

list_del_rcu(&p->thread_group);
remove_parent(p);
}

Expand Down Expand Up @@ -964,13 +963,6 @@ asmlinkage long sys_exit(int error_code)
do_exit((error_code&0xff)<<8);
}

task_t fastcall *next_thread(const task_t *p)
{
return pid_task(p->pids[PIDTYPE_TGID].pid_list.next, PIDTYPE_TGID);
}

EXPORT_SYMBOL(next_thread);

/*
* Take down every thread in the group. This is called by fatal signals
* as well as by sys_exit_group (below).
Expand Down
4 changes: 3 additions & 1 deletion kernel/fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,7 @@ static task_t *copy_process(unsigned long clone_flags,
* We dont wake it up yet.
*/
p->group_leader = p;
INIT_LIST_HEAD(&p->thread_group);
INIT_LIST_HEAD(&p->ptrace_children);
INIT_LIST_HEAD(&p->ptrace_list);

Expand Down Expand Up @@ -1165,7 +1166,9 @@ static task_t *copy_process(unsigned long clone_flags,
retval = -EAGAIN;
goto bad_fork_cleanup_namespace;
}

p->group_leader = current->group_leader;
list_add_tail_rcu(&p->thread_group, &p->group_leader->thread_group);

if (current->signal->group_stop_count > 0) {
/*
Expand Down Expand Up @@ -1213,7 +1216,6 @@ static task_t *copy_process(unsigned long clone_flags,
list_add_tail(&p->tasks, &init_task.tasks);
__get_cpu_var(process_counts)++;
}
attach_pid(p, PIDTYPE_TGID, p->tgid);
attach_pid(p, PIDTYPE_PID, p->pid);
nr_threads++;
}
Expand Down

0 comments on commit 47e6532

Please sign in to comment.