Skip to contentSkip to conversation

net/sched: refine fq_codel memory limits

PATCH Applied Eric Dumazet 5 participants 13 messages May 12 – May 15

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

cover net/sched: refine fq_codel memory limits

Packets that are associated with local sockets sk_wmem_alloc do not really need additional memory control.

First patch makes is_skb_wmem() available to modules.

Second patch uses is_skb_wmem() in fq_codel.

Eric Dumazet (2):
net: make is_skb_wmem() available to modules net/sched: fq_codel: local packets no longer count against memory
limit

 include/net/sock.h         | 12 +++++++++++-
 include/net/tcp.h          |  1 -
 net/core/skbuff.c          |  2 +-
 net/core/sock.c            |  3 +++
 net/core/sock_destructor.h | 12 ------------
 net/ipv4/inet_fragment.c   |  2 --
 net/ipv4/tcp_output.c      |  1 +
 net/sched/sch_fq_codel.c   |  2 +-
 8 files changed, 17 insertions(+), 18 deletions(-)
 delete mode 100644 net/core/sock_destructor.h
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
#1 lore raw

PATCH 1/2 net: make is_skb_wmem() available to modules

Following patch will use is_skb_wmem() from fq_codel.

Provide __sock_wfree() only if CONFIG_INET=y

---
 include/net/sock.h         | 12 +++++++++++-
 include/net/tcp.h          |  1 -
 net/core/skbuff.c          |  2 +-
 net/core/sock.c            |  3 +++
 net/core/sock_destructor.h | 12 ------------
 net/ipv4/inet_fragment.c   |  2 --
 net/ipv4/tcp_output.c      |  1 +
 7 files changed, 16 insertions(+), 17 deletions(-)
 delete mode 100644 net/core/sock_destructor.h
include/net/sock.h +11 -1
index dccd3738c3687056b67c8de44fce9842dcc365ec..219917959b54582fdd3d78e8042e1bdfc43decd0 100644
@@ -1850,8 +1850,18 @@ static inline struct sock *sk_clone_lock(const struct sock *sk, const gfp_t prio
 
 struct sk_buff *sock_wmalloc(struct sock *sk, unsigned long size, int force,
 			     gfp_t priority);
-void __sock_wfree(struct sk_buff *skb);
 void sock_wfree(struct sk_buff *skb);
+#ifdef CONFIG_INET
+void __sock_wfree(struct sk_buff *skb);
+void tcp_wfree(struct sk_buff *skb);
+#endif
+static inline bool is_skb_wmem(const struct sk_buff *skb)
+{
+	return skb->destructor == sock_wfree ||
+	       (IS_ENABLED(CONFIG_INET) && skb->destructor == __sock_wfree) ||
+	       (IS_ENABLED(CONFIG_INET) && skb->destructor == tcp_wfree);
+}
+
 struct sk_buff *sock_omalloc(struct sock *sk, unsigned long size,
 			     gfp_t priority);
 void skb_orphan_partial(struct sk_buff *skb);
include/net/tcp.h +0 -1
index 3c4e6adb0dbdcefdfa6c95d1738e2039dede3f32..5715e60c519a79232a3bed6682aa2c9cf97be22a 100644
@@ -390,7 +390,6 @@ static inline bool tcp_release_cb_cond(struct sock *sk)
 	return false;
 }
 
-void tcp_wfree(struct sk_buff *skb);
 void tcp_write_timer_handler(struct sock *sk);
 void tcp_delack_timer_handler(struct sock *sk);
 int tcp_ioctl(struct sock *sk, int cmd, int *karg);
net/core/skbuff.c +1 -1
index 7dad68e3b5186cf622a3ed5a6e87c09d46bc3fd6..11871836aa88ea1f16414a94628eb50336cd9653 100644
@@ -78,6 +78,7 @@
 #include <net/mpls.h>
 #include <net/mptcp.h>
 #include <net/mctp.h>
