Home » Linux » “zero copy networking” vs “kernel bypass”?

“zero copy networking” vs “kernel bypass”?

Posted by: admin November 30, 2017 Leave a comment

Questions:

What is the difference between “zero-copy networking” and “kernel bypass”? Are they two phrases meaning the same thing, or different? Is kernel bypass a technique used within “zero copy networking” and this is the relationship?

Answers:

What is the difference between “zero-copy networking” and “kernel bypass”? Are they two phrases meaning the same thing, or different? Is kernel bypass a technique used within “zero copy networking” and this is the relationship?

TL;DR – They are different concepts, but it is quite likely that zero copy is supported within kernel bypass API/framework.


User Bypass

This mode of communicating should also be considered. It maybe possible for DMA-to-DMA transactions which do not involve the CPU at all. The idea is to use splice() or similar functions to avoid user space at all. Note, that with splice(), the entire data stream does not need to bypass user space. Headers can be read in user space and data streamed directly to disk. The most common downfall of this is splice() doesn’t do checksum offloading.

Zero copy

The zero copy concept is only that the network buffers are fixed in place and are not moved around. In many cases, this is not really beneficial. Most modern network hardware supports scatter gather, also know as buffer descriptors, etc. The idea is the network hardware understands physical pointers. The buffer descriptor typically consists of,

  1. Data pointer
  2. Length
  3. Next buffer descriptor

The benefit is that the network headers do not need to exist side-by-side and IP, TCP, and Application headers can reside physically seperate from the application data.

If a controller doesn’t support this, then the TCP/IP headers must precede the user data so that they can be filled in before sending to the network controller.

zero copy also implies some kernel-user MMU setup so that pages are shared.

Kernel Bypass

Of course, you can bypass the kernel. This is what pcap and other sniffer software has been doing for some time. However, it is difficult to see a case where user space will have a definite win unless it is tied to the particular hardware. Some network controllers may have scatter gather supported in the controller and others may not.

There are various incarnation of kernel interfaces to accomplish kernel by-pass.


To put this together…

Are they two phrases meaning the same thing, or different?

They are different as above hopefully explains.

Is kernel bypass a technique used within “zero copy networking” and this is the relationship?

It is the opposite. Kernel bypass can use zero copy and most likely will support it as the buffers are completely under control of the application. Also, there is no memory sharing between the kernel and user space (meaning no need for MMU shared pages and whatever cache/TLB effects that may cause). So if you are using kernel bypass, it will often be advantageous to support zero copy; so the things may seem the same at first.

If scatter-gather DMA is available (most modern controllers) either user space or the kernel can use it. zero copy is not as useful in this case.

Reference:

Questions:
Answers:

Zero-copy networking

You’re doing zero-copy networking when you never copy the data between the user-space and the kernel-space (I mean memory space). By example:

C language
recv(fd, buffer, BUFFER_SIZE, 0);

By default the data are copied:

  1. The kernel gets the data from the network stack
  2. The kernel copies this data to the buffer, which is in the user-space.

With zero-copy method, the data are not copied and come to the user-space directly from the network stack.

Kernel Bypass

The kernel bypass is when you manage yourself, in the user-space, the network stack and hardware stuff. It is hard, but you will gain a lot of performance (there is zero copy, since all the data are in the user-space). This link could be interesting if you want more information.

Questions:
Answers:

Other examples of kernel bypass and zero copy are DPDK and RDMA. When an application uses DPDK it is bypassing the kernel TCP/IP stack. The application is creating the Ethernet frames and the NIC grabbing those frames with DMA directly from user space memory so it’s zero copy because there is no copy from user space to kernel space. Applications can do similar things with RDMA. The application writes to queue pairs that the NIC directly access and transmits. RDMA iblibverbs is used inside the kernel as well so when iSER is using RDMA it’s not Kernel bypass but it is zero copy.

http://dpdk.org/

https://www.openfabrics.org/index.php/openfabrics-software.html

Questions:
Answers:

ZERO-COPY:

When transmitting and receiving packets,
all packet data must be copied from user-space buffers to kernel-space buffers for transmitting and vice versa for receiving. A zero-copy driver avoids this by having user space and the driver share packet buffer memory directly.

Instead of having the transmit and receive point to buffers in kernel space which will later require to copy, a region of memory in user space is allocated, and mapped to a given region of physical memory, to be shared memory between the kernel buffers and the user-space buffers, then point each descriptor buffer to its corresponding place in the newly allocated memory.