From: Stelian I. <sio...@cd...> - 2016-05-12 13:09:53
|
On Wed, 2016-05-11 at 10:42 -0400, Douglas Katzman wrote: > Is there something he can do with *all-threads-locks* and > *make-thread-lock* to automatically decide, specifically for run > -program, > that forking without copying memory mappings is ok? > > like: > grab all-thread-lock and make-thread-lock ; deadlock possible? > if only 1 thread in all-threads then > fork with madv_nofork, run program > release locks in parent > else > release locks > do normal thing The sharing of mapping cannot be applied atomically, since it's not a property of fork(). A way to do this would be to add a boolean parameter to spawn() that enables this behavior, then add a lock to serialize spawn() calls, and inside spawn(): if(share_on_fork) { madvise(READ_ONLY_SPACE_START, READ_ONLY_SPACE_SIZE, MADV_DONTFORK); madvise(STATIC_SPACE_START, STATIC_SPACE_SIZE, MADV_DONTFORK); madvise(DYNAMIC_SPACE_START, DYNAMIC_SPACE_SIZE, MADV_DONTFORK); } else { madvise(READ_ONLY_SPACE_START, READ_ONLY_SPACE_SIZE, MADV_DOFORK); madvise(STATIC_SPACE_START, STATIC_SPACE_SIZE, MADV_DOFORK); madvise(DYNAMIC_SPACE_START, DYNAMIC_SPACE_SIZE, MADV_DOFORK); } And this won't work if there are libraries that fork() and create processes. Another approach would be to enable this by default - because most people don't do fork() concurrency - but add a Lisp function to turn it off at runtime. -- Stelian Ionescu a.k.a. fe[nl]ix Quidquid latine dictum sit, altum videtur. |