Subject: Re: Speeding up fork/wait path
To: Jaromir Dolecek <jdolecek@NetBSD.org>
From: Chuck Silvers <chuq@chuq.com>
List: tech-kern
Date: 10/26/2003 16:41:42
On Sun, Oct 26, 2003 at 11:33:39PM +0100, Jaromir Dolecek wrote:
> It may need to take lock from uvm_lwp_exit() -> uvm_uarea_free(),
> and does need to take lock at least for i386 also in cpu_wait() ->
> tss_free(). So the work indeed needs to be done from (separate)
> process/lwp context.

freeing the uarea (ie. the kernel stack) can't be run on the stack
being freed, so this must be done by another thread.


> I'm not sure about uvm_proc_exit() -> vmspace_free() - this may
> be callable without process context, I can see only simplelocks
> in the codepath. But since we need to execute the last (or only)
> lwp before tearing down the process, even uvm_proc_exit()
> can't be called sooner.

however, an exiting user process should be able to tear down its own
user address space.  it doesn't need it anymore at this point.


> The option to make sys_wait4() able to collect info from SDEAD
> process (with reaper still doing the final execution) is IMHO
> fragile and I'd prefer to not go that path.
> 
> I guess the only remaining choice now is to make sys_wait4() able
> to tear down SDEAD process completely itself if it gets to it before
> the reaper, so that it wouldn't need to wait for reaper
> to execute the child before collecting the child status. Would
> this be somehow fundamentally wrong, or would this be okay to do?
> The parent would get charged the time it would take to execute the
> child, but IMHO this is fine. Arguably the time should be charged
> to the child, but this might not be simple to implement. IIRC
> parent is charged all the time the child run anyway, so it doesn't
> matter much if the final teardown time is charged only to the parent
> and not the child.

I'd rather see the child do its own vmspace_free(), and then defer the
remaining work to another thread.  proc0 already wakes up periodically
and does a little work, so having that thread free the uareas seems
reasonable.  it will probably take a little fiddling to get this working
but it doesn't seem like it should be very hard.

-Chuck