3 ms·
It's not that bad. The real problem is fork(), which is just a bad syscall in general (note how the single most common desktop OS doesn't have any equivalent to
by jcranmer 5y ago
It's not that bad. The real problem is fork(), which is just a bad syscall in general (note how the single most common desktop OS doesn't have any equivalent to fork and seems to get along just fine). You can still allow mmap in a CoW-less world (you'll have to prevent concurrent file modification, which--again--a certain common operating system does!). Memory reservation is completely orthogonal to CoW: lazy page table initialization isn't the same thing as copy-on-write.
- j16sdiz 5y agoWindows have PAGE_WRITECOPY and PAGE_EXECUTE_WRITECOPY. Those are essential for efficient shared library loading.
- jabl 5y agoThis paper argues that fork+exec is the wrong primitive for launching new processes: https://www.microsoft.com/en-us/research/publication/a-fork-in-the-road/ https://www.microsoft.com/en-us/research/publication/a-fork-... posix_spawn can take care of many common cases today.
- zxzax 5y agoUnfortunately, on Linux there is no posix_spawn syscall. It's implemented in glibc as a wrapper around clone + exec.
- geofft 5y agoYes, but it's a wrapper around clone(CLONE_VFORK | CLONE_VM) (aka vfork) + exec, which makes a big difference. CLONE_VFORK means that the parent process is suspended until the child either exits or execs, and CLONE_VM means that no copy-on-write happens - the child has full read/write access to the original memory space until it execs (or exits). In the child, posix_spawn is careful to work within temporary memory so it doesn't overwrite anything that the parent process might care about, including global variables etc. Then once exec succeeds (or fails, and the process exits), posix_spawn in the parent cleans up that temporary memory. This means that posix_spawn doesn't require any copy-on-write support from the kernel. Or in other words, there's no posix_spawn syscall and there shouldn't be because it's a library function, but there is a vfork syscall.
- zxzax 5y agoI generally agree with the comments in the research paper about clone + vfork, most applications seem to not use it at all (either directly or indirectly through posix_spawn) for those reasons.