libroot: Implement a "partial" vfork.

The original meaning of vfork is "fork, sharing virtual memory" (until
exec). We don't implement that, and may never do so. However, since
calling any functions besides exec() in a vfork'ed child is "undefined
behavior", we can take advantage of that fact at least by not calling
any of the pre- and post-fork hooks, saving a lot of page faults from
copy-on-write.

On one run of the "compile HaikuDepot and the mime_db" benchmark with -j4,
the total waits count on the top two VMCaches by contention dropped
from 62125 and 58927, to 52034 and 41225.

musl apparently does more or less this same thing (vfork() is fork()
but without calling any of the hooks.)
This commit is contained in:
Augustin Cavalier
2024-12-16 14:28:51 -05:00
parent e534029ca0
commit 91bb4d0238
+7 -2
View File
@@ -185,6 +185,11 @@ fork(void)
pid_t
vfork(void)
{
return fork();
thread_id thread = _kern_fork();
if (thread < 0) {
// something went wrong
__set_errno(thread);
thread = -1;
}
return thread;
}