From nobody Sat Feb 7 14:19:14 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602180648; cv=none; d=zohomail.com; s=zohoarc; b=JYRzKr1KwnZqsinm2WICOUhvBGpMxKzCrHYbgBO3EcMUzCUmdhEa9iWq0XQXvrjkHHnSwFrKx2EaChkk/PyGq3CFu/2k7Rfw+HG77PbICprhik4LTw4X4R3R6xP1dqoH3L14cq1YyqNhm/Ak9U5BqwD/K17Aw3VRSQMeZhJAadU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602180648; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=PFgUTZ228dHIBt3X/tMJFgOgAJ0mrxSUdayTcOBqwpw=; b=ZO8z5jYCVrK/oxYq9mCkxiT5TvAZyZqfjDEA5dmMa5B3S1SmAa3gwqcNeoWBqtZQNxI3uvNVs++G5MjTNShdEZ7hkTWHhBr98YkWDF1WxMDfyF3kHTZeezDnNdORoWsaeR0eiP2klrES0Rh5jct0vPjIrWdgJ30F/2Rnyqs3VE4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1602180648936945.8121176431289; Thu, 8 Oct 2020 11:10:48 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-309-Udem8UebMmm9yzp5P28KAg-1; Thu, 08 Oct 2020 14:10:44 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4BC8A191E2A3; Thu, 8 Oct 2020 18:10:38 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BE50660CD1; Thu, 8 Oct 2020 18:10:36 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 5CF948C7B8; Thu, 8 Oct 2020 18:10:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 098IAVPN007174 for ; Thu, 8 Oct 2020 14:10:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3B83238A; Thu, 8 Oct 2020 18:10:31 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.164]) by smtp.corp.redhat.com (Postfix) with ESMTP id B18D819C4F for ; Thu, 8 Oct 2020 18:10:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602180647; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=PFgUTZ228dHIBt3X/tMJFgOgAJ0mrxSUdayTcOBqwpw=; b=Od5TYL2pOoGINLdcc+HMGVWY6zDuklR2oZUO3qcspg1Bn4N6lqDBoJn0+V7qQhnkOgVsAl TrZ105WxOZHoyB9c4NAjAi0+JdZIutOcMzsgLWKQGfX3zavLm5k+5JQ2AfcPPwPNhBbcn0 YQy4o4bnS0Vzi8pZKqPls3lY2hs5ntA= X-MC-Unique: Udem8UebMmm9yzp5P28KAg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/2] virnetdev: Introduce virNetDevSetRootQDisc() Date: Thu, 8 Oct 2020 20:10:24 +0200 Message-Id: <7903a2924ce643c019520fbed22257bbe3dd8723.1602180558.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This helper changes the root qdisc on given interface. Ideally, it would be written using netlink but my attempts to write the code were not successful and thus I've fallen back to virCommand() + tc. Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza --- src/libvirt_private.syms | 1 + src/util/virnetdev.c | 46 ++++++++++++++++++++++++++++++++++++++++ src/util/virnetdev.h | 3 +++ 3 files changed, 50 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 7cf8bea962..0778bc6d5b 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2581,6 +2581,7 @@ virNetDevSetOnline; virNetDevSetPromiscuous; virNetDevSetRcvAllMulti; virNetDevSetRcvMulti; +virNetDevSetRootQDisc; virNetDevSetupControl; virNetDevSysfsFile; virNetDevValidateConfig; diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index e711a6dc8a..5c7660dab4 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -3394,3 +3394,49 @@ virNetDevRunEthernetScript(const char *ifname, const= char *script) =20 return virCommandRun(cmd, NULL); } + + +/** + * virNetDevSetRootQDisc: + * @ifname: the interface name + * @qdisc: queueing discipline to set + * + * For given interface @ifname set its root queueing discipline + * to @qdisc. This can be used to replace the default qdisc + * (usually pfifo_fast or whatever is set in + * /proc/sys/net/core/default_qdisc) with different qdisc. + * + * Returns: 0 on success, + * -1 if failed to exec tc (with error reported) + * -2 if tc failed (with no error reported) + */ +int +virNetDevSetRootQDisc(const char *ifname, + const char *qdisc) +{ + g_autoptr(virCommand) cmd =3D NULL; + g_autofree char *outbuf =3D NULL; + g_autofree char *errbuf =3D NULL; + int status; + + /* Ideally, we would have a netlink implementation and just + * call it here. But honestly, I tried and failed miserably. + * Fallback to spawning tc. */ + cmd =3D virCommandNewArgList(TC, "qdisc", "add", "dev", ifname, + "root", "handle", "0:", qdisc, + NULL); + + virCommandAddEnvString(cmd, "LC_ALL=3DC"); + virCommandSetOutputBuffer(cmd, &outbuf); + virCommandSetErrorBuffer(cmd, &errbuf); + + if (virCommandRun(cmd, &status) < 0) + return -1; + + if (status !=3D 0) { + VIR_DEBUG("Setting qdisc failed: output=3D'%s' err=3D'%s'", outbuf= , errbuf); + return -2; + } + + return 0; +} diff --git a/src/util/virnetdev.h b/src/util/virnetdev.h index 5f581323ed..82943b8e08 100644 --- a/src/util/virnetdev.h +++ b/src/util/virnetdev.h @@ -312,4 +312,7 @@ int virNetDevSysfsFile(char **pf_sysfs_device_link, int virNetDevRunEthernetScript(const char *ifname, const char *script) G_GNUC_NO_INLINE; =20 +int virNetDevSetRootQDisc(const char *ifname, + const char *qdisc); + G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNetDevRxFilter, virNetDevRxFilterFree); --=20 2.26.2 From nobody Sat Feb 7 14:19:14 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602180670; cv=none; d=zohomail.com; s=zohoarc; b=f4KgV34jrCsv++VjtZfqQOurFHsZfZF3hSqWH3eun+Zb27DPwuevn7YJmvJoMhqcqhhZZUxaG4Ldn4AqUkPLvooR37EAunlhV/VUSjPgAdOyARWrFOnchN26Yfl3OoXCYVgn23Aiq8HnRsZN0vSDX+evavKZBslBdtwU/VJPpro= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602180670; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=URszTDXijeeBoTMOfPQ0YbBb0zetinMUcaP+eIPVuz8=; b=dRlPVM/gOraTXlz6nR4lPtK1TKLLScIyjoRh/1H/FCGPF6sBEh7jHPTlpqU9tYaTIAqceR+SlgMlwmtbQlXpa14BnncBi8/dWhaNQgU6SHBm0GMEhJBnzjxb8hXzseR+49PF37Qvl4jCLW3XdWBJ3MyNSsO3DrWDxb1y+aUFgfA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 160218067036299.03612407423918; Thu, 8 Oct 2020 11:11:10 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-513-gdcDf9eoMKuFXQPFSSy6tQ-1; Thu, 08 Oct 2020 14:10:55 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C2DF8AFD00; Thu, 8 Oct 2020 18:10:49 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9F4EE100164C; Thu, 8 Oct 2020 18:10:49 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 3572F1832FC1; Thu, 8 Oct 2020 18:10:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 098IAW3D007182 for ; Thu, 8 Oct 2020 14:10:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id 18F8138A; Thu, 8 Oct 2020 18:10:32 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.164]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8EA1E19C4F for ; Thu, 8 Oct 2020 18:10:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602180669; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=URszTDXijeeBoTMOfPQ0YbBb0zetinMUcaP+eIPVuz8=; b=iTOrOBd4CkFUi2oIdbTtydMndPWrUMUVEQut8CGdiLKd+SlefJP4pyWf48V/AV9Zc5OpAQ RGIXVTeKYOpNaqs7gbWBrGf0GFIV02U7L5NWlGTMZteDpPInGSH4dkettJ9xs0FOxepzEX 6D9BRDggR6RlP9/gJLHZ6KmKnO+6EGU= X-MC-Unique: gdcDf9eoMKuFXQPFSSy6tQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/2] qemu: Set noqueue qdisc for TAP devices Date: Thu, 8 Oct 2020 20:10:25 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" By default, pfifo_fast queueing discipline (qdisc) is set on newly created interfaces (including TAPs). This qdisc has three queues and packets that want to be sent through given NIC are placed into one of the queues based on TOS field. Queues are then emptied based on their priority allowing interactive sessions stay interactive whilst something else is downloading a large file. Obviously, this means that kernel has to be involved and some locking has to happen (when placing packets into queues). If virtualization is taken into account then the above algorithm happens twice - once in the guest and the second time in the host. This is arguably not optimal as it burns host CPU cycles needlessly. Guest already made it choice and sent packets in the order it wants. To resolve this, Linux kernel offers 'noqueue' qdisc which can be applied on virtual interfaces and in fact for 'lo' it is by default: lo: mtu 65536 qdisc noqueue Set it for other TAP devices we create for domains too. With this change I was able to squeeze 1Mbps more from a macvtap attached to a guest and to my 1Gbps LAN (as measured by iperf3). Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1329644 Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza --- src/qemu/qemu_command.c | 2 ++ src/qemu/qemu_domain.c | 36 ++++++++++++++++++++++++++++++++++++ src/qemu/qemu_domain.h | 4 ++++ src/qemu/qemu_hotplug.c | 2 ++ 4 files changed, 44 insertions(+) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 9519861e92..eec860382c 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -8267,6 +8267,8 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver, } } =20 + qemuDomainInterfaceSetDefaultQDisc(driver, net); + if (net->mtu && virNetDevSetMTU(net->ifname, net->mtu) < 0) goto cleanup; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 9623123d3c..72da28666f 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11048,3 +11048,39 @@ qemuDomainFileWrapperFDClose(virDomainObjPtr vm, } return ret; } + + +/** + * qemuDomainInterfaceSetDefaultQDisc: + * @driver: QEMU driver + * @net: domain interface + * + * Set the noqueue qdisc on @net if running as privileged. The + * noqueue qdisc is a lockless transmit and thus faster than the + * default pfifo_fast (at least in theory). But we can modify + * root qdisc only if we have CAP_NET_ADMIN. + * + * Returns: 0 on success, + * -1 otherwise. + */ +int +qemuDomainInterfaceSetDefaultQDisc(virQEMUDriverPtr driver, + virDomainNetDefPtr net) +{ + virDomainNetType actualType =3D virDomainNetGetActualType(net); + + if (!driver->privileged || !net->ifname) + return 0; + + /* We want only those types which are represented as TAP + * devices in the host. */ + if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_ETHERNET || + actualType =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK || + actualType =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE || + actualType =3D=3D VIR_DOMAIN_NET_TYPE_DIRECT) { + if (virNetDevSetRootQDisc(net->ifname, "noqueue") < 0) + return -1; + } + + return 0; +} diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 9bf32e16c9..91b3b67cb6 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -1046,3 +1046,7 @@ qemuDomainOpenFile(virQEMUDriverPtr driver, int qemuDomainFileWrapperFDClose(virDomainObjPtr vm, virFileWrapperFdPtr fd); + +int +qemuDomainInterfaceSetDefaultQDisc(virQEMUDriverPtr driver, + virDomainNetDefPtr net); diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 7a54fcb221..2c184b9ba0 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1368,6 +1368,8 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver, virNetDevSetMTU(net->ifname, net->mtu) < 0) goto cleanup; =20 + qemuDomainInterfaceSetDefaultQDisc(driver, net); + for (i =3D 0; i < tapfdSize; i++) { if (qemuSecuritySetTapFDLabel(driver->securityManager, vm->def, tapfd[i]) < 0) --=20 2.26.2