Skip to content

Commit

Permalink
Enable the vhost backend for the virtio-net interfaces in the KVM hyp…
Browse files Browse the repository at this point in the history
…ervisor

Using vhost as the backend for virtio-net in a QEMU/KVM setup bypasses QEMU's
user-space network packet processing by moving packet handling directly into
the Linux kernel. Normally, QEMU would process network I/O in user space,
which incurs significant CPU overhead and latency due to frequent context
switching between user space (QEMU) and kernel space. With vhost, packet
processing is handled by a dedicated kernel thread, avoiding QEMU for most
networking tasks. This direct kernel handling minimizes the need for QEMU’s
intervention, resulting in lower latency, higher throughput, and better
CPU efficiency for network-intensive applications running on virtual machines.

Using vhost is a clear choice with no downsides, as it is already included
in eve-kernel and does not increase the EVE image size. Reducing QEMU overhead
is especially important for EVE, where we enforce cgroup CPU quotas to limit
an application to using no more than N CPUs at a time, with N being the number
of vCPUs assigned to the app in its configuration (see pkg/pillar/containerd/oci.go,
method UpdateFromDomain()). These CPU quotas apply to both the application and
QEMU itself, so removing QEMU from packet processing is essential to prevent
it from consuming CPU cycles needed by the application.

Signed-off-by: Milan Lenco <milan@zededa.com>
  • Loading branch information
milan-zededa authored and OhmSpectator committed Nov 17, 2024
1 parent 905baf7 commit 2db86b8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/pillar/hypervisor/kvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,9 @@ const qemuNetTemplate = `
br = "{{.Bridge}}"
script = "/etc/xen/scripts/qemu-ifup"
downscript = "no"
{{- if eq .Driver "virtio-net-pci" }}
vhost = "on"
{{- end}}
[device "net{{.NetID}}"]
driver = "{{.Driver}}"
Expand Down
14 changes: 14 additions & 0 deletions pkg/pillar/hypervisor/kvm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ func TestCreateDomConfigOnlyCom1(t *testing.T) {
br = "bn0"
script = "/etc/xen/scripts/qemu-ifup"
downscript = "no"
vhost = "on"
[device "net0"]
driver = "virtio-net-pci"
Expand All @@ -346,6 +347,7 @@ func TestCreateDomConfigOnlyCom1(t *testing.T) {
br = "bn0"
script = "/etc/xen/scripts/qemu-ifup"
downscript = "no"
vhost = "on"
[device "net1"]
driver = "virtio-net-pci"
Expand Down Expand Up @@ -610,6 +612,7 @@ func TestCreateDomConfigOnlyCom1(t *testing.T) {
br = "bn0"
script = "/etc/xen/scripts/qemu-ifup"
downscript = "no"
vhost = "on"
[device "net0"]
driver = "virtio-net-pci"
Expand All @@ -632,6 +635,7 @@ func TestCreateDomConfigOnlyCom1(t *testing.T) {
br = "bn0"
script = "/etc/xen/scripts/qemu-ifup"
downscript = "no"
vhost = "on"
[device "net1"]
driver = "virtio-net-pci"
Expand Down Expand Up @@ -863,6 +867,7 @@ func TestCreateDomConfigOnlyCom1(t *testing.T) {
br = "bn0"
script = "/etc/xen/scripts/qemu-ifup"
downscript = "no"
vhost = "on"
[device "net0"]
driver = "virtio-net-pci"
Expand All @@ -885,6 +890,7 @@ func TestCreateDomConfigOnlyCom1(t *testing.T) {
br = "bn0"
script = "/etc/xen/scripts/qemu-ifup"
downscript = "no"
vhost = "on"
[device "net1"]
driver = "virtio-net-pci"
Expand Down Expand Up @@ -1352,6 +1358,7 @@ func domConfigArm64() string {
br = "bn0"
script = "/etc/xen/scripts/qemu-ifup"
downscript = "no"
vhost = "on"
[device "net0"]
driver = "virtio-net-pci"
Expand All @@ -1374,6 +1381,7 @@ func domConfigArm64() string {
br = "bn0"
script = "/etc/xen/scripts/qemu-ifup"
downscript = "no"
vhost = "on"
[device "net1"]
driver = "virtio-net-pci"
Expand Down Expand Up @@ -1649,6 +1657,7 @@ func domConfigAmd64FML() string {
br = "bn0"
script = "/etc/xen/scripts/qemu-ifup"
downscript = "no"
vhost = "on"
[device "net0"]
driver = "virtio-net-pci"
Expand All @@ -1671,6 +1680,7 @@ func domConfigAmd64FML() string {
br = "bn0"
script = "/etc/xen/scripts/qemu-ifup"
downscript = "no"
vhost = "on"
[device "net1"]
driver = "virtio-net-pci"
Expand Down Expand Up @@ -2234,6 +2244,7 @@ func domConfigAmd64() string {
br = "bn0"
script = "/etc/xen/scripts/qemu-ifup"
downscript = "no"
vhost = "on"
[device "net0"]
driver = "virtio-net-pci"
Expand All @@ -2256,6 +2267,7 @@ func domConfigAmd64() string {
br = "bn0"
script = "/etc/xen/scripts/qemu-ifup"
downscript = "no"
vhost = "on"
[device "net1"]
driver = "virtio-net-pci"
Expand Down Expand Up @@ -2520,6 +2532,7 @@ func domConfigContainerVNC() string {
br = "bn0"
script = "/etc/xen/scripts/qemu-ifup"
downscript = "no"
vhost = "on"
[device "net0"]
driver = "virtio-net-pci"
Expand All @@ -2542,6 +2555,7 @@ func domConfigContainerVNC() string {
br = "bn0"
script = "/etc/xen/scripts/qemu-ifup"
downscript = "no"
vhost = "on"
[device "net1"]
driver = "virtio-net-pci"
Expand Down

0 comments on commit 2db86b8

Please sign in to comment.