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 <[email protected]>
  • Loading branch information
milan-zededa committed Nov 15, 2024
1 parent 905baf7 commit 697087c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/pillar/hypervisor/kvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ const qemuNetTemplate = `
br = "{{.Bridge}}"
script = "/etc/xen/scripts/qemu-ifup"
downscript = "no"
vhost = "on"
[device "net{{.NetID}}"]
driver = "{{.Driver}}"
Expand Down
16 changes: 16 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 @@ -1950,6 +1960,7 @@ func domConfigAmd64Legacy() string {
br = "bn0"
script = "/etc/xen/scripts/qemu-ifup"
downscript = "no"
vhost = "on"
[device "net0"]
driver = "e1000"
Expand All @@ -1972,6 +1983,7 @@ func domConfigAmd64Legacy() string {
br = "bn0"
script = "/etc/xen/scripts/qemu-ifup"
downscript = "no"
vhost = "on"
[device "net1"]
driver = "e1000"
Expand Down Expand Up @@ -2234,6 +2246,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 +2269,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 +2534,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 +2557,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 697087c

Please sign in to comment.