From: Prasanna Meda Bring the total_forks under tasklist_lock. When most of the fork code icluding nr_threads is moved to copy_process() from do_fork() code in 2.6, this is left out. Althought accuracy of total_forks is not important, it would be nice to add this. It does not involve additional cost, and the code will be cleaner if it is grouped with nr_threads. The difference is, total_forks will increase on fork, but nr_threads will increase on fork and decrease on the exit. I also moved extern decleration to sched.h from proc_misc.c. Signed-off-by: Prasanna Meda Signed-off-by: Andrew Morton --- 25-akpm/fs/proc/proc_misc.c | 1 - 25-akpm/include/linux/sched.h | 1 + 25-akpm/kernel/fork.c | 12 ++++++------ 3 files changed, 7 insertions(+), 7 deletions(-) diff -puN fs/proc/proc_misc.c~fork-total_forks-not-counted-under-tasklist_lock fs/proc/proc_misc.c --- 25/fs/proc/proc_misc.c~fork-total_forks-not-counted-under-tasklist_lock 2004-11-22 20:25:53.676355648 -0800 +++ 25-akpm/fs/proc/proc_misc.c 2004-11-22 20:25:53.684354432 -0800 @@ -322,7 +322,6 @@ static struct file_operations proc_slabi int show_stat(struct seq_file *p, void *v) { int i; - extern unsigned long total_forks; unsigned long jif; u64 sum = 0, user = 0, nice = 0, system = 0, idle = 0, iowait = 0, irq = 0, softirq = 0; diff -puN include/linux/sched.h~fork-total_forks-not-counted-under-tasklist_lock include/linux/sched.h --- 25/include/linux/sched.h~fork-total_forks-not-counted-under-tasklist_lock 2004-11-22 20:25:53.678355344 -0800 +++ 25-akpm/include/linux/sched.h 2004-11-22 20:25:53.685354280 -0800 @@ -88,6 +88,7 @@ extern unsigned long avenrun[]; /* Load #define CT_TO_SECS(x) ((x) / HZ) #define CT_TO_USECS(x) (((x) % HZ) * 1000000/HZ) +extern unsigned long total_forks; extern int nr_threads; extern int last_pid; DECLARE_PER_CPU(unsigned long, process_counts); diff -puN kernel/fork.c~fork-total_forks-not-counted-under-tasklist_lock kernel/fork.c --- 25/kernel/fork.c~fork-total_forks-not-counted-under-tasklist_lock 2004-11-22 20:25:53.680355040 -0800 +++ 25-akpm/kernel/fork.c 2004-11-22 20:25:53.686354128 -0800 @@ -48,13 +48,13 @@ #include #include -/* The idle threads do not count.. - * Protected by write_lock_irq(&tasklist_lock) +/* + * Protected counters by write_lock_irq(&tasklist_lock) */ -int nr_threads; - -int max_threads; unsigned long total_forks; /* Handle normal Linux uptimes. */ +int nr_threads; /* The idle threads do not count.. */ + +int max_threads; /* tunable limit on nr_threads */ DEFINE_PER_CPU(unsigned long, process_counts) = 0; @@ -1034,6 +1034,7 @@ static task_t *copy_process(unsigned lon } nr_threads++; + total_forks++; write_unlock_irq(&tasklist_lock); retval = 0; @@ -1166,7 +1167,6 @@ long do_fork(unsigned long clone_flags, wake_up_new_task(p, clone_flags); else p->state = TASK_STOPPED; - ++total_forks; if (unlikely (trace)) { current->ptrace_message = pid; _