Subject: Re: popen reentrant (was Re: SA/pthread and vfork)
To: Greywolf <greywolf@starwolf.com>
From: Jason Thorpe <thorpej@wasabisystems.com>
List: tech-kern
Date: 09/14/2003 18:28:44
On Sunday, September 14, 2003, at 01:01  PM, Greywolf wrote:

> If you fork(), even if you don't touch any of the pages before calling
> exec(), you still have to copy all the parent's pages into the child.
> This could potentially run you out of (virtual and physical) memory.

You don't copy all of the pages ... we use COW for this.

So, let me just provide a little history lesson...

When the Mach VM system was being integrated into BSD by Hibler, et al, 
they decided that the spiffy new VM system didn't need the orignal 
vfork() semantics because it was better than the old (VAX-centric) VM 
system.  However, since applications used vfork(), they decided to 
preserve the parent-waits-for-child-to-exec-or-exit semantics.

Now, it turns out that setting up an entire-address-space-COW for a 
large process is still pretty expensive; you have to traverse all of 
its VM map entries, and might have to revoke write permissions on pages 
(thus causing cache and TLB flushes).  All of this work is totally 
pointless if the child is simply going to exec.  "Why burn cycles if 
there is no good reason to?"

This was the primary motivation behind my restoring the 
shared-address-space semantics of vfork().

         -- Jason R. Thorpe <thorpej@wasabisystems.com>