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?


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, pcap does not prevent the normal kernel processing; but the concept is similar to what a kernel bypass framework would allow. Ie, directly deliver packets to user space where processing headers would happen.

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. A difficulty is what happens with the received data and producing the data for transmission. Often this involve other devices and so there are many solutions.


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:

  • Technical reference on OnLoad, a high band width kernel by-pass system.
  • PF Ring as of 2.6.32, if configured
  • Linux kernel network buffer management by David Miller. This gives an idea of how the protocols headers/trailers are managed in the kernel.

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.