Expand description
Copy-on-Write (COW) support for fork()
This module provides the core functionality for copy-on-write memory management, allowing efficient fork() implementation by sharing pages between parent and child until one of them writes to a shared page.
§Design
- Pages are marked as COW by clearing the WRITABLE bit and setting a software COW flag
- The COW flag is stored in bit 9 of the PTE (available for software use on x86_64)
- When a write fault occurs on a COW page:
- If refcount > 1: allocate new frame, copy content, update PTE
- If refcount == 1: just mark page as writable (no copy needed)
§SMP Safety
- Atomic refcount per frame (lock-free inc/dec)
- COW_LOCK protects flag changes and frame free
- TLB shootdown is performed after modifying page table flags
Functions§
- frame_
clear_ cow - Clear COW flag on a frame (SMP-safe).
- frame_
dec_ ref - Performs the frame dec ref operation.
- frame_
get_ refcount - Performs the frame get refcount operation.
- frame_
inc_ ref - Performs the frame inc ref operation.
- frame_
is_ cow - Check if a frame is marked as COW (lock-free read).
- frame_
is_ dll - Check if a frame is a DLL frame (lock-free read).
- frame_
set_ cow - Set COW flag on a frame (SMP-safe).
- frame_
set_ dll - Mark a frame as DLL (shared, never COW) (SMP-safe).