Skip to main content

Module cow

Module cow 

Source
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:
    1. If refcount > 1: allocate new frame, copy content, update PTE
    2. 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).