page faults when spawning subprocesses

Kasper Dupont kasperd at daimi.au.dk
Wed Nov 9 06:24:55 EST 2005


Dave Kirby wrote:
> 
> 5) WTF can I do about it?

Maybe using vfork rather than fork would help. But
I'm not sure that will work as intended when there
are multiple threads, in fact I'm not sure fork
will work either. You could have fork racing against
another thread being in a critical region thus
duplicating the memory map at some point where some
data structures are in an inconsistent state and
apparently locked by some thread existing in the
parent.

A possible solution would be to use fork to create
two processes before creating any threads. Have
the communicate over pipes or sockets when new
processes are to be created. Then one process can
create all the threads you need, and the other can
fork off children.

Even in that case vfork may come in handy. If you
dislike the semantics of vfork, but still want the
parent to block until the child has called execve,
then you can do so manually using a pipe. Create
the pipe before calling fork, in parent process
you close write end and try to read from the pipe,
in child process you close read end and mark write
end close on exec. When exec succeeds, the pipe is
closed and parent gets EOF.

(I have tried some of this in C, but I must admit,
I don't know if it can be done in Python as well.)

-- 
Kasper Dupont
Note to self: Don't try to allocate
256000 pages with GFP_KERNEL on x86.



More information about the Python-list mailing list