Article View: linux.kernel.netdev
Article #14105Re: [PATCH net-next v3 2/3] net/sched: fq, fq_codel, fq_pie: skip empty rounds in the deficit-refill dequeue loop
From: Eric Dumazet
Date: Tue, 10 Nov 2026 18:25
Date: Tue, 10 Nov 2026 18:25
166 lines
15521 bytes
15521 bytes
Le mar. 10 nov. 2026 ร 15:30, Victor Nogueira <victor@mojatatu.com> a รฉcrit :
>
> The issue: fq, fq_codel and fq_pie refill the head flow one quantum per
> iteration until it has credit. With a size table that inflates the packet
> length to 1 MiB and a quantum of 256 that is ~4096 iterations per packet,
> so a dequeue over N flows can spin N * 4096 times under the qdisc lock
> with BH disabled.
I am quite worried by the complexity this series adds to six dequeue paths,
for a problem that needs a pretty unusual size table to show up.
I do not think the round tracking (first/scanned) is needed.
As long as no flow can be served, a round gives one quantum to every flow
and leaves the list in the same order. So the number of rounds needed
before the first flow can be served can be computed from the current head,
at any time, and added to all flows in one pass. There is no need to know
where the round started, nor to fix up 'first' in the throttle, drop and
detach paths.
Empty flows do not need to be removed in the bulk pass either: give them
the credit they would have had when detached, and let the normal path
detach them on their next visit. For fq_codel, this also keeps the reset
of the CoDel vars done by codel_dequeue(), which was one of the v2 issues.
To bound the cost of the scans, a dequeue-local refill counter is enough:
scan after a few refills, then allow the next scan only after as many
refills as flows scanned. The scan stops at the first flow with credit,
so normal setups only look at a couple of flows.
Something like the following for fq. It adds a helper and a few lines
where the head flow is refilled, and does not touch the other paths.
All flows share the same quantum, so the scan needs a single divide,
plus one per empty flow about to be detached.
With a setup close to yours (8192 flows, stab overhead 1MB, quantum 256,
fq under tbf), the longest fq_dequeue() goes from 8.4 ms to 19 us, and
the total time spent in fq_dequeue() during the drain goes from 138 ms
to 3.4 ms. The dequeue order captured with tcpdump on four mixed loads
is the same before and after.
The same helper shape should work for fq_codel, fq_pie, drr and sfq.
For DRR, a class whose child returns NULL from peek() can simply abort
the scan, as the main loop already handles that case.
ETS has at most 16 bands, I would leave it alone.
Also please, one patch per qdisc.
diff --git a/net/sched/sch_fq.c b/net/sched/sch_fq.c
index a282812c192eedea36320c21df2fdde793880b14..d0515ab14956af0b6a63d896b7cf659fbb77cf1d
100644
--- a/net/sched/sch_fq.c
+++ b/net/sched/sch_fq.c
@@ -732,11 +732,82 @@ static struct fq_flow_head
*fq_pband_head_select(struct fq_perband_flows *pband)
return pband->old_flows.first ? &pband->old_flows : NULL;
}
+/* Called from fq_dequeue() when the first flow of pband->old_flows has
+ * no credit, and new_flows is empty.
+ *
+ * As long as no flow can be served, each round gives one quantum to every
+ * flow and leaves old_flows in the same order. When packets are much bigger
+ * than the quantum (for example inflated by a size table), thousands of such
+ * rounds can be needed. Add them all at once.
+ *
+ * An empty flow gets the credit it would have had when detached by the
+ * one-quantum loop. It stays in the list and is detached on its next visit.
+ *
+ * Returns true if credits were changed, and the number of flows looked at
+ * in *scanned.
+ */
+static bool fq_skip_rounds(const struct fq_sched_data *q,
+ const struct fq_perband_flows *pband,
+ unsigned int *scanned)
+{
+ u32 add = U32_MAX, quantum = q->quantum;
+ int max_credit = INT_MIN;
+ unsigned int n = 0;
+ bool changed = false;
+ struct fq_flow *f;
+
+ for (f = pband->old_flows.first; f; f = f->next) {
+ n++;
+ /* fq_flow_add_tail() would move f to another band. */
+ if (f->band != q->band_nr)
+ goto out;
+ if (!f->qlen)
+ continue;
+ if (f->credit > 0)
+ goto out;
+ max_credit = max(max_credit, f->credit);
+ }
+
+ /* All flows have the same quantum: the non-empty flow with the
+ * highest credit is the first one to get credit.
+ */
+ if (max_credit != INT_MIN)
+ add = DIV_ROUND_UP(1U - (u32)max_credit, quantum) * quantum;
+
+ for (f = pband->old_flows.first; f; f = f->next) {
+ int credit = f->credit;
+
+ if (!f->qlen) {
+ if (credit > 0)
+ continue;
+ /* Only flows to be detached need a divide. */
+ if (add > (u32)-credit) {
+ f->credit = credit + DIV_ROUND_UP(1U -
(u32)credit,
+
quantum) * quantum;
+ changed = true;
+ continue;
+ }
+ }
+ f->credit = credit + add;
+ changed = true;
+ }
+out:
+ *scanned = n;
+ return changed;
+}
+
+/* Number of one-quantum refills in fq_dequeue() before fq_skip_rounds()
+ * is tried.
+ */
+#define FQ_SKIP_ROUNDS_THRESH 8
+
static struct sk_buff *fq_dequeue(struct Qdisc *sch)
{
struct fq_sched_data *q = qdisc_priv(sch);
u64 offload_horizon = fq_offload_horizon(sch, q);
+ unsigned int next_skip = FQ_SKIP_ROUNDS_THRESH;
struct fq_perband_flows *pband;
+ unsigned int refills = 0;
struct fq_flow_head *head;
u64 time_next_packet = 0;
struct sk_buff *skb;
@@ -782,6 +853,16 @@ static struct sk_buff *fq_dequeue(struct Qdisc *sch)
f = head->first;
retry = 0;
if (f->credit <= 0) {
+ if (unlikely(++refills >= next_skip) &&
+ head == &pband->old_flows) {
+ unsigned int scanned;
+ bool skipped = fq_skip_rounds(q, pband, &scanned);
+
+ /* Bound the cost of scans to the number of refills. */
+ next_skip = refills + scanned;
+ if (skipped)
+ goto begin;
+ }
f->credit += q->quantum;
head->first = f->next;
fq_flow_add_tail(q, f, OLD_FLOW);
Technical Details
Message-ID:
<CAL4Wiir0Gev+Uh6+S9oMkKnb6Keq=84PZWj81zTEySbv0zqOvQ@mail.gmail.com>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-360519-linux-kernel-netdev=dewy.ruReferences:
<QDISC-TIAE.v3.r0.20261109173518@mojatatu.com> <QDISC-TIAE.v3.r0.20261109173518-2@mojatatu.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-360519-linux-kernel-netdev=dewy.ru
From: edumazet@kernel.org (Eric Dumazet)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v3 2/3] net/sched: fq, fq_codel, fq_pie: skip
empty rounds in the deficit-refill dequeue loop
Date: Tue, 10 Nov 2026 19:25:57 +0100
Organization: Usenet Network
Message-ID: <CAL4Wiir0Gev+Uh6+S9oMkKnb6Keq=84PZWj81zTEySbv0zqOvQ@mail.gmail.com>
References: <QDISC-TIAE.v3.r0.20261109173518@mojatatu.com> <QDISC-TIAE.v3.r0.20261109173518-2@mojatatu.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
logging-data="671380"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:P7NfW/p7ePftmux00VZT68lIiLw= sha256:HYlOcpGV2kvKhpn8tiBjhb39TlgLWbkd5G4h3dBsIVk=
sha1:fLBndbzLMfZRzLL2Odwr86jNUPM= sha256:oZRpeTQ6hUN3w+FLQfA4oxOP1j55unwpeswGVfunwlQ=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id D1090113CB7; Tue, 10 Nov 2026 21:28:00 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.501
X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31
tests=[DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1,
RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id Q7q4AoKrl8US;
Tue, 10 Nov 2026 21:27:53 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-360519-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
by mail.dewy.ru (Postfix) with ESMTPS id 7FB00113C87; Tue, 10 Nov 2026 21:27:44 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sto.lore.kernel.org (Postfix) with ESMTP id BE9A1611D04; Tue, 10 Nov 2026 18:26:19 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1794335173;
b=pYsqlA1xo11P4LBGmB77VLFdn9bmZq8dV0UdytqMgKk4AMK11a3KgF7g12fQtjCgEz5y
9BJGpaMiK41mbrL3tY/YerZquel7JbhmQRKaoA4+46oH55tAOCiuL/KqpA0xTUbGd86JT
zEAD4ddfTq7SNQ2UiAIEI4X0gEVGLZxR7PGQ/R0MmmdKkMGilEmVVvXVSyodnDDtXbutk
98znTIl4hVUyK1y4KLvcHflszYbqOnkWgHHJ1hqKagAO8OCqVVcla6b+nBjF2ATVjI4J6
bHlvS7Fv780m3U47cnU/285qR6OqFoQ5Wcst86Beq80JkU8sPwIJ+otUS13soJ53IuQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794335173;
h=X-Original-To:Received:Received:DKIM-Signature:Received:
X-Gm-Message-State:X-Received:X-Mailing-List:List-Id:List-Post:
List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
MIME-Version:References:In-Reply-To:From:Date:
X-Gmail-Original-Message-ID:X-Gm-Features:Message-ID:Subject:To:Cc:
Content-Type:Content-Transfer-Encoding;
bh=o/zk2YQgV579zMwD3M9nV9Vt6kgb+n47Jpfk4DZuUto=;
b=TiwiaB+JGKWWbUD9NSlbAB6sAcgfFVEM77xl0s7QSHxYfB03HcvYpUgFMpkjEmMcAF6B
8enoPIDBpQDymYmMNbSUFwXAO8H+KJO64aw4+YNItQxQbbophNV187gwp0HPYx1pua1TX
uTDJoOtVHwW1oZldfCZ/P1VU76IzlqHDXZZc51tog0832g7EU43bQHElKsPvXXp5LzeUc
o2XVjTDSjfKV+6uk8nP7Ux5R4TVQCNolR0d+cPNyfvPl89vG1ZmHf/IlaPT1zc4UC/Rcl
gaey+n0bfIdcQ2xtcreLnsx26ICn9nGUk5WR7Cu0xdZwgLyV/5AUiiJI+El3MHBxQiA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=YdpXQV46;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 7E940606A336;
Tue, 10 Nov 2026 18:26:13 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=YdpXQV46
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1794335172;
b=vVZujMIoqKo/mdct3pEQmnP3x1s1n8/8aACLWAmmSast1ERFjig36YLtnNNCkT56lFdX
U30+OgpDShwEgrN2hGbNheOLGfevwnUkACH+FVEg354V/5+z/18yVxzAMGWpi5trmrUvc
6Ls8jImr9gZzq3ZD83826vuknI2U27pY9o39B3plIlYiXr+uA9bOkD1+knrJtJo3Lkfb9
MEhPj1qxaAa7P99fibD0pvp0emkzncndv96XwLTrRO97UxI9weymPyh5Q23RZVq69gJnC
HGDM8Fyx/HTC+eoRszOmvCq0BGzdhEgaEe8bUBECneIkONNFHGnVUslSx+0EOpvS4Nw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794335172;
h=Received:DKIM-Signature:Received:X-Gm-Message-State:X-Received:
MIME-Version:References:In-Reply-To:From:Date:
X-Gmail-Original-Message-ID:X-Gm-Features:Message-ID:Subject:To:Cc:
Content-Type:Content-Transfer-Encoding;
bh=o/zk2YQgV579zMwD3M9nV9Vt6kgb+n47Jpfk4DZuUto=;
b=z53gNTGKRuEWPFptRHEXxO4hPzFZrx1I3NM6aQJ9+Lak/vfn0j/0BCY4t00eFRwVQRW5
waZMgIkwVYeFPtufkkwYLlbkOEb3Lc041CKiXq9CYTVD98MHLdNCOpg1+3AL2/YnotBA1
9ZmiL/UpUn6hpdHh8z38xoGirHRQnNYdMpGRdIYORPjVyTL1IYlq74VrL7Fw20YRfqsGm
VjrRaAUjRPOZhbYeTpeqcy0vuU+Dsy30oZq0CbhQBdvUYPUjx4T374G8s6fAkK42rsVvd
73f7HLSWGhwPcTVaAP4T1UspwYH2jZlhI3li4tnAUs79xv+wT8uJjDvJ7IPrbvquTbA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=YdpXQV46;
arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature ECDSA (prime256v1))
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 568C6606A321
for <netdev@vger.kernel.org>; Tue, 10 Nov 2026 18:26:12 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3102F1F0089F
for <netdev@vger.kernel.org>; Tue, 10 Nov 2026 18:26:12 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
s=k20260515; t=1794335172;
bh=o/zk2YQgV579zMwD3M9nV9Vt6kgb+n47Jpfk4DZuUto=;
h=References:In-Reply-To:From:Date:Subject:To:Cc;
b=YdpXQV46t0dzvXfp0xl/75HDZIaRMCUC4TDUx3OSiqmVKQbub10YLJlNEwyOsvLAv
Cc9l7r1AUD0BDcHI6FRUngDEwjaJxjLxS9gc5b+ojK1s+T7+jl62oN+07gfFkkmtuq
6SUguWs/2dEpfd/810mUSV1QjV4Ox3TuOGdncVfoTID+ayBaxYNtaNGTCMxUuaGKnp
oRpS3AGwiKK8K30MYJhVMzEqY30dJpjLMrURsUPe1qQ863SUhb2mJW485VRw16Q9p6
O/Lz9FwsodYPHOZY950eUlNab3cN1+gtHdCF1fZXCaQEouXmZOrqoaQ7qThNIZvObf
QQc2rc3SS8mSw==
X-Received: by mail-lj1-f182.google.com with SMTP id 38308e7fff4ca-3ab3dd966e1so19261621fa.2
for <netdev@vger.kernel.org>; Tue, 10 Nov 2026 10:26:12 -0800 (PST)
X-Gm-Message-State: APuU4Z+LPl9Wr42jeYDiRtVMoG2B/8CSsuOlNCixG6jwFaWwHcngXj3v
0pnpI2FLXPEuvhu7qvb01zHg5S3MfQDd1AhMgw37t47wFA3Arwkpy3VEpspAJhNeRVA9Cb1Nlrz
9DAhx2J6I/ShIWrqKejqD4opBvilNj1I=
X-Received: by 2002:a05:651c:556:b0:3ac:a2b0:ac56 with SMTP id
38308e7fff4ca-3ae0967bd7amr6657991fa.29.1794335170933; Tue, 10 Nov 2026
10:26:10 -0800 (PST)
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-In-Reply-To: <QDISC-TIAE.v3.r0.20261109173518-2@mojatatu.com>
X-Gmail-Original-Message-ID: <CAL4Wiir0Gev+Uh6+S9oMkKnb6Keq=84PZWj81zTEySbv0zqOvQ@mail.gmail.com>
X-Gm-Features: AclHuK9PGaJG-lc-A3PNIbFpeP8DspAFjQpIiIvsAC-3-FXg1x-0OGkVO3q5aPo
X-Cc: netdev@vger.kernel.org, Jiri Pirko <jiri@resnulli.us>,
"David S . Miller" <davem@davemloft.net>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>, Jamal Hadi Salim <jhs@mojatatu.com>,
sashiko-bot <sashiko-bot@kernel.org>, Shuah Khan <shuah@kernel.org>,
linux-kselftest@vger.kernel.org