Subject: Speeding up fork/wait path
To: None <tech-kern@NetBSD.org>
From: Jaromir Dolecek <jdolecek@NetBSD.org>
List: tech-kern
Date: 10/25/2003 23:00:44
According to how I read the source (for i386 at least),
it seems the exit process is currently like this:

1. process exits, all but uarea and vmspace freed, process goes to state SDEAD
  -> cpu_exit() -> switch_exit() to idle context -> exit2() (puts process/lwp to
  deadprocs/deadlwps list, and wakeups reaper), MD code then
  schedules other process
2. reaper calls cpu_wait() (on i386 frees TSS) and uvm_{lwp|proc}_exit()
   (frees uarea), then changes state of process or lwp to LSZOMB
3. parent calling wait can now collect the child via wait4()

So, it's currently necessary to do two extra context switches (to reaper
and back to parent).

I'm not sure I completely understand the logic, but I cannot see
why it would be necessary to run the final child cleanup (work
done by reaper) from process context. Neither of those two
routines can block, can it? Theoretically it might be possible
to do the cleanup directly from within exit2/lwp_exit2, avoiding
the reaper entirely, right?

Jaromir
-- 
Jaromir Dolecek <jdolecek@NetBSD.org>            http://www.NetBSD.cz/
-=- We should be mindful of the potential goal, but as the tantric    -=-
-=- Buddhist masters say, ``You may notice during meditation that you -=-
-=- sometimes levitate or glow.   Do not let this distract you.''     -=-