Hasty Briefsbeta

Bilingual

Moving Beyond Fork() + Exec()

2 days ago
  • #system calls
  • #performance optimization
  • #process creation
  • fork() is an expensive system call due to copying the entire process state, often followed by exec() which discards that copied memory.
  • Spawn templates are a proposed optimization for repeatedly launching the same executable, allowing setup costs to be spread across multiple invocations.
  • A template is created using spawn_template_create(), caching kernel information to speed up future executions.
  • Specific process invocations are configured via spawn_template_spawn_args, including argv, envp, and actions for file descriptor and signal changes.
  • Internally, spawn_template_spawn() follows a path similar to fork()/exec() but is faster due to cached template information, with benchmarks showing about 2% improvement.
  • Reviewers suggest focusing on eliminating fork() entirely by creating pristine processes instead, potentially using pidfd abstractions.
  • The goal is to support a proper posix_spawn() implementation in user space, replacing the fork()/exec() pattern with a more efficient API.