New upstream version 18.11-rc1
[deb_dpdk.git] / doc / guides / howto / virtio_user_for_container_networking.rst
1 ..  SPDX-License-Identifier: BSD-3-Clause
2     Copyright(c) 2016 Intel Corporation.
3
4 .. _virtio_user_for_container_networking:
5
6 Virtio_user for Container Networking
7 ====================================
8
9 Container becomes more and more popular for strengths, like low overhead, fast
10 boot-up time, and easy to deploy, etc. How to use DPDK to accelerate container
11 networking becomes a common question for users. There are two use models of
12 running 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
21 This page will only cover aggregation model.
22
23 Overview
24 --------
25
26 The virtual device, virtio-user, with unmodified vhost-user backend, is designed
27 for high performance user space container networking or inter-process
28 communication (IPC).
29
30 The overview of accelerating container networking by virtio-user is shown
31 in :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
39 Different virtio PCI devices we usually use as a para-virtualization I/O in the
40 context of QEMU/VM, the basic idea here is to present a kind of virtual devices,
41 which can be attached and initialized by DPDK. The device emulation layer by
42 QEMU in VM's context is saved by just registering a new kind of virtual device
43 in DPDK's ether layer. And to minimize the change, we reuse already-existing
44 virtio PMD code (driver/net/virtio/).
45
46 Virtio, in essence, is a shm-based solution to transmit/receive packets. How is
47 memory shared? In VM's case, qemu always shares the whole physical layout of VM
48 to vhost backend. But it's not feasible for a container, as a process, to share
49 all 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
51 addresses in these areas can be used to transmit or receive packets.
52
53 Sample Usage
54 ------------
55
56 Here we use Docker as container engine. It also applies to LXC, Rocket with
57 some 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
101 Note: If we run all above setup on the host, it's a shm-based IPC.
102
103 Limitations
104 -----------
105
106 We 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.