IBV_FORK_INIT(3)
π IBV_FORK_INIT π
okay bestie, so this is a page from the Libibverbs Programmer's Manual β IBV_FORK_INIT(3) β and honestly it's giving "small function, big consequences" energy. let's get into it π«Ά
β¨ NAME β¨
ibv_fork_init β the glow-up that makes libibverbs fork()-safe π±
πΈ SYNOPSIS πΈ
#include <infiniband/verbs.h>
int ibv_fork_init(void);
literally that's it. one function, zero arguments, no cap. π
π¦ DESCRIPTION π¦
so like, ibv_fork_init() initializes libibverbs's internal data structures so they can handle fork() function calls correctly and avoid data corruption. and yes, that applies whether fork() gets called explicitly by you, or implicitly β like when something calls system() under the hood. sneaky!! π
now here's the tea: you do not need this function if all your parent process threads are always blocked until every child process ends, or until the child processes change address spaces via an exec() operation. in that case you're already safe, no cap. π
π RETURN VALUE π
ibv_fork_init()returns0on success β slay β¨- on failure it returns the value of
errno, which tells you the failure reason π - and specifically: an error value of
EINVALindicates that there had already been RDMA memory registration, so it's not safe anymore to fork. that's a hard no, bestie π
π NOTES π
ibv_fork_init()works on Linux kernels that support theMADV_DONTFORKflag formadvise()β that's 2.6.17 and higher β- setting the environment variable
RDMAV_FORK_SAFEorIBV_FORK_SAFEhas the exact same effect as callingibv_fork_init()π - setting the environment variable
RDMAV_HUGEPAGES_SAFEtells the library to check the underlying page size used by the kernel for memory regions. this is required if an application uses huge pages either directly or indirectly via a library such aslibhugetlbfsπ - calling
ibv_fork_init()will reduce performance β it adds an extra system call for every memory registration, plus additional memory allocated to track memory regions. the precise performance impact depends on the workload and usually will not be significant, so likeβ¦ breathe π§ - setting
RDMAV_HUGEPAGES_SAFEadds further overhead to all memory registrations. more safety, more cost, that's the vibe check π₯
ngl the tradeoff here is real: extra syscall per registration + extra tracking memory = a little slower, but way safer when forking is in the picture. read the room (and your workload) π
π SEE ALSO π
π AUTHOR π
Dotan Barak <dotanba@gmail.com> β icon, legend, the moment π«Ά
and that's the whole page, bestie!! π this one's from libibverbs, dated 2006-10-31, and it lives at IBV_FORK_INIT(3) β go forth and fork responsibly π¦βπ
π¦ where this page comes from
- alpine 3.24: rdma-core-doc 61.0-r0 Β· GPL-2.0-only OR BSD-2-Clause
- centos-stream 10: rdma-core-devel 62.0-3.el10 Β· GPLv2 or BSD
- centos-stream 9: rdma-core-devel 61.0-3.el9 Β· GPLv2 or BSD
- centos-stream 9: rdma-core-devel 61.0-3.el9 Β· GPLv2 or BSD
- ubuntu jammy: libibverbs-dev 39.0-1 Β· BSD-MIT OR GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms