gpt4 book ai didi

linux - 避免在用户空间和内核空间之间复制数据,反之亦然

转载 作者:太空狗 更新时间:2023-10-29 11:11:29 26 4
gpt4 key购买 nike

我正在开发一种用于并行计算的主动消息传递协议(protocol)来替代 TCP/IP。我的目标是减少数据包的延迟。由于环境是 LAN,我可以用更简单的协议(protocol)替换 TCP/IP 以减少数据包延迟。我没有编写任何设备驱动程序,我只是想用更简单的东西替换 TCP/IP 堆栈。现在我想避免将数据包的数据从用户空间复制到内核空间,反之亦然。我听说过 mmap()。这是最好的方法吗?如果是,如果您可以提供一些示例的链接,那就太好了。我是 Linux 新手,非常感谢您的帮助。谢谢...

谢谢,巴拉

最佳答案

你应该使用 UDP,它已经相当快了。至少它的速度足以让 W32/SQLSlammer 在整个互联网上传播。

关于您最初的问题,请参阅 (vm)splicetee Linux 系统调用。

来自手册页:

The three system calls splice(2), vmsplice(2), and tee(2)), provide userspace programs with full control over an arbitrary kernel buffer, implemented within the kernel using the same type of buffer that is used for a pipe. In overview, these system calls perform the following tasks:

splice(2)

  moves data from the buffer to an arbitrary file descriptor, or vice

versa, or from one buffer to another.

tee(2)

  "copies" the data from one buffer to another.

vmsplice(2)

  "copies" data from user space into the buffer.

Though we talk of copying, actual copies are generally avoided. The kernel does this by implementing a pipe buffer as a set of reference-counted pointers to pages of kernel memory. The kernel creates "copies" of pages in a buffer by creating new pointers (for the output buffer) referring to the pages, and increasing the reference counts for the pages: only pointers are copied, not the pages of the buffer.

关于linux - 避免在用户空间和内核空间之间复制数据,反之亦然,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2761156/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com