Re: [9fans] rio leak

2013-12-05 Thread cinap_lenrek
i just tried something out. it appears that _schedexecwait()'s
purpose is to serve thredwaitchan():

  Threadwaitchan returns a channel of pointers to Waitmsg
  structures (see wait(2)). When an exec'ed process exits, a
  pointer to a Waitmsg is sent to this channel.  These Waitmsg
  structures have been allocated with malloc(2) and should be
  freed after use.

when threadwaitchan isnt used, we can rfork the execing child
with RFNOWAIT which will make the process doing the original
procexecl() not wait for the child.

i just tried this out with rio (and abaco) and it seems to work fine.

diff -r 42807d2e3f4b sys/src/libthread/main.c
--- a/sys/src/libthread/main.c  Thu Dec 05 22:43:44 2013 +0100
+++ b/sys/src/libthread/main.c  Fri Dec 06 23:50:34 2013 +0100
@@ -121,9 +121,10 @@
 int
 _schedexec(Execargs *e)
 {
-   int pid;
+   int pid, flag;
 
-   switch(pid = rfork(RFREND|RFNOTEG|RFFDG|RFMEM|RFPROC)){
+   flag = (_threadwaitchan == nil) ? RFNOWAIT : 0;
+   switch(pid = rfork(RFREND|RFNOTEG|RFFDG|RFMEM|RFPROC|flag)){
case 0:
efork(e);
default:

this is saving a couple of few processes. is it worth it?

--
cinap



Re: [9fans] rio leak

2013-12-05 Thread erik quanstrom
On Thu Dec  5 18:01:07 EST 2013, cinap_len...@felloff.net wrote:
> i just tried something out. it appears that _schedexecwait()'s
> purpose is to serve thredwaitchan():
> 
>   Threadwaitchan returns a channel of pointers to Waitmsg
>   structures (see wait(2)). When an exec'ed process exits, a
>   pointer to a Waitmsg is sent to this channel.  These Waitmsg
>   structures have been allocated with malloc(2) and should be
>   freed after use.
> 
> when threadwaitchan isnt used, we can rfork the execing child
> with RFNOWAIT which will make the process doing the original
> procexecl() not wait for the child.
> 
> i just tried this out with rio (and abaco) and it seems to work fine.
> 
> diff -r 42807d2e3f4b sys/src/libthread/main.c
> --- a/sys/src/libthread/main.cThu Dec 05 22:43:44 2013 +0100
> +++ b/sys/src/libthread/main.cFri Dec 06 23:50:34 2013 +0100
> @@ -121,9 +121,10 @@
>  int
>  _schedexec(Execargs *e)
>  {
> - int pid;
> + int pid, flag;
>  
> - switch(pid = rfork(RFREND|RFNOTEG|RFFDG|RFMEM|RFPROC)){
> + flag = (_threadwaitchan == nil) ? RFNOWAIT : 0;
> + switch(pid = rfork(RFREND|RFNOTEG|RFFDG|RFMEM|RFPROC|flag)){
>   case 0:
>   efork(e);
>   default:
> 
> this is saving a couple of few processes. is it worth it?

hey, that's pretty cool.  i'll bet that with this change the leaked memory
actually shows up as leaked.

- erik