xref: /dpdk/doc/guides/howto/virtio_user_for_container_networking.rst (revision 25d11a86c56d50947af33d0b79ede622809bd8b9)
1..  SPDX-License-Identifier: BSD-3-Clause
2    Copyright(c) 2016 Intel Corporation.
3
4.. _virtio_user_for_container_networking:
5
6Virtio_user for Container Networking
7====================================
8
9Container becomes more and more popular for strengths, like low overhead, fast
10boot-up time, and easy to deploy, etc. How to use DPDK to accelerate container
11networking becomes a common question for users. There are two use models of
12running DPDK inside containers, as shown in
13:numref:`figure_use_models_for_running_dpdk_in_containers`.
14
15.. _figure_use_models_for_running_dpdk_in_containers:
16
17.. figure:: img/use_models_for_running_dpdk_in_containers.*
18
19   Use models of running DPDK inside container
20
21This page will only cover aggregation model.
22
23Overview
24--------
25
26The virtual device, virtio-user, with unmodified vhost-user backend, is designed
27for high performance user space container networking or inter-process
28communication (IPC).
29
30The overview of accelerating container networking by virtio-user is shown
31in :numref:`figure_virtio_user_for_container_networking`.
32
33.. _figure_virtio_user_for_container_networking:
34
35.. figure:: img/virtio_user_for_container_networking.*
36
37   Overview of accelerating container networking by virtio-user
38
39Different virtio PCI devices we usually use as a para-virtualization I/O in the
40context of QEMU/VM, the basic idea here is to present a kind of virtual devices,
41which can be attached and initialized by DPDK. The device emulation layer by
42QEMU in VM's context is saved by just registering a new kind of virtual device
43in DPDK's ether layer. And to minimize the change, we reuse already-existing
44virtio PMD code (driver/net/virtio/).
45
46Virtio, in essence, is a shm-based solution to transmit/receive packets. How is
47memory shared? In VM's case, qemu always shares the whole physical layout of VM
48to vhost backend. But it's not feasible for a container, as a process, to share
49all virtual memory regions to backend. So only those virtual memory regions
50(aka, hugepages initialized in DPDK) are sent to backend. It restricts that only
51addresses in these areas can be used to transmit or receive packets.
52
53Sample Usage
54------------
55
56Here we use Docker as container engine. It also applies to LXC, Rocket with
57some minor changes.
58
59#. Compile DPDK.
60
61    .. code-block:: console
62
63        make install RTE_SDK=`pwd` T=x86_64-native-linuxapp-gcc
64
65#. Write a Dockerfile like below.
66
67    .. code-block:: console
68
69	cat <<EOT >> Dockerfile
70	FROM ubuntu:latest
71	WORKDIR /usr/src/dpdk
72	COPY . /usr/src/dpdk
73	ENV PATH "$PATH:/usr/src/dpdk/x86_64-native-linuxapp-gcc/app/"
74	EOT
75
76#. Build a Docker image.
77
78    .. code-block:: console
79
80	docker build -t dpdk-app-testpmd .
81
82#. Start a testpmd on the host with a vhost-user port.
83
84    .. code-block:: console
85
86        $(testpmd) -l 0-1 -n 4 --socket-mem 1024,1024 \
87            --vdev 'eth_vhost0,iface=/tmp/sock0' \
88            --file-prefix=host --no-pci -- -i
89
90#. Start a container instance with a virtio-user port.
91
92    .. code-block:: console
93
94        docker run -i -t -v /tmp/sock0:/var/run/usvhost \
95            -v /dev/hugepages:/dev/hugepages \
96            dpdk-app-testpmd testpmd -l 6-7 -n 4 -m 1024 --no-pci \
97            --vdev=virtio_user0,path=/var/run/usvhost \
98            --file-prefix=container \
99            -- -i
100
101Note: If we run all above setup on the host, it's a shm-based IPC.
102
103Limitations
104-----------
105
106We have below limitations in this solution:
107 * Cannot work with --huge-unlink option. As we need to reopen the hugepage
108   file to share with vhost backend.
109 * Cannot work with --no-huge option. Currently, DPDK uses anonymous mapping
110   under this option which cannot be reopened to share with vhost backend.
111 * Cannot work when there are more than VHOST_MEMORY_MAX_NREGIONS(8) hugepages.
112   If you have more regions (especially when 2MB hugepages are used), the option,
113   --single-file-segments, can help to reduce the number of shared files.
114 * Applications should not use file name like HUGEFILE_FMT ("%smap_%d"). That
115   will bring confusion when sharing hugepage files with backend by name.
116 * Root privilege is a must. DPDK resolves physical addresses of hugepages
117   which seems not necessary, and some discussions are going on to remove this
118   restriction.
119