为什么 Linux 内核中没有零拷贝网络? [英] Why no zero-copy networking in linux kernel?

查看:21
本文介绍了为什么 Linux 内核中没有零拷贝网络?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道为什么Linux内核(或任何其他主流操作系统)没有零拷贝网络功能的原因?零拷贝是指,数据包/数据流不会被复制以传递给用户空间中的应用程序,但例如使用内存池类型的分配器在内核和用户空间之间共享内存.我自己提出了 3 个理论:

I'd like to know the reasons for why the linux kernel (or any other mainstream OS) does not have a feature for zero copy networking ? By zero copy I mean, that an packet/datastream does not get copied for passing to an application in userspace but e.g. uses a memory-pool type of allocator to share the memory between kernel and userspace. I've came up with 3 theory's on my own:

a) 我想存在安全问题.但是当它们只是用作缓冲区时,真的没有办法在用户空间和内核之间安全地共享内存吗?

a) I guess there are security concerns. But is there really no way of making memory shared securily between userspace and kernel when they are just used as a buffer ?

b) 我想存在稳定性问题.但是我们不能假设谁使用零拷贝网络,例如需要为内核调用实例化并传递内存池是否知道内存管理?足够了解以避免泄漏?

b) I guess there are stability concerns. But can't we assume that whoever uses zero-copy networking and e.g. needs to instanciate and pass a memory-pool for the kernel call is aware of memory management? Aware enough to avoid leaks ?

c) 到目前为止还没有完成/不需要.我真的无法想象没有人要求此功能,因为使用小数据包大小的每个人通常都会受到慢" TCP 堆栈实现的瓶颈,并且有 3rd 方工具提供 0-copy 网络以用于特殊用途网卡.

c) It just haven't been done/needed so far. I can't really imagine that nobody requested this feature, as everybody who is using small packet sizes is typically bottlenecked by the "slow" TCP-stack implementation and there are 3rd party tools out there offered for 0-copy networking for usage with special network cards.

随意发表任何猜测,但请注明您是否假设或更深入地了解保持 StackOverflow 质量的原因:-)

Feel free to post any guesses, but please mark whether you are assuming or have a deeper knowledge of the reasons to keep StackOverflow-quality :-)

推荐答案

现在零拷贝网络有几种选择:

There are a few options nowadays for zero-copy networking:

  • PF_RING ZC (Zero Copy).
  • Linux native zero-copy TCP.
  • Intel Data Plane Development Kit.
  • OpenOnload for proprietary hardware.

请注意,使用 TCP 进行零复制可能不方便,因为 TCP 段携带标头和有效负载,但应用程序只关心有效负载,因此必须将有效负载而不是标头复制到应用程序的连续缓冲区中.

Note, that zero-copy with TCP may be inconvenient, because TCP segments carry headers and payload, but applications are only concerned with payload, so that payload but not headers must be copied into a contiguous buffer for your application.

这篇关于为什么 Linux 内核中没有零拷贝网络?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