Off-XDF:实现共享母套接字

AF-XDP: Implement Shared Umem sockets

我要实施XDP_SHARED_UMEM:https://www.kernel.org/doc/html/latest/networking/af_xdp.html#xdp-shared-umem-bind-flag

libbpf 库函数 xsk_socket__create (https://github.com/libbpf/libbpf/blob/master/src/xsk.c) 检查 xsk_umem->refcount 值。如果它大于 1,则设置 struct sockaddr_xdpXDP_SHARED_UMEM 选项。

据我理解正确,我 "just" 需要传递我想与之共享 umem 的套接字的原始 umem 结构,其余由 libbpf 完成。

我尝试这样做的方法是让第一个进程将其 umem-struct 复制到共享内存区域,第二个进程可以从中加载它。但是因为 struct xsk_umem 是在 xsk.c 中定义的,所以它对用户是隐藏的,我不能做这样的事情:

memcpy(shdm_ptr, umem, sizeof(struct xsk_umem))

我不知道他们如何期望有人使用共享 umem 功能?

on the xdp-newbies 邮件列表对此进行了讨论。在此举报备案。

不建议您尝试使用多进程设置。比约恩说:

Note that if you'd like to do a multi-process setup with shared umem, you: need to have a control process that manages the fill/completion rings, and synchronize between the processes, OR re-mmap the fill/completetion ring from the socket owning the umem in multiple processes and synchronize the access to them. Neither is pleasant.

Honestly, not a setup I'd recommend.

他补充道:

Just for completeness; To setup shared umem:

  1. create socket 0 and register the umem to this.
  2. mmap the fr/cr using socket 0
  3. create socket 1, 2, n and refer to socket 0 for the umem.

So, in a multiprocess solution step 3 would be done in separate processes, and step 2 depending on your application. You'd need to pass socket 0 to the other processes and share the umem memory from the process where socket 0 was created. This is pretty much a threaded solution, given all the shared state.

I advice not taking this path.

(致谢 Björn。)