diff options
author | Oleg Nesterov <oleg@tv-sign.ru> | 2006-03-28 19:11:07 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-03-28 21:36:41 -0500 |
commit | 73b9ebfe126a4a886ee46cbab637374d7024668a (patch) | |
tree | d7ba00d4ce76b49c1569334956cd196b35977a04 /kernel/fork.c | |
parent | c97d98931ac52ef110b62d9b75c6a6f2bfbc1898 (diff) |
[PATCH] pidhash: don't count idle threads
fork_idle() does unhash_process() just after copy_process(). Contrary,
boot_cpu's idle thread explicitely registers itself for each pid_type with nr
= 0.
copy_process() already checks p->pid != 0 before process_counts++, I think we
can just skip attach_pid() calls and job control inits for idle threads and
kill unhash_process(). We don't need to cleanup ->proc_dentry in fork_idle()
because with this patch idle threads are never hashed in
kernel/pid.c:pid_hash[].
We don't need to hash pid == 0 in pidmap_init(). free_pidmap() is never
called with pid == 0 arg, so it will never be reused. So it is still possible
to use pid == 0 in any PIDTYPE_xxx namespace from kernel/pid.c's POV.
However with this patch we don't hash pid == 0 for PIDTYPE_PID case. We still
have have PIDTYPE_PGID/PIDTYPE_SID entries with pid == 0: /sbin/init and
kernel threads which don't call daemonize().
Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'kernel/fork.c')
-rw-r--r-- | kernel/fork.c | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/kernel/fork.c b/kernel/fork.c index 74c67629ee62..0c32e28cdc5f 100644 --- a/kernel/fork.c +++ b/kernel/fork.c | |||
@@ -1181,25 +1181,26 @@ static task_t *copy_process(unsigned long clone_flags, | |||
1181 | */ | 1181 | */ |
1182 | p->ioprio = current->ioprio; | 1182 | p->ioprio = current->ioprio; |
1183 | 1183 | ||
1184 | add_parent(p); | 1184 | if (likely(p->pid)) { |
1185 | if (unlikely(p->ptrace & PT_PTRACED)) | 1185 | add_parent(p); |
1186 | __ptrace_link(p, current->parent); | 1186 | if (unlikely(p->ptrace & PT_PTRACED)) |
1187 | 1187 | __ptrace_link(p, current->parent); | |
1188 | if (thread_group_leader(p)) { | 1188 | |
1189 | p->signal->tty = current->signal->tty; | 1189 | if (thread_group_leader(p)) { |
1190 | p->signal->pgrp = process_group(current); | 1190 | p->signal->tty = current->signal->tty; |
1191 | p->signal->session = current->signal->session; | 1191 | p->signal->pgrp = process_group(current); |
1192 | attach_pid(p, PIDTYPE_PGID, process_group(p)); | 1192 | p->signal->session = current->signal->session; |
1193 | attach_pid(p, PIDTYPE_SID, p->signal->session); | 1193 | attach_pid(p, PIDTYPE_PGID, process_group(p)); |
1194 | 1194 | attach_pid(p, PIDTYPE_SID, p->signal->session); | |
1195 | list_add_tail(&p->tasks, &init_task.tasks); | 1195 | |
1196 | if (p->pid) | 1196 | list_add_tail(&p->tasks, &init_task.tasks); |
1197 | __get_cpu_var(process_counts)++; | 1197 | __get_cpu_var(process_counts)++; |
1198 | } | ||
1199 | attach_pid(p, PIDTYPE_TGID, p->tgid); | ||
1200 | attach_pid(p, PIDTYPE_PID, p->pid); | ||
1201 | nr_threads++; | ||
1198 | } | 1202 | } |
1199 | attach_pid(p, PIDTYPE_TGID, p->tgid); | ||
1200 | attach_pid(p, PIDTYPE_PID, p->pid); | ||
1201 | 1203 | ||
1202 | nr_threads++; | ||
1203 | total_forks++; | 1204 | total_forks++; |
1204 | spin_unlock(¤t->sighand->siglock); | 1205 | spin_unlock(¤t->sighand->siglock); |
1205 | write_unlock_irq(&tasklist_lock); | 1206 | write_unlock_irq(&tasklist_lock); |
@@ -1263,7 +1264,7 @@ task_t * __devinit fork_idle(int cpu) | |||
1263 | if (!task) | 1264 | if (!task) |
1264 | return ERR_PTR(-ENOMEM); | 1265 | return ERR_PTR(-ENOMEM); |
1265 | init_idle(task, cpu); | 1266 | init_idle(task, cpu); |
1266 | unhash_process(task); | 1267 | |
1267 | return task; | 1268 | return task; |
1268 | } | 1269 | } |
1269 | 1270 | ||