HeadlinesBriefing favicon HeadlinesBriefing.com

Linux kernel explores spawn templates to trim fork‑exec overhead

Hacker News •
×

Linux developers have long relied on the costly fork() + exec() sequence to launch new programs. Fork clones the entire process state, then exec replaces it, discarding the copied memory. The pattern appears in tools that repeatedly invoke the same binary, such as Git wrappers, and has motivated several optimization attempts, including vfork. The overhead becomes especially problematic in high‑frequency services that spawn dozens of workers per second.

Li Chen recently submitted a patch set introducing “spawn templates,” a kernel API that caches executable metadata after an initial open. Applications create a template via spawn_template_create(), receiving a file descriptor that represents the pre‑loaded binary. Subsequent launches fill a spawn_template_spawn_args structure with argv, envp and a list of actions—close, dup, open, or signal tweaks—then call spawn_template_spawn() to start the process more quickly.

Reviewers noted the 2 % speed gain is modest, but the design keeps all execve checks intact, preserving security. Critics like Mateusz Guzik argue that eliminating fork altogether would deliver far larger savings, proposing a pristine‑process model. Christian Brauner suggested building the interface atop pidfd, enabling a native posix_spawn() implementation. Chen agreed the broader API direction is preferable, leaving spawn templates out of the mainline.