Monday, August 7, 2017

zero copy buffer

Zero-copy networking

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.

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.
-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.
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.
https://stackoverflow.com/questions/18343365/zero-copy-networking-vs-kernel-bypass
- 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.

Ref:
https://stackoverflow.com/questions/18343365/zero-copy-networking-vs-kernel-bypass -> best
http://www.linuxjournal.com/article/6345 -> detailed


What is DPDK( DATA plan developerment KIT)

DPDK is a set of libraries and drivers for fast packet processing.
It is designed to run on any processors. The first supported CPU was Intel x86 and it is now extended to IBM POWER and ARM.
It runs mostly in Linux userland. A FreeBSD port is available for a subset of DPDK features.

Usage

These libraries can be used to:
  • receive and send packets within the minimum number of CPU cycles (usually less than 80 cycles)
  • develop fast packet capture algorithms (tcpdump-like)
  • run third-party fast path stacks

Ref:http://dpdk.org/



No comments:

Post a Comment