+#include <net/tcp.h>
 #include <net/can.h>
 #include <net/page_pool/helpers.h>
 #include <net/psp/types.h>
@@ -96,7 +97,6 @@
 #include "devmem.h"
 #include "net-sysfs.h"
 #include "netmem_priv.h"
-#include "sock_destructor.h"
 
 #ifdef CONFIG_SKB_EXTENSIONS
 static struct kmem_cache *skbuff_ext_cache __ro_after_init;
net/core/sock.c +3 -0
index b37b664b6eb92f375d6708a5a609f35f07ee2897..f362e3ce1efb672bc463c54b7a1b8f05785cba45 100644
@@ -2708,6 +2708,7 @@ EXPORT_SYMBOL(sock_wfree);
 /* This variant of sock_wfree() is used by TCP,
  * since it sets SOCK_USE_WRITE_QUEUE.
  */
+#ifdef CONFIG_INET
 void __sock_wfree(struct sk_buff *skb)
 {
 	struct sock *sk = skb->sk;
@@ -2715,6 +2716,8 @@ void __sock_wfree(struct sk_buff *skb)
 	if (refcount_sub_and_test(skb->truesize, &sk->sk_wmem_alloc))
 		__sk_free(sk);
 }
+EXPORT_SYMBOL_GPL(__sock_wfree);
+#endif
 
 void skb_set_owner_w(struct sk_buff *skb, struct sock *sk)
 {
net/core/sock_destructor.h deleted +0 -12
deleted file mode 100644
index 2f396e6bfba5a364727f98b160bf2fd3a3731958..0000000000000000000000000000000000000000
@@ -1,12 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-#ifndef _NET_CORE_SOCK_DESTRUCTOR_H
-#define _NET_CORE_SOCK_DESTRUCTOR_H
-#include <net/tcp.h>
-
-static inline bool is_skb_wmem(const struct sk_buff *skb)
-{
-	return skb->destructor == sock_wfree ||
-	       skb->destructor == __sock_wfree ||
-	       (IS_ENABLED(CONFIG_INET) && skb->destructor == tcp_wfree);
-}
-#endif
net/ipv4/inet_fragment.c +0 -2
index 393770920abd794a47a933f2694afe3e2d08d25a..86b100694659ee51292625216113f9411b98a351 100644
@@ -24,8 +24,6 @@
 #include <net/ip.h>
 #include <net/ipv6.h>
 
-#include "../core/sock_destructor.h"
-
 /* Use skb->cb to track consecutive/adjacent fragments coming at
  * the end of the queue. Nodes in the rb-tree queue will
  * contain "runs" of one or more adjacent fragments.
net/ipv4/tcp_output.c +1 -0
index 75eb18a2ad4e7ee126806e7a7cbf3d27a452cba5..47647a99e32443a3925a9a160a2da58f530e32e1 100644
@@ -1415,6 +1415,7 @@ void tcp_wfree(struct sk_buff *skb)
 out:
 	sk_free(sk);
 }
+EXPORT_SYMBOL_GPL(tcp_wfree);
 
 /* Note: Called under soft irq.
  * We can call TCP stack right away, unless socket is owned by user.
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
#3 lore raw

PATCH 2/2 net/sched: fq_codel: local packets no longer count against memory limit

In reply to Eric Dumazet

Commit 95b58430abe7 ("fq_codel: add memory limitation per queue") claimed that the 32Mb default was "reasonable even for heavy duty usages."

In practice, this is not the case.

Packets that are associated with local sockets sk_wmem_alloc do not really need additional memory control.

---
 net/sched/sch_fq_codel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/sch_fq_codel.c +1 -1
index 1b1de693d4c64a1f5f4e9e788371829dea91740e..71107dc52be799a14f370f2ad74d2eadd93992c1 100644
@@ -212,7 +212,7 @@ static int fq_codel_enqueue(struct sk_buff *skb, struct Qdisc *sch,
 		q->new_flow_count++;
 		WRITE_ONCE(flow->deficit, q->quantum);
 	}
-	get_codel_cb(skb)->mem_usage = skb->truesize;
+	get_codel_cb(skb)->mem_usage = is_skb_wmem(skb) ? 0 : skb->truesize;
 	q->memory_usage += get_codel_cb(skb)->mem_usage;
 	memory_limited = q->memory_usage > q->memory_limit;
 	qdisc_qlen_inc(sch);
Signature · 1 line
2.54.0.563.g4f69b47b94-goog
#4 lore raw

Re: [PATCH net-next 2/2] net/sched: fq_codel: local packets no longer count against memory limit

Quoted 4 lines · Eric Dumazet

Commit 95b58430abe7 ("fq_codel: add memory limitation per queue") claimed that the 32Mb default was "reasonable even for heavy duty usages."

In practice, this is not the case.

Well, the assumption lasted a decade, so that's pretty good? :)

Quoted 13 lines

Packets that are associated with local sockets sk_wmem_alloc do not really need additional memory control.

---
 net/sched/sch_fq_codel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/sch_fq_codel.c +0 -0
index 1b1de693d4c64a1f5f4e9e788371829dea91740e..71107dc52be799a14f370f2ad74d2eadd93992c1 100644

net/sched/sch_fq_codel.c static int fq_codel_enqueue(struct sk_buff *skb, struct Qdisc *sch, · line 216

Quoted 6 lines
net/sched/sch_fq_codel.c +1 -1
@@ -212,7 +212,7 @@ static int fq_codel_enqueue(struct sk_buff *skb, struct Qdisc *sch,
 		q->new_flow_count++;
 		WRITE_ONCE(flow->deficit, q->quantum);
 	}
-	get_codel_cb(skb)->mem_usage = skb->truesize;
+	get_codel_cb(skb)->mem_usage = is_skb_wmem(skb) ? 0 : skb->truesize;
 	q->memory_usage += get_codel_cb(skb)->mem_usage;

Only one concern here: q->memory_usage is exposed to userspace in the stats, so this will look like the packets queued are zero-length to anyone watching, which may end up confusing folks? Also, there will be no way to see how many bytes are actually in the qdisc.

Should we keep a separate counter so we can still accurately report the memory usage to userspace?

-Toke

#5 lore raw

Re: [PATCH net-next 2/2] net/sched: fq_codel: local packets no longer count against memory limit

Quoted 18 lines · Toke Høiland-Jørgensen
Quoted 4 lines · Eric Dumazet

Commit 95b58430abe7 ("fq_codel: add memory limitation per queue") claimed that the 32Mb default was "reasonable even for heavy duty usages."

In practice, this is not the case.

Well, the assumption lasted a decade, so that's pretty good? :)

Quoted 8 lines

Packets that are associated with local sockets sk_wmem_alloc do not really need additional memory control.

---
 net/sched/sch_fq_codel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines

net/sched/sch_fq_codel.c static int fq_codel_enqueue(struct sk_buff *skb, struct Qdisc *sch, · line 216

Quoted 11 lines
net/sched/sch_fq_codel.c +1 -1
index 1b1de693d4c64a1f5f4e9e788371829dea91740e..71107dc52be799a14f370f2ad74d2eadd93992c1 100644
@@ -212,7 +212,7 @@ static int fq_codel_enqueue(struct sk_buff *skb, struct Qdisc *sch,
              q->new_flow_count++;
              WRITE_ONCE(flow->deficit, q->quantum);
      }
-     get_codel_cb(skb)->mem_usage = skb->truesize;
+     get_codel_cb(skb)->mem_usage = is_skb_wmem(skb) ? 0 : skb->truesize;
      q->memory_usage += get_codel_cb(skb)->mem_usage;

Only one concern here: q->memory_usage is exposed to userspace in the stats, so this will look like the packets queued are zero-length to anyone watching, which may end up confusing folks? Also, there will be no way to see how many bytes are actually in the qdisc.

Standard qdisc stats show the amount of bytes and packets.

None of the other qdiscs seem to care (except cake which copy/pasted fq_codel)

Quoted 3 lines

Should we keep a separate counter so we can still accurately report the memory usage to userspace?

Only purpose of mem usage counter was to have an idea of how close of the 32Mb limit we were,
this is still reported for forwarded packets (router workload)

All these counters take precious resources, I would rather not add another one.

#6 lore raw

Re: [PATCH net-next 2/2] net/sched: fq_codel: local packets no longer count against memory limit

Quoted 36 lines · Eric Dumazet
Quoted 18 lines · Toke Høiland-Jørgensen
Quoted 4 lines · Eric Dumazet

Commit 95b58430abe7 ("fq_codel: add memory limitation per queue") claimed that the 32Mb default was "reasonable even for heavy duty usages."

In practice, this is not the case.

Well, the assumption lasted a decade, so that's pretty good? :)

Quoted 8 lines

Packets that are associated with local sockets sk_wmem_alloc do not really need additional memory control.

---
 net/sched/sch_fq_codel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines

net/sched/sch_fq_codel.c static int fq_codel_enqueue(struct sk_buff *skb, struct Qdisc *sch, · line 216

Quoted 11 lines
net/sched/sch_fq_codel.c +1 -1
index 1b1de693d4c64a1f5f4e9e788371829dea91740e..71107dc52be799a14f370f2ad74d2eadd93992c1 100644
@@ -212,7 +212,7 @@ static int fq_codel_enqueue(struct sk_buff *skb, struct Qdisc *sch,
              q->new_flow_count++;
              WRITE_ONCE(flow->deficit, q->quantum);
      }
-     get_codel_cb(skb)->mem_usage = skb->truesize;
+     get_codel_cb(skb)->mem_usage = is_skb_wmem(skb) ? 0 : skb->truesize;
      q->memory_usage += get_codel_cb(skb)->mem_usage;

Only one concern here: q->memory_usage is exposed to userspace in the stats, so this will look like the packets queued are zero-length to anyone watching, which may end up confusing folks? Also, there will be no way to see how many bytes are actually in the qdisc.

Quoted 3 lines

Standard qdisc stats show the amount of bytes and packets.

None of the other qdiscs seem to care (except cake which copy/pasted fq_codel)

Right, the cake stats was why I asked. Pretty sure there are people who watch these; but now that you mention it, I may have confused the standard backlog_bytes stat field with this one...

Quoted 8 lines
Quoted 2 lines

Should we keep a separate counter so we can still accurately report the memory usage to userspace?

Only purpose of mem usage counter was to have an idea of how close of the 32Mb limit we were, this is still reported for forwarded packets (router workload)

All these counters take precious resources, I would rather not add another one.

Right, fair (and see above). In that case:

maintainer
#7 lore raw

Re: [PATCH net-next 2/2] net/sched: fq_codel: local packets no longer count against memory limit

In reply to Eric Dumazet
Quoted 18 lines · Eric Dumazet

Commit 95b58430abe7 ("fq_codel: add memory limitation per queue") claimed that the 32Mb default was "reasonable even for heavy duty usages."

In practice, this is not the case.

Packets that are associated with local sockets sk_wmem_alloc do not really need additional memory control.

---
 net/sched/sch_fq_codel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/sch_fq_codel.c +0 -0
index 1b1de693d4c64a1f5f4e9e788371829dea91740e..71107dc52be799a14f370f2ad74d2eadd93992c1 100644

net/sched/sch_fq_codel.c static int fq_codel_enqueue(struct sk_buff *skb, struct Qdisc *sch, · line 218

Quoted 8 lines
net/sched/sch_fq_codel.c +1 -1
@@ -212,7 +212,7 @@ static int fq_codel_enqueue(struct sk_buff *skb, struct Qdisc *sch,
 		q->new_flow_count++;
 		WRITE_ONCE(flow->deficit, q->quantum);
 	}
-	get_codel_cb(skb)->mem_usage = skb->truesize;
+	get_codel_cb(skb)->mem_usage = is_skb_wmem(skb) ? 0 : skb->truesize;
 	q->memory_usage += get_codel_cb(skb)->mem_usage;
 	memory_limited = q->memory_usage > q->memory_limit;
 	qdisc_qlen_inc(sch);

I *think* this patch is causing TDC self-tests failures:

# not ok 704 a4bb - Test FQ_CODEL with HTB parent - force packet drop with empty queue
# Could not match regex pattern. Verify command output:
# qdisc fq_codel 10: parent 1:10 limit 10240p flows 1 quantum 1514 target 99us interval 999us memory_limit 1b ecn drop_batch 64 
#  Sent 490 bytes 5 pkt (dropped 0, overlimits 0 requeues 0) 
#  backlog 0b 0p requeues 0
#   maxpacket 98 drop_overlimit 0 new_flow_count 1 ecn_mark 0
#   new_flows_len 1 old_flows_len 0

whole log at:

https://github.com/p4tc-dev/tc-executor/tree/storage/artifacts/645644/1-tdc-sh

Looking at the test code, I think the patch broke it, but the failures started a little afterward the patch merge, so I'm possibly misunderstanding something here.

Thanks,

Paolo

author Reviewed-by Victor Nogueira Acked-by Jamal Hadi Salim
#8 lore raw

Re: [PATCH net-next 2/2] net/sched: fq_codel: local packets no longer count against memory limit

Quoted 43 lines · Paolo Abeni
Quoted 18 lines · Eric Dumazet

Commit 95b58430abe7 ("fq_codel: add memory limitation per queue") claimed that the 32Mb default was "reasonable even for heavy duty usages."

In practice, this is not the case.

Packets that are associated with local sockets sk_wmem_alloc do not really need additional memory control.

---
 net/sched/sch_fq_codel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/sch_fq_codel.c +0 -0
index 1b1de693d4c64a1f5f4e9e788371829dea91740e..71107dc52be799a14f370f2ad74d2eadd93992c1 100644

net/sched/sch_fq_codel.c static int fq_codel_enqueue(struct sk_buff *skb, struct Qdisc *sch, · line 218

Quoted 8 lines
net/sched/sch_fq_codel.c +1 -1
@@ -212,7 +212,7 @@ static int fq_codel_enqueue(struct sk_buff *skb, struct Qdisc *sch,
              q->new_flow_count++;
              WRITE_ONCE(flow->deficit, q->quantum);
      }
-     get_codel_cb(skb)->mem_usage = skb->truesize;
+     get_codel_cb(skb)->mem_usage = is_skb_wmem(skb) ? 0 : skb->truesize;
      q->memory_usage += get_codel_cb(skb)->mem_usage;
      memory_limited = q->memory_usage > q->memory_limit;
      qdisc_qlen_inc(sch);

I *think* this patch is causing TDC self-tests failures:

# not ok 704 a4bb - Test FQ_CODEL with HTB parent - force packet drop with empty queue
# Could not match regex pattern. Verify command output:
# qdisc fq_codel 10: parent 1:10 limit 10240p flows 1 quantum 1514 target 99us interval 999us memory_limit 1b ecn drop_batch 64
#  Sent 490 bytes 5 pkt (dropped 0, overlimits 0 requeues 0)
#  backlog 0b 0p requeues 0
#   maxpacket 98 drop_overlimit 0 new_flow_count 1 ecn_mark 0
#   new_flows_len 1 old_flows_len 0

whole log at:

https://github.com/p4tc-dev/tc-executor/tree/storage/artifacts/645644/1-tdc-sh

Quoted 8 lines

Looking at the test code, I think the patch broke it, but the failures started a little afterward the patch merge, so I'm possibly misunderstanding something here.

Thanks,

Paolo

It seems this test uses a memory limit of 1 byte.

$TC qdisc add dev $DUMMY parent 1:10 handle 10: fq_codel memory_limit 1 flows 1 target 0.1ms interval 1ms

This might be a typo, I think they expected a limit of 0 packet.

commit cbe9588b12d058cbb16735fd468c82ec4b3d1256

Author: Cong Wang <[email protected]>
Date:   Thu Apr 3 14:16:32 2025 -0700

selftests/tc-testing: Add a test case for FQ_CODEL with HTB parent

Add a test case for FQ_CODEL with HTB parent to verify packet drop behavior when the queue becomes empty. This helps ensure proper notification mechanisms between qdiscs.

Note this is best-effort, it is hard to play with those parameters perfectly to always trigger ->qlen_notify().

#9 lore raw

Re: [PATCH net-next 2/2] net/sched: fq_codel: local packets no longer count against memory limit

Quoted 74 lines · Eric Dumazet
Quoted 43 lines · Paolo Abeni
Quoted 18 lines · Eric Dumazet

Commit 95b58430abe7 ("fq_codel: add memory limitation per queue") claimed that the 32Mb default was "reasonable even for heavy duty usages."

In practice, this is not the case.

Packets that are associated with local sockets sk_wmem_alloc do not really need additional memory control.

---
 net/sched/sch_fq_codel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/sch_fq_codel.c +0 -0
index 1b1de693d4c64a1f5f4e9e788371829dea91740e..71107dc52be799a14f370f2ad74d2eadd93992c1 100644

net/sched/sch_fq_codel.c static int fq_codel_enqueue(struct sk_buff *skb, struct Qdisc *sch, · line 218

Quoted 8 lines
net/sched/sch_fq_codel.c +1 -1
@@ -212,7 +212,7 @@ static int fq_codel_enqueue(struct sk_buff *skb, struct Qdisc *sch,
              q->new_flow_count++;
              WRITE_ONCE(flow->deficit, q->quantum);
      }
-     get_codel_cb(skb)->mem_usage = skb->truesize;
+     get_codel_cb(skb)->mem_usage = is_skb_wmem(skb) ? 0 : skb->truesize;
      q->memory_usage += get_codel_cb(skb)->mem_usage;
      memory_limited = q->memory_usage > q->memory_limit;
      qdisc_qlen_inc(sch);

I *think* this patch is causing TDC self-tests failures:

# not ok 704 a4bb - Test FQ_CODEL with HTB parent - force packet drop with empty queue
# Could not match regex pattern. Verify command output:
# qdisc fq_codel 10: parent 1:10 limit 10240p flows 1 quantum 1514 target 99us interval 999us memory_limit 1b ecn drop_batch 64
#  Sent 490 bytes 5 pkt (dropped 0, overlimits 0 requeues 0)
#  backlog 0b 0p requeues 0
#   maxpacket 98 drop_overlimit 0 new_flow_count 1 ecn_mark 0
#   new_flows_len 1 old_flows_len 0

whole log at:

https://github.com/p4tc-dev/tc-executor/tree/storage/artifacts/645644/1-tdc-sh

Quoted 8 lines

Looking at the test code, I think the patch broke it, but the failures started a little afterward the patch merge, so I'm possibly misunderstanding something here.

Thanks,

Paolo

It seems this test uses a memory limit of 1 byte.

$TC qdisc add dev $DUMMY parent 1:10 handle 10: fq_codel memory_limit 1 flows 1 target 0.1ms interval 1ms

This might be a typo, I think they expected a limit of 0 packet.

commit cbe9588b12d058cbb16735fd468c82ec4b3d1256

Author: Cong Wang <[email protected]>
Date:   Thu Apr 3 14:16:32 2025 -0700

selftests/tc-testing: Add a test case for FQ_CODEL with HTB parent

Add a test case for FQ_CODEL with HTB parent to verify packet drop behavior when the queue becomes empty. This helps ensure proper notification mechanisms between qdiscs.

Note this is best-effort, it is hard to play with those parameters perfectly to always trigger ->qlen_notify().

Quoted 6 lines

I do not think we care much about the precise
get_codel_cb(skb)->mem_usage value.

A value of 2 bytes would let the test pass.

net/sched/sch_fq_codel.c +0 -0
index 71107dc52be799a14f370f2ad74d2eadd93992c1..916f4d7756e0cb9ec6e81ba69cce59910ee2545a

100644

net/sched/sch_fq_codel.c +0 -0
@@ -212,7 +212,7 @@ static int fq_codel_enqueue(struct sk_buff *skb,

struct Qdisc *sch,

                q->new_flow_count++;
                WRITE_ONCE(flow->deficit, q->quantum);
        }
-       get_codel_cb(skb)->mem_usage = is_skb_wmem(skb) ? 0 : skb->truesize;
+       get_codel_cb(skb)->mem_usage = is_skb_wmem(skb) ? 2 : skb->truesize;
        q->memory_usage += get_codel_cb(skb)->mem_usage;
        memory_limited = q->memory_usage > q->memory_limit;
        qdisc_qlen_inc(sch);
maintainer
#10 lore raw

Re: [PATCH net-next 2/2] net/sched: fq_codel: local packets no longer count against memory limit

In reply to Eric Dumazet
Quoted 52 lines · Eric Dumazet
Quoted 42 lines · Paolo Abeni
Quoted 18 lines · Eric Dumazet

Commit 95b58430abe7 ("fq_codel: add memory limitation per queue") claimed that the 32Mb default was "reasonable even for heavy duty usages."

In practice, this is not the case.

Packets that are associated with local sockets sk_wmem_alloc do not really need additional memory control.

---
 net/sched/sch_fq_codel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/sch_fq_codel.c +0 -0
index 1b1de693d4c64a1f5f4e9e788371829dea91740e..71107dc52be799a14f370f2ad74d2eadd93992c1 100644

net/sched/sch_fq_codel.c static int fq_codel_enqueue(struct sk_buff *skb, struct Qdisc *sch, · line 218

Quoted 8 lines
net/sched/sch_fq_codel.c +1 -1
@@ -212,7 +212,7 @@ static int fq_codel_enqueue(struct sk_buff *skb, struct Qdisc *sch,
              q->new_flow_count++;
              WRITE_ONCE(flow->deficit, q->quantum);
      }
-     get_codel_cb(skb)->mem_usage = skb->truesize;
+     get_codel_cb(skb)->mem_usage = is_skb_wmem(skb) ? 0 : skb->truesize;
      q->memory_usage += get_codel_cb(skb)->mem_usage;
      memory_limited = q->memory_usage > q->memory_limit;
      qdisc_qlen_inc(sch);

I *think* this patch is causing TDC self-tests failures:

# not ok 704 a4bb - Test FQ_CODEL with HTB parent - force packet drop with empty queue
# Could not match regex pattern. Verify command output:
# qdisc fq_codel 10: parent 1:10 limit 10240p flows 1 quantum 1514 target 99us interval 999us memory_limit 1b ecn drop_batch 64
#  Sent 490 bytes 5 pkt (dropped 0, overlimits 0 requeues 0)
#  backlog 0b 0p requeues 0
#   maxpacket 98 drop_overlimit 0 new_flow_count 1 ecn_mark 0
#   new_flows_len 1 old_flows_len 0

whole log at:

https://github.com/p4tc-dev/tc-executor/tree/storage/artifacts/645644/1-tdc-sh

Quoted 8 lines

Looking at the test code, I think the patch broke it, but the failures started a little afterward the patch merge, so I'm possibly misunderstanding something here.

Thanks,

Paolo

Quoted 6 lines

It seems this test uses a memory limit of 1 byte.

$TC qdisc add dev $DUMMY parent 1:10 handle 10: fq_codel memory_limit 1 flows 1 target 0.1ms interval 1ms

This might be a typo, I think they expected a limit of 0 packet.

FTR, I think/agree a change to the self-tests would be preferable.

/P

#11 lore raw

Re: [PATCH net-next 2/2] net/sched: fq_codel: local packets no longer count against memory limit

Quoted 53 lines · Paolo Abeni
Quoted 52 lines · Eric Dumazet
Quoted 50 lines · Paolo Abeni
Quoted 18 lines · Eric Dumazet

Commit 95b58430abe7 ("fq_codel: add memory limitation per queue") claimed that the 32Mb default was "reasonable even for heavy duty usages."

In practice, this is not the case.

Packets that are associated with local sockets sk_wmem_alloc do not really need additional memory control.

---
  net/sched/sch_fq_codel.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/sch_fq_codel.c +0 -0
index 1b1de693d4c64a1f5f4e9e788371829dea91740e..71107dc52be799a14f370f2ad74d2eadd93992c1 100644

net/sched/sch_fq_codel.c static int fq_codel_enqueue(struct sk_buff *skb, struct Qdisc *sch, · line 218

Quoted 8 lines
net/sched/sch_fq_codel.c +1 -1
@@ -212,7 +212,7 @@ static int fq_codel_enqueue(struct sk_buff *skb, struct Qdisc *sch,
               q->new_flow_count++;
               WRITE_ONCE(flow->deficit, q->quantum);
       }
-     get_codel_cb(skb)->mem_usage = skb->truesize;
+     get_codel_cb(skb)->mem_usage = is_skb_wmem(skb) ? 0 : skb->truesize;
       q->memory_usage += get_codel_cb(skb)->mem_usage;
       memory_limited = q->memory_usage > q->memory_limit;
       qdisc_qlen_inc(sch);

I *think* this patch is causing TDC self-tests failures:

# not ok 704 a4bb - Test FQ_CODEL with HTB parent - force packet drop with empty queue
# Could not match regex pattern. Verify command output:
# qdisc fq_codel 10: parent 1:10 limit 10240p flows 1 quantum 1514 target 99us interval 999us memory_limit 1b ecn drop_batch 64
#  Sent 490 bytes 5 pkt (dropped 0, overlimits 0 requeues 0)
#  backlog 0b 0p requeues 0
#   maxpacket 98 drop_overlimit 0 new_flow_count 1 ecn_mark 0
#   new_flows_len 1 old_flows_len 0

whole log at:

https://github.com/p4tc-dev/tc-executor/tree/storage/artifacts/645644/1-tdc-sh

Looking at the test code, I think the patch broke it, but the failures started a little afterward the patch merge, so I'm possibly misunderstanding something here.

Thanks,

Paolo

Quoted 8 lines
Quoted 6 lines

It seems this test uses a memory limit of 1 byte.

$TC qdisc add dev $DUMMY parent 1:10 handle 10: fq_codel memory_limit 1 flows 1 target 0.1ms interval 1ms

This might be a typo, I think they expected a limit of 0 packet.

FTR, I think/agree a change to the self-tests would be preferable.

Eric, do you have a tdc fix lined up for this one? If not, I can work something out here and send.

cheers,
Victor

#12 lore raw
In reply to Eric Dumazet
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Tue, 12 May 2026 09:48:57 +0000 you wrote:

Packets that are associated with local sockets sk_wmem_alloc do not really need additional memory control.

First patch makes is_skb_wmem() available to modules.

Second patch uses is_skb_wmem() in fq_codel.

[...]

Here is the summary with links:
- [net-next,1/2] net: make is_skb_wmem() available to modules

    https://git.kernel.org/netdev/net-next/c/f0de88303d5e
  - [net-next,2/2] net/sched: fq_codel: local packets no longer count against memory limit
    https://git.kernel.org/netdev/net-next/c/150061a20651

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html