Hi all, I've been working on (or rather, struggling with) with the scsh-process egg for a bit the past couple of days, and I've been thinking about fork. It's probably better if we clean up the parent process state that's lying around in the child's continuation of a (process-fork) call which we will never call anyway.
This should avoid issues like we've seen with #1367 when forking lots of processes, and in general decrease memory use of child processes. Initially I thought I could just (##sys#call-with-cthulhu thunk) because the C_termination_continuation also exits with code 0, but then I remembered that (exit) will call ##sys#exit-handler (which the C code will not do), so I think this patch is correct. Both for master and chicken-5. Cheers, Peter
From b1eb4a6a978097c40338458b6b58856b397cb5e2 Mon Sep 17 00:00:00 2001 From: Peter Bex <[email protected]> Date: Fri, 10 Nov 2017 21:38:04 +0100 Subject: [PATCH] Similar to 118fce and 596332, clean up old state upon fork When fork receives a thunk to run in the child process, call it with a clean, empty continuation rather than keeping any cruft from the parent around. This should allow GC of objects that are no longer necessary and improve memory use somewhat, and perhaps prevent situations like that in #1367 when using processes instead of threads. --- posixunix.scm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/posixunix.scm b/posixunix.scm index 5ac48082..0e22c28e 100644 --- a/posixunix.scm +++ b/posixunix.scm @@ -1294,8 +1294,10 @@ static C_word C_i_fifo_p(C_word name) ##sys#kill-other-threads (lambda (thunk) (thunk))) (lambda () - (thunk) - (exit 0))) + (##sys#call-with-cthulhu + (lambda () + (thunk) + (exit 0))))) pid))))) (define (process-execute filename #!optional (arglist '()) envlist exactf) -- 2.11.0
From 610a2a6511d06b65b23ce46ca468004202ce00fe Mon Sep 17 00:00:00 2001 From: Peter Bex <[email protected]> Date: Fri, 10 Nov 2017 21:38:04 +0100 Subject: [PATCH] Similar to 118fce and 596332, clean up old state upon fork When fork receives a thunk to run in the child process, call it with a clean, empty continuation rather than keeping any cruft from the parent around. This should allow GC of objects that are no longer necessary and improve memory use somewhat, and perhaps prevent situations like that in #1367 when using processes instead of threads. --- posixunix.scm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/posixunix.scm b/posixunix.scm index 9304b395..11a00e07 100644 --- a/posixunix.scm +++ b/posixunix.scm @@ -1564,8 +1564,10 @@ EOF ##sys#kill-other-threads (lambda (thunk) (thunk))) (lambda () - (thunk) - (exit 0))) + (##sys#call-with-cthulhu + (lambda () + (thunk) + (exit 0))))) pid))))) (define (process-execute filename #!optional (arglist '()) envlist) -- 2.11.0
signature.asc
Description: PGP signature
_______________________________________________ Chicken-hackers mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/chicken-hackers
