c - AF-XDP : Implement Shared Umem sockets

标签 c linux xdp-bpf

我想实现 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 选项。

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

我尝试的方法是让第一个进程将其 umem 结构复制到第二个进程可以从中加载它的共享内存区域。但由于 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。)

关于c - AF-XDP : Implement Shared Umem sockets,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60615240/

相关文章:

c - 尝试从 TLS 数据包中提取 SNI 时出现 BPF 验证错误

cpu - 测试 XDP 与 DPDK

linux-kernel - xdp如何判断流量方向?

c - 如何在 C 中找到二叉树的最深 UNIQUE 节点

linux - 如何将匹配的文件移动到另一个目录?

c - 拒绝指针的数组大小的宏

python - C 语言的 subprocess.popen (python)

linux - 无法通过curl到Jboss服务器8080端口通过IPv6地址访问

c - qsort死循环导致错误C

c - 使用 geany 制作/构建