You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
mm: per-child copy-on-write address space for fork() (opt-in, stacked)
Follow-up to the base fork() PR: gives a forked child its own address space
with copy-on-write of private mappings, so a forked child has real memory
isolation like Linux fork() while MAP_SHARED / shm stays shared. Also gated
behind CONFIG_fork (default off): with it disabled none of this is compiled and
OSv's single-address-space model and context-switch path are unchanged.
With CONFIG_fork enabled:
- mmu::address_space object (page-table root + vma_list); the previous global
becomes 'address space 0' (kernel + init app).
- Per-thread current address space; the context switch loads the target CR3
only when the address space differs (a no-op for AS0-only workloads). Kernel
PML4 entries are shared across all address spaces so OSv code + the kernel
heap work identically after a switch.
- fork() clones the parent's vmas into a child address space: PRIVATE writable
mappings are write-protected in both and copied on the first write (reusing
OSv's existing COW fault machinery); MAP_SHARED / shm map the same physical
pages (truly shared). execve() returns the thread to AS0.
- Lock/condvar wait_records for fork-child (non-AS0) threads are allocated from
the AS-shared kernel heap instead of the thread stack, so a wait_record queued
on a shared kernel mutex resolves to the same physical page for any waker
across address spaces (kernel-stack coherence).
Validated: tst-fork-cow proves a forked child's private memory stays private
while MAP_SHARED stays shared; tst-fork stays 10/10.
Known limitation (documented): the child's stack is still relocated+copied
rather than same-VA COW, so a child that unwinds a very deep call chain (e.g. a
multi-process server forking backends) can still hit a stack-fidelity issue
(tst-fork-deep); the same-VA stack fix is a further follow-up. This PR delivers
memory-isolated fork for the common cases with COW proven.
Copyright (C) 2026 Greg Burd
#Generate gen/config/kernel_conf.mk AND individual option headers gen/include/osv/kernel_config_* based on the latest gen/config/kernel.conf and gen/include/osv/kernel_config.h
70
70
#The gen/config/kernel_conf.mk is included by the main OSv makefile and the headers gen/include/osv/kernel_config_* included by relevant source files
0 commit comments