locking reasoning within fork1()

LI Xin delphij at delphij.net
Sat Mar 10 14:38:18 UTC 2007


Hi,

During the AsiaBSDCon DevSummit we have go through the current KSE and
some userland threading code, and I think that brings me back to the
fork1() vs others races.

The current logic, especially the locking order found in fork1() looks
not very ideal according to my read.  I have pursued some code from
other BSDs, and I think we might want to address the following problems:

 - At which point we should consider that a process really exists?  At
this point, there is no clear point that we can call a process as
"really born".  It looks to me that PRS_NEW just indicate that a process
is not "fully initialized", but it does not provide information about
"how much initialization did we done".  This would make several
operation very questionable, and is more error-prone.  As Guo (cc'ed)
pointed out, there are chances that kill(0, ..) and kill(-1, ..) would
not cover PRS_NEW processes, there might be also some other places where
should take care of.

 - The locking scheme does not look pretty.  We grab and release locks
again and again, and it might be more optimal to collapse some work
together, and re-consider synchornization with other parts of the kernel.

 - Certain parts of struct proc is mostly not accessed frequently.  For
the sake of better exploit of cache, we may want to consider to move
certain parts out from the struct.

 - The PID allocation is somewhat expensive when there are a lot of
processes.  This might not be a very big deal, though, but given that it
requires to hold a sx_xlock, our scalability could be limited due to
this.  tjr@ has a proposed hash based PID allocation patch in his p4
branch, and NetBSD have an O(1) algorithm that may worth to have a look at.

Cheers,
-- 
Xin LI <delphij at delphij.net>	http://www.delphij.net/
FreeBSD - The Power to Serve!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 249 bytes
Desc: OpenPGP digital signature
Url : http://lists.freebsd.org/pipermail/freebsd-arch/attachments/20070310/32dcfb8a/signature.pgp


More information about the freebsd-arch mailing list