Re: Q: nr_threads locking

From: Manfred Spraul (manfred@colorfullife.com)
Date: Mon Apr 21 2003 - 13:49:49 EST


Andrew Morton wrote:

>It would be possible, yes.
>
>But thread creation is a "rare" event compared to pagefaults and syscalls.
>An atomic_t will be OK there.
>
>
Actually, the code is correct. The documentation it bogus. lock_kernel()
never achieved any protection: the copy_xy() functions can sleep.

What about the attached docu update?

--
    Manfred

--- 2.5/kernel/fork.c 2003-04-20 11:19:14.000000000 +0200 +++ build-2.5/kernel/fork.c 2003-04-21 20:44:37.000000000 +0200 @@ -43,7 +43,9 @@ extern int copy_semundo(unsigned long clone_flags, struct task_struct *tsk); extern void exit_semundo(struct task_struct *tsk); -/* The idle threads do not count.. */ +/* The idle threads do not count.. + * Protected by write_lock_irq(&tasklist_lock) + */ int nr_threads; int max_threads; @@ -792,9 +794,9 @@ atomic_inc(&p->user->processes); /* - * Counter increases are protected by - * the kernel lock so nr_threads can't - * increase under us (but it may decrease). + * If multiple threads are within copy_process(), then this check + * triggers too late. This doesn't hurt, the check is only there + * to stop root fork bombs. */ if (nr_threads >= max_threads) goto bad_fork_cleanup_count;

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Wed Apr 23 2003 - 22:00:30 EST