From: Jakub Kicinski <kuba@kernel.org>
To: William Liu <will@willsroot.io>
Cc: netdev@vger.kernel.org, jhs@mojatatu.com,
xiyou.wangcong@gmail.com, pabeni@redhat.com, jiri@resnulli.us,
davem@davemloft.net, edumazet@google.com, horms@kernel.org,
savy@syst3mfailure.io, victor@mojatatu.com
Subject: Re: [PATCH net v4 1/2] net/sched: Fix backlog accounting in qdisc_dequeue_internal
Date: Tue, 12 Aug 2025 07:38:02 -0700 [thread overview]
Message-ID: <20250812073802.28f86ab2@kernel.org> (raw)
In-Reply-To: <OF2YXaY19FGNBLPjTD_cAIQim1BVjj7pzMkq8j5mXSQJr9Kd6N04zf2YkLCEpxnIz-zrljMlV0Ask-hlUDuc3rkzIKfF7MzY-jgVtyTi2Q4=@willsroot.io>
On Tue, 12 Aug 2025 02:10:02 +0000 William Liu wrote:
> > AFAICT only if the backlog adjustment is using the prev_qlen,
> > prev_backlog approach, which snapshots the backlog. In that case,
> > yes, the "internal drops" will mess up the count.
>
> Yep, that's why I added the dropped_qlen and dropped_backlog
> variables, though that is not a very pretty solution.
>
> But even looking at the method you suggested (copy pasting for
> reference):
>
> pkts = 0;
> bytes = 0;
> while (sch->q.qlen > sch->limit ||
> q->memory_usage > q->memory_limit) {
> struct sk_buff *skb = qdisc_dequeue_internal(sch, false);
> pkts++;
> bytes += qdisc_pkt_len(skb);
> rtnl_kfree_skbs(skb, skb);
> }
> qdisc_tree_reduce_backlog(sch, pkts, bytes);
>
> qdisc_dequeue_internal can trigger fq_codel_dequeue, which can
> trigger qdisc_tree_reduce_backlog before returning (the only qdisc
> out of these that does so in its dequeue handler).
>
> Let's say the limit only goes down by one, and packet A is at the
> front of the queue. qdisc_dequeue_internal takes the dequeue path,
> and fq_codel_dequeue triggers a qdisc_tree_reduce_backlog from that
> packet before returning the skb. Would this final
> qdisc_tree_reduce_backlog after the limit drop not double count?
The packets that got counted in qdisc_tree_reduce_backlog() inside
->dequeue are freed immediately via
drop_func()
kfree_skb_reason(skb, SKB_DROP_REASON_QDISC_CONGESTED);
in the scenario you're describing ->dequeue should return NULL.
If that's possible, then we have another bug here :$
Normally backlogs get adjusted as the packet travels down the hierarchy
thru the parent chain. ->dequeue is part of this normal path so skbs it
returns are still in the parent's backlogs. qdisc_tree_reduce_backlog()
is only called when we need to do something to an skb outside of the
normal ->enqueue/->dequeue flow that iterates the hierarchy.
next prev parent reply other threads:[~2025-08-12 14:38 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-27 23:56 [PATCH net v4 1/2] net/sched: Fix backlog accounting in qdisc_dequeue_internal William Liu
2025-07-27 23:57 ` [PATCH net v4 2/2] selftests/tc-testing: Check backlog stats in gso_skb case William Liu
2025-07-30 17:54 ` Cong Wang
2025-07-30 17:59 ` William Liu
2025-08-08 21:27 ` [PATCH net v4 1/2] net/sched: Fix backlog accounting in qdisc_dequeue_internal Jakub Kicinski
2025-08-10 21:06 ` William Liu
2025-08-11 15:29 ` Jakub Kicinski
2025-08-11 16:52 ` William Liu
2025-08-11 17:24 ` Jakub Kicinski
2025-08-11 17:51 ` William Liu
2025-08-12 0:51 ` Jakub Kicinski
2025-08-12 2:10 ` William Liu
2025-08-12 14:38 ` Jakub Kicinski [this message]
2025-08-12 16:59 ` William Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250812073802.28f86ab2@kernel.org \
--to=kuba@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=savy@syst3mfailure.io \
--cc=victor@mojatatu.com \
--cc=will@willsroot.io \
--cc=xiyou.wangcong@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).