Container becomes more and more popular for strengths, like low overhead, fast boot-up time, and easy to deploy, etc. How to use DPDK to accelerate container networking becomes a common question for users. There are two use models of running DPDK inside containers, as shown in Figure.
Use models of running DPDK inside container
This page will only cover aggregation model.
The virtual device, virtio-user, with unmodified vhost-user backend, is designed for high performance user space container networking or inter-process communication (IPC).
The overview of accelerating container networking by virtio-user is shown in Figure.
Overview of accelerating container networking by virtio-user
Different virtio PCI devices we usually use as a para-virtualization I/O in the context of QEMU/VM, the basic idea here is to present a kind of virtual devices, which can be attached and initialized by DPDK. The device emulation layer by QEMU in VM’s context is saved by just registering a new kind of virtual device in DPDK’s ether layer. And to minimize the change, we reuse already-existing virtio PMD code (driver/net/virtio/).
Virtio, in essence, is a shm-based solution to transmit/receive packets. How is memory shared? In VM’s case, qemu always shares the whole physical layout of VM to vhost backend. But it’s not feasible for a container, as a process, to share all virtual memory regions to backend. So only those virtual memory regions (aka, hugepages initialized in DPDK) are sent to backend. It restricts that only addresses in these areas can be used to transmit or receive packets.
Here we use Docker as container engine. It also applies to LXC, Rocket with some minor changes.
Compile DPDK.
make install RTE_SDK=`pwd` T=x86_64-native-linuxapp-gcc
Write a Dockerfile like below.
cat <<EOT >> Dockerfile FROM ubuntu:latest WORKDIR /usr/src/dpdk COPY . /usr/src/dpdk ENV PATH "$PATH:/usr/src/dpdk/x86_64-native-linuxapp-gcc/app/" EOT
Build a Docker image.
docker build -t dpdk-app-testpmd .
Start a testpmd on the host with a vhost-user port.
$(testpmd) -l 0-1 -n 4 --socket-mem 1024,1024 \ --vdev 'eth_vhost0,iface=/tmp/sock0' \ --file-prefix=host --no-pci -- -i
Start a container instance with a virtio-user port.
docker run -i -t -v /tmp/sock0:/var/run/usvhost \ -v /dev/hugepages:/dev/hugepages \ dpdk-app-testpmd testpmd -l 6-7 -n 4 -m 1024 --no-pci \ --vdev=virtio_user0,path=/var/run/usvhost \ --file-prefix=container \ -- -i
Note: If we run all above setup on the host, it’s a shm-based IPC.