xref: /dpdk/doc/guides/howto/virtio_user_for_container_networking.rst (revision 79238624c2b19bd71a20839ebf304e1eeb8dee9c)
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#. Write a Dockerfile like below.
60
61    .. code-block:: console
62
63	cat <<EOT >> Dockerfile
64	FROM ubuntu:latest
65	WORKDIR /usr/src/dpdk
66	COPY . /usr/src/dpdk
67	ENV PATH "$PATH:/usr/src/dpdk/<build_dir>/app/"
68	EOT
69
70#. Build a Docker image.
71
72    .. code-block:: console
73
74	docker build -t dpdk-app-testpmd .
75
76#. Start a testpmd on the host with a vhost-user port.
77
78    .. code-block:: console
79
80        $(testpmd) -l 0-1 -n 4 --socket-mem 1024,1024 \
81            --vdev 'eth_vhost0,iface=/tmp/sock0' \
82            --file-prefix=host --no-pci -- -i
83
84#. Start a container instance with a virtio-user port.
85
86    .. code-block:: console
87
88        docker run -i -t -v /tmp/sock0:/var/run/usvhost \
89            -v /dev/hugepages:/dev/hugepages \
90            dpdk-app-testpmd testpmd -l 6-7 -n 4 -m 1024 --no-pci \
91            --vdev=virtio_user0,path=/var/run/usvhost \
92            --file-prefix=container \
93            -- -i
94
95Note: If we run all above setup on the host, it's a shm-based IPC.
96
97Limitations
98-----------
99
100We have below limitations in this solution:
101 * Cannot work with --huge-unlink option. As we need to reopen the hugepage
102   file to share with vhost backend.
103 * Cannot work with --no-huge option. Currently, DPDK uses anonymous mapping
104   under this option which cannot be reopened to share with vhost backend.
105 * Cannot work when there are more than VHOST_MEMORY_MAX_NREGIONS(8) hugepages.
106   If you have more regions (especially when 2MB hugepages are used), the option,
107   --single-file-segments, can help to reduce the number of shared files.
108 * Applications should not use file name like HUGEFILE_FMT ("%smap_%d"). That
109   will bring confusion when sharing hugepage files with backend by name.
110 * Root privilege is a must. DPDK resolves physical addresses of hugepages
111   which seems not necessary, and some discussions are going on to remove this
112   restriction.
113