aboutsummaryrefslogtreecommitdiffstats
path: root/doc/guides/howto/virtio_user_for_container_networking.rst
blob: 476ce3a63c6016d8a127ca159bc8cafc8989d867 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
..  SPDX-License-Identifier: BSD-3-Clause
    Copyright(c) 2016 Intel Corporation.

.. _virtio_user_for_container_networking:

Virtio_user for Container Networking
====================================

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
:numref:`figure_use_models_for_running_dpdk_in_containers`.

.. _figure_use_models_for_running_dpdk_in_containers:

.. figure:: img/use_models_for_running_dpdk_in_containers.*

   Use models of running DPDK inside container

This page will only cover aggregation model.

Overview
--------

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 :numref:`figure_virtio_user_for_container_networking`.

.. _figure_virtio_user_for_container_networking:

.. figure:: img/virtio_user_for_container_networking.*

   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.

Sample Usage
------------

Here we use Docker as container engine. It also applies to LXC, Rocket with
some minor changes.

#. Compile DPDK.

    .. code-block:: console

        make install RTE_SDK=`pwd` T=x86_64-native-linuxapp-gcc

#. Write a Dockerfile like below.

    .. code-block:: console

	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.

    .. code-block:: console

	docker build -t dpdk-app-testpmd .

#. Start a testpmd on the host with a vhost-user port.

    .. code-block:: console

        $(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.

    .. code-block:: console

        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 --txqflags=0xf00 --disable-hw-vlan

Note: If we run all above setup on the host, it's a shm-based IPC.

Limitations
-----------

We have below limitations in this solution:
 * Cannot work with --huge-unlink option. As we need to reopen the hugepage
   file to share with vhost backend.
 * Cannot work with --no-huge option. Currently, DPDK uses anonymous mapping
   under this option which cannot be reopened to share with vhost backend.
 * Cannot work when there are more than VHOST_MEMORY_MAX_NREGIONS(8) hugepages.
   If you have more regions (especially when 2MB hugepages are used), the option,
   --single-file-segments, can help to reduce the number of shared files.
 * Applications should not use file name like HUGEFILE_FMT ("%smap_%d"). That
   will bring confusion when sharing hugepage files with backend by name.
 * Root privilege is a must. DPDK resolves physical addresses of hugepages
   which seems not necessary, and some discussions are going on to remove this
   restriction.