我想实现 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_xdp
的 XDP_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:
- create socket 0 and register the umem to this.
- mmap the fr/cr using socket 0
- 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/